@Test public void testAddDisplayValue() { List<String> processVarStartValues = Arrays.asList( "** Variable Definitions **", "employee", "reason", "performance" ); ListBoxValues processVarValues = new ListBoxValues("Constant ...", "Edit ", null, ActivityDataIOEditorViewImpl.EXPRESSION_MAX_DISPLAY_LENGTH); String value = "sVar1"; String displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals(value, displayValue); value = "\"hello\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals(value, displayValue); value = "sVar"; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals(value, displayValue); value = "\"abcdeabcde\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals(value, displayValue); value = "sLongVar123"; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals(value, displayValue); value = "sVeryLongVariableName123"; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals(value, displayValue); value = "\"abcdeabcde1\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals("\"abcdeabcde...(01)\"", displayValue); value = "\"0123456789x\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals("\"0123456789...\"", displayValue); value = "\"0123456789y\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals("\"0123456789...(01)\"", displayValue); value = "\"0123456789z\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals("\"0123456789...(02)\"", displayValue); value = "\"hello then goodbye\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals("\"hello then...\"", displayValue); value = "\"hello then hello\""; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals("\"hello then...(01)\"", displayValue); value = "hello then hello"; displayValue = processVarValues.addDisplayValue(value); Assert.assertEquals(value, displayValue); displayValue = "sVar1"; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals(displayValue, value); displayValue = "\"hello\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals(displayValue, value); displayValue = "sVar"; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals(displayValue, value); displayValue = "\"abcdeabcde\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals(displayValue, value); displayValue = "sLongVar123"; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals(displayValue, value); displayValue = "sVeryLongVariableName123"; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals(displayValue, value); displayValue = "\"abcdeabcde...(01)\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals("\"abcdeabcde1\"", value); displayValue = "\"0123456789...\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals("\"0123456789x\"", value); displayValue = "\"0123456789...(01)\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals("\"0123456789y\"", value); displayValue = "\"0123456789...(02)\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals("\"0123456789z\"", value); displayValue = "\"hello then...\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals("\"hello then goodbye\"", value); displayValue = "\"hello then...(01)\""; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals("\"hello then hello\"", value); displayValue = "hello then hello"; value = processVarValues.getValueForDisplayValue(displayValue); Assert.assertEquals(displayValue, value); final String keyFirst = "1st"; final String valueFirst = "First"; final String keySecond = "Second"; final String valueSecond = "Second"; ListBoxValues test2 = new ListBoxValues("Constant ...", "Edit ", null); test2.mapDisplayValuesToValues.put(keyFirst, valueFirst); test2.mapDisplayValuesToValues.put(keySecond, valueSecond); assertEquals(keyFirst, test2.addDisplayValue(valueFirst)); assertEquals(keySecond, test2.addDisplayValue(valueSecond)); }
protected String addDisplayValue(final String value) { if (mapDisplayValuesToValues.containsValue(value)) { for (Map.Entry<String, String> entry : mapDisplayValuesToValues.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); } } } String displayValue = value; if (maxDisplayLength > 0 && value != null && isQuoted(value) && value.length() > maxDisplayLength + 2) { String displayValueStart = value.substring(0, maxDisplayLength + 1); int nextIndex = 0; for (String existingDisplayValue : mapDisplayValuesToValues.keySet()) { if (existingDisplayValue.startsWith(displayValueStart)) { if (existingDisplayValue.length() == (maxDisplayLength + 9)) { String sExistingIndex = existingDisplayValue.substring(existingDisplayValue.length() - 4, existingDisplayValue.length() - 2); try { int existingIndex = Integer.parseInt(sExistingIndex); if (nextIndex <= existingIndex) { nextIndex = existingIndex + 1; } } catch (NumberFormatException nfe) { } } else { if (nextIndex == 0) { nextIndex++; } } } } if (nextIndex == 0) { displayValue = displayValueStart + "..." + "\""; } else { String sNextIndex = Integer.toString(nextIndex); if (nextIndex < 10) { sNextIndex = "0" + sNextIndex; } displayValue = displayValueStart + "...(" + sNextIndex + ")\""; } } mapDisplayValuesToValues.put(displayValue, value); return displayValue; }
ListBoxValues { protected String addDisplayValue(final String value) { if (mapDisplayValuesToValues.containsValue(value)) { for (Map.Entry<String, String> entry : mapDisplayValuesToValues.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); } } } String displayValue = value; if (maxDisplayLength > 0 && value != null && isQuoted(value) && value.length() > maxDisplayLength + 2) { String displayValueStart = value.substring(0, maxDisplayLength + 1); int nextIndex = 0; for (String existingDisplayValue : mapDisplayValuesToValues.keySet()) { if (existingDisplayValue.startsWith(displayValueStart)) { if (existingDisplayValue.length() == (maxDisplayLength + 9)) { String sExistingIndex = existingDisplayValue.substring(existingDisplayValue.length() - 4, existingDisplayValue.length() - 2); try { int existingIndex = Integer.parseInt(sExistingIndex); if (nextIndex <= existingIndex) { nextIndex = existingIndex + 1; } } catch (NumberFormatException nfe) { } } else { if (nextIndex == 0) { nextIndex++; } } } } if (nextIndex == 0) { displayValue = displayValueStart + "..." + "\""; } else { String sNextIndex = Integer.toString(nextIndex); if (nextIndex < 10) { sNextIndex = "0" + sNextIndex; } displayValue = displayValueStart + "...(" + sNextIndex + ")\""; } } mapDisplayValuesToValues.put(displayValue, value); return displayValue; } }
ListBoxValues { protected String addDisplayValue(final String value) { if (mapDisplayValuesToValues.containsValue(value)) { for (Map.Entry<String, String> entry : mapDisplayValuesToValues.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); } } } String displayValue = value; if (maxDisplayLength > 0 && value != null && isQuoted(value) && value.length() > maxDisplayLength + 2) { String displayValueStart = value.substring(0, maxDisplayLength + 1); int nextIndex = 0; for (String existingDisplayValue : mapDisplayValuesToValues.keySet()) { if (existingDisplayValue.startsWith(displayValueStart)) { if (existingDisplayValue.length() == (maxDisplayLength + 9)) { String sExistingIndex = existingDisplayValue.substring(existingDisplayValue.length() - 4, existingDisplayValue.length() - 2); try { int existingIndex = Integer.parseInt(sExistingIndex); if (nextIndex <= existingIndex) { nextIndex = existingIndex + 1; } } catch (NumberFormatException nfe) { } } else { if (nextIndex == 0) { nextIndex++; } } } } if (nextIndex == 0) { displayValue = displayValueStart + "..." + "\""; } else { String sNextIndex = Integer.toString(nextIndex); if (nextIndex < 10) { sNextIndex = "0" + sNextIndex; } displayValue = displayValueStart + "...(" + sNextIndex + ")\""; } } mapDisplayValuesToValues.put(displayValue, value); return displayValue; } ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final int maxDisplayLength,
                         final boolean allowEmpty);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final int maxDisplayLength);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final boolean allowEmpty);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester);  ListBoxValues(final ListBoxValues copy,
                         final boolean copyCustomValues); }
