public Slot(@Nullable Character value, @Nullable SlotValidator... validators) { this(RULES_DEFAULT, value, SlotValidatorSet.setOf(validators)); }
@Override protected Slot slotFromNonUnderscoredChar(char character) { if (!Character.isDigit(character)) { rule = Slot.RULE_INPUT_MOVES_INPUT | Slot.RULE_INPUT_REPLACE; final Slot hardcoded = PredefinedSlots.hardcodedSlot(character); return character == PLUS_SIGN ? hardcoded : hardcoded.withTags(Slot.TAG_DECORATION); } final Slot slot = new Slot(rule, character, SlotValidatorSet.setOf(new SlotValidators.DigitValidator())); rule = Slot.RULE_INPUT_MOVES_INPUT; return slot; } }
@Test public void replace(){ Mask mask = new MaskImpl( new Slot[]{ new Slot(Slot.RULE_INPUT_REPLACE, '1', SlotValidatorSet.setOf(new SlotValidators.GenerousValidator())), new Slot(Slot.RULE_INPUT_REPLACE, '2', SlotValidatorSet.setOf(new SlotValidators.GenerousValidator())), new Slot(Slot.RULE_INPUT_REPLACE, '3', SlotValidatorSet.setOf(new SlotValidators.GenerousValidator())), new Slot(Slot.RULE_INPUT_REPLACE, null, SlotValidatorSet.setOf(new SlotValidators.GenerousValidator())) }, true ); assertEquals("123", mask.toString()); assertEquals(1,mask.insertFront("0")); assertEquals(2,mask.insertAt(1, "1")); assertEquals("013", mask.toString()); }
@Test public void parcelable() { Slot before = new Slot(Slot.RULES_DEFAULT, 'x', SlotValidatorSet.setOf(new SlotValidators.MaskedDigitValidator())); Parcel parcel = Parcel.obtain(); before.writeToParcel(parcel, 0); parcel.setDataPosition(0); Slot after = Slot.CREATOR.createFromParcel(parcel); assertEquals(before, after); parcel.recycle(); }