public class DefaultGroovyMethodsSupport
extends Object
Support methods for DefaultGroovyMethods and PluginDefaultMethods.
| Type Params | Return Type | Name and description |
|---|---|---|
<T> |
protected static Collection<T> |
cloneSimilarCollection(Collection<T> orig, int newCapacity)Copies orig. |
<K, V> |
protected static Map<K, V> |
cloneSimilarMap(Map<K, V> orig)Copies orig. |
|
public static void |
closeQuietly(Closeable c)Closes the Closeable, ignoring any problems that might occur. |
|
public static void |
closeWithWarning(Closeable closeable)Close the Closeable. |
<T> |
protected static T[] |
createSimilarArray(T[] orig, int newCapacity)Allocates an array with the component type of orig and
length newCapacity. |
<T> |
protected static Collection<T> |
createSimilarCollection(Iterable<T> iterable)Builds an empty collection whose concrete type matches iterable
when it is a Collection. |
<T> |
protected static Collection<T> |
createSimilarCollection(Collection<T> collection)Builds an empty collection of the same kind as collection,
using collection.size() as the capacity where the kind
accepts one. |
<T> |
protected static Collection<T> |
createSimilarCollection(Collection<T> orig, int newCapacity)Builds an empty collection of the same kind as orig.
|
<T> |
protected static List<T> |
createSimilarList(List<T> orig, int newCapacity)Builds an empty list of the same kind as orig.
|
<K, V> |
protected static Map<K, V> |
createSimilarMap(Map<K, V> orig)Builds an empty map of the same kind as orig. |
|
protected static Collection |
createSimilarOrDefaultCollection(Object object)Builds an empty collection whose concrete type matches object
when object is a Collection. |
<T> |
protected static Queue<T> |
createSimilarQueue(Queue<T> orig)Builds an empty queue of the same kind as orig.
|
<T> |
protected static Set<T> |
createSimilarSet(Set<T> orig)Builds an empty set of the same kind as orig. |
|
protected static int |
normaliseIndex(int i, int size)Converts a possibly negative index to a real index into the array. |
|
protected static boolean |
sameType(Collection[] cols)Determines if all items of given array are of the same type. |
|
protected static boolean |
sameType(Iterable[] iters)Reports whether the elements of iters fit one type.
|
|
protected static RangeInfo |
subListBorders(int size, Range range)Resolves range to list borders for getAt and putAt.
|
|
protected static RangeInfo |
subListBorders(int size, EmptyRange range)Resolves an empty range to list borders for getAt and putAt. |
|
protected static IntRange |
subListRange(RangeInfo info, IntRange range)Rebuilds an IntRange from borders that were prepared for a sub-list. |
|
protected static void |
writeUTF16BomIfRequired(Writer writer, String charset)Writes a UTF-16 byte-order mark to writer when charset
names UTF-16BE or UTF-16LE. |
|
protected static void |
writeUTF16BomIfRequired(Writer writer, Charset charset)Writes a UTF-16 byte-order mark to writer when the canonical
name of charset is UTF-16BE or UTF-16LE.
|
|
protected static void |
writeUTF16BomIfRequired(OutputStream stream, String charset)Writes a UTF-16 byte-order mark to stream when charset
names UTF-16BE or UTF-16LE. |
|
protected static void |
writeUTF16BomIfRequired(OutputStream stream, Charset charset)Writes a UTF-16 byte-order mark to stream when the canonical
name of charset is UTF-16BE or UTF-16LE.
|
Copies orig. When orig implements Cloneable,
the copy is the result of calling clone and newCapacity
is ignored. Otherwise an empty collection of a similar concrete type
is created with room for newCapacity elements, then filled
from orig.
T - element typeorig - collection to copynewCapacity - capacity of the replacement when orig cannot be clonedorig Copies orig. When orig implements Cloneable,
the copy is the result of calling clone. Otherwise an empty
map of a similar concrete type is created and filled from orig.
K - key typeV - value typeorig - map to copyorigCloses the Closeable, ignoring any problems that might occur.
c - the thing to closeClose the Closeable. Logging a warning if any problems occur.
closeable - the thing to close Allocates an array with the component type of orig and
length newCapacity. Elements of orig are not copied.
An Object[] source produces an Object[] result
rather than a reflective array of Object.
T - component typeorig - array whose component type is reusednewCapacity - length of the allocated arraynewCapacity Builds an empty collection whose concrete type matches iterable
when it is a Collection. Any other iterable yields a new
ArrayList. Elements of iterable are not copied.
T - element typeiterable - source of the concrete collection type Builds an empty collection of the same kind as collection,
using collection.size() as the capacity where the kind
accepts one.
T - element typecollection - collection to imitate Builds an empty collection of the same kind as orig.
A set, list, or queue keeps that kind. Anything else becomes an
ArrayList with capacity newCapacity. The capacity
is not applied to a set or a queue.
T - element typeorig - collection to imitatenewCapacity - initial capacity of a list that is not one of the preserved list classes Builds an empty list of the same kind as orig.
LinkedList, Stack, Vector, and
CopyOnWriteArrayList are preserved. Any other list becomes
an ArrayList with capacity newCapacity.
T - element typeorig - list to imitatenewCapacity - initial capacity when the result is an ArrayList Builds an empty map of the same kind as orig. A sorted map
keeps its comparator: a ConcurrentSkipListMap stays that
class, and any other SortedMap becomes a TreeMap.
ConcurrentHashMap, Hashtable, Properties,
IdentityHashMap, and WeakHashMap are preserved.
Any other map becomes a LinkedHashMap, so insertion order
is kept.
K - key typeV - value typeorig - map to imitate Builds an empty collection whose concrete type matches object
when object is a Collection. Any other value,
including null, yields a new ArrayList.
object - collection to imitate, or any other value Builds an empty queue of the same kind as orig.
An ArrayBlockingQueue is recreated with its original
capacity, the sum of its size and remaining capacity. A
PriorityQueue keeps its comparator. ArrayDeque,
ConcurrentLinkedQueue, DelayQueue,
LinkedBlockingDeque, LinkedBlockingQueue,
PriorityBlockingQueue, and SynchronousQueue are
each recreated as the same class. Any other queue becomes a
LinkedList.
T - element typeorig - queue to imitate Builds an empty set of the same kind as orig. A sorted set
keeps its comparator: a ConcurrentSkipListSet stays that
class, and any other SortedSet becomes a TreeSet.
A CopyOnWriteArraySet is preserved. Any other set becomes
a LinkedHashSet, so insertion order is kept.
T - element typeorig - set to imitate Converts a possibly negative index to a real index into the array.
Throws ArrayIndexOutOfBoundsException when i is negative and its magnitude
exceeds size.
i - the unnormalized indexsize - the array sizeDetermines if all items of given array are of the same type.
cols - an array of collections Reports whether the elements of iters fit one type.
The type is taken from the first element. When that element is a
Number, later numbers of any numeric class are accepted.
No elements counts as one type.
iters - iterables whose elements are comparedtrue when every element fits the type of the first element Resolves range to list borders for getAt and putAt.
An IntRange or NumberRange supplies its own borders.
Any other range has its endpoints normalised against size,
and the ends are swapped when the normalised start sits past the
normalised end, which is how a range written with a negative end is applied.
The end border is one past the last included index.
size - length of the list being indexedrange - range to resolveResolves an empty range to list borders for getAt and putAt. Both borders are the normalised start, so the slice contains no elements.
size - length of the list being indexedrange - empty range whose start is normalised Rebuilds an IntRange from borders that were prepared for a
sub-list. The exclusive end in info becomes an inclusive end,
an exclusive bound is stepped back to the original endpoint, and the
inclusive ends are swapped when info runs backwards.
info - borders previously computed for rangerange - original range, whose inclusive ends are restored Writes a UTF-16 byte-order mark to writer when charset
names UTF-16BE or UTF-16LE. Any other charset name
writes nothing. The name is resolved with Charset.forName.
An illegal name or an unsupported charset fails in that call.
writer - destination for the markcharset - charset name to test Writes a UTF-16 byte-order mark to writer when the canonical
name of charset is UTF-16BE or UTF-16LE.
Any other charset writes nothing.
writer - destination for the markcharset - charset whose canonical name is tested Writes a UTF-16 byte-order mark to stream when charset
names UTF-16BE or UTF-16LE. Any other charset name
writes nothing. The name is resolved with Charset.forName.
An illegal name or an unsupported charset fails in that call.
stream - destination for the markcharset - charset name to test Writes a UTF-16 byte-order mark to stream when the canonical
name of charset is UTF-16BE or UTF-16LE.
Big-endian writes FE FF; little-endian writes FF FE.
Any other charset writes nothing.
stream - destination for the markcharset - charset whose canonical name is tested