/** * Applies a procedure to each (key,value) pair of the receiver, if any. Iteration order is guaranteed to be * <i>identical</i> to the order used by method {@link #forEachKey(ByteProcedure)}. * * @param procedure the procedure to be applied. Stops iteration if the procedure returns <tt>false</tt>, otherwise * continues. * @return <tt>false</tt> if the procedure stopped before all keys where iterated over, <tt>true</tt> otherwise. */ @Override public boolean forEachPair(ByteByteProcedure procedure) { for (int i = table.length; i-- > 0;) { if (state[i] == FULL && !procedure.apply(table[i], values[i])) { return false; } } return true; }
@Override public boolean apply(byte key) { return procedure.apply(key, get(key)); } }
@Override public boolean apply(byte key, byte value) { if (condition.apply(key, value)) { keyList.add(key); valueList.add(value); } return true; } }
/** * Fills all pairs satisfying a given condition into the specified lists. Fills into the lists, starting at index 0. * After this call returns the specified lists both have a new size, the number of pairs satisfying the condition. * Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link * #forEachKey(ByteProcedure)}. <p> <b>Example:</b> <br> * <pre> * ByteByteProcedure condition = new ByteByteProcedure() { // match even values only * public boolean apply(byte key, byte value) { return value%2==0; } * } * keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt> * </pre> * * @param condition the condition to be matched. Takes the current key as first and the current value as second * argument. * @param keyList the list to be filled with keys, can have any size. * @param valueList the list to be filled with values, can have any size. */ @Override public void pairsMatching(ByteByteProcedure condition, ByteArrayList keyList, ByteArrayList valueList) { keyList.clear(); valueList.clear(); for (int i = table.length; i-- > 0;) { if (state[i] == FULL && condition.apply(table[i], values[i])) { keyList.add(table[i]); valueList.add(values[i]); } } }
/** * Applies a procedure to each (key,value) pair of the receiver, if any. Iteration order is guaranteed to be * <i>identical</i> to the order used by method {@link #forEachKey(ByteProcedure)}. * * @param procedure the procedure to be applied. Stops iteration if the procedure returns <tt>false</tt>, otherwise * continues. * @return <tt>false</tt> if the procedure stopped before all keys where iterated over, <tt>true</tt> otherwise. */ @Override public boolean forEachPair(ByteByteProcedure procedure) { for (int i = table.length; i-- > 0;) { if (state[i] == FULL && !procedure.apply(table[i], values[i])) { return false; } } return true; }
/** * Applies a procedure to each (key,value) pair of the receiver, if any. Iteration order is guaranteed to be * <i>identical</i> to the order used by method {@link #forEachKey(ByteProcedure)}. * * @param procedure the procedure to be applied. Stops iteration if the procedure returns <tt>false</tt>, otherwise * continues. * @return <tt>false</tt> if the procedure stopped before all keys where iterated over, <tt>true</tt> otherwise. */ @Override public boolean forEachPair(ByteByteProcedure procedure) { for (int i = table.length; i-- > 0;) { if (state[i] == FULL) { if (!procedure.apply(table[i], values[i])) { return false; } } } return true; }
@Override public boolean apply(byte key) { return procedure.apply(key, get(key)); } }
@Override public boolean apply(byte key) { return procedure.apply(key, get(key)); } }
@Override public boolean apply(byte key, byte value) { if (condition.apply(key, value)) { keyList.add(key); valueList.add(value); } return true; } }
@Override public boolean apply(byte key, byte value) { if (condition.apply(key, value)) { keyList.add(key); valueList.add(value); } return true; } }
/** * Fills all pairs satisfying a given condition into the specified lists. Fills into the lists, starting at index 0. * After this call returns the specified lists both have a new size, the number of pairs satisfying the condition. * Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link * #forEachKey(ByteProcedure)}. <p> <b>Example:</b> <br> * <pre> * ByteByteProcedure condition = new ByteByteProcedure() { // match even values only * public boolean apply(byte key, byte value) { return value%2==0; } * } * keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt> * </pre> * * @param condition the condition to be matched. Takes the current key as first and the current value as second * argument. * @param keyList the list to be filled with keys, can have any size. * @param valueList the list to be filled with values, can have any size. */ @Override public void pairsMatching(ByteByteProcedure condition, ByteArrayList keyList, ByteArrayList valueList) { keyList.clear(); valueList.clear(); for (int i = table.length; i-- > 0;) { if (state[i] == FULL && condition.apply(table[i], values[i])) { keyList.add(table[i]); valueList.add(values[i]); } } }
/** * Fills all pairs satisfying a given condition into the specified lists. Fills into the lists, starting at index 0. * After this call returns the specified lists both have a new size, the number of pairs satisfying the condition. * Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link * #forEachKey(ByteProcedure)}. <p> <b>Example:</b> <br> * <pre> * ByteByteProcedure condition = new ByteByteProcedure() { // match even values only * public boolean apply(byte key, byte value) { return value%2==0; } * } * keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt> * </pre> * * @param condition the condition to be matched. Takes the current key as first and the current value as second * argument. * @param keyList the list to be filled with keys, can have any size. * @param valueList the list to be filled with values, can have any size. */ @Override public void pairsMatching(ByteByteProcedure condition, ByteArrayList keyList, ByteArrayList valueList) { keyList.clear(); valueList.clear(); for (int i = table.length; i-- > 0;) { if (state[i] == FULL && condition.apply(table[i], values[i])) { keyList.add(table[i]); valueList.add(values[i]); } } }