From: <bea...@us...> - 2006-10-19 19:23:03
|
Revision: 303 http://svn.sourceforge.net/cishell/?rev=303&view=rev Author: bearsfan Date: 2006-10-19 12:22:57 -0700 (Thu, 19 Oct 2006) Log Message: ----------- Removed duplicate converter chains revised. Now does it correctly by overwriting the hashcode method as well as the equals method. Unique coverter chains are now detected through the Hashset Modified Paths: -------------- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2006-10-19 17:47:11 UTC (rev 302) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2006-10-19 19:22:57 UTC (rev 303) @@ -33,7 +33,7 @@ * * @author Bruce Herr (bh...@bh...) */ -public class ConverterImpl implements Converter, AlgorithmFactory, AlgorithmProperty, Comparable { +public class ConverterImpl implements Converter, AlgorithmFactory, AlgorithmProperty { private ServiceReference[] refs; private BundleContext bContext; private Dictionary props; @@ -121,6 +121,18 @@ public MetaTypeProvider createParameters(Data[] dm) { return null; } + + public int hashCode() { + return toString().hashCode(); + } + + public String toString() { + String str =""; + for (int j = 0; j < refs.length; ++j) { + str += refs[j].getProperty(Constants.SERVICE_ID) + " " + refs[j].getProperty(Constants.SERVICE_PID) + "-> "; + } + return str; + } public boolean equals(Object o) { boolean equals = false; @@ -171,8 +183,4 @@ return dm; } } - - public int compareTo(Object o) { - return equals(o) ? 0 : 1; - } } Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java 2006-10-19 17:47:11 UTC (rev 302) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java 2006-10-19 19:22:57 UTC (rev 303) @@ -130,7 +130,7 @@ * @param outFormat The format to convert to */ public Converter[] findConverters(String inFormat, String outFormat) { - //saveGraph(); + saveGraph(); if (inFormat != null && inFormat.length() > 0 && outFormat != null && outFormat.length() > 0) { @@ -325,42 +325,19 @@ converters = findConverters(format, outFormat); set.addAll(new HashSet(Arrays.asList(converters))); } - if (!(data.getData() instanceof File) && data.getData() != null) { Iterator iter = getClassesFor(data.getData().getClass()).iterator(); while (iter.hasNext()) { Class c = (Class) iter.next(); converters = findConverters(c.getName(), outFormat); - //this is a bit of a hack to remove the duplicate converters - addUniqueConverters(set, converters); - //set.addAll(new HashSet(Arrays.asList(converters))); + set.addAll(new HashSet(Arrays.asList(converters))); } } - + return (Converter[]) set.toArray(new Converter[0]); } - + /** - * Only add the unique converters to the 'Converter set' - * @param set The set of unique converters - * @param converters List of potential converters - */ - private void addUniqueConverters(Set set, Converter[] converters) { - for (int i = 0; i < converters.length; ++i) { - boolean uniqueConverter = true; - for (Iterator iter = set.iterator(); iter.hasNext();) { - if (iter.next().equals(converters[i])) { - uniqueConverter = false; - break; - } - } - if (uniqueConverter) { - set.add(converters[i]); - } - } - } - - /** * Get all the classes implemented and extended * @param clazz The class to query * @return Interfaces and base classes This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |