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.
 
Field Summary
static int NOT_FOUND
          Constant used by list functions to indicate that no entry could be found.
 
Method Summary
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 extends PartBean>
int
findDuplicateSerialNumberInList(List<T> list)
          Finds the position of the first entry with a duplicate serial number.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
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.
See Also:
equalLists(List, List)
Returns:
the computed hash code.
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.
See Also:
equalLists(List, List)
Returns:
the computed hash code.
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

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

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


OpenPermis Role Based Access Control 0.9.0 (Build 16)
2009/08/13 07:16:59
Copyright (c) 2002-2007 Ergon Informatik AG