public IntMapGraph(Int2ObjectMap<IntSet> map) { this.map = map; if (map.defaultReturnValue() == null || !map.defaultReturnValue().equals(IntSets.EMPTY_SET)) { LOGGER.warn("It is necessary to set default return value of the map as the empty set."); map.defaultReturnValue(IntSets.EMPTY_SET); } int maxNodeIndex = 0, numArcs = 0; for (Entry<IntSet> x : map.int2ObjectEntrySet()) { if (x.getIntKey() > maxNodeIndex) maxNodeIndex = x.getIntKey(); for (int succ : x.getValue()) { if (succ > maxNodeIndex) maxNodeIndex = succ; numArcs++; } } this.numArcs = numArcs; this.numNodes = maxNodeIndex+1; }
public void addQuantity(WorldObject worldObject, int quantity) { String name = worldObject.getProperty(Constants.NAME); boolean found = false; for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject object = entry.getValue(); if (object.getProperty(Constants.NAME).equals(name)) { object.setProperty(Constants.QUANTITY, object.getProperty(Constants.QUANTITY) + quantity); found = true; return; } } if (!found) { worldObject.setProperty(Constants.QUANTITY, quantity); add(worldObject); } }
@Override public double error(FM fm, ListWiseFMData test) { return test.streamByGroup().map(Entry::getValue) .mapToDouble((List<? extends FMInstance> group) -> { double[] p = getP(group); double[] q = getQ(fm, group); return IntStream.range(0, group.size()) .mapToDouble(i -> -p[i] * log(q[i])) .sum(); }) .average().getAsDouble(); }
public void checkAgreementWith(ImmutableGraph g, Int2ObjectFunction<String> names) { for (Entry<IntSet> q2ev : query2evaluateddocs.int2ObjectEntrySet()) { int query = q2ev.getIntKey(); IntSet successors = new IntOpenHashSet(g.successorArray(query), 0, g.outdegree(query)); for (int evaluated : q2ev.getValue()) { if (!successors.contains(evaluated)) { LOGGER.error( "The query " + names.get(query) + " contains evaluated document " + names.get(evaluated) + ", but this was not present in its successors" ); } } } }
public<T> void removeQuantity(ManagedProperty<T> propertyKey, int quantity) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject object = entry.getValue(); if (object.hasProperty(propertyKey)) { object.increment(Constants.QUANTITY, -quantity); if (object.getProperty(Constants.QUANTITY) == 0) { worldObjects.remove(entry.getIntKey()); } return; } } }
public<T> int getQuantityFor(ManagedProperty<T> propertyKey) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey)) { return worldObject.getProperty(Constants.QUANTITY); } } return 0; }
public int getQuantityFor(ManagedProperty<?> propertyKey1, ManagedProperty<?> propertyKey2, Function<WorldObject, Boolean> testFunction) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey1) && worldObject.hasProperty(propertyKey2)) { if (testFunction.apply(worldObject)) { return worldObject.getProperty(Constants.QUANTITY); } } } return 0; }
public<T> List<WorldObject> getWorldObjects(ManagedProperty<T> propertyKey, T value) { List<WorldObject> result = new ArrayList<>(); for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey)) { if (worldObject.getProperty(propertyKey) == value) { result.add(worldObject); } } } return result; }
public List<WorldObject> getWorldObjectsByFunction(ManagedProperty<?> propertyKey, Function<WorldObject, Boolean> testFunction) { List<WorldObject> result = new ArrayList<>(); for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey)) { if (testFunction.apply(worldObject)) { result.add(worldObject); } } } return result; }
public<T> int getIndexFor(Function<WorldObject, Boolean> testFunction) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (testFunction.apply(worldObject)) { return entry.getIntKey(); } } return -1; }
public<T> int getIndexFor(ManagedProperty<T> propertyKey) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey)) { return entry.getIntKey(); } } return -1; }
public<T> int getIndexFor(ManagedProperty<T> propertyKey, Function<WorldObject, Boolean> testFunction) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey) && testFunction.apply(worldObject)) { return entry.getIntKey(); } } return -1; }
public<T> int getIndexFor(ManagedProperty<T> propertyKey, T value) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey) && worldObject.getProperty(propertyKey) == value) { return entry.getIntKey(); } } return -1; }
public<T> int getIndexFor(ManagedProperty<T> propertyKey, T value, Function<WorldObject, Boolean> testFunction) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey) && (worldObject.getProperty(propertyKey) == value) && testFunction.apply(worldObject)) { return entry.getIntKey(); } } return -1; }
public<T> void removeAllQuantity(ManagedProperty<T> propertyKey) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(propertyKey)) { worldObjects.remove(entry.getIntKey()); return; } } }
public WorldObjectContainer copy() { WorldObjectContainer result = new WorldObjectContainer(); result.currentIndex = currentIndex; for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); result.worldObjects.put(entry.getIntKey(), worldObject.deepCopy()); } return result; }
public int getIndexFor(StringProperty property, String value, Function<WorldObject, Boolean> testFunction) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject.hasProperty(property) && worldObject.getProperty(property).equals(value)) { if (testFunction.apply(worldObject)) { return entry.getIntKey(); } } } return -1; }
public int getIndexFor(WorldObject worldObjectToFind) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); if (worldObject == worldObjectToFind) { return entry.getIntKey(); } } return -1; }
public void moveItemsFrom(WorldObjectContainer otherInventory) { ObjectIterator<Entry<WorldObject>> iterator = otherInventory.worldObjects.int2ObjectEntrySet().fastIterator(); while(iterator.hasNext()) { Entry<WorldObject> otherEntry = iterator.next(); WorldObject otherWorldObject = otherEntry.getValue(); if (otherWorldObject.getProperty(Constants.QUANTITY) == null) { throw new IllegalStateException("otherWorldObject.getProperty(Constants.QUANTITY) is null: " + otherWorldObject); } addQuantity(otherWorldObject, otherWorldObject.getProperty(Constants.QUANTITY)); iterator.remove(); } }
public int getUnmodifiedTotalWeight() { int totalWeight = 0; for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject worldObject = entry.getValue(); Integer weight = worldObject.getProperty(Constants.WEIGHT); if (weight != null) { int quantity = worldObject.getProperty(Constants.QUANTITY); totalWeight += (weight.intValue() * quantity); } } return totalWeight; }
@Override public Stream<Entry<List<? extends FMInstance>>> streamByGroup() { return groupList.stream() .map(i -> new AbstractInt2ObjectMap.BasicEntry<>(i, map.get(i))); }
public ObjectSet<Int2DoubleMap.Entry> getEvaluatedDocsWithNumericRelevance(int query) { return query2doc2relevance.get(query).int2DoubleEntrySet(); }
public void iterate(ObjIntConsumer<WorldObject> consumer) { for(Entry<WorldObject> entry : worldObjects.int2ObjectEntrySet()) { WorldObject object = entry.getValue(); consumer.accept(object, entry.getIntKey()); } }
public Stream<Entry<List<? extends FMInstance>>> streamByGroup();