ListBoxValues { protected String addDisplayValue(final String value) { if (mapDisplayValuesToValues.containsValue(value)) { for (Map.Entry<String, String> entry : mapDisplayValuesToValues.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); } } } String displayValue = value; if (maxDisplayLength > 0 && value != null && isQuoted(value) && value.length() > maxDisplayLength + 2) { String displayValueStart = value.substring(0, maxDisplayLength + 1); int nextIndex = 0; for (String existingDisplayValue : mapDisplayValuesToValues.keySet()) { if (existingDisplayValue.startsWith(displayValueStart)) { if (existingDisplayValue.length() == (maxDisplayLength + 9)) { String sExistingIndex = existingDisplayValue.substring(existingDisplayValue.length() - 4, existingDisplayValue.length() - 2); try { int existingIndex = Integer.parseInt(sExistingIndex); if (nextIndex <= existingIndex) { nextIndex = existingIndex + 1; } } catch (NumberFormatException nfe) { } } else { if (nextIndex == 0) { nextIndex++; } } } } if (nextIndex == 0) { displayValue = displayValueStart + "..." + "\""; } else { String sNextIndex = Integer.toString(nextIndex); if (nextIndex < 10) { sNextIndex = "0" + sNextIndex; } displayValue = displayValueStart + "...(" + sNextIndex + ")\""; } } mapDisplayValuesToValues.put(displayValue, value); return displayValue; } ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final int maxDisplayLength,
                         final boolean allowEmpty);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final int maxDisplayLength);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final boolean allowEmpty);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester);  ListBoxValues(final ListBoxValues copy,
                         final boolean copyCustomValues); String getEditPrefix(); void addValues(final List<String> acceptableValues); void addValues(final Map<String, String> acceptableValues); String addCustomValue(final String newValue,
                                 final String oldValue); List<String> update(final String currentValue); List<String> getAcceptableValuesWithCustomValues(); List<String> getAcceptableValuesWithoutCustomValues(); boolean isCustomValue(final String value); String getValueForDisplayValue(final String key); String getDisplayNameForValue(final String value); String getNonCustomValueForUserString(final String userValue); String toString(); }
