org.openpermis.policy.bean.basic
Class BasicUtilities

java.lang.Object
  extended by org.openpermis.policy.bean.basic.BasicUtilities

public final class BasicUtilities
extends Object

Helper functions for part implementations.

Since:
0.1.0

Nested Class Summary
static class BasicUtilities.DetailsProvider<T>
          Provides string details about an item.
private static interface BasicUtilities.Validator<T>
          Validator interface for validateList(List, Validator).
 
Field Summary
private static int MULTI_HASH_CODE_MULTIPLIER
          Multiplier used when combining hash codes.
private static int MULTI_HASH_CODE_SEED
          Seed value used when combining hash codes.
static int NOT_FOUND
          Constant used by list functions to indicate that no entry could be found.
 
Constructor Summary
private BasicUtilities()
          Objects of this class cannot be instantiated.
 
Method Summary
static
<T extends PartBean>
void
assertListIsLegal(PartBean owner, String type, List<T> list)
          Asserts that the list specified is legal.
private static IllegalArgumentException createException(String details, int pos, String type)
          Creates an illegal argument exception from the details specified.
static boolean equalLists(List<?> list1, List<?> list2)
          Compares two lists without respecting the list order.
static boolean equalObjects(Object obj1, Object obj2)
          Convenience function to test if two objects are both null or equivalent.
static
<T> int
findDuplicateListEntry(List<T> list)
          Finds the position of the first entry which is contained twice.
static
<T extends PartBean>
int
findDuplicateSerialNumberInList(List<T> list)
          Finds the position of the first entry with a duplicate serial number.
static
<T extends PartBean>
int
findInvalidSerialNumberInList(List<T> list, SerialNumber context)
          Finds the position of the first entry with an invalid serial number.
static
<T> int
findNullListEntry(List<T> list)
          Finds the first entry which is null.
static
<T> String
getDetails(Iterable<T> collection, BasicUtilities.DetailsProvider<T> provider)
          Returns the details for the specified collection using the provider passed.
static String getIdentityDetails(Identifiable item)
          Returns the identity of the specified part item.
static
<T extends Identifiable>
String
getIdentityDetails(Iterable<T> collection)
          Returns the string details representation for the specified collection.
static
<T extends Nameable>
String
getNameDetails(Iterable<T> collection)
          Returns the string details representation for the specified collection.
static String getNameDetails(Nameable item)
          Returns the name of the specified part item.
static
<T extends PartBean>
String
getShortStringDetails(Iterable<T> collection)
          Returns the string details representation for the specified collection.
static
<T> String
getStringDetails(Iterable<T> collection)
          Returns the string details representation for the specified collection.
static int listHashCode(Iterator<?> iterator)
          Computes the hash code of a list without respecting the list order.
static int listHashCode(List<?> list)
          Computes the hash code of a list without respecting the list order.
static int multiHashCode(int... values)
          Convenience function to create a hash code by combining several other hash code values.
private static
<T> boolean
validateList(List<T> list, BasicUtilities.Validator<T> validator)
          Primitive to validate entries in a list.
static
<T extends Identifiable>
boolean
validateListIdentities(PartProblemReporter reporter, Part owner, String type, List<T> list)
          Validates all identities in the specified list.
static
<T extends Nameable>
boolean
validateListNames(PartProblemReporter reporter, Part owner, String type, List<T> list)
          Validates all names in the specified list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MULTI_HASH_CODE_SEED

private static final int MULTI_HASH_CODE_SEED
Seed value used when combining hash codes.

Constant Field Value:
17
See Also:
multiHashCode(int...), Constant Field Values
Since:
0.1.0

MULTI_HASH_CODE_MULTIPLIER

private static final int MULTI_HASH_CODE_MULTIPLIER
Multiplier used when combining hash codes.

Constant Field Value:
37
See Also:
multiHashCode(int...), Constant Field Values
Since:
0.1.0

NOT_FOUND

public static final int NOT_FOUND
Constant used by list functions to indicate that no entry could be found.

Constant Field Value:
-1
Since:
0.1.0
Constructor Detail

BasicUtilities

private BasicUtilities()
Objects of this class cannot be instantiated.

