void configureWith(int count) { poolIndex = 0; pool.setSize(0); pool.ensureCapacity(count); for (int i = 0; i < count; i++) { pool.add(world.create(archetype)); } Arrays.sort(pool.getData(), 0, pool.size()); }
IntBag.prototype.size=0; IntBag.prototype.clone = function() { var clone = new IntBag(); this.each(function(i, count) { clone.add(i, count);
/** * Removes the first occurrence of the value from this IntBag, if * it is present. * * @param value * the value to be removed * * @return true, if value was removed */ public boolean removeValue(int value) throws ArrayIndexOutOfBoundsException { int index = indexOf(value); if (index > -1) remove(index); return index > -1; }
@Override public IntBag read(Json json, JsonValue jsonData, Class type) { recursionLevel++; IntBag bag = new IntBag(); if (recursionLevel == 1) { JsonValue entityArray = jsonData.child; JsonValue entity = entityArray; while (entity != null) { Entity e = json.readValue(Entity.class, entity.child); translatedIds.set(Integer.parseInt(entity.name), e); bag.add(e.getId()); entity = entity.next; } } else { for (JsonValue child = jsonData.child; child != null; child = child.next) { bag.add(json.readValue(Integer.class, child)); } } recursionLevel--; return bag; }
public void setAll() { array.add("array"); bag.add("bag"); hashSet.add("hashSet"); arrayList.add("arrayList"); list.add("list"); hashMap.put("key", "map"); intBag.add(1); map.put("lock", "unlocked"); objectMap.put("obj", "map"); }
/** * Subscribe T to entity. * <p/> * Does nothing if already subscribed. * * @param subscriber subscriber * @param entityId entity to subscribe. */ public void subscribe(T subscriber, int entityId) { // hook subscriber to entity. IntBag entities = subscriberEntities.get(subscriber); if (entities == null) { entities = new IntBag(); subscriberEntities.put(subscriber, entities); } if (!entities.contains(entityId)) { entities.add(entityId); } // hook entity to subscriber. Bag<T> subscribers = entitySubscribers.get(entityId); if (subscribers == null) { subscribers = new Bag<>(); entitySubscribers.set(entityId, subscribers); } if (!subscribers.contains(subscriber)) { subscribers.add(subscriber); } }
IntBag xNeighbors = new IntBag(8); IntBag yNeighbors = new IntBag(8); // Get moore neighbors Bag neigh = s.protonLayer.getMooreNeighbors(location.getX(), location.getY(), 1, Grid2D.BOUNDED, new Bag(), xNeighbors, yNeighbors ); for (int i = 0; i < xNeighbors.numObjs; i++) { System.out.print(" x = " + xNeighbors.get(i)); System.out.println(" : y = " + yNeighbors.get(i));}
/** * Decodes the set bits as integers. The destination * {@link IntBag} is reset before the bits are transposed. * * @param out decoded ints end up here * @return Same as out */ public IntBag toIntBag(IntBag out) { out.setSize(0); if (isEmpty()) return out; for (int id = nextSetBit(0); id >= 0; id = nextSetBit(id + 1)) { out.add(id); } return out; }
/** * Removes from the underlying collection the last element returned by this iterator (optional operation). * This method can be called only once per call to next(). * The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method. * * @throws IllegalStateException - if the next() method has not yet been called, or the remove() method has already been called after the last call to the next() method */ public void remove() { if (state == State.NEXT_CALLED && index < indexEnd && indexEnd <= intBag.size()) { state = State.REMOVE_CALLED; intBag.remove(index); index--; indexEnd--; assert index < indexEnd; } else { throw new IllegalStateException(getErrorMessage(index)); } }
/** * Decodes the set bits as integers. The destination * {@link IntBag} is reset before the bits are transposed. * * @param out decoded ints end up here * @return Same as out */ public IntBag toIntBag(IntBag out) { if (isEmpty()) { out.setSize(0); return out; } int count = prepareBag(out, 1); int[] data = out.getData(); for (int i = 0, index = 0; count > index; i++) { long bitset = words[i]; int wordBits = i << 6; while (bitset != 0) { long t = bitset & -bitset; data[index] = wordBits + Long.bitCount(t - 1); bitset ^= t; index++; } } return out; }
public static IntBag toIntBag(BitSet bs, IntBag out) { if (bs.isEmpty()) { out.setSize(0); return out; } int size = bs.cardinality(); out.setSize(size); out.ensureCapacity(size); int[] activesArray = out.getData(); for (int i = 0, id = -1, s = size; s > i; i++) { id = bs.nextSetBit(id + 1); activesArray[i] = id; } return out; }
@Override protected void check(int id) { // -1 == not linked int target = fieldMutator.read(mapper.get(id), field); if (target != -1 && !activeEntityIds.unsafeGet(target)) { // target is dead or linked field is set to null/-1 target = -1; fieldMutator.write(target, mapper.get(id), field); } int oldTarget = sourceToTarget.get(id); if (target != oldTarget) { if (listener != null) { fireLinkListener(id, target); } sourceToTarget.set(id, target); } }
/** * generate error message */ private String getErrorMessage(final int indexVal) { final String message = "Tried accessing element: " + indexVal + "/" + indexEnd + "/" + intBag.size() + "/" + state.name(); return message; }