net.sf.mmm.util.lang.base
Class BasicUtilImpl

java.lang.Object
  extended by net.sf.mmm.util.lang.base.BasicUtilImpl
All Implemented Interfaces:
BasicUtil

@Singleton
@Named
public class BasicUtilImpl
extends Object
implements BasicUtil

This is the implementation of the BasicUtil interface.

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
getInstance()

Field Summary
private static BasicUtil instance
           
 
Fields inherited from interface net.sf.mmm.util.lang.api.BasicUtil
EMPTY_INT_ARRAY
 
Constructor Summary
BasicUtilImpl()
          The constructor.
 
Method Summary
 boolean compare(CharIterator charIterator1, CharIterator charIterator2)
          This method compares the given CharIterator instances char by char.
 int findInArray(Object value, Object[] array, boolean checkEqual)
          This method returns the index of the first element in the given array that equals (see checkEqual) to the given value.
 int findInArray(Object value, Object array, boolean checkEqual)
          This method returns the index of the first element in the given array that equals (see checkEqual) to the given value.
static BasicUtil getInstance()
          This method gets the singleton instance of this BasicUtilImpl.
 boolean isDeepEqual(Object o1, Object o2)
          This method checks if two given objects are equal to each other.
 boolean isEqual(Object[] array1, Object[] array2)
          This method checks if two given arrays are structurally equal to each other.
 boolean isEqual(Object o1, Object o2)
          This method checks if two given objects are equal to each other.
 boolean isInArray(Object value, Object[] array, boolean checkEqual)
          This method determines if the given array contains an element that equals (see checkEqual) to the given value.
 boolean isInArray(Object value, Object array, boolean checkEqual)
          This method determines if the given array contains an element that equals (see checkEqual) to the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static BasicUtil instance
See Also:
getInstance()
Constructor Detail

BasicUtilImpl

public BasicUtilImpl()
The constructor.

Method Detail

getInstance

public static BasicUtil getInstance()
This method gets the singleton instance of this BasicUtilImpl.
This design is the best compromise between easy access (via this indirection you have direct, static access to all offered functionality) and IoC-style design which allows extension and customization.
For IoC usage, simply ignore all static getInstance() methods and construct new instances via the container-framework of your choice (like plexus, pico, springframework, etc.). To wire up the dependent components everything is properly annotated using common-annotations (JSR-250). If your container does NOT support this, you should consider using a better one.

Returns:
the singleton instance.

isEqual

public boolean isEqual(Object o1,
                       Object o2)
This method checks if two given objects are equal to each other. In advance to Object.equals(Object) the objects may be null.

Specified by:
isEqual in interface BasicUtil
Parameters:
o1 - the first object to compare. It may be null.
o2 - the second object to compare. It may be null.
Returns:
true if both objects are null or the first is NOT null and o1.equals(o2), false otherwise.
See Also:
BasicUtil.isDeepEqual(Object, Object)

isEqual

public boolean isEqual(Object[] array1,
                       Object[] array2)
This method checks if two given arrays are structurally equal to each other. On arrays the equals-method only checks for identity. This method checks that both arrays have the same length and if so that the objects contained in the arrays are equal. Additionally the given arrays may be null.

Specified by:
isEqual in interface BasicUtil
Parameters:
array1 - the first array to compare. It may be null.
array2 - the second array to compare. It may be null.
Returns:
true if both arrays are null or the first is NOT null and both arrays have the same length and equal content, false otherwise.

isDeepEqual

public boolean isDeepEqual(Object o1,
                           Object o2)
This method checks if two given objects are equal to each other. In advance to Object.equals(Object) the objects may be null and arrays are compared structural recursively.

Specified by:
isDeepEqual in interface BasicUtil
Parameters:
o1 - the first object to compare. It may be null.
o2 - the second object to compare. It may be null.
Returns:
true if both objects are null or the first is NOT null and o1.equals(o2), false otherwise.

findInArray

public int findInArray(Object value,
                       Object[] array,
                       boolean checkEqual)
This method returns the index of the first element in the given array that equals (see checkEqual) to the given value.

Specified by:
findInArray in interface BasicUtil
Parameters:
value - is the value to check. It may be null.
array - is the array to check.
checkEqual - - if true the value only needs to be equal to an element, if false it needs to be the same (==).
Returns:
the according index or -1 if value is NOT contained in array.

findInArray

public int findInArray(Object value,
                       Object array,
                       boolean checkEqual)
This method returns the index of the first element in the given array that equals (see checkEqual) to the given value.
Unlike BasicUtil.findInArray(Object, Object[], boolean) this method also works for primitive arrays (such as int[]). In such case you need to supply the according object-type for value.

Specified by:
findInArray in interface BasicUtil
Parameters:
value - is the value to check. It may be null.
array - is the array to check.
checkEqual - - if true the value only needs to be equal to an element, if false it needs to be the same (==).
Returns:
the according index or -1 if value is NOT contained in array.

isInArray

public boolean isInArray(Object value,
                         Object[] array,
                         boolean checkEqual)
This method determines if the given array contains an element that equals (see checkEqual) to the given value.

Specified by:
isInArray in interface BasicUtil
Parameters:
value - is the value to check. It may be null.
array - is the array to check.
checkEqual - - if true the value only needs to be equal to an element, if false it needs to be the same (==).
Returns:
true if the array contains value.
See Also:
BasicUtil.findInArray(Object, Object[], boolean)

isInArray

public boolean isInArray(Object value,
                         Object array,
                         boolean checkEqual)
This method determines if the given array contains an element that equals (see checkEqual) to the given value.

Specified by:
isInArray in interface BasicUtil
Parameters:
value - is the value to check. It may be null.
array - is the array to check.
checkEqual - - if true the value only needs to be equal to an element, if false it needs to be the same (==).
Returns:
true if the array contains value.
See Also:
BasicUtil.findInArray(Object, Object, boolean)

compare

public boolean compare(CharIterator charIterator1,
                       CharIterator charIterator2)
This method compares the given CharIterator instances char by char.

Specified by:
compare in interface BasicUtil
Parameters:
charIterator1 - is the first CharIterator.
charIterator2 - is the second CharIterator.
Returns:
true if both CharIterators produced the same next chars until both ended at the same time.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.