private static Set<HttpMethod> initAllowedHttpMethods(Set<HttpMethod> declaredMethods) { if (declaredMethods.isEmpty()) { return EnumSet.allOf(HttpMethod.class).stream() .filter(method -> method != HttpMethod.TRACE) .collect(Collectors.toSet()); } else { Set<HttpMethod> result = new LinkedHashSet<>(declaredMethods); if (result.contains(HttpMethod.GET)) { result.add(HttpMethod.HEAD); } result.add(HttpMethod.OPTIONS); return result; } }
private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethods) { Set<HttpMethod> result = new LinkedHashSet<>(declaredMethods.size()); if (declaredMethods.isEmpty()) { for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { result.add(method); } } } else { for (String method : declaredMethods) { HttpMethod httpMethod = HttpMethod.valueOf(method); result.add(httpMethod); if (httpMethod == HttpMethod.GET) { result.add(HttpMethod.HEAD); } } result.add(HttpMethod.OPTIONS); } return result; }
/** * @param orig if null, return intersect */ public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect) { if (orig == null) return intersect; if (intersect == null || orig.isEmpty()) return Collections.emptySet(); Set<Object> set = new HashSet<Object>(orig.size()); for (Object p : orig) { if (intersect.contains(p)) set.add(p); } return set; } }
@Override public Enumeration<String> getParameterNames() { if (this.multipartParameterNames == null) { initializeMultipart(); } if (this.multipartParameterNames.isEmpty()) { return super.getParameterNames(); } // Servlet 3.0 getParameterNames() not guaranteed to include multipart form items // (e.g. on WebLogic 12) -> need to merge them here to be on the safe side Set<String> paramNames = new LinkedHashSet<>(); Enumeration<String> paramEnum = super.getParameterNames(); while (paramEnum.hasMoreElements()) { paramNames.add(paramEnum.nextElement()); } paramNames.addAll(this.multipartParameterNames); return Collections.enumeration(paramNames); }
@Test public void testOneDistanceIteration() { Iterator<Vector3i> iter = Diamond3iIterator.iterate(Vector3i.zero(), 1).iterator(); Set<Vector3i> expected = Sets.newHashSet(Vector3i.zero(), new Vector3i(1, 0, 0), new Vector3i(-1, 0, 0), new Vector3i(0, 1, 0), new Vector3i(0, -1, 0), new Vector3i(0, 0, 1), new Vector3i(0, 0, -1)); while (iter.hasNext()) { Vector3i next = iter.next(); assertTrue("Received Unexpected: " + next, expected.remove(next)); } assertTrue("Missing: " + expected, expected.isEmpty()); }
@Override public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() { if (this.persistenceUnitInfoNames.isEmpty()) { throw new IllegalStateException("No persistence units parsed from " + ObjectUtils.nullSafeToString(this.persistenceXmlLocations)); } if (this.persistenceUnitInfos.isEmpty()) { throw new IllegalStateException("All persistence units from " + ObjectUtils.nullSafeToString(this.persistenceXmlLocations) + " already obtained"); } if (this.persistenceUnitInfos.size() > 1 && this.defaultPersistenceUnitName != null) { return obtainPersistenceUnitInfo(this.defaultPersistenceUnitName); } PersistenceUnitInfo pui = this.persistenceUnitInfos.values().iterator().next(); this.persistenceUnitInfos.clear(); return pui; }
private int getParallelism(List<ProcessorNode> group) { Set<Integer> parallelisms = group.stream().map(Node::getParallelism).collect(Collectors.toSet()); if (parallelisms.size() > 1) { throw new IllegalStateException("Current group does not have same parallelism " + group); } return parallelisms.isEmpty() ? 1 : parallelisms.iterator().next(); }
/** * Checks that the {@code expectedNames} are part of the {@code actualNames}. If an {@code expectedName} is not * contained in the {@code actualNames}, the this method will return {@code true}. THe {@code missingNames} will * contain all the {@code expectedNames} that are not part of the {@code actualNames}. * * @param actualNames the names that should be used to check * @param expectedNames the names that should be contained in {@code actualNames} * @param missingNames the names that were not part of {@code expectedNames} * @return {@code true} if all {@code expectedNames} are part of the {@code actualNames}, {@code false} otherwise */ private static boolean noMissingElement(Set<String> actualNames, Set<String> expectedNames, Set<String> missingNames) { for (String field : expectedNames) { if (!actualNames.contains(field)) missingNames.add(field); } return missingNames.isEmpty(); }
@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()]); }
@Test public void testBlobSynchronizerForKeysToDownload() { BlobStore store = initLocalFs(); LocalFsBlobStoreSynchronizer sync = new LocalFsBlobStoreSynchronizer(store, conf); // test for keylist to download Set<String> zkSet = new HashSet<String>(); zkSet.add("key1"); Set<String> blobStoreSet = new HashSet<String>(); blobStoreSet.add("key1"); Set<String> resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet); assertTrue("Not Empty", resultSet.isEmpty()); zkSet.add("key1"); blobStoreSet.add("key2"); resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet); assertTrue("Not Empty", resultSet.isEmpty()); blobStoreSet.remove("key1"); blobStoreSet.remove("key2"); zkSet.add("key1"); resultSet = sync.getKeySetToDownload(blobStoreSet, zkSet); assertTrue("Unexpected keys to download", (resultSet.size() == 1) && (resultSet.contains("key1"))); }
private Set<String> getPackagesToScan(AnnotationMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes.fromMap( metadata.getAnnotationAttributes(DubboComponentScan.class.getName())); String[] basePackages = attributes.getStringArray("basePackages"); Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses"); String[] value = attributes.getStringArray("value"); // Appends value array attributes Set<String> packagesToScan = new LinkedHashSet<String>(Arrays.asList(value)); packagesToScan.addAll(Arrays.asList(basePackages)); for (Class<?> basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } if (packagesToScan.isEmpty()) { return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName())); } return packagesToScan; }
private Map<String, String> filterHeaders(Map<String, String> headers, Set<String> filteredHeaderNames) { if (filteredHeaderNames.isEmpty()) { return Collections.emptyMap(); } return headers.entrySet().stream() .filter(e -> filteredHeaderNames.contains(e.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
/** * Add exception type to catch block * @param type - null for 'all' or 'Throwable' handler */ public void addCatchType(@Nullable ClassInfo type) { if (type != null) { this.catchTypes.add(type); } else { if (!this.catchTypes.isEmpty()) { throw new JadxRuntimeException("Null type added to not empty exception handler: " + this); } } }