/** * Factory method to create an ordered map. * <p> * An <code>ArrayList</code> is used to retain order. * * @param <K> the key type * @param <V> the value type * @param map the map to decorate, must not be null * @return a new list ordered map * @throws NullPointerException if map is null * @since 4.0 */ public static <K, V> ListOrderedMap<K, V> listOrderedMap(final Map<K, V> 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 <K> the key type * @param <V> the value type * @param map the map to order, must not be null * @return an ordered map backed by the given map * @throws NullPointerException if the Map is null */ public static <K, V> OrderedMap<K, V> orderedMap(final Map<K, V> map) { return ListOrderedMap.listOrderedMap(map); }
ListOrderedMap optGroupMap = new ListOrderedMap(); while (classGroupIt.hasNext()) { VClassGroup group = (VClassGroup)classGroupIt.next(); List classes = group.getVitroClassList(); optGroupMap.put(group.getPublicName(),FormUtils.makeOptionListFromBeans(classes,"URI","Name",individualForEditing.getVClassURI(),null,false)); foo.setOptionLists(hash); ListOrderedMap dpMap = new ListOrderedMap(); if (!dpMap.containsKey(d.getURI())) { dpMap.put(d.getURI(), d); dpMap.put(existingDp.getURI(), existingDp); Iterator<String> dpHashIt = dpMap.mapIterator(); while (dpHashIt.hasNext()) { String uri = dpHashIt.next(); DataProperty dp = (DataProperty) dpMap.get(uri); DynamicField dynamo = new DynamicField(); dynamo.setName(dp.getPublicName());
@Override public int size() { return this.parent.size(); } @Override
/** * Puts the values contained in a supplied Map into the Map starting at * the specified index. * * @param index the index in the Map to start at. * @param map the Map containing the entries to be added. * @throws IndexOutOfBoundsException if the index is out of range [0, size] */ public void putAll(int index, final Map<? extends K, ? extends V> map) { if (index < 0 || index > insertOrder.size()) { throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + insertOrder.size()); } for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) { final K key = entry.getKey(); final boolean contains = containsKey(key); // The return value of put is null if the key did not exist OR the value was null // so it cannot be used to determine whether the key was added put(index, entry.getKey(), entry.getValue()); if (!contains) { // if no key was replaced, increment the index index++; } else { // otherwise put the next item after the currently inserted key index = indexOf(entry.getKey()) + 1; } } }
/** * Remove the stamp from stack (when resuming) */ private static void popTransactionStartStamp() { ListOrderedMap<Transaction, Timestamp> map = suspendedTxStartStamps.get(); if (map.size() > 0) { transactionStartStamp.set(map.remove(map.lastKey())); } else { Debug.logError("Error in transaction handling - no saved start stamp found - using NOW.", module); transactionStartStamp.set(UtilDateTime.nowTimestamp()); } }
/** * Sets the value at the specified index. * * @param index the index of the value to set * @param value the new value to set * @return the previous value at that index * @throws IndexOutOfBoundsException if the index is invalid * @since 3.2 */ public V setValue(final int index, final V value) { final K key = insertOrder.get(index); return put(key, value); }
/** * Gets the value at the specified index. * * @param index the index to retrieve * @return the key at the specified index * @throws IndexOutOfBoundsException if the index is invalid */ public V getValue(final int index) { return get(insertOrder.get(index)); }
@Override public void clear() { this.parent.clear(); }
public int doEndTag() throws JspException { try { JspWriter out = pageContext.getOut(); List optList = null; ListOrderedMap optGroups = null; try { optList = (List) getFormObject().getOptionLists().get(name); outputOptionsMarkup(optList,out); } catch (ClassCastException e){ // maybe it's a ListOrderedMap of optgroups optGroups = (ListOrderedMap) getFormObject().getOptionLists().get(name); OrderedMapIterator ogKey = optGroups.mapIterator(); while (ogKey.hasNext()) { String optGroupName = (String) ogKey.next(); out.println("<optgroup label=\""+StringEscapeUtils.ESCAPE_HTML4.translate(optGroupName)+"\">"); outputOptionsMarkup((List)optGroups.get(optGroupName),out); out.println("</optgroup>"); } } catch (NullPointerException npe) { System.out.println("OptionTag could not find option list for "+name); } } catch(Exception ex) { ex.printStackTrace(); throw new JspException(ex.getMessage()); } return SKIP_BODY; // EVAL_PAGE; did colnames only //EVAL_PAGE in connection pooled version; } }
/** * Returns the Map as a string. * * @return the Map as a String */ @Override public String toString() { if (isEmpty()) { return "{}"; } final StringBuilder buf = new StringBuilder(); buf.append('{'); boolean first = true; for (final Map.Entry<K, V> entry : entrySet()) { final K key = entry.getKey(); final V 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(); }
/** * Returns a List of Messages, sorted starting from newest to oldest, of all message that have already been retrieved * from Discord with this MessageHistory object using the {@link #retrievePast(int)}, {@link #retrieveFuture(int)}, and * {@link net.dv8tion.jda.core.entities.MessageChannel#getHistoryAround(String, int)} methods. * * @return A List of Messages, sorted newest to oldest. */ public List<Message> getRetrievedHistory() { int size = size(); if (size == 0) return Collections.emptyList(); else if (size == 1) return Collections.singletonList(history.getValue(0)); return Collections.unmodifiableList(new ArrayList<>(history.values())); }
throw new IllegalArgumentException("Message retrieval limit is between 1 and 100 messages. No more, no less. Limit provided: " + amount); if (history.isEmpty()) throw new IllegalStateException("No messages have been retrieved yet, so there is no message to act as a marker to retrieve more recent messages based on."); Route.CompiledRoute route = Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId()).withQueryParams("limit", Integer.toString(amount), "after", String.valueOf(history.firstKey())); return new RestAction<List<Message>>(getJDA(), route)
@Override public boolean isEmpty() { return this.parent.isEmpty(); }
@Override public boolean contains(final Object value) { return this.parent.containsKey(value); }
@Override public V get(final int index) { return this.parent.getValue(index); }
@Override public int size() { return this.parent.size(); }
@Override public void putAll(final Map<? extends K, ? extends V> map) { for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } }