/** * Factory method to create an ordered map. * <p> * An <code>ArrayList</code> is used to retain order. * * @param map the map to decorate, must not be null * @throws IllegalArgumentException if map is null */ public static OrderedMap decorate(Map map) { return new ListOrderedMap(map); }
/** * Returns a map that maintains the order of keys that are added * backed by the given map. * <p> * If a key is added twice, the order is determined by the first add. * The order is observed through the keySet, values and entrySet. * * @param map the map to order, must not be null * @return an ordered map backed by the given map * @throws IllegalArgumentException if the Map is null */ public static Map orderedMap(Map map) { return ListOrderedMap.decorate(map); }
/** * Sets the value at the specified index. * * @param index the index of the value to set * @return the previous value at that index * @throws IndexOutOfBoundsException if the index is invalid * @since Commons Collections 3.2 */ public Object setValue(int index, Object value) { Object key = insertOrder.get(index); return put(key, value); }
/** * Returns the Map as a string. * * @return the Map as a String */ public String toString() { if (isEmpty()) { return "{}"; } StringBuffer buf = new StringBuffer(); buf.append('{'); boolean first = true; Iterator it = entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); if (first) { first = false; } else { buf.append(", "); } buf.append(key == this ? "(this Map)" : key); buf.append('='); buf.append(value == this ? "(this Map)" : value); } buf.append('}'); return buf.toString(); }
lom.put(1, "testInsert1", "testInsert1v"); fail("should not be able to insert at pos 1 in empty Map"); } catch (IndexOutOfBoundsException ex) {} try { lom.put(-1, "testInsert-1", "testInsert-1v"); fail("should not be able to insert at pos -1 in empty Map"); } catch (IndexOutOfBoundsException ex) {} lom.put(0, "testInsert1", "testInsert1v"); assertEquals("testInsert1v", lom.getValue(0)); lom.put("testInsertPut", "testInsertPutv"); assertEquals("testInsert1v", lom.getValue(0)); assertEquals("testInsertPutv", lom.getValue(1)); lom.put(0, "testInsert0", "testInsert0v"); assertEquals("testInsert0v", lom.getValue(0)); assertEquals("testInsert1v", lom.getValue(1)); assertEquals("testInsertPutv", lom.getValue(2)); lom.put(3, "testInsert3", "testInsert3v"); assertEquals("testInsert0v", lom.getValue(0)); assertEquals("testInsert1v", lom.getValue(1)); assertEquals("testInsertPutv", lom.getValue(2)); assertEquals("testInsert3v", lom.getValue(3)); ListOrderedMap lom2 = new ListOrderedMap(); lom2.putAll(lom);
ListOrderedMap lom = (ListOrderedMap) map; try { lom.remove(0); } catch (IndexOutOfBoundsException ex) {} try { lom.remove(-1); } catch (IndexOutOfBoundsException ex) {} lom = (ListOrderedMap) map; try { lom.remove(-1); } catch (IndexOutOfBoundsException ex) {} try { lom.remove(lom.size()); } catch (IndexOutOfBoundsException ex) {} for (MapIterator it = lom.mapIterator(); it.hasNext();) { list.add(it.next()); Object value = lom.get(key); assertEquals(value, lom.remove(i)); list.remove(i); assertEquals(false, lom.containsKey(key));
private ListOrderedMap resetMap( final String[] names, final ListOrderedMap oldMap ) { ListOrderedMap newMap = new ListOrderedMap(); for ( String element : names ) { newMap.put( element, oldMap.get( element ) ); } return ( newMap ); }
public void addToCurrentInputs( final String key, final IActionParameter param ) { if ( currentInputs.containsKey( key ) ) { currentInputs.remove( key ); } currentInputs.put( key, param ); }
public Map getTypeOptions() throws Exception { ListOrderedMap typeOptions = new ListOrderedMap(); typeOptions.put(CHOOSE_SCHEME, getText("admin.projects.issuetypescheme.radio1")); if (!getAllProjects().isEmpty()) { typeOptions.put(CHOOSE_PROJECT, getText("admin.projects.issuetypescheme.radio2")); } typeOptions.put(CREATE_SCHEME, getText("admin.projects.issuetypescheme.radio4")); return typeOptions; }
public void testSetValueByIndex() { resetEmpty(); ListOrderedMap lom = (ListOrderedMap) map; try { lom.setValue(0, ""); } catch (IndexOutOfBoundsException ex) {} try { lom.setValue(-1, ""); } catch (IndexOutOfBoundsException ex) {} resetFull(); lom = (ListOrderedMap) map; try { lom.setValue(-1, ""); } catch (IndexOutOfBoundsException ex) {} try { lom.setValue(lom.size(), ""); } catch (IndexOutOfBoundsException ex) {} for (int i = 0; i < lom.size(); i++) { Object value = lom.getValue(i); Object input = new Integer(i); assertEquals(value, lom.setValue(i, input)); assertEquals(input, lom.getValue(i)); } }
public boolean contains(Object value) { return this.parent.containsKey(value); }
public Iterator iterator() { return new AbstractIteratorDecorator(parent.entrySet().iterator()) { public Object next() { return ((Map.Entry) iterator.next()).getValue(); } }; }
public void testGetByIndex() { resetEmpty(); ListOrderedMap lom = (ListOrderedMap) map; try { lom.get(0); } catch (IndexOutOfBoundsException ex) {} try { lom.get(-1); } catch (IndexOutOfBoundsException ex) {} resetFull(); lom = (ListOrderedMap) map; try { lom.get(-1); } catch (IndexOutOfBoundsException ex) {} try { lom.get(lom.size()); } catch (IndexOutOfBoundsException ex) {} int i = 0; for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) { assertSame(it.next(), lom.get(i)); } }
public Object getValue() { return parent.get(key); }
@Override public void validate(final ErrorCollection errors, final BulkMoveOperation bulkMoveOperation, final ApplicationUser applicationUser) { if (!regularIssues.isEmpty() && regularOptions.isEmpty()) { errors.addErrorMessage(authenticationContext.getI18nHelper() .getText("admin.errors.bean.issues.affected", "" + regularIssues.size())); } if (!subTaskIssues.isEmpty() && subTaskOptions.isEmpty()) { errors.addErrorMessage(authenticationContext.getI18nHelper() .getText("admin.errors.bean.subtasks.affected", "" + subTaskIssues.size())); } // Validate permission Set entries = bulkEditBeans.entrySet(); for (final Object entry1 : entries) { Map.Entry entry = (Map.Entry) entry1; IssueContext issueContext = (IssueContext) entry.getKey(); BulkEditBean bulkEditBean = (BulkEditBean) entry.getValue(); if (!bulkMoveOperation.canPerform(bulkEditBean, applicationUser)) { errors.addErrorMessage(authenticationContext.getI18nHelper().getText("admin.errors.bean.no.permission", "" + issueContext.getProjectObject().getName(), "" + issueContext.getIssueTypeObject().getName())); } } }
public void testGetValueByIndex() { resetEmpty(); ListOrderedMap lom = (ListOrderedMap) map; try { lom.getValue(0); } catch (IndexOutOfBoundsException ex) {} try { lom.getValue(-1); } catch (IndexOutOfBoundsException ex) {} resetFull(); lom = (ListOrderedMap) map; try { lom.getValue(-1); } catch (IndexOutOfBoundsException ex) {} try { lom.getValue(lom.size()); } catch (IndexOutOfBoundsException ex) {} int i = 0; for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) { it.next(); assertSame(it.getValue(), lom.getValue(i)); } }
public Object remove(int index) { return this.parent.remove(index); } }
public boolean isEmpty() { return this.parent.isEmpty(); }