RollUpBitMask { public static RollUpBitMask fromMask(final short[] mask) { if (mask.length > MASK_LENGTH) { throw new RuntimeException("Array is too long"); } short tempMask = 0; final int len = mask.length; for (short i = 0; i < len; i++) { if (mask[i] == 1) { tempMask = setMaskValueAtPosition(i, tempMask); } else if (mask[i] != 0) { throw new RuntimeException(String.format("Value at mask position %s is not one of 1 or 0", mask[i])); } } return new RollUpBitMask(tempMask); } private  RollUpBitMask(final short mask); static RollUpBitMask fromShort(final short maskValue); static RollUpBitMask fromMask(final short[] mask); static RollUpBitMask fromRolledupTagList(final String allTags, final String rolledUpTags); static byte[] byteValueFromTagList(final String allTags, final String rolledUpTags); static int intValueFromTagList(final String allTags, final String rolledUpTags); static RollUpBitMask fromTagPositions(final List<Integer> tagPositions); static RollUpBitMask fromTagPositions(final SortedSet<Integer> tagPositions); static RollUpBitMask fromBytes(final byte[] bytes); static Set<RollUpBitMask> getRollUpBitMasks(final int tagCount); static Set<List<Boolean>> getRollUpPermutationsAsBooleans(final int tagCount); static Set<List<Integer>> getRollUpPermutationsAsPositions(final int tagCount); SortedSet<Integer> getTagPositions(); List<Integer> getTagPositionsAsList(); List<Boolean> getBooleanMask(final int tagCount); boolean isTagPositionRolledUp(final int tagPosition); RollUpBitMask convert(final Map<Integer, Integer> newToOldFieldPositionMap); short asShort(); byte[] asBytes(); String asHexString(); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object obj); static final short MASK_LENGTH; static final RollUpBitMask ZERO_MASK; static final String ROLL_UP_TAG_VALUE; }
@Test void testFromMaskInvalidMask() { assertThatThrownBy(() -> { RollUpBitMask.fromMask(new short[]{0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}); }).isInstanceOf(RuntimeException.class); }
@Test void fromMaskInvalidMaskValue() { assertThatThrownBy(() -> { RollUpBitMask.fromMask(new short[]{9, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}); }).isInstanceOf(RuntimeException.class); }