Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Arrays.java « util « holoeverywhere « org « src « library « HoloEverywhere « 3rd_party « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5459b41ae10c7d5f13fbf63e8f5e389a9fe8f22f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

package org.holoeverywhere.util;

import java.lang.reflect.Array;

public class Arrays {
    @SuppressWarnings("unchecked")
    public static <T> T[] copyOfRange(T[] original, int from, int to) {
        return Arrays.copyOfRange(original, from, to,
                (Class<T[]>) original.getClass());
    }

    @SuppressWarnings("unchecked")
    public static <T, U> T[] copyOfRange(U[] original, int from, int to,
            Class<? extends T[]> newType) {
        int newSize = to - from;
        if (newSize < 0) {
            throw new IllegalArgumentException(from + " > " + to);
        }
        T[] copy = (Object) newType == (Object) Object[].class ? (T[]) new Object[newSize]
                : (T[]) Array.newInstance(newType.getComponentType(), newSize);
        System.arraycopy(original, from, copy, 0,
                Math.min(original.length - from, newSize));
        return copy;
    }

}