|
From: <pat...@us...> - 2010-06-20 19:33:22
|
Revision: 1076
http://cishell.svn.sourceforge.net/cishell/?rev=1076&view=rev
Author: pataphil
Date: 2010-06-20 19:33:14 +0000 (Sun, 20 Jun 2010)
Log Message:
-----------
* Cleaned AlgorithmUtilities.
* Refactored implodeList, renaming it to implodeItems and changing its signature to accept a Collection instead of List (making it more generic). Subsequently added implodeList back, wrapping implodeItems, to make depedencies happy.
* Added org.cishell.utilities.mutateParameter.MetaAttributeDefinition (container for AD type (required, optional) and AD itself).
* Added ListUtilities.
* Made DefaultDictionary Java 1.5 (K, V).
* Updated reference to implodeList in various places.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/DefaultDictionary.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ListUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/MetaAttributeDefinition.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/AlgorithmUtilities.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -20,26 +20,21 @@
// TODO: ISILoadAndCleanAlgorithmFactory should use this?
// It's copied directly from it (and cleaned up a little bit)...
public static AlgorithmFactory getAlgorithmFactoryByFilter(
- String filter, BundleContext bundleContext)
- throws AlgorithmNotFoundException {
+ String filter, BundleContext bundleContext) throws AlgorithmNotFoundException {
ServiceReference[] algorithmFactoryReferences;
-
+
try {
algorithmFactoryReferences = bundleContext.getServiceReferences(
AlgorithmFactory.class.getName(), filter);
} catch (InvalidSyntaxException invalidSyntaxException) {
throw new AlgorithmNotFoundException(invalidSyntaxException);
}
-
- if (algorithmFactoryReferences != null &&
- algorithmFactoryReferences.length != 0) {
- ServiceReference algorithmFactoryReference =
- algorithmFactoryReferences[0];
-
- AlgorithmFactory algorithmFactory =
- (AlgorithmFactory)bundleContext.getService(
- algorithmFactoryReference);
-
+
+ if (algorithmFactoryReferences != null && algorithmFactoryReferences.length != 0) {
+ ServiceReference algorithmFactoryReference = algorithmFactoryReferences[0];
+ AlgorithmFactory algorithmFactory = (AlgorithmFactory)bundleContext.getService(
+ algorithmFactoryReference);
+
return algorithmFactory;
}
else {
@@ -47,19 +42,18 @@
"algorithm that satisfied the following filter:\n" + filter);
}
}
-
+
public static AlgorithmFactory getAlgorithmFactoryByPID(
- String pid, BundleContext bundleContext)
- throws AlgorithmNotFoundException {
+ String pid, BundleContext bundleContext) throws AlgorithmNotFoundException {
String filter = "(service.pid=" + pid + ")";
-
+
return getAlgorithmFactoryByFilter(filter, bundleContext);
}
public static Data[] cloneSingletonData(Data[] data) {
- return new Data[]{ new BasicData(data[0].getMetadata(),
- data[0].getData(),
- data[0].getFormat()) };
+ return new Data[] {
+ new BasicData(data[0].getMetadata(), data[0].getData(), data[0].getFormat())
+ };
}
/**
@@ -82,29 +76,30 @@
* receiving a new data item, the Data Manager algorithm would set this new
* property to the data item's label if not set already.
*/
+ @SuppressWarnings("unchecked") // Raw Dictionary
public static String guessSourceDataFilename(Data data) {
if (data == null) {
return "";
}
-
+
Dictionary metadata = data.getMetadata();
String label = (String) metadata.get(DataProperty.LABEL);
Data parent = (Data) metadata.get(DataProperty.PARENT);
-
+
if (label != null && label.indexOf(File.separator) != -1) {
/* If fileSeparator is a single backslash,
* escape it for the split() regular expression.
*/
String escapedFileSeparator = File.separator;
+
if ("\\".equals(escapedFileSeparator)) {
escapedFileSeparator = "\\\\";
}
-
- String[] pathTokens = label.split(escapedFileSeparator);
+ String[] pathTokens = label.split(escapedFileSeparator);
String guessedFilename = pathTokens[pathTokens.length - 1];
-
int lastExtensionSeparatorIndex = guessedFilename.lastIndexOf(".");
+
if (lastExtensionSeparatorIndex != -1) {
// Part before the extension ("foo" for "foo.bar").
String guessedNameProper =
@@ -130,8 +125,7 @@
Dictionary parameters,
CIShellContext ciShellContext)
throws AlgorithmExecutionException {
- Algorithm algorithm =
- algorithmFactory.createAlgorithm(data, parameters, ciShellContext);
+ Algorithm algorithm = algorithmFactory.createAlgorithm(data, parameters, ciShellContext);
if ((progressMonitor != null) && (algorithm instanceof ProgressTrackable)) {
ProgressTrackable progressTrackable = (ProgressTrackable)algorithm;
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -79,8 +79,7 @@
List prefixList = list.subList(0, requestedPrefixSize);
if (!prefixList.isEmpty()) {
- affixes.add(
- StringUtilities.implodeList(prefixList, separator));
+ affixes.add(StringUtilities.implodeItems(prefixList, separator));
}
affixes.add(ellipsis);
@@ -91,13 +90,13 @@
list.size());
if (!suffixList.isEmpty()) {
affixes.add(
- StringUtilities.implodeList(suffixList, separator));
+ StringUtilities.implodeItems(suffixList, separator));
}
- return StringUtilities.implodeList(affixes, separator);
+ return StringUtilities.implodeItems(affixes, separator);
} else {
// Just implode the list.
- return StringUtilities.implodeList(list, separator);
+ return StringUtilities.implodeItems(list, separator);
}
}
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -102,6 +102,6 @@
//TODO: Consider abstracting what you're wrapping with and making this a StringUtility.
public static String implodeAndWrap(List<String> values) {
- return "(" + StringUtilities.implodeList(values, ", ") + ")";
+ return "(" + StringUtilities.implodeItems(values, ", ") + ")";
}
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DefaultDictionary.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DefaultDictionary.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DefaultDictionary.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -4,30 +4,29 @@
import java.util.Enumeration;
import java.util.Hashtable;
-public class DefaultDictionary extends Dictionary {
- Object defaultValue;
- Dictionary wrappedDictionary;
+public class DefaultDictionary<K, V> extends Dictionary<K, V> {
+ V defaultValue;
+ Dictionary<K, V> wrappedDictionary;
- public DefaultDictionary(
- Object defaultValue, Dictionary wrappedDictionary) {
+ public DefaultDictionary(V defaultValue, Dictionary<K, V> wrappedDictionary) {
this.defaultValue = defaultValue;
this.wrappedDictionary = wrappedDictionary;
}
- public DefaultDictionary(Object defaultValue) {
- this(defaultValue, new Hashtable());
+ public DefaultDictionary(V defaultValue) {
+ this(defaultValue, new Hashtable<K, V>());
}
public Object getDefaultValue() {
return this.defaultValue;
}
- public Enumeration elements() {
+ public Enumeration<V> elements() {
return this.wrappedDictionary.elements();
}
- public Object get(Object key) {
- Object wrappedDictionaryGetResult = this.wrappedDictionary.get(key);
+ public V get(Object key) {
+ V wrappedDictionaryGetResult = this.wrappedDictionary.get(key);
if (wrappedDictionaryGetResult == null)
return this.defaultValue;
@@ -39,15 +38,15 @@
return this.wrappedDictionary.isEmpty();
}
- public Enumeration keys() {
+ public Enumeration<K> keys() {
return this.wrappedDictionary.keys();
}
- public Object put(Object key, Object value) {
+ public V put(K key, V value) {
return this.wrappedDictionary.put(key, value);
}
- public Object remove(Object key) {
+ public V remove(Object key) {
return this.wrappedDictionary.remove(key);
}
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ListUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ListUtilities.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ListUtilities.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -0,0 +1,18 @@
+package org.cishell.utilities;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ListUtilities {
+ public static<T> List<T> createAndFillList(T... contents) {
+ return fillList(new ArrayList<T>(), contents);
+ }
+
+ public static<T> List<T> fillList(List<T> list, T... contents) {
+ for (T content : contents) {
+ list.add(content);
+ }
+
+ return list;
+ }
+}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -1,11 +1,14 @@
package org.cishell.utilities;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
+import java.util.StringTokenizer;
public class StringUtilities {
- public static String implodeStringArray(String[] stringArray,
- String separator) {
+ // TODO: Make this wrap implodeItems.
+ public static String implodeStringArray(String[] stringArray, String separator) {
final int stringArrayLength = stringArray.length;
StringBuffer workingResultString = new StringBuffer();
@@ -18,16 +21,25 @@
return workingResultString.toString();
}
-
+
+ /* TODO: This is a wrapper for implodeItems. All new/updated code should refer to implodeItems
+ * from now on.
+ */
+ @SuppressWarnings("unchecked") // Raw List.
public static String implodeList(List list, String separator) {
+ return implodeItems(list, separator);
+ }
+
+ public static<T> String implodeItems(Collection<T> items, String separator) {
StringBuffer workingResultString = new StringBuffer();
-
- final int listLength = list.size();
-
- for (int ii = 0; ii < listLength; ii++) {
- workingResultString.append(list.get(ii));
+
+ for (Iterator<T> it = items.iterator(); it.hasNext(); ) {
+// for (int ii = 0; ii < listLength; ii++) {
+// workingResultString.append(list.get(ii));
+ workingResultString.append(it.next());
- boolean isLastElement = (ii == listLength - 1);
+// boolean isLastElement = (ii == listLength - 1);
+ boolean isLastElement = !it.hasNext();
if (!isLastElement) {
workingResultString.append(separator);
}
@@ -36,9 +48,8 @@
return workingResultString.toString();
}
- public static String[] filterStringsByPattern(String[] stringsToFilter,
- String pattern) {
- ArrayList filteredStrings = new ArrayList();
+ public static String[] filterStringsByPattern(String[] stringsToFilter, String pattern) {
+ ArrayList<String> filteredStrings = new ArrayList<String>();
for (int ii = 0; ii < stringsToFilter.length; ii++) {
if (!stringsToFilter[ii].matches(pattern)) {
@@ -51,7 +62,7 @@
public static String[] filterEmptyStrings(String[] stringsToFilter) {
// TODO: This maybe should use filterStringsByPattern?
- ArrayList filteredStrings = new ArrayList();
+ ArrayList<String> filteredStrings = new ArrayList<String>();
for (int ii = 0; ii < stringsToFilter.length; ii++) {
if (!"".equals(stringsToFilter[ii])) {
@@ -147,8 +158,7 @@
return true;
}
- public static int countOccurrencesOfChar(
- CharSequence characters, char target) {
+ public static int countOccurrencesOfChar(CharSequence characters, char target) {
int count = 0;
for (int ii = 0; ii < characters.length(); ii++) {
@@ -196,7 +206,7 @@
}
public static final String[] simpleCleanStrings(String[] strings) {
- List cleanedStrings = new ArrayList();
+ List<String> cleanedStrings = new ArrayList<String>();
for (int ii = 0; ii < strings.length; ii ++) {
cleanedStrings.add(StringUtilities.simpleClean(strings[ii]));
@@ -302,17 +312,36 @@
}
public static String getNthToken(
- String originalString,
- String separator,
- int index,
- boolean trim) {
+ String originalString, String separator, int index, boolean trim) {
+ return getAllTokens(originalString, separator, trim)[index];
+ }
+ public static String[] getAllTokens(
+ String originalString, String separator, boolean trim) {
String[] tokens = originalString.split(separator);
if (trim) {
- return tokens[index].trim();
+ String[] trimmedTokens = new String[tokens.length];
+
+ for (int ii = 0; ii < tokens.length; ii++) {
+ trimmedTokens[ii] = tokens[ii].trim();
+ }
+
+ return trimmedTokens;
} else {
- return tokens[index];
+ return tokens;
}
}
+
+ public static String[] tokenizeByWhitespace(String originalString) {
+ StringTokenizer tokenizer = new StringTokenizer(originalString);
+ int tokenCount = tokenizer.countTokens();
+ String[] tokens = new String[tokenCount];
+
+ for (int ii = 0; ii < tokenCount; ii++) {
+ tokens[ii] = tokenizer.nextToken();
+ }
+
+ return tokens;
+ }
}
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -13,7 +13,7 @@
public final int type;
public final int size;
- public static final Map<Integer, String> TYPE_MAP = constructTypeMap();
+ public static final Map<Integer, String> TYPE_MAP = constructTypeMap();
public static final Set<Integer> SIZED_TYPES = constructSizedTypes();
private static Map<Integer, String> constructTypeMap() { //if this ever gets derby specific, it shouldn't go here
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -162,7 +162,7 @@
for(String key : primaryKeys) {
keys.add(key + " = ?");
}
- return StringUtilities.implodeList(Lists.newArrayList(keys), separator);
+ return StringUtilities.implodeItems(Lists.newArrayList(keys), separator);
}
public Remover constructRemover(Connection connection) throws SQLException {
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java 2010-06-20 19:16:46 UTC (rev 1075)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -59,7 +59,7 @@
String foreignColumn = pair.foreign;
updateStatements.add(foreignColumn + " = ?");
}
- return StringUtilities.implodeList(Lists.newArrayList(updateStatements), separator);
+ return StringUtilities.implodeItems(Lists.newArrayList(updateStatements), separator);
}
public Repointer constructRepointer(Connection connection) throws SQLException {
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/MetaAttributeDefinition.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/MetaAttributeDefinition.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/MetaAttributeDefinition.java 2010-06-20 19:33:14 UTC (rev 1076)
@@ -0,0 +1,21 @@
+package org.cishell.utilities.mutateParameter;
+
+import org.osgi.service.metatype.AttributeDefinition;
+
+public class MetaAttributeDefinition {
+ private int type;
+ private AttributeDefinition attributeDefinition;
+
+ public MetaAttributeDefinition(int type, AttributeDefinition attributeDefinition) {
+ this.type = type;
+ this.attributeDefinition = attributeDefinition;
+ }
+
+ public int getType() {
+ return this.type;
+ }
+
+ public AttributeDefinition getAttributeDefinition() {
+ return this.attributeDefinition;
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|