Since:
0.1.0
Method Detail

multiHashCode

public static final int multiHashCode(int... values)
Convenience function to create a hash code by combining several other hash code values.

Use this method instead of combining multiple hash codes yourself. This method provides a suitable distribution of hash codes.

Parameters:
values - the values to combine.
Returns:
the combined hash code.
Since:
0.1.0

listHashCode

public static final int listHashCode(List<?> list)
Computes the hash code of a list without respecting the list order.

Use if a list is used as if it were a set that allows multiple objects that are equal.

Notes:
Only use in conjunction with equalLists(List, List)!
Parameters:
list - the list for which to compute the hash code.
Returns:
the computed hash code.
See Also:
equalLists(List, List)
Since:
0.1.0

listHashCode

public static final int listHashCode(Iterator<?> iterator)
Computes the hash code of a list without respecting the list order.

Use if a list is used as if it were a set that allows multiple objects that are equal.

Notes:
Only use in conjunction with equalLists(List, List)!
Parameters:
iterator - the iterator for which to compute the hash code.
Returns:
the computed hash code.
See Also:
equalLists(List, List)
Since:
0.1.0

equalLists

public static final boolean equalLists(List<?> list1,
                                       List<?> list2)
Compares two lists without respecting the list order.

Use if a list is used as if it were a set that allows multiple objects that are equal.

Notes:
Only use in conjunction with listHashCode(List)!
Parameters:
list1 - the first list.
list2 - the second list.
Returns:
true if the two lists have an equivalent content, disregarding the order of their entries.
Since:
0.1.0

equalObjects

public static final boolean equalObjects(Object obj1,
                                         Object obj2)
Convenience function to test if two objects are both null or equivalent.

Parameters:
obj1 - the first object.
obj2 - the second object.
Returns:
true if both objects are null or equivalent.
Since:
0.1.0

createException

private static final IllegalArgumentException createException(String details,
                                                              int pos,
                                                              String type)
Creates an illegal argument exception from the details specified.

Parameters:
details - the exception cause.
pos - the position to include.
type - the type in which the cause was detected, may be null.
Returns:
the exception created.
Since:
0.1.0

assertListIsLegal

public static <T extends PartBean> void assertListIsLegal(PartBean owner,
                                                          String type,
                                                          List<T> list)
                              throws IllegalArgumentException
Asserts that the list specified is legal.

Lists are considered legal if the following conditions are met:

Type Parameters:
T - the type of the list to validate.
Parameters:
owner - the part that owns (or will own) the list, may be null.
type - the type of list (used in exceptions thrown), may be null.
list - the list to validate. may be null.
Throws:
IllegalArgumentException - thrown if any of the conditions listed above is violated.
Since:
0.1.0

findNullListEntry

public static <T> int findNullListEntry(List<T> list)
Finds the first entry which is null.

Type Parameters:
T - the type of the list to search.
Parameters:
list - the list to search.
Returns:
the index of the first entry found, NOT_FOUND if there is no such entry.
Since:
0.1.0

findDuplicateListEntry

public static <T> int findDuplicateListEntry(List<T> list)
Finds the position of the first entry which is contained twice.

Comparison is done by comparing the object identity (==).

Type Parameters:
T - the type of the list to search.
Parameters:
list - the list to search.
Returns:
the index of the first entry found, NOT_FOUND if there is no such entry.
Since:
0.1.0

findDuplicateSerialNumberInList

public static <T extends PartBean> int findDuplicateSerialNumberInList(List<T> list)
Finds the position of the first entry with a duplicate serial number.

Type Parameters:
T - the type of the list to search.
Parameters:
list - the list to search.
Returns:
the index of the first entry found, NOT_FOUND if there is no such entry.
Since:
0.1.0

findInvalidSerialNumberInList

public static <T extends PartBean> int findInvalidSerialNumberInList(List<T> list,
                                                                     SerialNumber context)
Finds the position of the first entry with an invalid serial number.

An entry is considered to have an invalid serial number if:

SerialNumber.UNDEFINED serial numbers are ignored.

