[openrtm-commit:00060] r175 - in trunk/rtmtools/jp.go.aist.rtm.toolscommon: META-INF src/jp/go/aist/rtm/toolscommon/model/component/impl src/jp/go/aist/rtm/toolscommon/util test/jp/go/aist/rtm/toolscommon/util

openrtm @ openrtm.org openrtm @ openrtm.org
2011年 5月 19日 (木) 12:24:57 JST


Author: ta
Date: 2011-05-19 12:24:57 +0900 (Thu, 19 May 2011)
New Revision: 175

Added:
   trunk/rtmtools/jp.go.aist.rtm.toolscommon/test/jp/go/aist/rtm/toolscommon/util/ConnectorUtilTest.java
Modified:
   trunk/rtmtools/jp.go.aist.rtm.toolscommon/META-INF/MANIFEST.MF
   trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/OutPortImpl.java
   trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/PortImpl.java
   trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/util/ConnectorUtil.java
Log:
RTSE updates.

- fix datatype checking for dataport connection in openrtm-aist-1.1/1.0.

Modified: trunk/rtmtools/jp.go.aist.rtm.toolscommon/META-INF/MANIFEST.MF
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.toolscommon/META-INF/MANIFEST.MF	2011-05-18 05:46:03 UTC (rev 174)
+++ trunk/rtmtools/jp.go.aist.rtm.toolscommon/META-INF/MANIFEST.MF	2011-05-19 03:24:57 UTC (rev 175)
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: jp.go.aist.rtm.toolscommon; singleton:=true
-Bundle-Version: 1.1.0.v20110517
+Bundle-Version: 1.1.0.v20110519
 Bundle-ClassPath: .,
  lib/commons-lang-2.2.jar
 Bundle-Vendor: %providerName

Modified: trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/OutPortImpl.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/OutPortImpl.java	2011-05-18 05:46:03 UTC (rev 174)
+++ trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/OutPortImpl.java	2011-05-19 03:24:57 UTC (rev 175)
@@ -28,7 +28,8 @@
 public class OutPortImpl extends PortImpl implements OutPort {
 
 	/**
-	 * <!-- begin-user-doc --> <!-- end-user-doc -->
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
 	 * @generated
 	 */
 	protected OutPortImpl() {
@@ -36,7 +37,8 @@
 	}
 
 	/**
-	 * <!-- begin-user-doc --> <!-- end-user-doc -->
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
 	 * @generated
 	 */
 	@Override
@@ -49,16 +51,18 @@
 		return false;
 	}
 