ListBoxValues { protected String addDisplayValue(final String value) { if (mapDisplayValuesToValues.containsValue(value)) { for (Map.Entry<String, String> entry : mapDisplayValuesToValues.entrySet()) { if (value.equals(entry.getValue())) { return entry.getKey(); } } } String displayValue = value; if (maxDisplayLength > 0 && value != null && isQuoted(value) && value.length() > maxDisplayLength + 2) { String displayValueStart = value.substring(0, maxDisplayLength + 1); int nextIndex = 0; for (String existingDisplayValue : mapDisplayValuesToValues.keySet()) { if (existingDisplayValue.startsWith(displayValueStart)) { if (existingDisplayValue.length() == (maxDisplayLength + 9)) { String sExistingIndex = existingDisplayValue.substring(existingDisplayValue.length() - 4, existingDisplayValue.length() - 2); try { int existingIndex = Integer.parseInt(sExistingIndex); if (nextIndex <= existingIndex) { nextIndex = existingIndex + 1; } } catch (NumberFormatException nfe) { } } else { if (nextIndex == 0) { nextIndex++; } } } } if (nextIndex == 0) { displayValue = displayValueStart + "..." + "\""; } else { String sNextIndex = Integer.toString(nextIndex); if (nextIndex < 10) { sNextIndex = "0" + sNextIndex; } displayValue = displayValueStart + "...(" + sNextIndex + ")\""; } } mapDisplayValuesToValues.put(displayValue, value); return displayValue; } ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final int maxDisplayLength,
                         final boolean allowEmpty);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final int maxDisplayLength);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester,
                         final boolean allowEmpty);  ListBoxValues(final String customPrompt,
                         final String editPrefix,
                         final ValueTester valueTester);  ListBoxValues(final ListBoxValues copy,
                         final boolean copyCustomValues); String getEditPrefix(); void addValues(final List<String> acceptableValues); void addValues(final Map<String, String> acceptableValues); String addCustomValue(final String newValue,
                                 final String oldValue); List<String> update(final String currentValue); List<String> getAcceptableValuesWithCustomValues(); List<String> getAcceptableValuesWithoutCustomValues(); boolean isCustomValue(final String value); String getValueForDisplayValue(final String key); String getDisplayNameForValue(final String value); String getNonCustomValueForUserString(final String userValue); String toString(); static final String EDIT_SUFFIX; }