java.rmi.constraint
Class ConstraintAlternatives

java.lang.Object
  |
  +--java.rmi.constraint.ConstraintAlternatives
All Implemented Interfaces:
RelativeTimeConstraint, SecurityConstraint, java.io.Serializable

public final class ConstraintAlternatives
extends java.lang.Object
implements RelativeTimeConstraint, java.io.Serializable

Combines constraint alternatives of uniform type into a single overall constraint. The semantics of this aggregate constraint is that at least one of the individual constraints must be satisfied. All of the individual constraints must be instances of the same concrete class, and there must be at least two constraints.

Note that this class implements RelativeTimeConstraint even though the constraint elements might not implement RelativeTimeConstraint.

Since:
1.4
See Also:
Serialized Form

Constructor Summary
ConstraintAlternatives(java.util.Collection c)
          Creates an instance containing the specified alternative constraints, with unnecessary constraints removed.
ConstraintAlternatives(SecurityConstraint[] constraints)
          Creates an instance containing the specified alternative constraints, with unnecessary constraints removed.
 
Method Summary
static SecurityConstraint create(java.util.Collection c)
          Returns a constraint representing the specified alternative constraints, with unnecessary constraints removed.
static SecurityConstraint create(SecurityConstraint[] constraints)
          Returns a constraint representing the specified alternative constraints, with unnecessary constraints removed.
 java.util.Set elements()
          Returns an immutable set of all the constraints.
 boolean equals(java.lang.Object obj)
          Two instances of this class are equal if they have the same constraints (ignoring order).
 java.lang.Class getElementType()
          Returns the concrete class of the constraint elements.
 int hashCode()
          Returns a hash code value for this object.
 SecurityConstraint makeAbsolute(long baseTime)
          Returns the original ConstraintAlternatives instance if the constraint elements are not instances of RelativeTimeConstraint, otherwise converts each constraint element using its makeAbsolute method and returns the result of invoking the create method of this class with the converted constraints.
 SecurityConstraint reduceBy(SecurityConstraint c)
          Returns the smallest representable subset of this constraint that contains the intersection of this constraint with the specified constraint, or null if there is no intersection.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstraintAlternatives

public ConstraintAlternatives(SecurityConstraint[] constraints)
Creates an instance containing the specified alternative constraints, with unnecessary constraints removed. Constraints are removed as follows. First duplicate constraints are removed. Then for each remaining constraint c1, if there exists another remaining constraint c2 such that c2.reduceBy(c1) equals c1, then c1 is removed. The parameter passed to this constructor is neither modified nor retained; subsequent changes to that parameter have no effect on the instance created.
Parameters:
constraints - the alternative constraints
Throws:
NullPointerException - if the parameter is null or any element is null
java.lang.IllegalArgumentException - if any of the elements are instances of ConstraintAlternatives, or if the elements are not all instances of the same concrete class, or if the elements are not all instances of trusted constraint classes, or if fewer than two elements remain after unnecessary constraints are removed

ConstraintAlternatives

public ConstraintAlternatives(java.util.Collection c)
Creates an instance containing the specified alternative constraints, with unnecessary constraints removed. Constraints are removed as follows. First duplicate constraints are removed. Then for each remaining constraint c1, if there exists another remaining constraint c2 such that c2.reduceBy(c1) equals c1, then c1 is removed. The parameter passed to this constructor is neither modified nor retained; subsequent changes to that parameter have no effect on the instance created.
Parameters:
constraints - the alternative constraints
Throws:
NullPointerException - if the parameter is null or any element is null
java.lang.IllegalArgumentException - if any of the elements are instances of ConstraintAlternatives, or if the elements are not all instances of the same concrete class, or if the elements are not all instances of trusted constraint classes, or if fewer than two elements remain after unnecessary constraints are removed
Method Detail

create

