private String slotsToString() { final StringBuilder result = new StringBuilder(slots.length); for (Slot slot : slots) { Character value = slot.getValue(); if (value == null) { value = Slot.PLACEHOLDER_DEFAULT; } result.append(value); } return result.toString(); } }
private int emptySlotsOnTail() { int count = 0; Slot slot = slots.getLastSlot(); while (slot != null && slot.getValue() == null) { count++; slot = slot.getPrevSlot(); } return count; }
@Override public int getInitialInputPosition() { int cursorPosition = 0; Slot slot = slots.getSlot(cursorPosition); while (slot != null && slot.getValue() != null) { cursorPosition++; slot = slot.getNextSlot(); } return cursorPosition; }
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; }
int index = 0; while (slot != null) { Character c = slot.getValue();
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; }
@Test public void invalidValueNotRemovedFromNext() { Slot first = new Slot('0', new SlotValidators.DigitValidator()); Slot second = new Slot('a', new SlotValidators.LetterValidator()); first.setNextSlot(second); second.setPrevSlot(first); first.setValue(null); Assert.assertEquals(new Character('a'), second.getValue()); }
@Test public void validValueCopiedFromNext() { Slot first = new Slot('1', new SlotValidators.DigitValidator()); Slot second = new Slot('2', new SlotValidators.DigitValidator()); first.setNextSlot(second); second.setPrevSlot(first); first.setValue(null); Assert.assertEquals(new Character('2'), first.getValue()); }
@Test public void clear() throws Exception { SlotsList list2 = SlotsList.ofArray(new Slot[]{ PredefinedSlots.any(), PredefinedSlots.any(), PredefinedSlots.any(), PredefinedSlots.digit(), }); for (Slot slot : list2) { slot.setValue('0'); assertNotNull(slot.getValue()); } list2.clear(); for (Slot slot : list2) { assertNull(slot.getValue()); } }
@Test public void validValueRemovedFromNext() { Slot first = new Slot('1', new SlotValidators.DigitValidator()); Slot second = new Slot('2', new SlotValidators.DigitValidator()); first.setNextSlot(second); second.setPrevSlot(first); first.setValue(null); Assert.assertNull(second.getValue()); }
@Test public void invalidValueNotCopiedFromNext() { Slot first = new Slot('0', new SlotValidators.DigitValidator()); Slot second = new Slot('a', new SlotValidators.LetterValidator()); first.setNextSlot(second); second.setPrevSlot(first); first.setValue(null); Assert.assertNull(first.getValue()); }