/** * Adds the counts from the provided {@code Counter} to the current counts, adding new elements as * needed. */ public void add(Counter<? extends T> counter) { for (Map.Entry<? extends T, Integer> e : counter) { T t = e.getKey(); Integer cur = counts.get(t); counts.put(t, (cur == null) ? e.getValue() : cur + e.getValue()); } }
/** Counts the object, increasing its total count by 1. */ public int count(T obj) { int count = counts.get(obj); count++; counts.put(obj, count); sum++; return count; }
/** * Counts the object, increasing its total count by the specified positive amount. * * @param count a positive value for the number of times the object occurred * @throws IllegalArgumentException if {@code count} is not a positive value. */ public int count(T obj, int count) { if (count < 1) throw new IllegalArgumentException("Count must be positive: " + count); int oldCount = counts.get(obj); int newCount = count + oldCount; counts.put(obj, newCount); sum += count; return newCount; }
public boolean equals(Object o) { if (o instanceof Counter) { Counter<?> c = (Counter<?>) o; if (counts.size() != c.size() || sum != c.sum()) return false; for (Map.Entry<?, Integer> e : c) { int i = counts.get(e.getKey()); if (i != e.getValue()) return false; } return true; } return false; }
private void load() { logger.trace("Loading creature postures datatable."); final DataTable dataTable = dataTableManager.getTable(dataTableName); for (int row = 0; row < dataTable.getNumRows(); ++row) { postures.put(dataTable.getStringValue("posture", row), dataTable.getIntValue("value", row)); } dataTableManager.close(dataTableName); logger.debug(String.format("Loaded %d creature postures.", postures.size())); }
@Override public void reload() { synchronized (this) { postures.clear(); load(); } }
/** * Replaces the contents of this vertex data by the provided one. This is a deep copy. The vertex * attribute are each individually cloned. * * @param data The data to copy. */ public void copy(VertexData data) { clear(); indices.addAll(data.indices); final TIntObjectIterator<VertexAttribute> iterator = data.attributes.iterator(); while (iterator.hasNext()) { iterator.advance(); attributes.put(iterator.key(), iterator.value().clone()); } nameToIndex.putAll(data.nameToIndex); }
/** * Sets a property of the window * * @param id of the property * @param value value of property */ public void setProperty(int id, int value) { properties.put(id, value); switch (Spout.getPlatform()) { case PROXY: case SERVER: callProtocolEvent(new WindowPropertyEvent(this, id, value)); break; case CLIENT: // TODO: Window properties break; default: throw new IllegalStateException("Unknown platform: " + Spout.getPlatform()); } }
/** * Returns the index associated to the attribute name, or -1 if no attribute has the name. * * @param name The name to lookup * @return The index, or -1 if no attribute has the name */ public int getAttributeIndex(String name) { return nameToIndex.get(name); }
/** * Returns the value of the specified property. * * @param prop * @return value of property */ public int getProperty(WindowProperty prop) { return properties.get(prop); }
/** * Returns an unmodifiable set of all the attribute names. * * @return A set of all the attribute names */ public Set<String> getAttributeNames() { return Collections.unmodifiableSet(nameToIndex.keySet()); }
/** * Returns a view of the items currently being counted. The returned view is read-only; any * attempts to modify this view will throw an {@link UnsupportedOperationException}. */ public Set<T> items() { return Collections.unmodifiableSet(counts.keySet()); }
public int hashCode() { return counts.hashCode(); }
/** Returns the number of times the specified object has been seen by this counter. */ public int getCount(T obj) { return counts.get(obj); }
/** * Returns true if an attribute has the provided name. * * @param name The name to lookup * @return Whether or not an attribute possesses the name */ public boolean hasAttribute(String name) { return nameToIndex.containsKey(name); }
/** * Removes the attribute at the provided index. If no attribute is found, nothing will be removed. * * @param index The index of the attribute to remove */ public void removeAttribute(int index) { attributes.remove(index); nameToIndex.remove(getAttributeName(index)); }
/** Resets the counts for all objects. The size of {@link #items()} will be 0 after this call. */ public void reset() { counts.clear(); sum = 0; }
/** Clears all the vertex data. */ public void clear() { indices.clear(); attributes.clear(); nameToIndex.clear(); }
/** Returns the number of instances that are currently being counted. */ public int size() { return counts.size(); }
/** * Adds an attribute. * * @param attribute The attribute to add */ public void addAttribute(int index, VertexAttribute attribute) { attributes.put(index, attribute); nameToIndex.put(attribute.getName(), index); }
@Override public String toString() { return counts.toString(); }