/** * Given an A object key, finds the position in the ordering that A has, or -1 if key is not present. * Unlike {@link java.util.List#indexOf(Object)}, this runs in constant time. * @param key the A to find the position of * @return the int index of key in the ordering, or -1 if it is not present */ public int indexOfA(Object key) { return keysA.getInt(key); } /**
public int[] getArray(K[] keys) { if(keys == null) return new int[0]; int len = keys.length; int[] vals = new int[len]; for (int i = 0; i < len; i++) { vals[i] = getInt(keys[i]); } return vals; }
/** * Given a B object key, finds the position in the ordering that B has, or -1 if key is not present. * Unlike {@link java.util.List#indexOf(Object)}, this runs in constant time. * @param key the B to find the position of * @return the int index of key in the ordering, or -1 if it is not present */ public int indexOfB(Object key) { return keysB.getInt(key); }
public int indexOf(CharSequence item) { return names.getInt(item); } public char[][] getChars(CharSequence item)
/** * Gets the identifying number corresponding to the given name. * @param name the name to look up, like "room1" * @return the corresponding identifying number, or -1 if no such name exists */ public int nameToNumber(String name) { return names.getInt(name); }
public int[] getArray(Collection<? extends K> keys) { if(keys == null) return new int[0]; int len = keys.size(), i = 0; int[] vals = new int[len]; for(K k : keys) { vals[i++] = getInt(k); } return vals; }
public int[][] getInts(CharSequence item) { int i = names.getInt(item); int[][] d = null; if(i >= 0 && i < intMaps.size()) { d = intMaps.get(i); } return d; }
public double[][] getDoubles(CharSequence item) { int i = names.getInt(item); double[][] d = null; if(i >= 0 && i < charMaps.size()) { d = doubleMaps.get(i); } return d; }
public float[][] getFloats(CharSequence item) { int i = names.getInt(item); float[][] d = null; if(i >= 0 && i < floatMaps.size()) { d = floatMaps.get(i); } return d; }
/** * Takes a String produced by {@link #toMnemonic(long)} or {@link #toMnemonic(long, boolean)} and returns the long * used to encode that gibberish String. This can't take just any String; if the given parameter isn't at least 24 * characters long, this can throw an {@link IndexOutOfBoundsException}, and if it isn't made purely from the 3-char * syllables toMnemonic() produces, it won't produce a meaningful result. * @param mnemonic a gibberish String produced by {@link #toMnemonic(long)} or {@link #toMnemonic(long, boolean)} * @return the long used to generate {@code mnemonic} originally */ public long fromMnemonic(String mnemonic) { long result = 0L; for (int i = 0; i < 8; i++) { result |= (items.getInt(mnemonic.substring(i * 3, i * 3 + 3)) & 0xFFL) << (i << 3); } return result; }
public char[][] getChars(CharSequence item) { int i = names.getInt(item); char[][] d = null; if(i >= 0 && i < charMaps.size()) { d = charMaps.get(i); } return d; }
/** * Given an A object, finds the associated B object (it will be at the same point in the ordering). * @param key an A object to use as a key * @return the B object associated with key, or null if key was not present */ public B getBFromA(Object key) { return keysB.keyAt(keysA.getInt(key)); }
/** * Returns the weight of the item if the item is in the table. Returns zero * if the item is not in the table. * * @param item the item searched for * @return the weight of the item, or zero */ public int weight(T item) { int i = table.getInt(item); return i < 0 ? 0 : weights.get(i); }
public int addIfAbsent(final K k) { int kPos; if((kPos = getInt(k)) < 0) return add(k); return kPos; }
/** * Given a B object, finds the associated A object (it will be at the same point in the ordering). * @param key a B object to use as a key * @return the A object associated with key, or null if key was not present */ public A getAFromB(Object key) { return keysA.keyAt(keysB.getInt(key)); }
/** * Given an E element key that could be used in one or more bundles this uses, gets all indices in the ordering * that contain a bundle with that element. From such an index, you can use {@link #getSingleAt(int)} to get the * S key at that position, {@link #getBundleElementsAt(int)} to get the E element keys at that position, * {@link #getBundleVariationAt(int)} to get the possible variation at that position, or {@link #getCodeAt(int)} to * get the coded bundle at that position. * @return an OrderedSet of all coded 2D int array bundles that contain the given element, or null if E is not in any bundles */ public int[] getManyIndices(E element) { if(element == null) return null; int pos; if((pos = elements.getInt(element)) < 0) return null; return mm.get(pos).toArray(); }
/** * Given an index of the keyset to look up a key in (lookingUp), an index of the keyset to get from (getting), and * an Object key to look up (key), finds the Object key in the keyset specified by getting that is associated with * key in the keyset specified by lookingUp. key and the returned value will be at the same point in the ordering. * @param lookingUp which keyset to look up the {@code key} parameter in * @param getting which keyset to get a value from * @param key an object to use as a key, which should be the right type for the keyset at lookingUp * @return the object from getting's keyset that is associated with key, or null if key was not present */ public Object getFrom(int lookingUp, int getting, Object key) { if(lookingUp >= 0 && lookingUp < keyCount && getting >= 0 && getting < keyCount) return keys[getting].keyAt(keys[lookingUp].getInt(key)); return null; }
/** * Given an E element key that could be used in one or more bundles this uses, gets all bundles in this object that * contain the given element, as coded 2D int arrays. These coded bundles can be given to * {@link #elementsFromCode(int[][])} and {@link #variationFromCode(int[][])} to get usable information from them. * @param element an E element key to look up (probably a component of one or more bundles) * @return an OrderedSet of all coded 2D int array bundles that contain the given element, or null if E is not in any bundles */ public OrderedSet<int[][]> getManyCoded(E element) { if(element == null) return null; int pos; if((pos = elements.getInt(element)) < 0) return null; return bm.keysA.keysAt(mm.get(pos)); }
/** * Given an E1 element key that could be used in one or more bundles this uses, gets all bundles in this object that * contain the given element, as coded 2D int arrays. These coded bundles can be given to * {@link #elementsFromCode(int[][])} and {@link #variationFromCode(int[][])} to get usable information from them. * @param element an E1 element key to look up (probably a component of one or more bundles) * @return an OrderedSet of all coded 2D int array bundles that contain the given element, or null if E1 is not in any bundles */ public OrderedSet<int[][]> getManyCoded(E1 element) { if(element == null) return null; int pos; if((pos = elements1.getInt(element)) < 0) return null; return bm.keysA.keysAt(mm1.get(pos)); }
public IntVLA getMany(Iterable<? extends K> keys) { if(keys == null) return new IntVLA(); IntVLA vals = new IntVLA(); for(K k : keys) { vals.add(getInt(k)); } return vals; }