Beispiel #1
0
 /**
  * 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());
   }
 }
Beispiel #2
0
 /** 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;
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
  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()));
  }
Beispiel #6
0
 @Override
 public void reload() {
   synchronized (this) {
     postures.clear();
     load();
   }
 }
Beispiel #7
0
 /**
  * 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);
 }
Beispiel #8
0
 /**
  * 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());
   }
 }
Beispiel #9
0
 /**
  * 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);
 }
Beispiel #10
0
 /**
  * Returns the value of the specified property.
  *
  * @param prop
  * @return value of property
  */
 public int getProperty(WindowProperty prop) {
   return properties.get(prop);
 }
Beispiel #11
0
 /**
  * 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());
 }
Beispiel #12
0
 /**
  * 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());
 }
Beispiel #13
0
 public int hashCode() {
   return counts.hashCode();
 }
Beispiel #14
0
 /** Returns the number of times the specified object has been seen by this counter. */
 public int getCount(T obj) {
   return counts.get(obj);
 }
Beispiel #15
0
 /**
  * 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);
 }
Beispiel #16
0
 /**
  * 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));
 }
Beispiel #17
0
 /** Resets the counts for all objects. The size of {@link #items()} will be 0 after this call. */
 public void reset() {
   counts.clear();
   sum = 0;
 }
Beispiel #18
0
 /** Clears all the vertex data. */
 public void clear() {
   indices.clear();
   attributes.clear();
   nameToIndex.clear();
 }
Beispiel #19
0
 /** Returns the number of instances that are currently being counted. */
 public int size() {
   return counts.size();
 }
Beispiel #20
0
 /**
  * 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);
 }
Beispiel #21
0
 @Override
 public String toString() {
   return counts.toString();
 }