@Override public V get(Object o) { return (o instanceof Right ? unmaskNull(getValue(((Right) o).ordinal())) : null); }
@Override public V put(Right right, V value) { return updateValue(right.ordinal(), maskNull(value)); }
@Override @SuppressWarnings("unchecked") protected Object clone() throws CloneNotSupportedException { RightMap<V> clone = (RightMap<V>) super.clone(); clone.rights.addAll(rights); clone.size = size(); return clone; }
@Override @SuppressWarnings("unchecked") public void putAll(Map<? extends Right, ? extends V> map) { if (map instanceof RightMap) { RightMap<? extends V> rmap = (RightMap<? extends V>) map; for (int i = 0; i < Right.size(); i++) { updateValue(i, rmap.getValue(i)); } } else { super.putAll(map); } }
@Override public boolean containsKey(Object o) { return o instanceof Right && getValue(((Right) o).ordinal()) != null; }
@Override public boolean containsValue(Object o) { return rights.contains(maskNull(o)); }
@Override public void remove() { if (lastIndex < 0) { throw new IllegalStateException(); } updateValue(lastIndex, null); lastIndex = -1; } }
/** * Serialization support. * * @param s the output stream * @throws IOException on error */ private void writeObject(ObjectOutputStream s) throws IOException { // Write out the key type and any hidden stuff s.defaultWriteObject(); // Write out size (number of Mappings) s.writeInt(size); // Write out keys and values (alternating) for (Map.Entry<Right, V> e : entrySet()) { s.writeObject(e.getKey()); s.writeObject(e.getValue()); } }
/** * Serialization support. * * @param s the input stream * @throws IOException on error * @throws ClassNotFoundException on error */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the key type and any hidden stuff s.defaultReadObject(); rights = new ArrayList<Object>(Right.size()); // Read the keys and values, and put the mappings in the HashMap for (int i = 0; i < s.readInt(); i++) { Right key = (Right) s.readObject(); V value = (V) s.readObject(); put(key, value); } } }
size--; return unmaskNull(oldValue);
@Override protected XWikiSecurityAccess settle(UserSecurityReference user, Collection<GroupSecurityReference> groups, SecurityRuleEntry entry, Policies policies) { XWikiSecurityAccess access = new XWikiSecurityAccess(); Map<Right, Integer> priorities = new RightMap<Integer>(); SecurityReference reference = entry.getReference(); Set<Right> enabledRights = Right.getEnabledRights(reference.getSecurityType()); // Evaluate rules from current level for (Right right : enabledRights) { for (SecurityRule obj : entry.getRules()) { if (obj.match(right)) { resolveLevel(right, user, groups, obj, access, policies, priorities); if (access.get(right) == ALLOW) { implyRights(right, access, reference, policies, priorities); } } } } return access; }
@Override public boolean equals(Object o) { if (!(o instanceof RightMap)) { return super.equals(o); } RightMap rmap = (RightMap) o; // Key types match, compare each value for (int i = 0; i < Right.size(); i++) { Object val = getValue(i); Object rval = rmap.getValue(i); if (rval != val && (rval == null || !rval.equals(val))) { return false; } } return true; }
@Override public String toString() { StringBuilder sb = new StringBuilder("["); boolean first = true; for (int i = 0; i < rights.size(); i++) { if (getValue(i) != null) { if (first) { first = false; } else { sb.append(", "); } sb.append(Right.get(i).getName()) .append(" = ") .append(unmaskNull(getValue(i)).toString()); } } sb.append("]"); return sb.toString(); }