net.jini.core.constraint
Class Constraint

java.lang.Object
  extended by net.jini.core.constraint.Constraint

 class Constraint
extends Object

Constraint utility methods.

Author:
Sun Microsystems, Inc.

Constructor Summary
private Constraint()
          Non-instantiable.
 
Method Summary
(package private) static boolean contains(Object[] arr, int i, Object obj)
          Returns true if the non-null object is equal to any of the elements of the array with index less than i.
(package private) static boolean equal(Object[] arr1, Object[] arr2)
          Returns true if the two arrays are the same length and contain equal elements (but the order of the elements need not be the same in both arrays).
(package private) static int hash(Object[] elements)
          Returns the sum of the hash codes of all elements of the given array.
(package private) static Class[] reduce(Class[] classes, boolean keepSupers)
          Verifies that there is at least one element, and returns a new array of the elements, in arbitrary order, with redundant classes removed as follows.
(package private) static Principal[] reduce(Collection c)
          Verifies that all elements of the collection are instances of principal classes, and that there is at least one element, and returns an array of the elements, in arbitrary order, with duplicates removed.
(package private) static Class[] reduce(Collection c, boolean keepSupers)
          Verifies that all elements of the collection are classes, and that there is at least one element, and returns an array of the elements, in arbitrary order, with redundant classes removed as follows.
(package private) static Principal[] reduce(Principal[] principals)
          Verifies that there is at least one element, and returns a new array of the elements, in arbitrary order, with duplicates removed.
private static Class[] reduce0(Class[] classes, boolean keepSupers)
          Verifies that there is at least one element, and returns an array of the elements, in arbitrary order, with redundant classes removed as follows.
private static Principal[] reduce0(Principal[] principals)
          Verifies that there is at least one element, and returns an array of the elements, in arbitrary order, with duplicates removed.
(package private) static String toString(Object[] a)
          Returns a sorted comma-separated list of the toString form of the elements of the array.
(package private) static Object[] trim(Object[] elements, int len)
          Returns an array containing the first len elements of the specified array, with the same element type as the specified array.
(package private) static void verify(Class c)
          Verifies that the class is not a primitive or array class, and either isn't final or is assignable to Principal.
(package private) static void verify(Class[] classes)
          Verifies that there is at least one element, that they are all valid classes, and that no class is assignable to any other class.
(package private) static void verify(Principal[] principals)
          Verifies that there is at least one element, and that there are no duplicates;
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Constraint

private Constraint()
Non-instantiable.

Method Detail

trim

static Object[] trim(Object[] elements,
                     int len)
Returns an array containing the first len elements of the specified array, with the same element type as the specified array.


hash

static int hash(Object[] elements)
Returns the sum of the hash codes of all elements of the given array.


equal

static boolean equal(Object[] arr1,
                     Object[] arr2)
Returns true if the two arrays are the same length and contain equal elements (but the order of the elements need not be the same in both arrays). The arrays must not contain duplicates.


contains

static boolean contains(Object[] arr,
                        int i,
                        Object obj)
Returns true if the non-null object is equal to any of the elements of the array with index less than i.


toString

static String toString(Object[] a)
Returns a sorted comma-separated list of the toString form of the elements of the array. If the first element is a Class instance, then all of the elements must be Class instances.


reduce

static Principal[] reduce(Collection c)
Verifies that all elements of the collection are instances of principal classes, and that there is at least one element, and returns an array of the elements, in arbitrary order, with duplicates removed.


reduce

static Principal[] reduce(Principal[] principals)
Verifies that there is at least one element, and returns a new array of the elements, in arbitrary order, with duplicates removed.


reduce0

private static Principal[] reduce0(Principal[] principals)
Verifies that there is at least one element, and returns an array of the elements, in arbitrary order, with duplicates removed. The argument may be modified. If no duplicates need to be removed, the argument may be returned.


verify

static void verify(Principal[] principals)
            throws InvalidObjectException
Verifies that there is at least one element, and that there are no duplicates;

Throws:
InvalidObjectException

reduce

static Class[] reduce(Collection c,
                      boolean keepSupers)
Verifies that all elements of the collection are classes, and that there is at least one element, and returns an array of the elements, in arbitrary order, with redundant classes removed as follows. For any two classes c1 and c2, if c1.isAssignableFrom(c2) is true, then c2 is removed if keepSupers is true, otherwise c1 is removed.


reduce

static Class[] reduce(Class[] classes,
                      boolean keepSupers)
Verifies that there is at least one element, and returns a new array of the elements, in arbitrary order, with redundant classes removed as follows. For any two classes c1 and c2, if c1.isAssignableFrom(c2) is true, then c2 is removed if keepSupers is true, otherwise c1 is removed.


reduce0

private static Class[] reduce0(Class[] classes,
                               boolean keepSupers)
Verifies that there is at least one element, and returns an array of the elements, in arbitrary order, with redundant classes removed as follows. For any two classes c1 and c2, if c1.isAssignableFrom(c2) is true, then c2 is removed if keepSupers is true, otherwise c1 is removed. The array argument may be modified. If no classes need to be removed, the array argument may be returned. Note #1: Here we're removing ck, and we close the gap by moving the last already-processed element (common[i - 1]) down to replace it. We don't need to arraycopy all of the elements down because order doesn't matter. In the degenerate case (k == i - 1) we copy an element onto itself, but that does no harm.


verify

static void verify(Class c)
Verifies that the class is not a primitive or array class, and either isn't final or is assignable to Principal.


verify

static void verify(Class[] classes)
            throws InvalidObjectException
Verifies that there is at least one element, that they are all valid classes, and that no class is assignable to any other class.

Throws:
InvalidObjectException


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.