Type Parameters:
T - the type of the list to search.
Parameters:
list - the list to search.
context - the serial number whose context is to be matched, must not be null and must not be SerialNumber.UNDEFINED.
Returns:
the index of the first entry found, NOT_FOUND if there is no such entry.
Since:
0.1.0

validateList

private static <T> boolean validateList(List<T> list,
                                        BasicUtilities.Validator<T> validator)
Primitive to validate entries in a list.

Type Parameters:
T - the type of list to validate.
Parameters:
list - the list to validate.
validator - the validator to use.
Returns:
true if the list is valid.
Since:
0.1.0

validateListNames

public static <T extends Nameable> boolean validateListNames(PartProblemReporter reporter,
                                                             Part owner,
                                                             String type,
                                                             List<T> list)
Validates all names in the specified list.

Entries with duplicate names are reported using the specified reporter.

Type Parameters:
T - the type of list to validate.
Parameters:
reporter - the reporter to use, may be null.
owner - the owner used when reporting problems.
type - the type used when reporting problems.
list - the list to validate, must not be null.
Returns:
true if there are no duplicate names in the list.
Since:
0.1.0

validateListIdentities

public static <T extends Identifiable> boolean validateListIdentities(PartProblemReporter reporter,
                                                                      Part owner,
                                                                      String type,
                                                                      List<T> list)
Validates all identities in the specified list.

Entries with duplicate identities are reported using the specified reporter.

Type Parameters:
T - the type of list to validate.
Parameters:
reporter - the reporter to use, may be null.
owner - the owner used when reporting problems.
type - the type used when reporting problems.
list - the list to validate, must not be null.
Returns:
true if there are no duplicate identities in the list.
Since:
0.1.0

getDetails

public static <T> String getDetails(Iterable<T> collection,
                                    BasicUtilities.DetailsProvider<T> provider)
Returns the details for the specified collection using the provider passed.

The collection is surrounded by curly brackets to indicate that it's a collection.

Type Parameters:
T - the type of collection to process.
Parameters:
collection - the collection to process.
provider - the provider to use for string details.
Returns:
the string representation requested.
Since:
0.1.0

getStringDetails

public static <T> String getStringDetails(Iterable<T> collection)
Returns the string details representation for the specified collection.

The details are created using Object.toString() of the items.

Type Parameters:
T - the type of collection to process.
Parameters:
collection - the collection to process.
Returns:
the string representation requested.
Since:
0.1.0

getShortStringDetails

public static <T extends PartBean> String getShortStringDetails(Iterable<T> collection)
Returns the string details representation for the specified collection.

The details are created using Object.toString() of the items.

Type Parameters:
T - the type of collection to process.
Parameters:
collection - the collection to process.
Returns:
the string representation requested.
Since:
0.1.0

getIdentityDetails

public static <T extends Identifiable> String getIdentityDetails(Iterable<T> collection)
Returns the string details representation for the specified collection.

The details are created using the Identifiable.getIdentity() of the items.

Type Parameters:
T - the type of collection to process.
Parameters:
collection - the collection to process.
Returns:
the string representation requested.
Since:
0.1.0

getNameDetails

public static <T extends Nameable> String getNameDetails(Iterable<T> collection)
Returns the string details representation for the specified collection.

The details are created using the Nameable.getName() of the items.

Type Parameters:
T - the type of collection to process.
Parameters:
collection - the collection to process.
Returns:
the string representation requested.
Since:
0.3.0

getIdentityDetails

public static String getIdentityDetails(Identifiable item)
Returns the identity of the specified part item.

The value is returned in square brackets to indicate that it's an object.

Parameters:
item - the item to inspect, may be null.
Returns:
the identity of the specified part item or the string representation of null if the item specified is null.
Since:
0.1.0

getNameDetails

public static String getNameDetails(Nameable item)
Returns the name of the specified part item.

The value is returned in curly brackets to indicate that it's an object.

Parameters:
item - the item to inspect, may be null.
Returns:
the name of the specified part item or the string representation of null if the item specified is null.
Since:
0.1.0


PERMIS Role Based Access Control 0.4.0 (Build 15)
2009/05/20 08:14:59
Copyright (c) 2002-2007 Ergon Informatik AG