|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.myjavatools.lib.foundation.Objects
public abstract class Objects
Objects is a utility class that contains various unsorted static methods for foundation package
Maps
,
Function
Constructor Summary | |
---|---|
Objects()
|
Method Summary | ||
---|---|---|
static
|
addAll(java.util.Collection<T> collection,
java.lang.Iterable<T> toAdd)
Adds all elements of iterable to a collection. |
|
static boolean |
equal(java.lang.Object x,
java.lang.Object y)
The method that everyone needs and nobody wants to make public. |
|
static
|
indexOf(T what,
java.util.List<T> list,
int fromIndex)
Gets the index of the next element of a list that equals to specified object |
|
static
|
indexOf(T what,
T[] array)
Gets the index of the first element of an array that equals to specified object |
|
static
|
indexOf(T what,
T[] array,
int fromIndex)
Gets the index of the next element of an array that equals to specified object |
|
static
|
isEmpty(T data)
In a "creative", anti-scientific way checks whether a string or a container is empty. |
|
static
|
oneOf(T... arglist)
Chooses the first non-empty object out of objects in parameter list. |
|
static
|
toSet(T... elements)
Deprecated. since 5.0; the usefulness of this method is doubtful |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Objects()
Method Detail |
---|
public static <T> int indexOf(T what, T[] array)
what
- T the object to look for in arrayarray
- T[] array of objects to look for what
indexOf("abc", new String[] {"123", "abc", "xyz"})
returns 1;indexOf(null, new String[] {"123", "abc", null})
returns 2;public static boolean equal(java.lang.Object x, java.lang.Object y)
x
- Objecty
- Object
public static <T> int indexOf(T what, T[] array, int fromIndex)
what
- T the object to look for in arrayarray
- T[] array of objects to look for whatfromIndex
- int start search from this position
indexOf("abc", new String[] {"abc", "abc", "xyz", 1})
returns 1;indexOf(null, new String[] {"123", "abc", null}}, 1)
returns 2;public static <T> int indexOf(T what, java.util.List<T> list, int fromIndex)
what
- T the object to look for in listlist
- List<T> list of objects to look for whatfromIndex
- int start search from this position
List l = new ArrayList();
l.add("abc"); l.add("abc"), l.add("xyz");
indexOf("abc", list, 1}
returns 1;List l = new ArrayList();
l.add("abc"); l.add("abc"), l.add(null);
indexOf(null, list, 1}
returns 2;public static <T> java.util.Set<T> toSet(T... elements)
elements
- T[] elements to fill the set
toSet(new String[] {"1", "2", "3").size()
return 3;toSet(3, 1, 4, 1, 5, 9, 2, 6, 5).size()
returns 7.public static <T> boolean isEmpty(T data)
Collection
, a Map
, an array, a String
.
data
- a Collection or a Map or an array or a string to check
isEmpty(""), isEmpty(null), isEmpty(new HashMap())
all return true;isEmpty(" "), isEmpty(new int[] {0})
returns false.public static <T> T oneOf(T... arglist)
arglist
- the first candidate ...
oneOf(null, "xyz")
returns "xyz";oneOf("abc", "xyz")
returns "abc";oneOf(null, "", "xyz")
returns "xyz";oneOf("abc", null, "xyz")
returns "abc";oneOf("", "def", null)
returns "def";oneOf(null, null, 2)
returns 2.oneOf("abc", null, "pqr", "xyz")
returns "abc";oneOf("", "def", null, "xyz")
returns "def";public static <T> void addAll(java.util.Collection<T> collection, java.lang.Iterable<T> toAdd)
collection
- CollectiontoAdd
- Iterable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |