|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jaxfront.core.util.io.files.Objects
public class Objects
Method Summary | |
---|---|
static java.util.Map |
asMap(java.lang.Object[] pairs)
Deprecated. |
static java.util.Map |
compose(java.util.Map f,
java.util.Map g)
composes two Maps (like functions, if you know what I mean) |
static long |
crc32(byte[] data)
Calculates crc32 on a byte array |
static long |
crc32(byte[] data,
int off,
int len)
Calculates crc32 on a byte array |
static java.util.Map |
getMap()
Map factory |
static java.util.Map |
getMap(int size)
Map factory |
static java.util.Set |
getSet(int size)
Set factory |
static int |
indexOf(java.lang.Object what,
java.util.List list)
Gets the index of the first element of an list that equals to specified object |
static int |
indexOf(java.lang.Object what,
java.util.List list,
int fromIndex)
Gets the index of the next element of a list that equals to specified object |
static int |
indexOf(java.lang.Object what,
java.lang.Object[] array)
Gets the index of the first element of an array that equals to specified object |
static int |
indexOf(java.lang.Object what,
java.lang.Object[] array,
int fromIndex)
Gets the index of the next element of an array that equals to specified object |
static java.util.Map |
inverse(java.util.Map f)
Inverses a Map |
static boolean |
isEmpty(java.lang.Object data)
In a "creative" way checks whether a string or a container is empty. |
static java.util.Collection |
map(java.util.Map m,
java.util.Collection domain)
Maps a Collection using Map. |
static java.util.List |
map(java.util.Map m,
java.util.List domain)
Maps a List using Map. |
static java.lang.Object[] |
map(java.util.Map m,
java.lang.Object[] domain)
Maps an array using Map. |
static java.lang.Object[] |
map(java.util.Map m,
java.lang.Object[] domain,
java.lang.Object defaultValue)
Maps an array using Map, with a default value. |
static java.lang.Object[] |
map(java.util.Map m,
java.lang.Object[] domain,
java.lang.Object[] defaultValues)
Maps an array using Map, with default values. |
static java.util.HashMap |
reallocate(java.util.Map map)
Reallocates Map to a new HashMap, to improve hash map access. |
static byte[] |
toBytes(char[] from)
Converts char array to byte array (per-element casting) |
static byte[] |
toBytes(long from)
Converts long to byte array (lower bytes first) |
static char[] |
toChars(byte[] from)
Converts byte array to char array (per-element casting) |
static java.util.Map |
toMap(java.lang.Object[] pairs)
makes a Map from key-value pairs |
static java.util.Map |
toMap(java.lang.Object key,
java.lang.Object value)
makes a singleton Map from a key-value pair |
static java.util.Map |
toMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2)
makes a Map from two key-value pairs |
static java.util.Map |
toMap(java.lang.Object key1,
java.lang.Object value1,
java.lang.Object key2,
java.lang.Object value2,
java.lang.Object key3,
java.lang.Object value3)
makes a Map from three key-value pairs |
static java.util.Set |
toSet(java.lang.Object[] objects)
makes a Set from an array of objects |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final java.lang.Object[] map(java.util.Map m, java.lang.Object[] domain)
m
- the mapdomain
- the domain array
Suppose we have the following: Map m = new HashMap();
m.put("a", "ValueOfA"); m.put("b", "ValueOfB"); m.put("c", "ValueOfC");
Then map(m, new String[] {"b", "x", "b"})
returns new String[] {"ValueOfB", null, "ValueOfB"}.
public static final java.util.List map(java.util.Map m, java.util.List domain)
m
- the mapdomain
- the domain list
Suppose we have the following: Map m = new HashMap();
m.put("a", "ValueOfA"); m.put("b", "ValueOfB"); m.put("c", "ValueOfC");
Then map(m, Arrays.asList(new String[] {"b", "x", "b"}))
returns a List that contains "ValueOfB", null, and "ValueOfB".
public static final java.util.Collection map(java.util.Map m, java.util.Collection domain)
m
- the mapdomain
- the domain list
Suppose we have the following: Map m = new HashMap();
m.put("a", "ValueOfA"); m.put("b", "ValueOfB"); m.put("c", "ValueOfC");
Then map(m, Arrays.asList(new String[] {"b", "x", "b"}))
returns a Collection that contains "ValueOfB", null, and "ValueOfB".
public static final java.lang.Object[] map(java.util.Map m, java.lang.Object[] domain, java.lang.Object defaultValue)
m
- the mapdomain
- the domain arraydefaultValue
- the value that is returned when an element of domain is not
in the list of m keys
Suppose we have the following: Map m = new HashMap();
m.add("a", "ValueOfA"); m.add("b", "ValueOfB", m.add("c", "ValueOfC");
Then map(m, new String[] {"b", "x", "b"}, "Johnny Doe")
returns new String[] {"ValueOfB", "Johnny Doe", "ValueOfB"}.
public static final java.lang.Object[] map(java.util.Map m, java.lang.Object[] domain, java.lang.Object[] defaultValues)
m
- the mapdomain
- the domain arraydefaultValues
- the values that are returned when an element of domain is not
in the list of m keys
Suppose we have the following: Map m = new HashMap();
m.add("a", "ValueOfA"); m.add("b", "ValueOfB", m.add("c", "ValueOfC");
Then map(m, new String[] {"b", "x", "b"}, new String[] {"Johnny A", "Johnny Bee", "Johnny Doe"})
returns new String[] {"ValueOfB", "Johnny Bee", "ValueOfB"}.
public static java.util.Map compose(java.util.Map f, java.util.Map g)
f
- Map first Mapg
- Map second Map
Suppose we have the following:
Map f = toMap(new String[] {"1", "one", "2", "two", "3", "three"});
Map g = toMap(new String[] {"one", "uno", "two", "dos", "three", "tres"});
Then compose(f, g)
returns the same map as produced by
toMap(new String[] {"1", "uno", "2", "dos", "3", "tres"});
public static java.util.Map inverse(java.util.Map f) throws java.lang.InstantiationException
f
- Map to inverse, must be monomorphic (one-to-one)
Suppose we have the following: Then
Map f = toMap(new String[] {"1", "one", "2", "two", "3", "three"});
inverse(f)
returns the same map as produced by
toMap(new String[] {"one", "1", "two", "2", "three", "3"});
java.lang.InstantiationException
- in case f is not one-to-one
public static final java.util.Map asMap(java.lang.Object[] pairs)
pairs
- the source array
Example:
asMap(new String[] {"1", "one", "2", "two", "3", "three"})
returns a map with three keys ("1", "2", "3"), and guess which values.
public static final boolean isEmpty(java.lang.Object 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[] {1})
returns false.public static final byte[] toBytes(char[] from)
from
- char array
toBytes(new char[] {0x0123, 0x4567, 0x89ab, 0xcdef})
returns {0x23, 0x67, (byte)0xab, (byte)0xef}.public static final char[] toChars(byte[] from)
from
- byte array
toChars(new byte[] {0x23, 0x67, (byte)0xab, (byte)0xef})
returns new char[] {0x23, 0x67, 0xab, 0xef}.public static final long crc32(byte[] data)
data
- source bytes
crc32(new byte[] {1, 2, 3})
returns 1438416925.public static final long crc32(byte[] data, int off, int len)
data
- source bytesoff
- offset in the arraylen
- length of the area to crc
crc32(new byte[] {0, 1, 2, 3, 4}, 1, 3)
returns 1438416925.public static final byte[] toBytes(long from)
from
- the long value
toBytes(0x0123456789abcdefl)
returns {(byte)0xef, (byte)0xcd, (byte)0xab, (byte)0x89, 0x67, 0x45, 0x23, 0x01}.public static int indexOf(java.lang.Object what, java.lang.Object[] array)
what
- the object to look for in arrayarray
- 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 int indexOf(java.lang.Object what, java.lang.Object[] array, int fromIndex)
what
- the object to look for in arrayarray
- array of objects to look for whatfromIndex
- 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 int indexOf(java.lang.Object what, java.util.List list)
what
- the object to look for in listlist
- list of objects to look for what
List l = new ArrayList();
l.add("123"); l.add("abc"), l.add("xyz");
indexOf("abc", list, 1}
returns 1;List l = new ArrayList();
l.add("123"); l.add("abc"), l.add(null);
indexOf(null, list)
returns 2;
public static int indexOf(java.lang.Object what, java.util.List list, int fromIndex)
what
- the object to look for in listlist
- list of objects to look for whatfromIndex
- 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 java.util.Map getMap()
public static java.util.Map getMap(int size)
size
- the number of keys
public static java.util.Set getSet(int size)
size
- the number of keys
public static java.util.Map toMap(java.lang.Object key, java.lang.Object value)
key
- Objectvalue
- Object
toMap("the key", "This is the value").get("the key");
returns "This is the value";public static java.util.Map toMap(java.lang.Object key1, java.lang.Object value1, java.lang.Object key2, java.lang.Object value2)
key1
- Object first keyvalue1
- Object first valuekey2
- Object second keyvalue2
- Object second value
toMap("2", "kaksi", "3", "kolmi").get("3");
returns "kolmi";public static java.util.Map toMap(java.lang.Object key1, java.lang.Object value1, java.lang.Object key2, java.lang.Object value2, java.lang.Object key3, java.lang.Object value3)
key1
- Object first keyvalue1
- Object first valuekey2
- Object second keyvalue2
- Object second valuekey3
- Object third keyvalue3
- Object third value
toMap("1", "un", "2", "deux", "3", "troix").get("2");
returns "deux";public static java.util.Map toMap(java.lang.Object[] pairs)
pairs
- Object[] odd elements of the array are keys, and even elements are values
pairs
array to even elements;
if pairs is null, returns null
toMap(new String[] {"1", "un", "2", "deux", "3", "troix"}).get("2");
returns "deux";public static java.util.Set toSet(java.lang.Object[] objects)
objects
- Object[] objects to fill the collection
toSet(new String[] {"1", "2", "3").size();
returns 3;public static java.util.HashMap reallocate(java.util.Map map)
map
- Map
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |