List of usage examples for java.util Set addAll
boolean addAll(Collection<? extends E> c);
From source file:ReflectUtil.java
/** * Returns a set of all interfaces implemented by class supplied. This includes all * interfaces directly implemented by this class as well as those implemented by * superclasses or interface superclasses. * // w w w . j av a2 s . c om * @param clazz * @return all interfaces implemented by this class */ public static Set<Class<?>> getImplementedInterfaces(Class<?> clazz) { Set<Class<?>> interfaces = new HashSet<Class<?>>(); if (clazz.isInterface()) interfaces.add(clazz); while (clazz != null) { for (Class<?> iface : clazz.getInterfaces()) interfaces.addAll(getImplementedInterfaces(iface)); clazz = clazz.getSuperclass(); } return interfaces; }
From source file:de.zib.gndms.voldmodel.Adis.java
private static Set<String> flatten(Collection<Set<String>> setset) { Set<String> result = new HashSet<String>(); for (Set<String> set : setset) { result.addAll(set); }//from ww w . j av a 2s . c o m return result; }
From source file:org.owasp.proxy.Main.java
private static HttpRequestHandler configureAJP(HttpRequestHandler rh, Configuration config) { if (config.ajpServer != null) { final DefaultAJPRequestHandler arh = new DefaultAJPRequestHandler(); arh.setTarget(config.ajpServer); AJPProperties ajpProperties = new AJPProperties(); ajpProperties.setRemoteAddress(config.ajpClientAddress); if (config.ajpClientCert != null && config.ajpClientCert.endsWith(".pem")) { try { BufferedReader in = new BufferedReader(new FileReader(config.ajpClientCert)); StringBuffer buff = new StringBuffer(); String line;//from w w w. j av a 2 s .co m while ((line = in.readLine()) != null) { buff.append(line); } in.close(); ajpProperties.setSslCert(buff.toString()); ajpProperties.setSslCipher("ECDHE-RSA-AES256-SHA"); ajpProperties.setSslSession("RANDOMID"); ajpProperties.setSslKeySize("256"); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(1); } } ajpProperties.setRemoteUser(config.ajpUser); ajpProperties.setAuthType("BASIC"); ajpProperties.setContext("/manager"); arh.setProperties(ajpProperties); final Set<String> ajpHosts = new HashSet<String>(); if (config.ajpHosts != null) ajpHosts.addAll(Arrays.asList(config.ajpHosts)); final HttpRequestHandler hrh = rh; return new HttpRequestHandler() { @Override public StreamingResponse handleRequest(InetAddress source, StreamingRequest request, boolean isContinue) throws IOException, MessageFormatException { InetSocketAddress target = request.getTarget(); if (ajpHosts.isEmpty() || ajpHosts.contains(target.getHostName()) || ajpHosts.contains(target.getAddress().getHostAddress())) { return arh.handleRequest(source, request, isContinue); } else { return hrh.handleRequest(source, request, isContinue); } } @Override public void dispose() throws IOException { arh.dispose(); hrh.dispose(); } }; } else { return rh; } }
From source file:cc.kave.commons.utils.json.JsonUtils.java
private static Set<Class<?>> getAllTypesFromHierarchyExceptObject(Class<?> elem, boolean includeElem) { Set<Class<?>> hierarchy = Sets.newHashSet(); if (elem == null || elem.equals(Object.class)) { return hierarchy; }/*from www . j av a2 s .c o m*/ if (includeElem) { hierarchy.add(elem); } for (Class<?> i : elem.getInterfaces()) { hierarchy.addAll(getAllTypesFromHierarchyExceptObject(i, true)); } hierarchy.addAll(getAllTypesFromHierarchyExceptObject(elem.getSuperclass(), true)); return hierarchy; }
From source file:net.i2p.util.I2PSSLSocketFactory.java
/** * Adapted from Jetty SslContextFactory.java * * @param toEnable Add all these to what is enabled, if supported * @param toExclude Remove all these from what is enabled * @since 0.9.16/*from ww w.j a v a 2 s .co m*/ */ private static String[] select(String[] enabledArr, String[] supportedArr, List<String> toEnable, List<String> toExclude) { Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PSSLSocketFactory.class); Set<String> selected = new HashSet<String>(enabledArr.length); selected.addAll(Arrays.asList(enabledArr)); selected.removeAll(toExclude); Set<String> supported = new HashSet<String>(supportedArr.length); supported.addAll(Arrays.asList(supportedArr)); for (String s : toEnable) { if (supported.contains(s)) { if (selected.add(s)) { if (log.shouldLog(Log.INFO)) log.info("Added, previously disabled: " + s); } } else if (log.shouldLog(Log.INFO)) { log.info("Not supported in this JVM: " + s); } } if (selected.isEmpty()) { // shouldn't happen, Java 6 supports TLSv1 log.logAlways(Log.WARN, "No TLS support for SSLEepGet, falling back"); return enabledArr; } if (log.shouldLog(Log.DEBUG)) { List<String> foo = new ArrayList<String>(selected); Collections.sort(foo); log.debug("Selected: " + foo); } return selected.toArray(new String[selected.size()]); }
From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.ManifestUtils.java
/** * Determine the Import-Package value based on the Export-Package entries in * the jars given as Resources./*from w w w .j a va 2 s .c o m*/ * @param resources * @return */ public static String[] determineImportPackages(Resource[] resources) { Set collection = new LinkedHashSet(); // for each resource for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; Manifest man = JarUtils.getManifest(resource); if (man != null) { // read the manifest // get the Export-Package Attributes attrs = man.getMainAttributes(); String exportedPackages = attrs.getValue(Constants.EXPORT_PACKAGE); // add it to the StringBuilder if (StringUtils.hasText(exportedPackages)) { collection.addAll(StringUtils.commaDelimitedListToSet(exportedPackages)); } } } // return the result as string String[] array = (String[]) collection.toArray(new String[collection.size()]); // clean whitespace just in case for (int i = 0; i < array.length; i++) { array[i] = StringUtils.trimWhitespace(array[i]); } return array; }
From source file:com.edgenius.wiki.render.RenderUtil.java
/** * @param input/* www .j a v a2s. co m*/ * @param key * @param regions * @param newlineKey * @return */ public static CharSequence createRegion(CharSequence input, String key, Collection<Region> regions, String newlineKey) { if (regions == null || regions.size() == 0) return input; //first, web split whole text by special border tag string some think like "key_regionKey_S|E" input = createRegionBorder(input, key, regions, newlineKey); //then we split them one by one. The split is dependent on the RegionComparator(), which ensure the split //from end to start, and from inside to outside. And this makes easier on below replacement process. Set<Region> sortRegions = new TreeSet<Region>(new RegionComparator()); sortRegions.addAll(regions); StringBuilder buf = new StringBuilder(input); StringBuilder regKey = new StringBuilder(key); int ks = key.length(); for (Region region : sortRegions) { //See our issue http://bug.edgenius.com/issues/34 //and SUN Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993 Pattern pat = Pattern.compile(new StringBuilder(key).append(region.getKey()).append("S(.*?)") .append(key).append(region.getKey()).append("E").toString(), Pattern.DOTALL); try { Matcher matcher = pat.matcher(buf); if (matcher.find()) { region.setBody(matcher.group(1)); buf.delete(matcher.start(), matcher.end()); regKey.delete(ks, regKey.length()); buf.insert(matcher.start(), regKey.append(region.getKey()).append(Region.REGION_SUFFIX)); } } catch (StackOverflowError e) { AuditLogger.error("StackOverflow Error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]"); } catch (Throwable e) { AuditLogger.error("Unexpected error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]", e); } } return buf; }
From source file:eu.esdihumboldt.hale.common.core.io.HaleIO.java
/** * Find the content type for the given input * /* w w w . j a v a 2s . c om*/ * @param <P> the provider interface type * * @param providerType the provider type, usually an interface * @param in the input supplier to use for testing, may be <code>null</code> * if the file name is not <code>null</code> * @param filename the file name, may be <code>null</code> if the input * supplier is not <code>null</code> * @return the content type or <code>null</code> if no matching content type * is found */ public static <P extends IOProvider> IContentType findContentType(Class<P> providerType, InputSupplier<? extends InputStream> in, String filename) { Collection<IOProviderDescriptor> providers = getProviderFactories(providerType); // collect supported content types Set<IContentType> supportedTypes = new HashSet<IContentType>(); for (IOProviderDescriptor factory : providers) { supportedTypes.addAll(factory.getSupportedTypes()); } // find matching content type List<IContentType> types = findContentTypesFor(supportedTypes, in, filename); if (types == null || types.isEmpty()) { return null; } // TODO choose? return types.iterator().next(); }
From source file:de.betterform.xml.xforms.ui.state.UIElementStateUtil.java
public static void dispatchBetterFormCustomMIPEvents(BindingElement bindingElement, Map<String, String> currentCustomProperties, Map<String, String> newCustomProperties) throws XFormsException { Set<String> keySet = new HashSet<String>(); if (currentCustomProperties != null) { keySet.addAll(currentCustomProperties.keySet()); }//from w ww. j a v a 2s . c om if (newCustomProperties != null) { keySet.addAll(newCustomProperties.keySet()); } Map<String, String> customMIP = new HashMap<String, String>(); for (String key : keySet) { if (hasPropertyChanged(currentCustomProperties, newCustomProperties, key)) { customMIP.put(key, "" + WordUtils.capitalize(newCustomProperties.get(key))); } } if (!customMIP.isEmpty()) { Container container = bindingElement.getContainerObject(); EventTarget eventTarget = bindingElement.getTarget(); container.dispatch(eventTarget, BetterFormEventNames.CUSTOM_MIP_CHANGED, customMIP); } }
From source file:AmazonDynamoDBSample.java
private static void oneTimeAddContacts() { String firstNameLastName = ""; String saltS = ""; String ssnhash = ""; Set<String> unionSet = new HashSet<>(); unionSet.addAll(set1); unionSet.addAll(set2);/* w w w . j av a2 s. com*/ String strArrr[] = unionSet.toArray(new String[unionSet.size()]); int numEntries = saltHashMap.size(); for (int i = 0; i < numEntries; i++) { firstNameLastName = strArrr[i]; saltS = saltHashMap.get(strArrr[i]); ssnhash = hashedssnHashMap.get(strArrr[i]); Map<String, AttributeValue> item = newContactItem(firstNameLastName, saltS, ssnhash); PutItemRequest putItemRequest = new PutItemRequest("contacts-table", item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); } }