public static SecurityConstraint create(SecurityConstraint[] constraints)
Returns a constraint representing the specified alternative constraints, with unnecessary constraints removed. Constraints are removed as follows. First duplicate constraints are removed. Then for each remaining constraint c1, if there exists another remaining constraint c2 such that c2.reduceBy(c1) equals c1, then c1 is removed. If a single constraint remains, then that constraint is returned, otherwise an instance of ConstraintAlternatives containing the remaining constraints is returned. The parameter passed to this method is neither modified nor retained; subsequent changes to that parameter have no effect on the instance created.
Parameters:
constraints - the alternative constraints
Returns:
a constraint representing the specified alternative constraints, with unnecessary constraints removed
Throws:
NullPointerException - if the parameter is null or any element is null
java.lang.IllegalArgumentException - if the parameter is empty, or if any of the elements are instances of ConstraintAlternatives, or if the elements are not all instances of the same concrete class, or if the elements are not all instances of trusted constraint classes.

create

public static SecurityConstraint create(java.util.Collection c)
Returns a constraint representing the specified alternative constraints, with unnecessary constraints removed. Constraints are removed as follows. First duplicate constraints are removed. Then for each remaining constraint c1, if there exists another remaining constraint c2 such that c2.reduceBy(c1) equals c1, then c1 is removed. If a single constraint remains, then that constraint is returned, otherwise an instance of ConstraintAlternatives containing the remaining constraints is returned. The parameter passed to this method is neither modified nor retained; subsequent changes to that parameter have no effect on the instance created.
Parameters:
constraints - the alternative constraints
Returns:
a constraint representing the specified alternative constraints, with unnecessary constraints removed
Throws:
NullPointerException - if the parameter is null or any element is null
java.lang.IllegalArgumentException - if the parameter is empty, or if any of the elements are instances of ConstraintAlternatives, or if the elements are not all instances of the same concrete class, or if the elements are not all instances of trusted constraint classes

elements

public java.util.Set elements()
Returns an immutable set of all the constraints. Any attempt to modify this set results in an UnsupportedOperationException being thrown.
Returns:
an immutable set of all of the constraints

reduceBy

public SecurityConstraint reduceBy(SecurityConstraint c)
Returns the smallest representable subset of this constraint that contains the intersection of this constraint with the specified constraint, or null if there is no intersection.

For any instance c1 of this class and any constraint instance c2, the result of c1.reduceBy(c2) is obtained as follows. If for any element e1 of c1, the result of e1.reduceBy(c2) equals c2, then the result of c1.reduceBy(c2) is c2. If c2 is itself an instance of this class and for each element e2 of c2 there exists an element e1 of c1 such that e1.reduceBy(e2) equals e2, then the result of c1.reduceBy(c2) is c2. If for each element e1 of c1, the result of e1.reduceBy(c2) is null, then the result of c1.reduceBy(c2) is null. Otherwise, a collection is formed from the non-null values returned by e1.reduceBy(c2) for each element e1 of c1. Each constraint in the collection that is an instance of ConstraintAlternatives is then replaced by all of the elements of that constraint. The result of c1.reduceBy(c2) is then the result of calling the create method of this class with the final collection.

Specified by:
reduceBy in interface SecurityConstraint
Following copied from interface: java.rmi.constraint.SecurityConstraint
Parameters:
c - a constraint
Returns:
the smallest representable subset of this constraint that intersects with the specified constraint, or null if there is no intersection

makeAbsolute

public SecurityConstraint makeAbsolute(long baseTime)
Returns the original ConstraintAlternatives instance if the constraint elements are not instances of RelativeTimeConstraint, otherwise converts each constraint element using its makeAbsolute method and returns the result of invoking the create method of this class with the converted constraints.
Specified by:
makeAbsolute in interface RelativeTimeConstraint
Following copied from interface: java.rmi.constraint.RelativeTimeConstraint
Parameters:
baseTime - an absolute time, specified in milliseconds from midnight, January 1, 1970 UTC
Returns:
a constraint that has the relative times converted to absolute times by adding the specified absolute time to each relative time

getElementType

public java.lang.Class getElementType()
Returns the concrete class of the constraint elements.
Returns:
the concrete class of the constraint elements

hashCode

public int hashCode()
Returns a hash code value for this object.
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Two instances of this class are equal if they have the same constraints (ignoring order).
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of this object.
Overrides:
toString in class java.lang.Object


Copyright © 2000 Sun Microsystems, Inc. All rights reserved