List of usage examples for com.google.common.collect ObjectArrays newArray
public static <T> T[] newArray(T[] reference, int length)
From source file:com.github.harmanpa.jrecon.utils.Transforms.java
public static <T> T[] applyArray(Class<T> t, T[] obj, String transform) throws ReconException { if ("inv".equals(transform)) { T[] out = ObjectArrays.newArray(t, obj.length); for (int i = 0; i < obj.length; i++) { out[i] = inverse(obj[i]);//from ww w. ja va 2 s. c om } return out; } if (transform.startsWith("aff")) { Number[] args = parseAffine(transform); T[] out = ObjectArrays.newArray(t, obj.length); for (int i = 0; i < obj.length; i++) { out[i] = affine(obj[i], args[0], args[1]); } return out; } if ("".equals(transform)) { return obj; } throw new ReconException("Unsupported transform: " + transform); }
From source file:net.sf.sprockets.util.Elements.java
/** * Get the elements in the array that are at the indexes. * //from ww w. j a v a 2 s . c om * @since 1.4.0 */ public static <T> T[] slice(T[] array, int... indexes) { T[] slice = ObjectArrays.newArray(array, indexes.length); for (int i = 0; i < indexes.length; i++) { slice[i] = array[indexes[i]]; } return slice; }
From source file:org.akraievoy.base.ObjArrays.java
@Nullable public static <T> T[] remove(@Nullable T[] arr, @Nullable T search) { if (arr == null || arr.length == 0) { return arr; }/* w w w.ja v a 2s . co m*/ int occurences = 0; for (int i = 0, arrLength = arr.length; i < arrLength; i++) { if (Objects.equal(arr[i], search)) { occurences += 1; } } if (occurences == 0) { return arr; } final T[] result = ObjectArrays.newArray(arr, arr.length - occurences); int resultPos = 0; for (int i = 0, arrLength = arr.length; i < arrLength; i++) { final T tCur = arr[i]; if (Objects.equal(tCur, search)) { continue; } result[resultPos] = tCur; resultPos++; } return result; }
From source file:org.richfaces.model.SequenceRowKey.java
public SequenceRowKey getParent() { if (simpleKeys.length == 0) { return null; }/*from w w w .j ava 2 s . c o m*/ Object[] parentSimpleKeys = ObjectArrays.newArray(simpleKeys, simpleKeys.length - 1); System.arraycopy(simpleKeys, 0, parentSimpleKeys, 0, parentSimpleKeys.length); return new SequenceRowKey(parentSimpleKeys); }
From source file:org.gradle.api.specs.OrSpec.java
public OrSpec<T> or(Spec<? super T>... specs) { if (specs.length == 0) { return this; }/*from w w w. j av a 2s.co m*/ Spec<? super T>[] thisSpecs = getSpecsArray(); int thisLength = thisSpecs.length; if (thisLength == 0) { return new OrSpec<T>(specs); } Spec<? super T>[] combinedSpecs = uncheckedCast( ObjectArrays.newArray(Spec.class, thisLength + specs.length)); System.arraycopy(thisSpecs, 0, combinedSpecs, 0, thisLength); System.arraycopy(specs, 0, combinedSpecs, thisLength, specs.length); return new OrSpec<T>(combinedSpecs); }
From source file:org.gradle.api.specs.AndSpec.java
public AndSpec<T> and(Spec<? super T>... specs) { if (specs.length == 0) { return this; }//from ww w.j a v a2s . c o m Spec<? super T>[] thisSpecs = getSpecsArray(); int thisLength = thisSpecs.length; if (thisLength == 0) { return new AndSpec<T>(specs); } Spec<? super T>[] combinedSpecs = uncheckedCast( ObjectArrays.newArray(Spec.class, thisLength + specs.length)); System.arraycopy(thisSpecs, 0, combinedSpecs, 0, thisLength); System.arraycopy(specs, 0, combinedSpecs, thisLength, specs.length); return new AndSpec<T>(combinedSpecs); }
From source file:ae.MappedList.java
@Override public Object[] toArray() { return toArray(ObjectArrays.newArray(this.type, size())); }
From source file:ae.MappedList.java
@SuppressWarnings("unchecked") @Override//ww w . j a v a 2 s . c o m public <T> T[] toArray(final T[] a) { final Object[] array; if (a.length < size()) { array = ObjectArrays.newArray(a.getClass(), size()); } else { array = a; } for (int i = 0; i < array.length; i++) { array[i] = this.mapper.apply(this.entities.get(i)); } if (array.length >= size()) { array[size()] = null; } return (T[]) array; }
From source file:org.richfaces.ui.iteration.tree.convert.SequenceRowKeyConverter.java
public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException { if (Strings.isNullOrEmpty(value)) { return null; }//from w ww . j a va 2 s. c om Iterable<String> split = SEPARATOR_SPLITTER.split(value); List<T> keysList = Lists.<T>newArrayList(); for (String s : split) { T convertedKey = clazz.cast(delegateConverter.getAsObject(context, component, s)); keysList.add(convertedKey); } return new SequenceRowKey(keysList.toArray(ObjectArrays.newArray(clazz, keysList.size()))); }
From source file:de.javauni.jarcade.utils.IdList.java
private void assureSize(int id) { if (elems.length < id) { synchronized (mutex) { if (elems.length < id) { nexts = ObjectArrays.newArray(elems, elems.length * 2); System.arraycopy(elems, 0, nexts, 0, elems.length); elems = nexts;//from ww w . j av a2 s .c o m nexts = null; // NOPMD } } } }