public static Method[] getPropertyMethods(PropertyDescriptor[] properties, boolean read, boolean write) { Set methods = new HashSet(); for (int i = 0; i < properties.length; i++) { PropertyDescriptor pd = properties[i]; if (read) { methods.add(pd.getReadMethod()); } if (write) { methods.add(pd.getWriteMethod()); } } methods.remove(null); return (Method[]) methods.toArray(new Method[methods.size()]); }
private static boolean fieldsEquals(RecordCursor cursor, Set<Field> fields) { if (fields.size() < 2) { return true; // Nothing to compare } Iterator<Field> fieldIterator = fields.iterator(); Field firstField = fieldIterator.next(); while (fieldIterator.hasNext()) { if (!fieldEquals(cursor, firstField, fieldIterator.next())) { return false; } } return true; }
private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException { Set<String> fileNames = new HashSet<>(); Iterator<String> fileIter = request.getFileNames(); while (fileIter.hasNext()) { fileNames.add(fileIter.next()); } assertEquals(2, fileNames.size()); assertTrue(fileNames.contains("file1")); assertTrue(fileNames.contains("file2")); MultipartFile file1 = request.getFile("file1"); MultipartFile file2 = request.getFile("file2"); Map<String, MultipartFile> fileMap = request.getFileMap(); List<String> fileMapKeys = new LinkedList<>(fileMap.keySet()); assertEquals(2, fileMapKeys.size()); assertEquals(file1, fileMap.get("file1")); assertEquals(file2, fileMap.get("file2")); assertEquals("file1", file1.getName()); assertEquals("", file1.getOriginalFilename()); assertNull(file1.getContentType()); assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes())); assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), FileCopyUtils.copyToByteArray(file1.getInputStream()))); assertEquals("file2", file2.getName()); assertEquals("myOrigFilename", file2.getOriginalFilename()); assertEquals("text/plain", file2.getContentType()); assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes())); assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), FileCopyUtils.copyToByteArray(file2.getInputStream()))); }
static char[] randomChars(Random rand, int size) { Set<Character> chars = new HashSet<>(size); for (int i = 0; i < size; i++) { char c; while (true) { c = (char) rand.nextInt(Character.MAX_VALUE - Character.MIN_VALUE + 1); if (!chars.contains(c)) { break; } } chars.add(c); } char[] retValue = new char[chars.size()]; int i = 0; for (char c : chars) { retValue[i++] = c; } Arrays.sort(retValue); return retValue; }
@Override public File[] listFiles( File directory ) { directory = canonicalFile( directory ); if ( files.containsKey( directory ) || !directories.contains( directory ) ) { // This means that you're trying to list files on a file, not a directory. return null; } List<String> directoryPathItems = splitPath( directory ); Set<File> found = new HashSet<>(); Iterator<File> files = new CombiningIterator<>( asList( this.files.keySet().iterator(), directories.iterator() ) ); while ( files.hasNext() ) { File file = files.next(); List<String> fileNamePathItems = splitPath( file ); if ( directoryMatches( directoryPathItems, fileNamePathItems ) ) { found.add( constructPath( fileNamePathItems, directoryPathItems ) ); } } return found.toArray( new File[found.size()] ); }
private Set<String> resolvePackagesToScan(Set<String> packagesToScan) { Set<String> resolvedPackagesToScan = new LinkedHashSet<String>(packagesToScan.size()); for (String packageToScan : packagesToScan) { if (StringUtils.hasText(packageToScan)) { String resolvedPackageToScan = environment.resolvePlaceholders(packageToScan.trim()); resolvedPackagesToScan.add(resolvedPackageToScan); } } return resolvedPackagesToScan; }
/** * Returns a new proxy for {@code interfaceType}. Proxies of the same interface are equal to each * other if the {@link DummyProxy} instance that created the proxies are equal. */ final <T> T newProxy(TypeToken<T> interfaceType) { Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet(); interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes()); // Make the proxy serializable to work with SerializableTester interfaceClasses.add(Serializable.class); Object dummy = Proxy.newProxyInstance( interfaceClasses.iterator().next().getClassLoader(), interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]), new DummyHandler(interfaceType)); @SuppressWarnings("unchecked") // interfaceType is T T result = (T) dummy; return result; }
@Test public void testLinger() throws Exception { long lingerMs = 10L; RecordAccumulator accum = createTestRecordAccumulator( 1024 + DefaultRecordBatch.RECORD_BATCH_OVERHEAD, 10 * 1024, CompressionType.NONE, lingerMs); accum.append(tp1, 0L, key, value, Record.EMPTY_HEADERS, null, maxBlockTimeMs); assertEquals("No partitions should be ready", 0, accum.ready(cluster, time.milliseconds()).readyNodes.size()); time.sleep(10); assertEquals("Our partition's leader should be ready", Collections.singleton(node1), accum.ready(cluster, time.milliseconds()).readyNodes); List<ProducerBatch> batches = accum.drain(cluster, Collections.singleton(node1), Integer.MAX_VALUE, 0).get(node1.id()); assertEquals(1, batches.size()); ProducerBatch batch = batches.get(0); Iterator<Record> iter = batch.records().records().iterator(); Record record = iter.next(); assertEquals("Keys should match", ByteBuffer.wrap(key), record.key()); assertEquals("Values should match", ByteBuffer.wrap(value), record.value()); assertFalse("No more records", iter.hasNext()); }
@Implementation protected @Nullable String[] getPackagesForUid(int uid) { String[] packageNames = packagesForUid.get(uid); if (packageNames != null) { return packageNames; } Set<String> results = new HashSet<>(); for (PackageInfo packageInfo : packageInfos.values()) { if (packageInfo.applicationInfo != null && packageInfo.applicationInfo.uid == uid) { results.add(packageInfo.packageName); } } return results.isEmpty() ? null : results.toArray(new String[results.size()]); }
Enumeration<String> parameterEnum = request.getParameterNames(); while (parameterEnum.hasMoreElements()) { parameterNames.add(parameterEnum.nextElement()); assertEquals(3, parameterNames.size()); assertTrue(parameterNames.contains("field3")); assertTrue(parameterNames.contains("field4")); assertTrue(parameterNames.contains("getField")); assertEquals("value3", request.getParameter("field3")); List<String> parameterValues = Arrays.asList(request.getParameterValues("field3")); String key = (String) o; parameterMapKeys.add(key); parameterMapValues.add(request.getParameterMap().get(key));
@Test @Graph( { "a TO b", "b TO c", "c TO a" } ) public void canCreateGraphFromMultipleStrings() { Map<String,Node> graph = data.get(); Set<Node> unique = new HashSet<>(); Node n = graph.get( "a" ); while ( unique.add( n ) ) { try ( Transaction ignored = graphdb.beginTx() ) { n = n.getSingleRelationship( RelationshipType.withName( "TO" ), Direction.OUTGOING ).getEndNode(); } } assertEquals( graph.size(), unique.size() ); }
public void noMoreSplits(PlanNodeId planNodeId) { if (noMoreSplits.contains(planNodeId)) { return; } noMoreSplits.add(planNodeId); if (noMoreSplits.size() < sourceStartOrder.size()) { return; } checkState(noMoreSplits.size() == sourceStartOrder.size()); checkState(noMoreSplits.containsAll(sourceStartOrder)); status.setNoMoreLifespans(); }
@Test public void testPopulatedSet() throws Exception { HasMap hasMap = (HasMap) this.beanFactory.getBean("set"); assertTrue(hasMap.getSet().size() == 3); assertTrue(hasMap.getSet().contains("bar")); TestBean jenny = (TestBean) this.beanFactory.getBean("jenny"); assertTrue(hasMap.getSet().contains(jenny)); assertTrue(hasMap.getSet().contains(null)); Iterator it = hasMap.getSet().iterator(); assertEquals("bar", it.next()); assertEquals(jenny, it.next()); assertEquals(null, it.next()); }
public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) { assertTrue(multiset.isEmpty()); assertEquals(0, multiset.size()); assertEquals(0, multiset.toArray().length); assertTrue(multiset.entrySet().isEmpty()); assertFalse(multiset.iterator().hasNext()); assertEquals(0, multiset.entrySet().size()); assertEquals(0, multiset.entrySet().toArray().length); assertFalse(multiset.entrySet().iterator().hasNext()); }
@SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests @Test public void setCollectionPropertyWithArrayValue() { IndexedTestBean target = new IndexedTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); Collection<String> coll = new HashSet<>(); coll.add("coll1"); accessor.setPropertyValue("collection", coll.toArray()); List<String> set = new LinkedList<>(); set.add("set1"); accessor.setPropertyValue("set", set.toArray()); List<String> sortedSet = new ArrayList<>(); sortedSet.add("sortedSet1"); accessor.setPropertyValue("sortedSet", sortedSet.toArray()); Set<String> list = new HashSet<>(); list.add("list1"); accessor.setPropertyValue("list", list.toArray()); assertEquals(1, target.getCollection().size()); assertTrue(target.getCollection().containsAll(coll)); assertEquals(1, target.getSet().size()); assertTrue(target.getSet().containsAll(set)); assertEquals(1, target.getSortedSet().size()); assertTrue(target.getSortedSet().containsAll(sortedSet)); assertEquals(1, target.getList().size()); assertTrue(target.getList().containsAll(list)); }
@Override TypeVariable<?> captureAsTypeVariable(Type[] upperBounds) { Set<Type> combined = new LinkedHashSet<>(asList(upperBounds)); // Since this is an artifically generated type variable, we don't bother checking // subtyping between declared type bound and actual type bound. So it's possible that we // may generate something like <capture#1-of ? extends Foo&SubFoo>. // Checking subtype between declared and actual type bounds // adds recursive isSubtypeOf() call and feels complicated. // There is no contract one way or another as long as isSubtypeOf() works as expected. combined.addAll(asList(typeParam.getBounds())); if (combined.size() > 1) { // Object is implicit and only useful if it's the only bound. combined.remove(Object.class); } return super.captureAsTypeVariable(combined.toArray(new Type[0])); } };