/** * Marshal the elements from the given enumeration into an array of the given type. * Enumeration elements must be assignable to the type of the given array. The array * returned will be a different instance than the array given. */ public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) { ArrayList<A> elements = new ArrayList<>(); while (enumeration.hasMoreElements()) { elements.add(enumeration.nextElement()); } return elements.toArray(array); }
/** * Returns exception chain starting from top up to root cause. */ public static Throwable[] getExceptionChain(Throwable throwable) { ArrayList<Throwable> list = new ArrayList<>(); list.add(throwable); while ((throwable = throwable.getCause()) != null) { list.add(throwable); } Throwable[] result = new Throwable[list.size()]; return list.toArray(result); }
@Test // SPR-14988 public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception { RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.GET); assertArrayEquals(new MediaType[]{MediaType.ALL}, new ArrayList<>( requestMappingInfo.getConsumesCondition().getConsumableMediaTypes()).toArray()); }
/** Builds a {@link MultiPhraseQuery}. */ public MultiPhraseQuery build() { int[] positionsArray = new int[this.positions.size()]; for (int i = 0; i < this.positions.size(); ++i) { positionsArray[i] = this.positions.get(i); } Term[][] termArraysArray = termArrays.toArray(new Term[termArrays.size()][]); return new MultiPhraseQuery(field, termArraysArray, positionsArray, slop); } }
@Override public void reduce(Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long[]>> out) { neighbors.clear(); Long id = 0L; for (Tuple2<Long, Long> n : values) { id = n.f0; neighbors.add(n.f1); } out.collect(new Tuple2<Long, Long[]>(id, neighbors.toArray(new Long[neighbors.size()]))); } }
public Message[] getMessages() { ArrayList<Object> list = new ArrayList<Object>(); for (Iterator<TxOperation> iter = operations.iterator(); iter.hasNext();) { TxOperation op = iter.next(); if (op.operationType == TxOperation.ADD_OPERATION_TYPE) { list.add(op.data); } } Message rc[] = new Message[list.size()]; list.toArray(rc); return rc; }
public static void compareResultsByLinesInMemoryWithStrictOrder(String expectedResultStr, String resultPath, String[] excludePrefixes) throws Exception { ArrayList<String> list = new ArrayList<>(); readAllResultLines(list, resultPath, excludePrefixes, true); String[] result = list.toArray(new String[list.size()]); String[] expected = expectedResultStr.split("\n"); Assert.assertEquals("Different number of lines in expected and obtained result.", expected.length, result.length); Assert.assertArrayEquals(expected, result); }
@Test // SPR-14988 public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception { RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.GET); assertArrayEquals(new MediaType[]{MediaType.ALL}, new ArrayList<>( requestMappingInfo.getConsumesCondition().getConsumableMediaTypes()).toArray()); }
private static InterceptorList ofList(final ArrayList<EJBClientInterceptorInformation> value) { if (value.isEmpty()) { return EMPTY; } else if (value.size() == 1) { return value.get(0).getSingletonList(); } else { return new InterceptorList(value.toArray(EJBClientInterceptorInformation.NO_INTERCEPTORS)); } }
@Override public void reduce(Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long[]>> out) { neighbors.clear(); Long id = 0L; for (Tuple2<Long, Long> n : values) { id = n.f0; neighbors.add(n.f1); } out.collect(new Tuple2<Long, Long[]>(id, neighbors.toArray(new Long[neighbors.size()]))); } }
/** * Returns the {@link DataSpec} instances passed to {@link #open(DataSpec)} since the last call to * this method. */ public final DataSpec[] getAndClearOpenedDataSpecs() { DataSpec[] dataSpecs = new DataSpec[openedDataSpecs.size()]; openedDataSpecs.toArray(dataSpecs); openedDataSpecs.clear(); return dataSpecs; }
public MessageAck[] getAcks() { ArrayList<Object> list = new ArrayList<Object>(); for (Iterator<TxOperation> iter = operations.iterator(); iter.hasNext();) { TxOperation op = iter.next(); if (op.operationType == TxOperation.REMOVE_OPERATION_TYPE) { list.add(op.data); } } MessageAck rc[] = new MessageAck[list.size()]; list.toArray(rc); return rc; }
/** @return an array containing all the public fields of this class and its super classes. See {@link Class#getFields()}. */ public Field[] getFields () { if (allFields == null) { ArrayList<Field> allFieldsList = new ArrayList<Field>(); Type t = this; while (t != null) { for (Field f : t.fields) { if (f.isPublic) allFieldsList.add(f); } t = t.getSuperclass(); } allFields = allFieldsList.toArray(new Field[allFieldsList.size()]); } return allFields; }
public GoTfsWorkspace[] queryWorkspaces(String workspaceName, String userName) { ArrayList<GoTfsWorkspace> goTfsWorkspaces = new ArrayList<>(); Workspace[] workspaces = client.queryWorkspaces(workspaceName, userName, null); for (Workspace workspace : workspaces) { goTfsWorkspaces.add(new GoTfsWorkspace(workspace)); } return goTfsWorkspaces.toArray(new GoTfsWorkspace[]{}); }