RollUpBitMask { public static RollUpBitMask fromShort(final short maskValue) { final int maxVal = (int) (Math.pow(2, MASK_LENGTH) - 1); final int minVal = 0; if (maskValue > maxVal || maskValue < 0) { throw new RuntimeException(String.format("Mask value must be between [%s] and [%s]", minVal, maxVal)); } return new RollUpBitMask(maskValue); } 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 testFromShort() { final RollUpBitMask rollUpBitMask = RollUpBitMask.fromShort((short) 2); assertThat(rollUpBitMask.asHexString()).isEqualTo("0002"); }
@Test void testFromShortTooSmall() { assertThatThrownBy(() -> { final short tooSmall = -1; RollUpBitMask.fromShort(tooSmall); }).isInstanceOf(RuntimeException.class); }