private int getBitsForName(final Permission permission) { final int bits; final String name = permission.getName(); final StringEnumeration nameEnumeration = getNameEnumeration(); if ("*".equals(name)) { // add all names bits = (1 << nameEnumeration.size()) - 1; } else { bits = 1 << nameEnumeration.indexOf(name); } return bits; }
/** * Construct a new instance. * * @param stringEnumeration the string enumeration (must not be {@code null}) * @param mapping the mapping function (must not be {@code null}) */ public StringMapping(final StringEnumeration stringEnumeration, final Function<String, T> mapping) { Assert.checkNotNullParam("stringEnumeration", stringEnumeration); Assert.checkNotNullParam("mapping", mapping); this.stringEnumeration = stringEnumeration; @SuppressWarnings("unchecked") final T[] items = (T[]) new Object[stringEnumeration.size()]; for (int i = 0; i < stringEnumeration.size(); i ++) { items[i] = mapping.apply(stringEnumeration.nameOf(i)); } this.items = items; }
/** * Construct a new instance. The given values are used as the string members in the order they are given. * * @param values the values * @return the string enumeration */ public static StringEnumeration of(String... values) { final int length = values.length; Data[] byId = new Data[length]; HashMap<String, Data> index = new HashMap<>(length); String str; for (int i = 0; i < length; i ++) { str = Assert.checkNotNullArrayParam("values", i, values[i]); index.put(str, byId[i] = new Data(i, str)); } return new StringEnumeration(index, byId); }
private int actionsMask() { return (1 << actionEnumeration.size()) - 1; }
private int getActionBit(final String actionName) throws IllegalArgumentException { return 1 << actionEnumeration.indexOf(actionName); }
private String getActionName(final int bit) throws IllegalArgumentException { return actionEnumeration.nameOf(Integer.numberOfTrailingZeros(bit)); }
/** * Construct a new instance. * * @param name the name of this permission * @param nameEnumeration the set of valid names for this permission type */ protected AbstractNameSetOnlyPermission(final String name, final StringEnumeration nameEnumeration) { super("*".equals(name) ? "*" : nameEnumeration.canonicalName(name)); this.nameEnumeration = nameEnumeration; }
public int size() { final int size = Long.bitCount(bitSet.get()); return size == getNameEnumeration().size() ? 1 : size; }
/** * Get an item from this mapping by the corresponding string name. * * @param str the string name * @return the item * @throws IllegalArgumentException if the string name is unknown */ public T getItemByString(String str) throws IllegalArgumentException { Assert.checkNotNullParam("str", str); return items[stringEnumeration.indexOf(str)]; }
private Permission permissionFor(int id) { return ((AbstractNamedPermission<?>)getSourcePermission()).withName(getNameEnumeration().nameOf(id)); }
/** * Construct a new instance. * * @param name the name of this permission * @param nameEnumeration the set of valid names for this permission type */ protected AbstractNameSetOnlyPermission(final String name, final StringEnumeration nameEnumeration) { super("*".equals(name) ? "*" : nameEnumeration.canonicalName(name)); this.nameEnumeration = nameEnumeration; }
private long getBitsForName(final Permission permission) { final long bits; final String name = permission.getName(); final StringEnumeration nameEnumeration = getNameEnumeration(); if ("*".equals(name)) { // add all names bits = (1L << nameEnumeration.size()) - 1; } else { bits = 1L << nameEnumeration.indexOf(name); } return bits; }
public int size() { final int size = Integer.bitCount(bitSet.get()); return size == getNameEnumeration().size() ? 1 : size; }
/** * Construct a new instance. * * @param stringEnumeration the string enumeration (must not be {@code null}) * @param mapping the mapping function (must not be {@code null}) */ public StringMapping(final StringEnumeration stringEnumeration, final Function<String, T> mapping) { Assert.checkNotNullParam("stringEnumeration", stringEnumeration); Assert.checkNotNullParam("mapping", mapping); this.stringEnumeration = stringEnumeration; @SuppressWarnings("unchecked") final T[] items = (T[]) new Object[stringEnumeration.size()]; for (int i = 0; i < stringEnumeration.size(); i ++) { items[i] = mapping.apply(stringEnumeration.nameOf(i)); } this.items = items; }
protected final int nameHashCode() { return nameEnumeration.indexOf(getName()); } }
private Permission permissionFor(int id) { return ((AbstractNamedPermission<?>)getSourcePermission()).withName(getNameEnumeration().nameOf(id)); }
/** * Construct a new instance. * * @param name the name of this permission * @param nameEnumeration the set of valid names for this permission type */ protected AbstractNameSetOnlyPermission(final String name, final StringEnumeration nameEnumeration) { super("*".equals(name) ? "*" : nameEnumeration.canonicalName(name)); this.nameEnumeration = nameEnumeration; }
/** * Construct a new instance. The given values are used as the string members in the order they are given. * * @param values the values * @return the string enumeration */ public static StringEnumeration of(String... values) { final int length = values.length; Data[] byId = new Data[length]; HashMap<String, Data> index = new HashMap<>(length); String str; for (int i = 0; i < length; i ++) { str = Assert.checkNotNullArrayParam("values", i, values[i]); index.put(str, byId[i] = new Data(i, str)); } return new StringEnumeration(index, byId); }
private long getBitsForName(final Permission permission) { final long bits; final String name = permission.getName(); final StringEnumeration nameEnumeration = getNameEnumeration(); if ("*".equals(name)) { // add all names bits = (1L << nameEnumeration.size()) - 1; } else { bits = 1L << nameEnumeration.indexOf(name); } return bits; }
/** * Get an item from this mapping by ID. * * @param index the index to look up * @return the mapped item for the given ID * @throws IllegalArgumentException if the given index is out of range */ public T getItemById(int index) throws IllegalArgumentException { Assert.checkMinimumParameter("index", 0, index); Assert.checkMaximumParameter("index", stringEnumeration.size() - 1, index); return items[index]; }