public int setValue(@Nullable Character newValue) { return setValue(newValue, false); }
public void clear() { if (isEmpty()) { return; } // iterate back because by default slots will try to pull new value from next slot // when someone try to remove their value Slot slot = lastSlot; while (slot != null) { slot.setValue(null); slot = slot.getPrevSlot(); } }
/** * Inserts slots at the and of the mask and mark newly inserted slot as 'extension' (extended * tail of non-terminated mask). 'Extended' slots will be removed when their values are cleared */ private void extendTail(int count) { if (terminated || count < 1) { return; } while (--count >= 0) { // create a copy of the last slot and make it the last one final Slot inserted = slots.insertSlotAt(slots.size(), slots.getLastSlot()); inserted.setValue(null); inserted.withTags(TAG_EXTENSION); } }
@Test public void setValueOffset(){ Slot b = new Slot(Slot.RULES_DEFAULT, null, null); assertEquals(1, b.setValue(' ')); assertEquals(1, b.setValue('2')); Slot c = new Slot(Slot.RULES_DEFAULT, null, null); c.setPrevSlot(b); b.setNextSlot(c); assertEquals(1, c.setValue('3')); Slot a = new Slot(Slot.RULE_INPUT_MOVES_INPUT, 'a', null); b.setPrevSlot(a); a.setNextSlot(b); assertEquals(1, a.setValue('a')); assertEquals(2, a.setValue('3')); Slot a0 = new Slot(Slot.RULE_INPUT_MOVES_INPUT, 'a', null); a.setPrevSlot(a); a0.setNextSlot(a); assertEquals(1, a0.setValue('a')); assertEquals(3, a0.setValue(' ')); }
final int insertOffset = slotCandidate.setValue(newValue, slotForInputIndex.indexOffset > 0);
@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 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()); }
@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()); }
final Slot s = slots.getSlot(cursorPosition); if (s != null && (!s.hardcoded() || (removeHardcoded && count == 1))) { cursorPosition += s.setValue(null);
@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()); } }