public int hardcodedSequenceEndIndex(int fromIndex) { if (hardcoded() && (nextSlot == null || !nextSlot.hardcoded())) { // I'm last hardcoded slot return fromIndex + 1; } if (hardcoded() && nextSlot.hardcoded()) { // me and my next neighbour are hardcoded return nextSlot.hardcodedSequenceEndIndex(++fromIndex); } // i'm not even hardcoded return -1; }
public boolean anyInputToTheRight() { if (value != null && !hardcoded()) { return true; } if (nextSlot != null) { return nextSlot.anyInputToTheRight(); } return false; }
public boolean canInsertHere(char newValue) { newValue = valueInterpreter == null ? newValue : valueInterpreter.interpret(newValue); if (hardcoded()) { return value.equals(newValue); } return validate(newValue); }
private void removeCurrentValue() { if (!hardcoded()) { value = pullValueFromSlot(nextSlot); } else if (prevSlot != null) { prevSlot.removeCurrentValue(); } }
private boolean filledFrom(final Slot initialSlot) { if (initialSlot == null) { throw new IllegalArgumentException("first slot is null"); } Slot nextSlot = initialSlot; do { if (!nextSlot.hasTag(TAG_EXTENSION)) { if (!nextSlot.hardcoded() && nextSlot.getValue() == null) { return false; } } nextSlot = nextSlot.getNextSlot(); } while (nextSlot != null); return true; }
/** * Looks for a slot to insert {@code value}. Search moves to the right from the specified one * (including it). While searching it checks whether the're any non-hardcoded slots that cannot * accept pending input if such slots are found it is marked in a resulting object. * * @param slot slot from where to start * @param value value to be inserted to slot * @return wrapper around index offset to the found slot and flag showing did search skip any * non-hardcoded slots */ private SlotIndexOffset validSlotIndexOffset(Slot slot, final char value) { final SlotIndexOffset result = new SlotIndexOffset(); while (slot != null && !slot.canInsertHere(value)) { if (!result.nonHarcodedSlotSkipped && !slot.hardcoded()) { result.nonHarcodedSlotSkipped = true; } slot = slot.getNextSlot(); result.indexOffset++; } return result; }
if (slots.checkIsIndex(cursorPosition)) { final Slot s = slots.getSlot(cursorPosition); if (s != null && (!s.hardcoded() || (removeHardcoded && count == 1))) { cursorPosition += s.setValue(null); do { slot = slots.getSlot(--tmpPosition); } while (slot != null && slot.hardcoded() && tmpPosition > 0); if (slots.checkIsIndex(position) && slots.getSlot(position).hardcoded() && count == 1) { cursorPosition = tmpPosition; } else {
private int setNewValue(int offset, @NonNull Character newValue, boolean fromLeft) { boolean changeCurrent = true; final boolean forbiddenInputFromLeft = fromLeft && checkRule(RULE_INPUT_MOVES_INPUT) && !checkRule(RULE_INPUT_REPLACE); if (hardcoded() && !forbiddenInputFromLeft && value.equals(newValue)) { return checkRule(RULE_FORBID_CURSOR_MOVE_RIGHT) ? offset : offset + 1; } int newOffset = 0; if (checkRule(RULE_INPUT_MOVES_INPUT) || forbiddenInputFromLeft) { // we should push new value further without replacing the current one newOffset = pushValueToSlot(offset + 1, newValue, nextSlot); changeCurrent = false; } if (value != null && ((rulesFlags & MASK_INPUT_RULES) == RULES_DEFAULT)) { // we should push current value further without pushValueToSlot(0, value, nextSlot); } if (changeCurrent) { value = newValue; newOffset = checkRule(RULE_FORBID_CURSOR_MOVE_RIGHT) ? offset : offset + 1; } return newOffset; }
private Character pullValueFromSlot(Slot slot) { if (slot == null) { return null; } Character result = null; if (!slot.hardcoded()) { result = slot.getValue(); if (result != null && !validate(result)) { return null; } slot.removeCurrentValue(); } else if (slot.getNextSlot() != null) { result = pullValueFromSlot(slot.getNextSlot()); } return result; }