/** * 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); }
/** * 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 void testPrintBinaryMinusOne() { assertThat(AclFormattingUtils.printBinary(0xffffffff)).isEqualTo( "********************************"); } }
@Test public void testPrintBinaryNegative() { assertThat(AclFormattingUtils.printBinary(0x80000000)).isEqualTo( "*..............................."); }
@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(); }
/** * 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); }