canonical example by Tabnine
private void usingArrayList() { ArrayList<String> list = new ArrayList<>(Arrays.asList("cat", "cow", "dog")); list.add("fish"); int size = list.size(); // size = 4 list.set(size - 1, "horse"); // replacing the last element to "horse" String removed = list.remove(1); // removed = "cow" String second = list.get(1); // second = "dog" }
/** * Add the specified locales as preferred request locales. * @param locales the locales to add * @since 4.3.6 * @see #locale(Locale) */ public MockHttpServletRequestBuilder locale(Locale... locales) { Assert.notEmpty(locales, "'locales' must not be empty"); this.locales.addAll(Arrays.asList(locales)); return this; }
@Test public void testGetBeanNamesForTypeWithOverride() throws Exception { List<String> names = Arrays.asList( BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class)); // includes 2 TestBeans from FactoryBeans (DummyFactory definitions) assertEquals(4, names.size()); assertTrue(names.contains("test")); assertTrue(names.contains("test3")); assertTrue(names.contains("testFactory1")); assertTrue(names.contains("testFactory2")); }
private List<String> extractCompactSerializationSplits() { List<String> tmpSplits = new ArrayList<>(Arrays.asList(compactSerialization.split("\\."))); if (compactSerialization.endsWith(".")) tmpSplits.add(""); if (tmpSplits.size() != 3) throw new OAuthBearerIllegalTokenException(OAuthBearerValidationResult.newFailure( "Unsecured JWS compact serializations must have 3 dot-separated Base64URL-encoded values")); return Collections.unmodifiableList(tmpSplits); }
public SortedMapSubmapTestMapGenerator( TestSortedMapGenerator<K, V> delegate, Bound to, Bound from) { super(delegate); this.to = to; this.from = from; SortedMap<K, V> emptyMap = delegate.create(); this.entryComparator = Helpers.entryComparator(emptyMap.comparator()); // derive values for inclusive filtering from the input samples SampleElements<Entry<K, V>> samples = delegate.samples(); @SuppressWarnings("unchecked") // no elements are inserted into the array List<Entry<K, V>> samplesList = Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4()); Collections.sort(samplesList, entryComparator); this.firstInclusive = samplesList.get(0).getKey(); this.lastInclusive = samplesList.get(samplesList.size() - 1).getKey(); }
@Test public void sameSizeReverse() throws Exception { MergerBiFunction<Integer> merger = new MergerBiFunction<Integer>(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.compareTo(o2); } }); List<Integer> list = merger.apply(Arrays.asList(3, 5), Arrays.asList(2, 4)); assertEquals(Arrays.asList(2, 3, 4, 5), list); } }
public void assertResponseCookies(String... cookies) { List<Cookie> actualCookies = takeResponseCookies(); List<String> actualCookieStrings = new ArrayList<>(); for (Cookie cookie : actualCookies) { actualCookieStrings.add(cookie.toString()); } assertEquals(Arrays.asList(cookies), actualCookieStrings); }
@Test public void collectionToObjectInteraction() throws Exception { List<List<String>> list = new ArrayList<>(); list.add(Arrays.asList("9", "12")); list.add(Arrays.asList("37", "23")); conversionService.addConverter(new CollectionToObjectConverter(conversionService)); assertTrue(conversionService.canConvert(List.class, List.class)); assertSame(list, conversionService.convert(list, List.class)); }
@SuppressWarnings("unchecked") @Test public void dispose() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestObserver<Object> to = Maybe.zip(Arrays.asList(pp.singleElement(), pp.singleElement()), addString) .test(); assertTrue(pp.hasSubscribers()); to.cancel(); assertFalse(pp.hasSubscribers()); }
@Test public void testHierarchicalNamesForAnnotationWithNoMatch() throws Exception { List<String> names = Arrays.asList( BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, Override.class)); assertEquals(0, names.size()); }
/** * @param allowHeapAllocation whether or not to include heap allocation as an alternative. * @param additional other means of allocation to try after the standard off/on heap alternatives. * @return an array of {@link NumberArrayFactory} with the desired alternatives. */ static NumberArrayFactory[] allocationAlternatives( boolean allowHeapAllocation, NumberArrayFactory... additional ) { List<NumberArrayFactory> result = new ArrayList<>( Collections.singletonList( OFF_HEAP ) ); if ( allowHeapAllocation ) { result.add( HEAP ); } result.addAll( asList( additional ) ); return result.toArray( new NumberArrayFactory[result.size()] ); }
@Override public Object[] getConstructorArgs() { if (outerClassInstance == null) { return constructorArgs; } List<Object> resultArgs = new ArrayList<Object>(constructorArgs.length + 1); resultArgs.add(outerClassInstance); resultArgs.addAll(Arrays.asList(constructorArgs)); return resultArgs.toArray(new Object[constructorArgs.length + 1]); }
private static List<Dependency> parseArtifactArgs(String artifactArgs) { List<String> artifacts = Arrays.asList(artifactArgs.split(",")); List<Dependency> dependencies = new ArrayList<>(artifacts.size()); for (String artifactOpt : artifacts) { if (artifactOpt.trim().isEmpty()) { continue; } dependencies.add(AetherUtils.parseDependency(artifactOpt)); } return dependencies; }
@Test public void secondEmpty() throws Exception { MergerBiFunction<Integer> merger = new MergerBiFunction<Integer>(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.compareTo(o2); } }); List<Integer> list = merger.apply(Arrays.asList(2, 4), Collections.<Integer>emptyList()); assertEquals(Arrays.asList(2, 4), list); }