public Map<String, ?> getInfo() { Map<String, Boolean> info = new MiniMap<>(3); info.put("acceptRequest", accept); info.put("rejectRequest", reject); info.put("cancelRequest", cancel); return info; }
/** * @see java.util.Map#putAll(java.util.Map) */ @Override public void putAll(final Map<? extends K, ? extends V> map) { for (final Entry<? extends K, ? extends V> entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } }
final int index = findKey(key); final int nullIndex = nextNullKey(lastSearchIndex); lastSearchIndex = nextIndex(nullIndex); keys[nullIndex] = key; values[nullIndex] = value;
/** * Finds a key by starting at lastSearchIndex and searching from there. If the key is found, * lastSearchIndex is advanced so the next key search can find the next key in the array, which * is the most likely to be retrieved. * * @param key * Key to find in map * @return Index of matching key or -1 if not found */ private int findKey(final Object key) { if (size > 0) { // Find key starting at search index final int index = findKey(lastSearchIndex, key); // Found match? if (index != -1) { // Start search at the next index next time lastSearchIndex = nextIndex(index); // Return index of key return index; } } return -1; }
@Override public MiniMap<Object, Object> read(final Kryo kryo, final Input input, final Class<? extends MiniMap<Object, Object>> type) { final int maxEntries = input.readInt( true ); final MiniMap<Object, Object> result = new MiniMap<Object, Object>( maxEntries ); final int size = input.readInt( true ); for ( int i = 0; i < size; i++ ) { final Object key = kryo.readClassAndObject( input ); final Object value = kryo.readClassAndObject( input ); result.put( key, value ); } return result; }
/** * Finds the index of the next non-null key. If the map is empty, -1 will be returned. * * @param start * Index to start at * @return Index of next non-null key */ private int nextKey(final int start) { int i = start; do { if (keys[i] != null) { return i; } i = nextIndex(i); } while (i != start); return -1; }
/** * @see java.util.Map#containsKey(java.lang.Object) */ @Override public boolean containsKey(final Object key) { return findKey(0, key) != -1; }
public PageParameters getPageParameters() { PageParameters result = new PageParameters(); if (parameters != null) { for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) { Entry entry = (Entry)i.next(); result.put(entry.getKey(), entry.getValue()); } } return result; }
@Override public void write(final Kryo kryo, final Output output, final MiniMap<Object, Object> map) { output.writeInt(getMaxEntries( map ), true); output.writeInt( map.size(), true); for (final Entry<?, ?> entry : map.entrySet()) { kryo.writeClassAndObject(output, entry.getKey()); kryo.writeClassAndObject(output, entry.getValue()); } if ( TRACE ) trace( "kryo", "Wrote map: " + map ); }
/** * @see java.util.Map#containsValue(java.lang.Object) */ public boolean containsValue(final Object value) { return findValue(0, value) != -1; }
/** * Constructor * * @param map * The map * @param maxEntries * The maximum number of entries this map can hold */ public MiniMap(final Map<? extends K, ? extends V> map, final int maxEntries) { this(maxEntries); putAll(map); }
@Override public MiniMap<Object, Object> read(final Kryo kryo, final Input input, final Class<? extends MiniMap<Object, Object>> type) { final int maxEntries = input.readInt( true ); final MiniMap<Object, Object> result = new MiniMap<Object, Object>( maxEntries ); final int size = input.readInt( true ); for ( int i = 0; i < size; i++ ) { final Object key = kryo.readClassAndObject( input ); final Object value = kryo.readClassAndObject( input ); result.put( key, value ); } return result; }
/** * Finds the index of the next non-null key. If the map is empty, -1 will be returned. * * @param start * Index to start at * @return Index of next non-null key */ private int nextKey(final int start) { int i = start; do { if (keys[i] != null) { return i; } i = nextIndex(i); } while (i != start); return -1; }
/** * Finds a key by starting at lastSearchIndex and searching from there. If the key is found, * lastSearchIndex is advanced so the next key search can find the next key in the array, which * is the most likely to be retrieved. * * @param key * Key to find in map * @return Index of matching key or -1 if not found */ private int findKey(final Object key) { if (size > 0) { // Find key starting at search index final int index = findKey(lastSearchIndex, key); // Found match? if (index != -1) { // Start search at the next index next time lastSearchIndex = nextIndex(index); // Return index of key return index; } } return -1; }
/** * @see java.util.Map#containsKey(java.lang.Object) */ public boolean containsKey(final Object key) { return findKey(0, key) != -1; }
/** * @return page parameters */ public PageParameters getPageParameters() { PageParameters result = new PageParameters(); if (parameters != null) { for (Iterator<Entry<String, Object>> i = parameters.entrySet().iterator(); i.hasNext();) { Entry<String, Object> entry = i.next(); result.put(entry.getKey(), entry.getValue()); } } return result; }
@Override public void write(final Kryo kryo, final Output output, final MiniMap<Object, Object> map) { output.writeInt(getMaxEntries( map ), true); output.writeInt( map.size(), true); for (final Entry<?, ?> entry : map.entrySet()) { kryo.writeClassAndObject(output, entry.getKey()); kryo.writeClassAndObject(output, entry.getValue()); } if ( TRACE ) trace( "kryo", "Wrote map: " + map ); }
/** * @see java.util.Map#containsValue(java.lang.Object) */ @Override public boolean containsValue(final Object value) { return findValue(0, value) != -1; }
/** * Constructor * * @param map * The map * @param maxEntries * The maximum number of entries this map can hold */ public MiniMap(final Map<? extends K, ? extends V> map, final int maxEntries) { this(maxEntries); putAll(map); }
private MiniMap pageParametersToMiniMap(PageParameters parameters) { if (parameters != null) { MiniMap map = new MiniMap(parameters, parameters.keySet().size()); return map; } else { return null; } }