+	@Override
 	public boolean validateTargetConnector(Port target) {
-		if (target instanceof InPort == false) {
+		if (!(target instanceof InPort)) {
 			return false;
 		}
-		if (isAllowDataType((InPort) target)) return true;
-		if (this.eContainer instanceof ComponentSpecification){
-			if (ConnectorUtil.getAllowDataTypes(this, (InPort) target)
-					.size() >= 1
-					|| ConnectorUtil.isAllowAnyDataType(this,
-							(InPort) target)) {
+		InPort inTarget = (InPort) target;
+		if (isAllowDataType(inTarget)) {
+			return true;
+		}
+		if (this.eContainer instanceof ComponentSpecification) {
+			if (!ConnectorUtil.getAllowDataTypes(this, inTarget).isEmpty()
+					|| ConnectorUtil.isAllowAnyDataType(this, inTarget)) {
 				return true;
 			}
 		}
@@ -66,17 +70,17 @@
 	}
 
 	private boolean isAllowDataType(InPort target) {
-		if (ConnectorUtil.getAllowDataTypes(this, target).size() < 1
-				&& !ConnectorUtil.isAllowAnyDataType(this,target)) 
+		if (ConnectorUtil.getAllowDataTypes(this, target).isEmpty()
+				&& !ConnectorUtil.isAllowAnyDataType(this, target))
 			return false;
-		if (ConnectorUtil.getAllowDataflowTypes(this, target).size() < 1
-				&& !ConnectorUtil.isAllowAnyDataflowType(this,target)) 
+		if (ConnectorUtil.getAllowDataflowTypes(this, target).isEmpty()
+				&& !ConnectorUtil.isAllowAnyDataflowType(this, target))
 			return false;
-		if (ConnectorUtil.getAllowInterfaceTypes(this, target).size() < 1
-				&& !ConnectorUtil.isAllowAnyInterfaceType(this, target)) 
+		if (ConnectorUtil.getAllowInterfaceTypes(this, target).isEmpty()
+				&& !ConnectorUtil.isAllowAnyInterfaceType(this, target))
 			return false;
-		if (ConnectorUtil.getAllowSubscriptionTypes(this, target).size() < 1
-				&& !ConnectorUtil.isAllowAnySubscriptionType(this, target)) 
+		if (ConnectorUtil.getAllowSubscriptionTypes(this, target).isEmpty()
+				&& !ConnectorUtil.isAllowAnySubscriptionType(this, target))
 			return false;
 		return true;
 	}

Modified: trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/PortImpl.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/PortImpl.java	2011-05-18 05:46:03 UTC (rev 174)
+++ trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/model/component/impl/PortImpl.java	2011-05-19 03:24:57 UTC (rev 175)
@@ -8,7 +8,6 @@
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 
 import jp.go.aist.rtm.toolscommon.model.component.Component;
@@ -538,18 +537,13 @@
 			eNotify(new ENotificationImpl(this, Notification.SET, ComponentPackage.PORT__INTERFACE_TYPE, oldInterfaceType, interfaceType));
 	}
 
-	@SuppressWarnings("unchecked")
-	public static boolean isExistAny(List targetList) {
-		boolean result = false;
-		for (Iterator iter = targetList.iterator(); iter.hasNext();) {
-			String target = (String) iter.next();
+	public static boolean isExistAny(List<String> targetList) {
+		for (String target : targetList) {
 			if (isAnyString(target)) {
-				result = true;
-				break;
+				return true;
 			}
 		}
-
-		return result;
+		return false;
 	}
 
 	/**

Modified: trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/util/ConnectorUtil.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/util/ConnectorUtil.java	2011-05-18 05:46:03 UTC (rev 174)
+++ trunk/rtmtools/jp.go.aist.rtm.toolscommon/src/jp/go/aist/rtm/toolscommon/util/ConnectorUtil.java	2011-05-19 03:24:57 UTC (rev 175)
@@ -3,7 +3,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Iterator;
 import java.util.List;
 
 import jp.go.aist.rtm.toolscommon.model.component.InPort;
@@ -72,7 +71,13 @@
 	 * @return
 	 */
 	public static List<String> getAllowDataTypes(OutPort source, InPort target) {
-		return getAllowList(source.getDataTypes(), target.getDataTypes());
+		List<String> sourceTypes = source.getDataTypes();
+		List<String> targetTypes = target.getDataTypes();
+		//
+		List<String> result = getAllowList(sourceTypes, targetTypes,
+				dataTypeComparer);
+		result = sortTypes(result);
+		return result;
 	}
 
 	/**
@@ -84,8 +89,13 @@
 	 */
 	public static List<String> getAllowInterfaceTypes(OutPort source,
 			InPort target) {
-		return getAllowList(source.getInterfaceTypes(), target
-				.getInterfaceTypes());
+		List<String> sourceTypes = source.getInterfaceTypes();
+		List<String> targetTypes = target.getInterfaceTypes();
+		//
+		List<String> result = getAllowList(sourceTypes, targetTypes,
+				ignoreCaseComparer);
+		result = sortTypes(result);
+		return result;
 	}
 
 	/**
@@ -97,8 +107,12 @@
 	 */
 	public static List<String> getAllowDataflowTypes(OutPort source,
 			InPort target) {
-		return getAllowList(source.getDataflowTypes(), target
-				.getDataflowTypes(), false);
+		List<String> sourceTypes = source.getDataflowTypes();
+		List<String> targetTypes = target.getDataflowTypes();
+		//
+		List<String> result = getAllowList(sourceTypes, targetTypes,
+				ignoreCaseComparer);
+		return result;
 	}
 
 	/**
@@ -110,14 +124,14 @@
 	 */
 	public static List<String> getAllowSubscriptionTypes(OutPort source,
 			InPort target) {
-		return getAllowList(source.getSubscriptionTypes(), target
-				.getSubscriptionTypes());
+		List<String> sourceTypes = source.getSubscriptionTypes();
+		List<String> targetTypes = target.getSubscriptionTypes();
+		//
+		List<String> result = getAllowList(sourceTypes, targetTypes,
+				ignoreCaseComparer);
+		return result;
 	}
 
-	private static List<String> getAllowList(List<String> one, List<String> two) {
-		return getAllowList(one, two, true);
-	}
-	
 	/**
 	 * 2つの文字列のリストを受け取り、両方に存在する文字列だけのリストを作成する。 「Any」が含まれる場合には、相手先すべての文字列を許す。
 	 * 返り値のリストに「Any」自体は含まれないことに注意すること。
@@ -128,58 +142,124 @@
 	 * 
 	 * @param one
 	 * @param two
+	 * @param comparer
 	 * @return
 	 */
-	private static List<String> getAllowList(List<String> one, List<String> two, boolean sorting) {
+	public static List<String> getAllowList(List<String> one, List<String> two,
+			TypeComparer comparer) {
 		boolean isAllowAny_One = PortImpl.isExistAny(one);
 		boolean isAllowAny_Two = PortImpl.isExistAny(two);
 
 		List<String> result = new ArrayList<String>();
-		for (String elem1 : one) {
-			if (PortImpl.isAnyString(elem1) == false) {
-				boolean isEqualsIgnoreCase = false;
-				for (String elem2 : two) {
-					if (isAllowAny_Two || elem1.equalsIgnoreCase(elem2)) {
-						isEqualsIgnoreCase = true;
+		for (String type1 : one) {
+			if (PortImpl.isAnyString(type1)) {
+				continue;
+			}
+			if (isAllowAny_Two) {
+				result.add(type1);
+			} else {
+				String match = null;
+				for (String type2 : two) {
+					match = comparer.match(type1, type2);
+					if (match != null) {
 						break;
 					}
 				}
-
-				if (isEqualsIgnoreCase) {
-					result.add(elem1);
+				if (match != null) {
+					result.add(match);
 				}
 			}
 		}
 		if (isAllowAny_One) {
-			for (String elem1 : two) {
-				if (PortImpl.isAnyString(elem1) == false) {
-					boolean isEqualsIgnoreCase = false;
-					for (String elem2 : result) {
-						if (elem1.equalsIgnoreCase(elem2)) {
-							isEqualsIgnoreCase = true;
-							break;
-						}
+			for (String type1 : two) {
+				if (PortImpl.isAnyString(type1)) {
+					continue;
+				}
+				String match = null;
+				for (String type2 : result) {
+					match = comparer.match(type1, type2);
+					if (match != null) {
+						break;
 					}
-
-					if (isEqualsIgnoreCase == false) {
-						result.add(elem1);
-					}
 				}
+				if (match == null) {
+					result.add(type1);
+				}
 			}
 		}
-		for (Iterator<String> iter = result.iterator(); iter.hasNext();) {
-			String elem = iter.next();
-			if (PortImpl.isAnyString(elem)) {
-				iter.remove();
+		for (String type : new ArrayList<String>(result)) {
+			if (PortImpl.isAnyString(type)) {
+				result.remove(type);
 			}
 		}
+		return result;
+	}
 
-		if(sorting) {
-			// リストを文字列順でソート
-			result = sortTypes(result);
+	/** 型比較インターフェース */
+	public static interface TypeComparer {
+		String match(String type1, String type2);
+	}
+
+	/** デフォルト型比較(IgnoreCase) */
+	static TypeComparer ignoreCaseComparer = new TypeComparer() {
+		@Override
+		public String match(String type1, String type2) {
+			if (type1 != null && type1.equalsIgnoreCase(type2)) {
+				return type1;
+			}
+			return null;
 		}
+	};
 
-		return result;
+	/** データ型比較 */
+	static TypeComparer dataTypeComparer = new TypeComparer() {
+		@Override
+		public String match(String type1, String type2) {
+			boolean isIFR1 = isIFR(type1);
+			boolean isIFR2 = isIFR(type2);
+			// IFR形式同士(1.1)、単純形式同士(1.0)の場合はデフォルト型比較
+			if (isIFR1 == isIFR2) {
+				return ignoreCaseComparer.match(type1, type2);
+			}
+			// 1.1/1.0混在時は後方一致によるあいまい比較
+			String ifrType = null;
+			String oldType = null;
+			if (isIFR1) {
+				ifrType = type1;
+				oldType = type2;
+			} else if (isIFR2) {
+				ifrType = type2;
+				oldType = type1;
+			}
+			if (ifrType == null) {
+				return null;
+			}
+			String ifr[] = ifrType.split(":");
+			String ifrSeg[] = ifr[1].split("/");
+			String oldSeg[] = oldType.split("::");
+			if (oldSeg.length > ifrSeg.length) {
+				return null;
+			}
+			for (int i = 1; i <= oldSeg.length; i++) {
+				String s1 = oldSeg[oldSeg.length - i];
+				String s2 = ifrSeg[ifrSeg.length - i];
+				if (!s1.equalsIgnoreCase(s2)) {
+					return null;
+				}
+			}
+			// 1.1/1.0混在時のConnectorProfileにはIFR形式を使用
+			// return oldType;
+			return ifrType;
+		}
+	};
+
+	/** IFR形式の場合はtrue (ex. IDL:RTC/TimedLong:1.0) */
+	static boolean isIFR(String type) {
+		String ifr[] = (type == null ? "" : type).split(":");
+		if (ifr.length == 3 && ifr[0].equals("IDL")) {
+			return true;
+		}
+		return false;
 	}
 
 	public static List<String> sortTypes(List<String> list) {
@@ -189,6 +269,7 @@
 	public static List<String> sortTypes(List<String> list,
 			final boolean reverse) {
 		Collections.sort(list, new Comparator<String>() {
+			@Override
 			public int compare(String a, String b) {
 				return a.compareTo(b) * (reverse ? -1 : 1);
 			}

Added: trunk/rtmtools/jp.go.aist.rtm.toolscommon/test/jp/go/aist/rtm/toolscommon/util/ConnectorUtilTest.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.toolscommon/test/jp/go/aist/rtm/toolscommon/util/ConnectorUtilTest.java	                        (rev 0)
+++ trunk/rtmtools/jp.go.aist.rtm.toolscommon/test/jp/go/aist/rtm/toolscommon/util/ConnectorUtilTest.java	2011-05-19 03:24:57 UTC (rev 175)
@@ -0,0 +1,182 @@
+package jp.go.aist.rtm.toolscommon.util;
+
+import java.util.List;
+
+import jp.go.aist.rtm.toolscommon.model.component.ComponentFactory;
+import jp.go.aist.rtm.toolscommon.model.component.InPort;
+import jp.go.aist.rtm.toolscommon.model.component.OutPort;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ConnectorUtilTest {
+
+	OutPort out;
+	InPort in;
+
+	@Before
+	public void setUp() throws Exception {
+		out = ComponentFactory.eINSTANCE.createOutPort();
+		in = ComponentFactory.eINSTANCE.createInPort();
+	}
+
+	@Test
+	public void testGetAllowDataTypes10_1() throws Exception {
+		// 1.0 名前空間あり
+		out.setDataType("RTC::TimedLong,RTC::TimedFloat,RTC::TimedDouble");
+		in.setDataType("RTC::TimedLong,RTC::TimedDouble");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(2, result.size());
+		assertTrue(result.contains("RTC::TimedLong"));
+		assertTrue(result.contains("RTC::TimedDouble"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes10_2() throws Exception {
+		// 1.0 名前空間不一致
+		out.setDataType("TimedLong,TimedFloat,RTC::TimedDouble");
+		in.setDataType("RTC::TimedLong,RTC::TimedDouble");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(1, result.size());
+		assertTrue(result.contains("RTC::TimedDouble"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes10_3() throws Exception {
+		// 1.0 Any含む(source)
+		out.setDataType("TimedLong,Any");
+		in.setDataType("RTC::TimedFloat,RTC::TimedDouble");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(2, result.size());
+		assertTrue(result.contains("RTC::TimedFloat"));
+		assertTrue(result.contains("RTC::TimedDouble"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes10_4() throws Exception {
+		// 1.0 Any含む(target)
+		out.setDataType("TimedLong,RTC::TimedDouble");
+		in.setDataType("Any,TimedLong");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(2, result.size());
+		assertTrue(result.contains("TimedLong"));
+		assertTrue(result.contains("RTC::TimedDouble"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes11_1() throws Exception {
+		// 1.1 IFR一致
+		out
+				.setDataType("IDL:RTC/TimedLong:1.0,IDL:RTC/TimedFloat:1.0,IDL:RTC/TimedDouble:1.0");
+		in.setDataType("IDL:RTC/TimedLong:1.0,IDL:RTC/TimedDouble:1.0");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(2, result.size());
+		assertTrue(result.contains("IDL:RTC/TimedLong:1.0"));
+		assertTrue(result.contains("IDL:RTC/TimedDouble:1.0"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes11_2() throws Exception {
+		// 1.1 IFR不一致(バージョン)
+		out
+				.setDataType("IDL:RTC/TimedLong:1.1,IDL:RTC/TimedFloat:1.0,IDL:RTC/TimedDouble:1.0");
+		in.setDataType("IDL:RTC/TimedLong:1.0,IDL:RTC/TimedDouble:1.0");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(1, result.size());
+		assertTrue(result.contains("IDL:RTC/TimedDouble:1.0"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes11_3() throws Exception {
+		// 1.1/1.0 混在(後方一致でIFR形式を返す)
+		out.setDataType("RTC::TimedLong,RTC::TimedFloat,TimedDouble");
+		in.setDataType("IDL:RTC/TimedLong:1.0,IDL:RTC/TimedDouble:1.0");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(2, result.size());
+		// assertTrue(result.contains("RTC::TimedLong"));
+		// assertTrue(result.contains("TimedDouble"));
+		assertTrue(result.contains("IDL:RTC/TimedLong:1.0"));
+		assertTrue(result.contains("IDL:RTC/TimedDouble:1.0"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes11_4() throws Exception {
+		// 1.1/1.0 混在(後方一致でIFR形式を返す)
+		out
+				.setDataType("IDL:RTC/TimedLong:1.0,IDL:RTC/TimedFloat:1.0,IDL:RTC/TimedDouble:1.0");
+		in.setDataType("RTC::TimedLong,TimedDouble");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(2, result.size());
+		// assertTrue(result.contains("RTC::TimedLong"));
+		// assertTrue(result.contains("TimedDouble"));
+		assertTrue(result.contains("IDL:RTC/TimedLong:1.0"));
+		assertTrue(result.contains("IDL:RTC/TimedDouble:1.0"));
+	}
+
+	@Test
+	public void testGetAllowDataTypes11_5() throws Exception {
+		// 1.1/1.0 名前空間が不一致
+		out.setDataType("RTC::TimedLong,AAA::TimedFloat,TimedDouble");
+		in
+				.setDataType("IDL:TimedLong:1.0,IDL:RTC/TimedFloat:1.0,IDL:AAA/BBB/TimedDouble:1.0");
+		List<String> result = ConnectorUtil.getAllowDataTypes(out, in);
+
+		assertEquals(1, result.size());
+		// assertTrue(result.contains("TimedDouble"));
+		assertTrue(result.contains("IDL:AAA/BBB/TimedDouble:1.0"));
+	}
+
+	@Test
+	public void testGetAllowDataflowTypes1() throws Exception {
+		out.setDataflowType("push,Pull");
+		in.setDataflowType("pull");
+		List<String> result = ConnectorUtil.getAllowDataflowTypes(out, in);
+
+		assertEquals(1, result.size());
+		assertTrue(result.contains("Pull"));
+	}
+
+	@Test
+	public void testGetAllowDataflowTypes2() throws Exception {
+		out.setDataflowType("Any");
+		in.setDataflowType("pull,push");
+		List<String> result = ConnectorUtil.getAllowDataflowTypes(out, in);
+
+		assertEquals(2, result.size());
+		assertTrue(result.contains("pull"));
+		assertTrue(result.contains("push"));
+	}
+
+	@Test
+	public void testGetAllowSubscriptionTypes1() throws Exception {
+		out.setSubscriptionType("flush,periodic");
+		in.setSubscriptionType("periodic");
+		List<String> result = ConnectorUtil.getAllowSubscriptionTypes(out, in);
+
+		assertEquals(1, result.size());
+		assertTrue(result.contains("periodic"));
+	}
+
+	@Test
+	public void testGetAllowSubscriptionTypes2() throws Exception {
+		out.setSubscriptionType("Any");
+		in.setSubscriptionType("flush,new");
+		List<String> result = ConnectorUtil.getAllowSubscriptionTypes(out, in);
+
+		assertEquals(2, result.size());
+		assertTrue(result.contains("flush"));
+		assertTrue(result.contains("new"));
+	}
+
+}



openrtm-commit メーリングリストの案内