public CumulativePermission clear(Permission permission) { this.mask &= ~permission.getMask(); this.pattern = AclFormattingUtils.demergePatterns(this.pattern, permission.getPattern()); return this; }
public CumulativePermission set(Permission permission) { this.mask |= permission.getMask(); this.pattern = AclFormattingUtils.mergePatterns(this.pattern, permission.getPattern()); return this; }
/** * Returns a representation of the active bits in the presented mask, with each active * bit being denoted by character '*'. * <p> * Inactive bits will be denoted by character {@link Permission#RESERVED_OFF}. * * @param i the integer bit mask to print the active bits for * * @return a 32-character representation of the bit mask */ public static String printBinary(int i) { return printBinary(i, '*', Permission.RESERVED_OFF); }
public String getPattern() { return AclFormattingUtils.printBinary(mask, code); }
@Test public final void testDemergePatterns() throws Exception { String original = "...........................A...R"; String removeBits = "...............................R"; assertThat(AclFormattingUtils.demergePatterns(original, removeBits)).isEqualTo( "...........................A...."); assertThat(AclFormattingUtils.demergePatterns("ABCDEF", "......")).isEqualTo( "ABCDEF"); assertThat(AclFormattingUtils.demergePatterns("ABCDEF", "GHIJKL")).isEqualTo( "......"); }
@Test public final void testMergePatterns() throws Exception { String original = "...............................R"; String extraBits = "...........................A...."; assertThat(AclFormattingUtils.mergePatterns(original, extraBits)).isEqualTo( "...........................A...R"); assertThat(AclFormattingUtils.mergePatterns("ABCDEF", "......")).isEqualTo( "ABCDEF"); assertThat(AclFormattingUtils.mergePatterns("ABCDEF", "GHIJKL")).isEqualTo( "GHIJKL"); }
/** * Returns a representation of the active bits in the presented mask, with each active * bit being denoted by the passed character. * <p> * Inactive bits will be denoted by character {@link Permission#RESERVED_OFF}. * * @param mask the integer bit mask to print the active bits for * @param code the character to print when an active bit is detected * * @return a 32-character representation of the bit mask */ public static String printBinary(int mask, char code) { Assert.doesNotContain(Character.toString(code), Character.toString(Permission.RESERVED_ON), () -> Permission.RESERVED_ON + " is a reserved character code"); Assert.doesNotContain(Character.toString(code), Character.toString(Permission.RESERVED_OFF), () -> Permission.RESERVED_OFF + " is a reserved character code"); return printBinary(mask, Permission.RESERVED_ON, Permission.RESERVED_OFF) .replace(Permission.RESERVED_ON, code); }
@Test public final void testDemergePatternsParametersConstraints() throws Exception { try { AclFormattingUtils.demergePatterns(null, "SOME STRING"); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { AclFormattingUtils.demergePatterns("SOME STRING", null); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { AclFormattingUtils.demergePatterns("SOME STRING", "LONGER SOME STRING"); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { AclFormattingUtils.demergePatterns("SOME STRING", "SAME LENGTH"); } catch (IllegalArgumentException notExpected) { fail("It shouldn't have thrown IllegalArgumentException"); } }
@Test public final void testMergePatternsParametersConstraints() throws Exception { try { AclFormattingUtils.mergePatterns(null, "SOME STRING"); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { AclFormattingUtils.mergePatterns("SOME STRING", null); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { AclFormattingUtils.mergePatterns("SOME STRING", "LONGER SOME STRING"); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { AclFormattingUtils.mergePatterns("SOME STRING", "SAME LENGTH"); } catch (IllegalArgumentException notExpected) { } }
@Test public void testPrintBinaryMinusOne() { assertThat(AclFormattingUtils.printBinary(0xffffffff)).isEqualTo( "********************************"); } }
public Builder remove(Permission permission) { this.mask &= ~permission.getMask(); this.pattern = AclFormattingUtils.demergePatterns(this.pattern, permission.getPattern()); return this; }
public Builder add(Permission permission) { this.mask |= permission.getMask(); this.pattern = AclFormattingUtils.mergePatterns(this.pattern, permission.getPattern()); return this; }
@Test public void testPrintBinaryNegative() { assertThat(AclFormattingUtils.printBinary(0x80000000)).isEqualTo( "*..............................."); }
public CumulativePermission clear(Permission permission) { this.mask &= ~permission.getMask(); this.pattern = AclFormattingUtils.demergePatterns(this.pattern, permission.getPattern()); return this; }
public CumulativePermission set(Permission permission) { this.mask |= permission.getMask(); this.pattern = AclFormattingUtils.mergePatterns(this.pattern, permission.getPattern()); return this; }
@Test public final void testBinaryPrints() throws Exception { assertThat(AclFormattingUtils.printBinary(15)).isEqualTo( "............................****"); try { AclFormattingUtils.printBinary(15, Permission.RESERVED_ON); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException notExpected) { } try { AclFormattingUtils.printBinary(15, Permission.RESERVED_OFF); fail("It should have thrown IllegalArgumentException"); } catch (IllegalArgumentException notExpected) { } assertThat(AclFormattingUtils.printBinary(15, 'x')).isEqualTo( "............................xxxx"); }
@Override public String getPattern() { return AclFormattingUtils.printBinary(mask, c); }
/** * Returns a representation of the active bits in the presented mask, with each active * bit being denoted by character '*'. * <p> * Inactive bits will be denoted by character {@link Permission#RESERVED_OFF}. * * @param i the integer bit mask to print the active bits for * * @return a 32-character representation of the bit mask */ public static String printBinary(int i) { return printBinary(i, '*', Permission.RESERVED_OFF); }
public String getPattern() { return AclFormattingUtils.printBinary(mask, code); }
public PermissionData(String pattern, int mask) { this.mask = mask; this.pattern = pattern != null? pattern : AclFormattingUtils.printBinary(mask); Action[] values = Action.values(); StringBuilder sb = new StringBuilder(values.length); for(Action a : values) { if((a.getMask() & this.mask) != 0) { sb.append(a.getLetter()); } } this.expression = sb.toString(); }