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. |