ItemIdComposer { @IntRange(from = MIN_SEGMENT, to = MAX_SEGMENT) public static int extractSegmentPart(long composedId) { return (int) ((composedId & BIT_MASK_SEGMENT) >>> BIT_OFFSET_SEGMENT); } private  ItemIdComposer(); static long composeExpandableChildId(@IntRange(from = MIN_GROUP_ID, to = MAX_GROUP_ID) long groupId, @IntRange(from = MIN_CHILD_ID, to = MAX_CHILD_ID) long childId); static long composeExpandableGroupId(@IntRange(from = MIN_GROUP_ID, to = MAX_GROUP_ID) long groupId); static boolean isExpandableGroup(long composedId); @IntRange(from = MIN_SEGMENT, to = MAX_SEGMENT) static int extractSegmentPart(long composedId); @IntRange(from = MIN_GROUP_ID, to = MAX_GROUP_ID) static long extractExpandableGroupIdPart(long composedId); @IntRange(from = MIN_CHILD_ID, to = MAX_CHILD_ID) static long extractExpandableChildIdPart(long composedId); static long extractWrappedIdPart(long composedId); static long composeSegment(@IntRange(from = MIN_SEGMENT, to = MAX_SEGMENT) int segment, long wrappedId); static final int BIT_OFFSET_RESERVED_SIGN_FLAG; static final int BIT_OFFSET_SEGMENT; static final int BIT_OFFSET_GROUP_ID; static final int BIT_OFFSET_CHILD_ID; static final int BIT_WIDTH_RESERVED_SIGN_FLAG; static final int BIT_WIDTH_SEGMENT; static final int BIT_WIDTH_GROUP_ID; static final int BIT_WIDTH_CHILD_ID; static final long BIT_MASK_RESERVED_SIGN_FLAG; static final long BIT_MASK_SEGMENT; static final long BIT_MASK_GROUP_ID; static final long BIT_MASK_CHILD_ID; static final int MIN_SEGMENT; static final int MAX_SEGMENT; static final long MIN_GROUP_ID; static final long MAX_GROUP_ID; static final long MIN_CHILD_ID; static final long MAX_CHILD_ID; static final long MIN_WRAPPED_ID; static final long MAX_WRAPPED_ID; }
@Test public void extractSegmentPart() throws Exception { assertThat(ItemIdComposer.extractSegmentPart(0L), is(0)); assertThat(ItemIdComposer.extractSegmentPart(1L << ItemIdComposer.BIT_OFFSET_SEGMENT), is(1)); assertThat(ItemIdComposer.extractSegmentPart(((long) ItemIdComposer.MIN_SEGMENT) << ItemIdComposer.BIT_OFFSET_SEGMENT), is(ItemIdComposer.MIN_SEGMENT)); assertThat(ItemIdComposer.extractSegmentPart(((long) ItemIdComposer.MAX_SEGMENT) << ItemIdComposer.BIT_OFFSET_SEGMENT), is(ItemIdComposer.MAX_SEGMENT)); assertThat(ItemIdComposer.extractSegmentPart(ItemIdComposer.BIT_MASK_RESERVED_SIGN_FLAG | ItemIdComposer.BIT_MASK_GROUP_ID | ItemIdComposer.BIT_MASK_CHILD_ID), is(0)); assertThat(ItemIdComposer.extractSegmentPart(ItemIdComposer.BIT_MASK_SEGMENT), is(ItemIdComposer.MAX_SEGMENT)); }