private int actionsMask() { return (1 << actionEnumeration.size()) - 1; }
public int size() { final int size = Long.bitCount(bitSet.get()); return size == getNameEnumeration().size() ? 1 : size; }
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; }
/** * 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]; }
/** * Get the canonical name for an index. If the index is out of range, an exception is thrown. * * @param index the index to seek * @return the canonical name (not {@code null}) */ public String nameOf(int index) { final Data[] byId = this.byId; Assert.checkMinimumParameter("index", 0, index); Assert.checkMaximumParameter("index", size() - 1, index); return byId[index].canonicalName; }
public Permission nextElement() { final int bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Integer.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } int bit = Integer.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Integer.numberOfTrailingZeros(bit)); }
public Permission nextElement() { final long bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Long.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } long bit = Long.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Long.numberOfTrailingZeros(bit)); }
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; }
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; }
/** * Construct a new instance. * * @param sourcePermission the source permission object (must not be {@code null}) * @param nameEnumeration the name enumeration for this permission type (must not be {@code null}) * @return the permission collection */ public static AbstractPermissionCollection newInstance(final AbstractPermission<?> sourcePermission, final StringEnumeration nameEnumeration) { Assert.checkNotNullParam("sourcePermission", sourcePermission); Assert.checkNotNullParam("nameEnumeration", nameEnumeration); final int size = nameEnumeration.size(); if (size <= 32) { return new IntNameSetPermissionCollection(sourcePermission, nameEnumeration); } else if (size <= 64) { return new LongNameSetPermissionCollection(sourcePermission, nameEnumeration); } else { // TODO: add GiantNameSetPermissionCollection which uses AtomicIntegerArray throw Assert.unsupported(); } }
public int size() { final int size = Integer.bitCount(bitSet.get()); return size == getNameEnumeration().size() ? 1 : size; }
/** * 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]; }
/** * 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]; }
/** * Get the canonical name for an index. If the index is out of range, an exception is thrown. * * @param index the index to seek * @return the canonical name (not {@code null}) */ public String nameOf(int index) { final Data[] byId = this.byId; Assert.checkMinimumParameter("index", 0, index); Assert.checkMaximumParameter("index", size() - 1, index); return byId[index].canonicalName; }
public Permission nextElement() { final int bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Integer.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } int bit = Integer.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Integer.numberOfTrailingZeros(bit)); }
public Permission nextElement() { final long bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Long.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } long bit = Long.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Long.numberOfTrailingZeros(bit)); }
public Permission nextElement() { final int bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Integer.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } int bit = Integer.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Integer.numberOfTrailingZeros(bit)); }
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; }
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; }