From: <pat...@us...> - 2009-07-21 13:07:49
|
Revision: 893 http://cishell.svn.sourceforge.net/cishell/?rev=893&view=rev Author: pataphil Date: 2009-07-21 13:07:46 +0000 (Tue, 21 Jul 2009) Log Message: ----------- Fixed 1.4 compatibility issues? Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2009-07-20 22:31:21 UTC (rev 892) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2009-07-21 13:07:46 UTC (rev 893) @@ -27,7 +27,8 @@ } } - for (String keyToAdd : keysToAdd) { + for (int ii = 0; ii < keysToAdd.length; ii++) { + String keyToAdd = keysToAdd[ii]; if (!union.contains(keyToAdd)) { union.add(keyToAdd); } Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-07-20 22:31:21 UTC (rev 892) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-07-21 13:07:46 UTC (rev 893) @@ -196,8 +196,9 @@ public static Date parseDate(String dateString) throws ParseException { - for (DateFormat format : ACCEPTED_DATE_FORMATS) { + for (int ii = 0; ii < ACCEPTED_DATE_FORMATS.length; ii++) { try { + DateFormat format = ACCEPTED_DATE_FORMATS[ii]; format.setLenient(false); Date date = format.parse(dateString); Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2009-07-20 22:31:21 UTC (rev 892) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2009-07-21 13:07:46 UTC (rev 893) @@ -5,15 +5,14 @@ import java.util.Set; public class MapUtilities { - public static String[] getValidKeysOfTypesInMap(Map map, - String[] types, - String[] keysToSkip, - String[] keysToAdd) + public static String[] getValidKeysOfTypesInMap( + Map map, String[] types, String[] keysToSkip, String[] keysToAdd) throws ColumnNotFoundException { ArrayList workingKeys = new ArrayList(); Set entrySet = map.entrySet(); - for (String type : types) { + for (int ii = 0; ii < types.length; ii++) { + String type = types[ii]; ArrayList keysForType = SetUtilities.getKeysOfMapEntrySetWithValue(entrySet, type); workingKeys = ArrayListUtilities.unionArrayLists( Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-07-20 22:31:21 UTC (rev 892) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-07-21 13:07:46 UTC (rev 893) @@ -30,7 +30,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return objectAsShortArray[0].doubleValue(); + return new Double(objectAsShortArray[0].doubleValue()); } } else if (object instanceof int[]) { @@ -50,7 +50,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return objectAsIntegerArray[0].doubleValue(); + return new Double(objectAsIntegerArray[0].doubleValue()); } } else if (object instanceof long[]) { @@ -70,7 +70,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return objectAsLongArray[0].doubleValue(); + return new Double(objectAsLongArray[0].doubleValue()); } } else if (object instanceof float[]) { @@ -90,7 +90,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return objectAsFloatArray[0].doubleValue(); + return new Double(objectAsFloatArray[0].doubleValue()); } } else if (object instanceof double[]) { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-07-20 22:31:21 UTC (rev 892) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-07-21 13:07:46 UTC (rev 893) @@ -125,7 +125,9 @@ ArrayList workingColumnNames = new ArrayList(); for (int ii = 0; ii < schema.getColumnCount(); ii++) { - for (Class objectClass : objectClasses) { + for (int jj = 0; jj < objectClasses.length; jj++) { + Class objectClass = objectClasses[jj]; + if (objectClass.isAssignableFrom(schema.getColumnType(ii))) { workingColumnNames.add(schema.getColumnName(ii)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-07-24 17:44:44
|
Revision: 896 http://cishell.svn.sourceforge.net/cishell/?rev=896&view=rev Author: jrbibers Date: 2009-07-24 17:44:30 +0000 (Fri, 24 Jul 2009) Log Message: ----------- Added ParameterMutator utilities for transforming ObjectClassDefinitions and AttributeDefinitions. See MutateParameterUtilities.mutateToDropdown() for an example usage. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/AttributeDefinitionTransformer.java 2009-07-24 17:44:30 UTC (rev 896) @@ -0,0 +1,19 @@ +package org.cishell.utilities.mutateParameter; + +import org.osgi.service.metatype.AttributeDefinition; + +/* There would be one implementation of this interface for each useful + * constructor of BasicAttributeDefinition, where the transform is defined as in + * DropdownTransformer. + */ +public interface AttributeDefinitionTransformer { + public boolean shouldTransform(AttributeDefinition ad); + public AttributeDefinition transform(AttributeDefinition oldAD); + public String transformID(String oldID); + public String transformName(String oldName); + public String transformDescription(String oldDescription); + public int transformType(int oldType); +} + + + Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownTransformer.java 2009-07-24 17:44:30 UTC (rev 896) @@ -0,0 +1,27 @@ +package org.cishell.utilities.mutateParameter; + +import org.cishell.reference.service.metatype.BasicAttributeDefinition; +import org.osgi.service.metatype.AttributeDefinition; + +public abstract class DropdownTransformer + implements AttributeDefinitionTransformer { + public AttributeDefinition transform(AttributeDefinition oldAD) { + if (shouldTransform(oldAD)) { + return + new BasicAttributeDefinition( + transformID(oldAD.getID()), + transformName(oldAD.getName()), + transformDescription(oldAD.getDescription()), + transformType(oldAD.getType()), + transformOptionLabels(oldAD.getOptionLabels()), + transformOptionValues(oldAD.getOptionValues())); + } + else { + return oldAD; + } + } + + public abstract String[] transformOptionLabels(String[] oldOptionLabels); + public abstract String[] transformOptionValues(String[] oldOptionValues); +} + Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/NullDropdownTransformer.java 2009-07-24 17:44:30 UTC (rev 896) @@ -0,0 +1,40 @@ +package org.cishell.utilities.mutateParameter; + +import org.osgi.service.metatype.AttributeDefinition; + +/* A dropdown-forming AttributeDefinition transformer which by default + * performs no transformation. + * This is a convenient access to DropdownTransformer where you may override + * methods to transform only the arguments that you wish to modify. + * The typical case would be extending shouldTransform (think of as a filter), + * transformOptionLabels, and transformOptionValues. + */ +public abstract class NullDropdownTransformer extends DropdownTransformer { + public boolean shouldTransform(AttributeDefinition ad) { + return false; + } + + public String transformID(String oldID) { + return oldID; + } + + public String transformName(String oldName) { + return oldName; + } + + public String transformDescription(String oldDescription) { + return oldDescription; + } + + public int transformType(int oldType) { + return oldType; + } + + public String[] transformOptionLabels(String[] oldOptionLabels) { + return oldOptionLabels; + } + + public String[] transformOptionValues(String[] oldOptionValues) { + return oldOptionValues; + } +} \ No newline at end of file Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/ObjectClassDefinitionTransformer.java 2009-07-24 17:44:30 UTC (rev 896) @@ -0,0 +1,51 @@ +package org.cishell.utilities.mutateParameter; + +import java.util.Iterator; +import java.util.List; + +import org.cishell.reference.service.metatype.BasicObjectClassDefinition; +import org.cishell.utilities.MutateParameterUtilities; +import org.osgi.service.metatype.AttributeDefinition; +import org.osgi.service.metatype.ObjectClassDefinition; + +public class ObjectClassDefinitionTransformer { + private static final int OUTGOING_ATTRIBUTES_FILTER = + ObjectClassDefinition.REQUIRED; + private static final int INCOMING_ATTRIBUTES_FILTER = + ObjectClassDefinition.ALL; + + /* Create newOCD from oldOCD by applying transformer + * to each AttributeDefinition. + */ + public static BasicObjectClassDefinition apply( + AttributeDefinitionTransformer transformer, + ObjectClassDefinition oldOCD) { + BasicObjectClassDefinition newOCD = + MutateParameterUtilities.createNewParameters(oldOCD); + + AttributeDefinition[] oldADs = + oldOCD.getAttributeDefinitions(INCOMING_ATTRIBUTES_FILTER); + for(int ii = 0; ii < oldADs.length; ii++) { + newOCD.addAttributeDefinition(OUTGOING_ATTRIBUTES_FILTER, + transformer.transform(oldADs[ii])); + } + + return newOCD; + } + + /* Convenience method for batching transformations. + * TODO Untested + */ + public static BasicObjectClassDefinition transform( + BasicObjectClassDefinition oldOCD, List transformers) { + BasicObjectClassDefinition newOCD = oldOCD; + + for ( Iterator it = transformers.iterator(); it.hasNext(); ) { + AttributeDefinitionTransformer transformer = + (AttributeDefinitionTransformer) it.next(); + newOCD = apply(transformer, newOCD); + } + + return newOCD; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-08-18 20:33:19
|
Revision: 927 http://cishell.svn.sourceforge.net/cishell/?rev=927&view=rev Author: jrbibers Date: 2009-08-18 20:33:00 +0000 (Tue, 18 Aug 2009) Log Message: ----------- Previous commit included what is probably a poor assumption: that the list would not include the option to default. Now defaulting never adds an option to the list; it only checks for the presence of the given default in the given options and, if found, swaps it the front of the structure (as the called code treats the first option in the structure as the default). Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2009-08-18 20:33:00 UTC (rev 927) @@ -0,0 +1,13 @@ +package org.cishell.utilities; + +public class ArrayUtilities { + public static int indexOf(Object[] array, Object target) { + for (int ii = 0; ii < array.length; ii++) { + if (target.equals(array[ii])) { + return ii; + } + } + + return -1; + } +} Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java 2009-08-18 19:52:44 UTC (rev 926) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/DropdownMutator.java 2009-08-18 20:33:00 UTC (rev 927) @@ -1,9 +1,9 @@ package org.cishell.utilities.mutateParameter; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import org.cishell.utilities.ArrayUtilities; import org.osgi.service.metatype.AttributeDefinition; import org.osgi.service.metatype.ObjectClassDefinition; @@ -25,70 +25,51 @@ return ObjectClassDefinitionTransformer.transform(ocd, transforms); } - public void add(String id, Collection options, String defaultOption) { - List defaultedOptions = new ArrayList(); - defaultedOptions.add(defaultOption); - defaultedOptions.addAll(options); - - add(id, defaultedOptions); + public void add(String id, List options, String defaultOption) { + add(id, swapToFront(options, defaultOption)); } - public void add(String id, Collection options) { + public void add(String id, List options) { add(id, options, options); } - public void add(String id, Collection optionLabels, String defaultOptionLabel, Collection optionValues, String defaultOptionValue) { - List defaultedOptionLabels = new ArrayList(); - defaultedOptionLabels.add(defaultOptionLabel); - defaultedOptionLabels.addAll(optionLabels); - - List defaultedOptionValues = new ArrayList(); - defaultedOptionValues.add(defaultOptionValue); - defaultedOptionValues.addAll(optionValues); - - add(id, defaultedOptionLabels, defaultedOptionValues); + public void add(String id, + List optionLabels, + String defaultOptionLabel, + List optionValues, + String defaultOptionValue) { + add(id, + swapToFront(optionLabels, defaultOptionLabel), + swapToFront(optionValues, defaultOptionValue)); } - public void add(String id, Collection optionLabels, Collection optionValues) { - add(id, (String[]) optionLabels.toArray(new String[0]), (String[]) optionValues.toArray(new String[0])); + public void add(String id, List optionLabels, List optionValues) { + add(id, + (String[]) optionLabels.toArray(new String[0]), + (String[]) optionValues.toArray(new String[0])); } public void add(String id, String[] options, String defaultOption) { - String[] defaultedOptions = new String[options.length + 1]; - defaultedOptions[0] = defaultOption; - for (int ii = 0; ii < options.length; ii++) { - defaultedOptions[ii+1] = options[ii]; - } - - System.out.println("options = "); - for (int ii = 0; ii < defaultedOptions.length; ii++) { - System.out.println(defaultedOptions[ii]); - } - - add(id, defaultedOptions); + add(id, swapToFront(options, defaultOption)); } public void add(String id, String[] options) { add(id, options, options); } - public void add(final String id, final String[] optionLabels, String defaultOptionLabel, final String[] optionValues, String defaultOptionValue) { - String[] defaultedOptionLabels = new String[optionLabels.length + 1]; - defaultedOptionLabels[0] = defaultOptionLabel; - for (int ii = 0; ii < optionLabels.length; ii++) { - defaultedOptionLabels[ii+1] = optionLabels[ii]; - } - - String[] defaultedOptionValues = new String[optionValues.length + 1]; - defaultedOptionValues[0] = defaultOptionValue; - for (int ii = 0; ii < optionValues.length; ii++) { - defaultedOptionValues[ii+1] = optionValues[ii]; - } - - add(id, defaultedOptionLabels, defaultedOptionValues); + public void add(final String id, + final String[] optionLabels, + String defaultOptionLabel, + final String[] optionValues, + String defaultOptionValue) { + add(id, + swapToFront(optionLabels, defaultOptionLabel), + swapToFront(optionValues, defaultOptionValue)); } - public void add(final String id, final String[] optionLabels, final String[] optionValues) { + public void add(final String id, + final String[] optionLabels, + final String[] optionValues) { transforms.add( new NullDropdownTransformer() { public boolean shouldTransform(AttributeDefinition ad) { @@ -104,4 +85,27 @@ } }); } + + private static List swapToFront(List list, String item) { + if (list.contains(item)) { + int index = list.indexOf(item); + String displacedItem = (String) list.get(0); + list.set(0, item); + list.set(index, displacedItem); + } + + return list; + } + + private static String[] swapToFront(String[] array, String item) { + int index = ArrayUtilities.indexOf(array, item); + + if (index != -1) { + String displacedItem = array[0]; + array[0] = item; + array[index] = displacedItem; + } + + return array; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-09-04 21:08:36
|
Revision: 945 http://cishell.svn.sourceforge.net/cishell/?rev=945&view=rev Author: jrbibers Date: 2009-09-04 21:08:26 +0000 (Fri, 04 Sep 2009) Log Message: ----------- In the colored-region style, we now report when some region was requested to be painted a particular color, but no region of that name could be found in the shapefile. Previously, if a user gave the algorithm a table with a row specifying a country named "Russian Federation", there would be no warning that that data wasn't represented in the output map (as our current world countries shapefile has a "Russia" feature, but no "Russian Federation" feature). If any such failures occur, the user is now told how many occurred, the NWB user console shows at least a few of them, and the complete list is written to the log file. Added two new implosion utilities in support of this. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2009-09-03 19:47:28 UTC (rev 944) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayListUtilities.java 2009-09-04 21:08:26 UTC (rev 945) @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.List; public class ArrayListUtilities { public static ArrayList unionArrayLists(ArrayList arrayList1, @@ -36,4 +37,68 @@ return union; } + + /* Implodes list to a String with the String.valueOf the elements separated + * by separator and where all elements except the first prefixSize and + * final suffixSize are represented only by ellipsis. + * + * Examples: + * - ({1, 2, 3, 4, 5, 6}, 2, 1, ", ", "...") returns "1, 2, ..., 5" + * - ({1, 2, 3, 4, 5, 6}, 7, 7, ", ", "...") returns "1, 2, 3" + * - ({1, 2, 3, 4, 5, 6}, 0, 2, ", ", "...") returns "1, 2, ..., 4, 5" + * - ({1, 2, 3, 4, 5, 6}, 2, 0, ", ", "...") returns "1, 2, ..." + * - ({1, 2, 3, 4, 5, 6}, -1, -1, ", ", "...") returns "1, 2, ..." + * - The empty list always returns "No elements" + * + * If requestedPrefixSize (resp. requestedSuffixSize) is less than + * prefixSizeMinimum (resp. suffixSizeMinimum), we instead use the minimum. + */ + public static String makePreview( + List list, + int requestedPrefixSize, + int requestedSuffixSize, + String separator, + String ellipsis) { + if (list.isEmpty()) { + return "No elements"; + } else { + // Adjust the requested sizes to reasonable numbers. + final int prefixSizeMinimum = 2; + requestedPrefixSize = + Math.max(prefixSizeMinimum, requestedPrefixSize); + final int suffixSizeMinimum = 0; + requestedSuffixSize = + Math.max(suffixSizeMinimum, requestedSuffixSize); + + // Check whether an ellipsis is necessary. + boolean ellipsisNecessary = + (list.size() > requestedPrefixSize + requestedSuffixSize); + if (ellipsisNecessary) { + // Implode the prefix, ellipsis, and suffix. + List affixes = new ArrayList(); + + List prefixList = list.subList(0, requestedPrefixSize); + if (!prefixList.isEmpty()) { + affixes.add( + StringUtilities.implodeList(prefixList, separator)); + } + + affixes.add(ellipsis); + + List suffixList = + list.subList( + list.size() - requestedSuffixSize, + list.size()); + if (!suffixList.isEmpty()) { + affixes.add( + StringUtilities.implodeList(suffixList, separator)); + } + + return StringUtilities.implodeList(affixes, separator); + } else { + // Just implode the list. + return StringUtilities.implodeList(list, separator); + } + } + } } \ 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 2009-09-03 19:47:28 UTC (rev 944) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-09-04 21:08:26 UTC (rev 945) @@ -1,5 +1,7 @@ package org.cishell.utilities; +import java.util.List; + public class StringUtilities { public static String implodeStringArray(String[] stringArray, String separator) { final int stringArrayLength = stringArray.length; @@ -14,4 +16,21 @@ return workingResultString.toString(); } + + public static String implodeList(List list, String separator) { + StringBuffer workingResultString = new StringBuffer(); + + final int listLength = list.size(); + + for (int ii = 0; ii < listLength; ii++) { + workingResultString.append(list.get(ii)); + + boolean isLastElement = (ii == listLength - 1); + if (!isLastElement) { + workingResultString.append(separator); + } + } + + return workingResultString.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-12 16:29:14
|
Revision: 958 http://cishell.svn.sourceforge.net/cishell/?rev=958&view=rev Author: pataphil Date: 2009-10-12 16:29:06 +0000 (Mon, 12 Oct 2009) Log Message: ----------- * Added FileUtilities.createTemporaryFileCopy, which wraps FileUtilities.copyFile. * Made custom exception type FileCopyingException for file copy operations. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileCopyingException.java 2009-10-12 16:29:06 UTC (rev 958) @@ -0,0 +1,21 @@ +package org.cishell.utilities; + +public class FileCopyingException extends Exception { + private static final long serialVersionUID = 1L; + + public FileCopyingException() { + super(); + } + + public FileCopyingException(String arg0) { + super(arg0); + } + + public FileCopyingException(Throwable arg0) { + super(arg0); + } + + public FileCopyingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-10-08 21:19:28 UTC (rev 957) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-10-12 16:29:06 UTC (rev 958) @@ -3,10 +3,13 @@ import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.nio.channels.FileChannel; import javax.imageio.ImageIO; @@ -173,6 +176,55 @@ return readTextStringBuffer.toString(); } + public static void copyFile(File sourceFile, File targetFile) + throws FileCopyingException { + try { + FileInputStream inputStream = new FileInputStream(sourceFile); + FileOutputStream outputStream = new FileOutputStream(targetFile); + + FileChannel readableChannel = inputStream.getChannel(); + FileChannel writableChannel = outputStream.getChannel(); + + writableChannel.truncate(0); + writableChannel.transferFrom( + readableChannel, 0, readableChannel.size()); + inputStream.close(); + outputStream.close(); + } catch (IOException ioException) { + String exceptionMessage = + "An error occurred when copying from the file \"" + + sourceFile.getAbsolutePath() + + "\" to the file \"" + + targetFile.getAbsolutePath() + + "\"."; + + throw new FileCopyingException(exceptionMessage, ioException); + } + } + + public static File createTemporaryFileCopy( + File sourceFile, String fileName, String fileExtension) + throws FileCopyingException { + try { + File temporaryTargetFile = + createTemporaryFileInDefaultTemporaryDirectory( + fileName, fileExtension); + + copyFile(sourceFile, temporaryTargetFile); + + return temporaryTargetFile; + } catch (IOException temporaryFileCreationException) { + String exceptionMessage = + "An error occurred when trying to create the temporary file " + + "with file name \"" + fileName + "\" " + + "and file extension \"" + fileExtension + "\" " + + "for copying file \"" + sourceFile.getAbsolutePath() + "\"."; + + throw new FileCopyingException( + exceptionMessage, temporaryFileCreationException); + } + } + private static File ensureDirectoryExists(String directoryPath) { File directory = new File(directoryPath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-10-14 21:28:09
|
Revision: 964 http://cishell.svn.sourceforge.net/cishell/?rev=964&view=rev Author: jrbibers Date: 2009-10-14 21:27:55 +0000 (Wed, 14 Oct 2009) Log Message: ----------- Added TableUtilities.copyTable for copying prefuse Tables. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -16,7 +16,7 @@ public static void swapFirstMatchToFront(Object[] array, List targets) { for (Iterator targetsIt = targets.iterator(); targetsIt.hasNext();) { - Object target = (Object) targetsIt.next(); + Object target = targetsIt.next(); int index = ArrayUtilities.indexOf(array, target); if ( index != -1 ) { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FAQCalendar.java 2009-10-14 21:27:55 UTC (rev 964) @@ -12,7 +12,9 @@ * @copyright 2004 Paul Hill */ public class FAQCalendar extends GregorianCalendar { - /** + private static final long serialVersionUID = 1L; + + /** * All minutes have this many milliseconds except the last minute of the day on a day defined with * a leap second. */ Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ImageUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -24,4 +24,4 @@ return bufferedImage; } -}; \ No newline at end of file +} \ No newline at end of file Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -20,7 +20,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsShortArray[0]); + return new Double(objectAsShortArray[0]); } } else if (object instanceof Short[]) { @@ -40,7 +40,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsIntArray[0]); + return new Double(objectAsIntArray[0]); } } else if (object instanceof Integer[]) { @@ -60,7 +60,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsLongArray[0]); + return new Double(objectAsLongArray[0]); } } else if (object instanceof Long[]) { @@ -80,7 +80,7 @@ throw new NumberFormatException(EMPTY_CELL_MESSAGE); } else { - return new Double((double)objectAsFloatArray[0]); + return new Double(objectAsFloatArray[0]); } } else if (object instanceof Float[]) { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-10-13 18:01:02 UTC (rev 963) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-10-14 21:27:55 UTC (rev 964) @@ -2,10 +2,12 @@ import java.util.ArrayList; import java.util.Date; +import java.util.Iterator; import java.util.List; import prefuse.data.Schema; import prefuse.data.Table; +import prefuse.data.Tuple; import prefuse.util.collections.IntIterator; public class TableUtilities { @@ -231,6 +233,9 @@ possibleNumberClasses); } + /** + * @deprecated Replace calls with schema.instantiate(). + */ public static Table createTableUsingSchema(Schema tableSchema) { final int numTableColumns = tableSchema.getColumnCount(); Table table = new Table(); @@ -293,4 +298,16 @@ return newTable; } + + public static Table copyTable(Table oldTable) { + Schema oldSchema = oldTable.getSchema(); + Table newTable = oldSchema.instantiate(); + + for (Iterator rowIt = oldTable.tuples(); rowIt.hasNext();) { + Tuple row = (Tuple) rowIt.next(); + newTable.addTuple(row); + } + + return newTable; + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-10-16 19:02:28
|
Revision: 965 http://cishell.svn.sourceforge.net/cishell/?rev=965&view=rev Author: pataphil Date: 2009-10-16 19:02:20 +0000 (Fri, 16 Oct 2009) Log Message: ----------- * Added StringUtilities.interpretObjectAsString and StringUtilities.isEmptyOrWhiteSpace. * Reviewed by Joseph. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-14 21:27:55 UTC (rev 964) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2009-10-16 19:02:20 UTC (rev 965) @@ -82,7 +82,7 @@ endDate.getMonth(), endDate.getDate()); - return (int)startDateCalendar.diffDayPeriods(endDateCalendar); + return (int) startDateCalendar.diffDayPeriods(endDateCalendar); } public static int calculateMonthsBetween(Date startDate, Date endDate) { Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-14 21:27:55 UTC (rev 964) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-10-16 19:02:20 UTC (rev 965) @@ -61,4 +61,33 @@ return (String[])filteredStrings.toArray(new String[0]); } + + /* + * This method is really meant to simplify working with Prefuse tables. + * Prefuse table columns are typed. If a column contains a null cell, + * Prefuse types that column as an array type, and it then represents + * null values with arrays of length 0. + */ + public static String interpretObjectAsString(Object object) { + if (object == null) { + return null; + } else if (object instanceof String[]) { + String[] objectAsStringArray = (String[])object; + + if (objectAsStringArray.length == 0) { + return null; + } else { + return objectAsStringArray[0]; + } + } else { + return object.toString(); + } + } + + // TODO Think about instead using a Pattern, "\s*". Don't have to though. + public static boolean isEmptyOrWhiteSpace(String test) { + String trimmed = test.trim(); + + return (trimmed.length() == 0); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-11-03 20:01:27
|
Revision: 976 http://cishell.svn.sourceforge.net/cishell/?rev=976&view=rev Author: jrbibers Date: 2009-11-03 20:01:05 +0000 (Tue, 03 Nov 2009) Log Message: ----------- Added new constructor for BasicDataPlus. This plug-in is intended to be 1.4 compatible and so should not use the new-in-1.5 String method contains. Use in NumberUtilities was corrected to test indexOf != -1. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java 2009-10-30 19:58:48 UTC (rev 975) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java 2009-11-03 20:01:05 UTC (rev 976) @@ -32,8 +32,19 @@ } /** + * The type of inner is assumed to be the toString value of its Class. * * @param inner The object wrapped by this Data. + * @param parent The parent of inner. + */ + public BasicDataPlus(Object inner, Data parent) { + this(inner); + setParent(parent); + } + + /** + * + * @param inner The object wrapped by this Data. * @param type The _TYPE constant from {@link DataProperty} * that best characterizes the type of inner. * @param parent The parent of inner. Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-10-30 19:58:48 UTC (rev 975) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-11-03 20:01:05 UTC (rev 976) @@ -119,7 +119,7 @@ */ public static String convertToDecimalNotation(String numberAsString) { // Check for a scientific notation delimiter. - if (numberAsString.contains("E") || numberAsString.contains("e")) { + if (numberAsString.indexOf("E") != -1 || numberAsString.indexOf("e") != -1) { Format format = new DecimalFormat(UNROUNDED_DECIMAL_PATTERN); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |