Package org.eclipse.cdt.core.parser.util
Class ArrayUtil
java.lang.Object
org.eclipse.cdt.core.parser.util.ArrayUtil
- Restriction:
- This class is not intended to be subclassed by clients.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]Takes contents of the two arrays up to the firstnullelement and concatenates them.static <T> voidaddAll(Collection<? super T> collection, T... elements) Adds all elements of an array to a collection.static <T> T[]Takes contents of the two arrays up to the firstnullelement and concatenates them.static Object[]Deprecated.static <T> T[]Assumes that array containsnulls at the end, only.static <T> T[]append(T[] array, T obj) Assumes that array containsnulls at the end, only.static <T> T[]Assumes that array containsnulls at the end, only.static <T> T[]appendAt(T[] array, int currentLength, T obj) Assumes that array containsnulls at the end, only.static voidMoves allnullelements to the end of the array.static <T> booleancontains(T[] array, T obj) Returns whether the specified array contains the specified object.static <T> booleancontainsEqual(T[] array, T obj) Assumes that array containsnulls at the end, only.static <S,T> T[] Stores the specified array contents in a new array of specified runtime type.static <T> T[]filter(T[] array, IUnaryPredicate<T> predicate) Filter the elements of an array down to just the ones that match the given predicate.static <T> intindexOf(T[] array, T obj) Returns the index into the specified array of the specified object, or -1 if the array does not contain the object, or if the array isnull.static <T> intindexOfEqual(T[] array, T obj) Assumes that array containsnulls at the end, only.static <T> T[]Inserts theobjat the beginning of the array, shifting the whole thing one index Assumes that array containsnulls at the end, only.static <T> T[]prepend(T[] array, T obj) Inserts theobjat the beginning of the array, shifting the whole thing one index Assumes that array containsnulls at the end, only.static <T> voidremove(T[] array, T element) Removes first occurrence of element in array and moves objects behind up front.static <T> T[]removeDuplicates(T[] array) Returns a new array that contains elements of the given array except duplicates andnulls.static <T> T[]removeFirst(T[] array) Returns a new array that contains all of the elements of the given array except the first one.static <T> T[]removeNulls(Class<T> c, T[] array) Removes all of thenulls from the array and returns a new array that contains all of the non-nullelements.static <T> T[]removeNulls(T[] array) Removes all of thenulls from the array and returns a new array that contains all of the non-nullelements.static Object[]removeNullsAfter(Class<?> c, Object[] array, int index) Deprecated.Usetrim(Object[], int)ortrimAt(Class, Object[], int)insteadstatic voidReverses order of elements in an array.static voidReverses order of elements in a subsection of an array.static int[]setInt(int[] array, int idx, int val) static <T> T[]static <T> T[]Trims the given array and returns a new array with nonullentries.static <T> T[]trim(T[] array) Trims the given array and returns a new array with nonullentries.static <T> T[]trim(T[] array, boolean forceNew) Trims the given array and returns a new array with nonullentries.static <T> T[]trim(T[] array, int newLength) Trims the given array and returns a new array with nonullentries.static <T> T[]To improve performance, this method should be used instead ofremoveNulls(Class, Object[])when all of the non-nullelements in the array are grouped together at the beginning of the array and all of the s are at the end of the array.
-
Constructor Details
-
ArrayUtil
public ArrayUtil()
-
-
Method Details
-
append
Assumes that array containsnulls at the end, only. Appends element after the last non-nullelement. If the array isnullor not large enough, a larger one is allocated, using the given class object. -
append
public static <T> T[] append(T[] array, T obj) Assumes that array containsnulls at the end, only. Appends element after the last non-nullelement. If the array is not large enough, a larger one is allocated. Nullarrayis supported for backward compatibility only and only when T is Object. -
append
@Deprecated public static Object[] append(Class<?> c, Object[] array, int currentLength, Object obj) Deprecated.UseappendAt(Class, Object[], int, Object)instead.- Since:
- 4.0
- Restriction:
- This method is not intended to be referenced by clients.
-
appendAt
Assumes that array containsnulls at the end, only. Appends object using the current length of the array.- Since:
- 5.1
-
appendAt
public static <T> T[] appendAt(T[] array, int currentLength, T obj) Assumes that array containsnulls at the end, only. Appends object using the current length of the array.- Parameters:
array- The array to append to. NotnullcurrentLength- The number of non-nullelements in the arrayobj- The object to append. Notnull- Returns:
- The modified array, which may be the same as the first parameter.
- Since:
- 5.4
-
trim
Trims the given array and returns a new array with nonullentries. Assumes thatnulls can be found at the end, only. ifarrayisnull, a new array of length 0 is returned ifforceNewistrue, a new array will always be created. ifforceNewisfalse, a new array will only be created if the original array containednullentries.- Parameters:
c- the type of the new arrayarray- the array to be trimmedforceNew-
-
trim
-
trim
public static <T> T[] trim(T[] array, boolean forceNew) Trims the given array and returns a new array with nonullentries. Assumes thatnulls can be found at the end, only. ifforceNewistrue, a new array will always be created. ifforceNewisfalse, a new array will only be created if the original array containednullentries.- Parameters:
array- the array to be trimmedforceNew-- Since:
- 5.2
-
trim
public static <T> T[] trim(T[] array) Trims the given array and returns a new array with nonullentries. Assumes thatnulls can be found at the end, only.- Parameters:
array- the array to be trimmed- Since:
- 5.2
-
trim
public static <T> T[] trim(T[] array, int newLength) Trims the given array and returns a new array with nonullentries. Assumes thatnulls can be found at the end, only. Similar totrimAt(Class, Object[], int), but uses the new length instead of index.- Parameters:
array- the array to be trimmednewLength- the new length of the array, has to be less or equal than the current length.- Returns:
- the modified array, which may be the same as the first parameter.
- Since:
- 5.4
-
addAll
Takes contents of the two arrays up to the firstnullelement and concatenates them.- Parameters:
c- The type of the element of the returned array if there was not enough free space in the destination array.dest- The destination array. The elements of the source array are added to this array if there is enough free space in it. May benull.source- The source array. May not benull.- Returns:
- The concatenated array, which may be the same as the first parameter.
-
addAll
Takes contents of the two arrays up to the firstnullelement and concatenates them.- Parameters:
dest- The destination array. The elements of the source array are added to this array if there is enough free space in it. May benull.source- The source array. May not benull.- Returns:
- The concatenated array, which may be the same as the first parameter.
- Since:
- 5.2
-
addAll
Adds all elements of an array to a collection. For anArrayListthis method is slightly more efficient thanCollections.addAll(Collection, Object...).- Since:
- 5.4
-
contains
public static <T> boolean contains(T[] array, T obj) Returns whether the specified array contains the specified object. The comparison is by object identity.- Parameters:
array- the array to searchobj- the object to search for- Returns:
trueif the specified array contains the specified object, or the specified array isnull
-
indexOf
public static <T> int indexOf(T[] array, T obj) Returns the index into the specified array of the specified object, or -1 if the array does not contain the object, or if the array isnull. Comparison is by object identity.- Parameters:
array- the array to searchobj- the object to search for- Returns:
- the index into the specified array of the specified object, or -1 if the array does
not contain the object, or if the array is
null
-
containsEqual
public static <T> boolean containsEqual(T[] array, T obj) Assumes that array containsnulls at the end, only. Returns whether the specified array contains the specified object. Comparison is by object identity.- Parameters:
array- the array to searchobj- the object to search for- Returns:
- true if the specified array contains the specified object, or the specified array is
null
-
indexOfEqual
public static <T> int indexOfEqual(T[] array, T obj) Assumes that array containsnulls at the end, only. Returns the index into the specified array of the specified object, or -1 if the array does not contain the object, or if the array isnull. Comparison is by equals().- Parameters:
array- the array to searchobj- the object to search for- Returns:
- the index into the specified array of the specified object, or -1 if the array does
not contain an equal object, or if the array is
null
-
compact
Moves allnullelements to the end of the array. The order of non-nullelements is preserved.- Since:
- 5.4
-
removeNulls
Removes all of thenulls from the array and returns a new array that contains all of the non-nullelements. If there are nonulls in the original array then the original array is returned. Note that this method should only be used when the placement ofnulls within the array is unknown (due to performance efficiency). -
removeNulls
public static <T> T[] removeNulls(T[] array) Removes all of thenulls from the array and returns a new array that contains all of the non-nullelements.If there are no
nulls in the original array then the original array is returned.Note that this method should only be used when the placement of
nulls within the array is unknown (due to performance efficiency).- Since:
- 5.2
-
removeNullsAfter
Deprecated.Usetrim(Object[], int)ortrimAt(Class, Object[], int)instead- Restriction:
- This method is not intended to be referenced by clients.
-
trimAt
To improve performance, this method should be used instead ofremoveNulls(Class, Object[])when all of the non-nullelements in the array are grouped together at the beginning of the array and all of the s are at the end of the array. The position of the last non-nullelement in the array must also be known.If you don't intend to pass
nullarray, consider usingtrim(Object[], int)instead.- Since:
- 5.1
-
prepend
Inserts theobjat the beginning of the array, shifting the whole thing one index Assumes that array containsnulls at the end, only. -
prepend
public static <T> T[] prepend(T[] array, T obj) Inserts theobjat the beginning of the array, shifting the whole thing one index Assumes that array containsnulls at the end, only. array must not benull.- Since:
- 5.2
-
remove
public static <T> void remove(T[] array, T element) Removes first occurrence of element in array and moves objects behind up front.- Since:
- 4.0
-
convert
Stores the specified array contents in a new array of specified runtime type.- Parameters:
target- the runtime type of the new arraysource- the source array- Returns:
- the current array stored in a new array with the specified runtime type,
or
nullif source isnull.
-
reverse
Reverses order of elements in an array.- Parameters:
array- the array- Since:
- 5.4
-
reverse
Reverses order of elements in a subsection of an array.- Parameters:
array- the arrayfromIndex- the index of the first affected element (inclusive)toIndex- the index of the last affected element (exclusive)- Since:
- 5.4
-
removeFirst
public static <T> T[] removeFirst(T[] array) Returns a new array that contains all of the elements of the given array except the first one.- Throws:
NullPointerException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 5.1
-
removeDuplicates
public static <T> T[] removeDuplicates(T[] array) Returns a new array that contains elements of the given array except duplicates andnulls. Duplicates are determined byObject.equals(Object)method.- Throws:
NullPointerException- ifarrayisnull- Since:
- 5.5
-
setInt
public static int[] setInt(int[] array, int idx, int val) -
filter
Filter the elements of an array down to just the ones that match the given predicate.- Since:
- 5.6
-
appendAt(Class, Object[], int, Object)instead.