List of usage examples for java.util TreeSet contains
public boolean contains(Object o)
From source file:org.geotools.styling.css.CssTranslator.java
/** * Translates a CSS stylesheet into an equivalent GeoTools {@link Style} object * /*from w ww. j a va 2s . c o m*/ * @param stylesheet * @return */ public Style translate(Stylesheet stylesheet) { // get the directives influencing translation int maxCombinations = getMaxCombinations(stylesheet); TranslationMode mode = getTranslationMode(stylesheet); int autoThreshold = getAutoThreshold(stylesheet); List<CssRule> allRules = stylesheet.getRules(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Starting with " + allRules.size() + " rules in the stylesheet"); } // prepare the full SLD builder StyleBuilder styleBuilder = new StyleBuilder(); styleBuilder.name("Default Styler"); // split rules by index and typename, then build the power set for each group and // generate the rules and symbolizers Map<Integer, List<CssRule>> zIndexRules = organizeByZIndex(allRules); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Split the rules into " + zIndexRules + " sets after z-index separation"); } int translatedRuleCount = 0; for (Map.Entry<Integer, List<CssRule>> zEntry : zIndexRules.entrySet()) { final Integer zIndex = zEntry.getKey(); List<CssRule> rules = zEntry.getValue(); Collections.sort(rules, CssRuleComparator.DESCENDING); Map<String, List<CssRule>> typenameRules = organizeByTypeName(rules); // build the SLD for (Map.Entry<String, List<CssRule>> entry : typenameRules.entrySet()) { String featureTypeName = entry.getKey(); List<CssRule> localRules = entry.getValue(); final FeatureType targetFeatureType = getTargetFeatureType(featureTypeName, localRules); if (targetFeatureType != null) { // attach the target feature type to all Data selectors to allow range based // simplification for (CssRule rule : localRules) { rule.getSelector().accept(new AbstractSelectorVisitor() { @Override public Object visit(Data data) { data.featureType = targetFeatureType; return super.visit(data); } }); } } // at this point we can have rules with selectors having two scale ranges // in or, we should split them, as we cannot represent them in SLD // (and yes, this changes their selectivity a bit, could not find a reasonable // solution out of this so far, past the power set we might end up with // and and of two selectors, that internally have ORs of scales, which could // be quite complicated to un-tangle) List<CssRule> flattenedRules = flattenScaleRanges(localRules); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Preparing power set expansion with " + flattenedRules.size() + " rules for feature type: " + featureTypeName); } // The simplifying visitor that will cache the results to avoid re-computing // over and over the same simplifications CachedSimplifyingFilterVisitor cachedSimplifier = new CachedSimplifyingFilterVisitor( targetFeatureType); // expand the css rules power set RulePowerSetBuilder builder = new RulePowerSetBuilder(flattenedRules, cachedSimplifier, maxCombinations) { protected java.util.List<CssRule> buildResult(java.util.List<CssRule> rules) { if (zIndex != null && zIndex > 0) { TreeSet<Integer> zIndexes = getZIndexesForRules(rules); if (!zIndexes.contains(zIndex)) { return null; } } return super.buildResult(rules); } }; List<CssRule> combinedRules = builder.buildPowerSet(); if (combinedRules.isEmpty()) { continue; } // create the feature type style for this typename FeatureTypeStyleBuilder ftsBuilder = styleBuilder.featureTypeStyle(); // regardless of the translation mode, the first rule matching is // the only one that we want to be applied (in exclusive mode it will be // the only one matching, the simple mode we want the evaluation to stop there) ftsBuilder.option(FeatureTypeStyle.KEY_EVALUATION_MODE, FeatureTypeStyle.VALUE_EVALUATION_MODE_FIRST); if (featureTypeName != null) { ftsBuilder.setFeatureTypeNames(Arrays.asList((Name) new NameImpl(featureTypeName))); } Collections.sort(combinedRules, CssRuleComparator.DESCENDING); int rulesCount = combinedRules.size(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Generated " + rulesCount + " combined rules after filtered power set expansion"); } String composite = null; Boolean compositeBase = null; // setup the tool that will eliminate redundant rules (if necessary) DomainCoverage coverage = new DomainCoverage(targetFeatureType, cachedSimplifier); if (mode == TranslationMode.Exclusive) { // create a SLD rule for each css one, making them exclusive, that is, // remove from each rule the union of the zoom/data domain matched by previous // rules coverage.exclusiveRulesEnabled = true; } else if (mode == TranslationMode.Auto) { if (rulesCount < autoThreshold) { LOGGER.fine("Sticking to Exclusive translation mode, rules number is " + rulesCount + " with a threshold of " + autoThreshold); coverage.exclusiveRulesEnabled = true; } else { LOGGER.info("Switching to Simple translation mode, rules number is " + rulesCount + " with a threshold of " + autoThreshold); coverage.exclusiveRulesEnabled = false; } } else { // just skip rules with the same selector coverage.exclusiveRulesEnabled = false; } // generate the SLD rules for (int i = 0; i < rulesCount; i++) { // skip eventual combinations that are not sporting any // root pseudo class CssRule cssRule = combinedRules.get(i); if (!cssRule.hasSymbolizerProperty()) { continue; } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Current domain coverage: " + coverage); LOGGER.fine("Adding rule to domain coverage: " + cssRule); LOGGER.fine("Rules left to process: " + (rulesCount - i)); } List<CssRule> derivedRules = coverage.addRule(cssRule); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Derived rules not yet covered in domain coverage: " + derivedRules.size() + "\n" + derivedRules); } for (CssRule derived : derivedRules) { buildSldRule(derived, ftsBuilder, targetFeatureType); translatedRuleCount++; // check if we have global composition going, and use the value of // the first rule providing the information (the one with the highest // priority) if (composite == null) { List<Value> values = derived.getPropertyValues(PseudoClass.ROOT, COMPOSITE) .get(COMPOSITE); if (values != null && !values.isEmpty()) { composite = values.get(0).toLiteral(); } } if (compositeBase == null) { List<Value> values = derived.getPropertyValues(PseudoClass.ROOT, COMPOSITE_BASE) .get(COMPOSITE_BASE); if (values != null && !values.isEmpty()) { compositeBase = Boolean.valueOf(values.get(0).toLiteral()); } } } if (composite != null) { ftsBuilder.option(COMPOSITE, composite); } if (Boolean.TRUE.equals(compositeBase)) { ftsBuilder.option(COMPOSITE_BASE, "true"); } } } } // check that we have generated at least one rule in output if (translatedRuleCount == 0) { throw new IllegalArgumentException("Invalid CSS style, no rule seems to activate " + "any symbolization. The properties activating the symbolizers are fill, " + "stroke, mark, label, raster-channels, has any been used in a rule matching any feature?"); } return styleBuilder.build(); }
From source file:edu.lternet.pasta.client.DataPackageManagerClient.java
/** * Determine the test identifier used for testing data package operations. * Eliminate identifiers that were previously deleted or are currently in use. * /*from w w w . j a va 2 s .com*/ * @param dpmClient * the DataPackageManagerClient object * @param scope * the scope value, e.g. "knb-lter-lno" * @param initialIdentifier the starting identifier value; keep incrementing until * we find an identifier that hasn't been used * @return an integer value appropriate for use as a test identifier */ static Integer determineTestIdentifier(DataPackageManagerClient dpmClient, String scope, String initialIdentifier) throws Exception { Integer identifier = null; /* * Determine the test identifier. Eliminate identifiers that were previously * deleted or are currently in use. */ TreeSet<String> deletedSet = new TreeSet<String>(); String deletedDataPackages = dpmClient.listDeletedDataPackages(); String[] deletedArray = deletedDataPackages.split("\n"); for (int i = 0; i < deletedArray.length; i++) { if (deletedArray[i] != null && !deletedArray[i].equals("") && deletedArray[i].startsWith(scope)) { deletedSet.add(deletedArray[i]); } } TreeSet<String> identifierSet = new TreeSet<String>(); String dataPackageIdentifiers = dpmClient.listDataPackageIdentifiers(scope); String[] identifierArray = dataPackageIdentifiers.split("\n"); for (int i = 0; i < identifierArray.length; i++) { if (identifierArray[i] != null && !identifierArray[i].equals("")) { identifierSet.add(identifierArray[i]); } } int identifierValue = new Integer(initialIdentifier).intValue(); while (identifier == null) { String identifierString = "" + identifierValue; String scopeDotIdentifier = scope + "." + identifierValue; if (!deletedSet.contains(scopeDotIdentifier) && !identifierSet.contains(identifierString)) { identifier = new Integer(identifierValue); } else { identifierValue++; } } return identifier; }
From source file:net.spfbl.data.Block.java
public static String clearCIDR(String ip, int mask) { try {/* ww w . j a v a2 s . c o m*/ if (Subnet.isValidIP(ip)) { TreeSet<String> blockSet = new TreeSet<String>(); String cidr; while ((cidr = CIDR.get(null, ip)) != null) { if (blockSet.contains(cidr)) { throw new ProcessException("FATAL BLOCK ERROR " + cidr); } else if (!CIDR.split(cidr)) { return cidr; } blockSet.add(cidr); } return null; } else { return null; } } catch (ProcessException ex) { Server.logError(ex); return null; } }
From source file:net.spfbl.data.Block.java
public static void clear(User user, String token, String name) { try {/*from w w w . j av a 2 s . com*/ String block; if (SubnetIPv4.isValidIPv4(token)) { String ip = SubnetIPv4.normalizeIPv4(token); if ((block = Block.clearCIDR(ip, 32)) != null) { Server.logInfo("false positive BLOCK '" + block + "' detected by '" + name + "'."); } } else if (SubnetIPv6.isValidIPv6(token)) { String ip = SubnetIPv6.normalizeIPv6(token); if ((block = Block.clearCIDR(ip, 64)) != null) { Server.logInfo("false positive BLOCK '" + block + "' detected by '" + name + "'."); } } TreeSet<String> blockSet = new TreeSet<String>(); while ((block = Block.find(null, user, token, false, true, true, false)) != null) { if (blockSet.contains(block)) { throw new ProcessException("FATAL BLOCK ERROR " + block); } else if (Block.drop(block)) { Server.logInfo("false positive BLOCK '" + block + "' detected by '" + name + "'."); } blockSet.add(block); } } catch (ProcessException ex) { Server.logError(ex); } }
From source file:net.spfbl.data.Block.java
public static void clearHREF(User user, String token, String name) { try {/*from www . j a va 2s .c o m*/ TreeSet<String> blockSet = new TreeSet<String>(); String block; while ((block = Block.findHREF(null, user, token, false)) != null) { if (blockSet.contains(block)) { throw new ProcessException("FATAL BLOCK ERROR " + block); } else if (Block.drop(block)) { Server.logInfo("false positive BLOCK '" + block + "' detected by '" + name + "'."); } blockSet.add(block); } } catch (ProcessException ex) { Server.logError(ex); } }
From source file:org.codehaus.enunciate.modules.jersey.JerseyDeploymentModule.java
@Override protected void doBuild() throws EnunciateException, IOException { super.doBuild(); File webappDir = getBuildDir(); webappDir.mkdirs();//from ww w . ja va 2 s . c o m File webinf = new File(webappDir, "WEB-INF"); File webinfClasses = new File(webinf, "classes"); getEnunciate().copyFile(new File(getGenerateDir(), "jaxrs-providers.list"), new File(webinfClasses, "jaxrs-providers.list")); getEnunciate().copyFile(new File(getGenerateDir(), "jaxrs-root-resources.list"), new File(webinfClasses, "jaxrs-root-resources.list")); getEnunciate().copyFile(new File(getGenerateDir(), "jaxrs-jaxb-types.list"), new File(webinfClasses, "jaxrs-jaxb-types.list")); getEnunciate().copyFile(new File(getGenerateDir(), "media-type-mappings.properties"), new File(webinfClasses, "media-type-mappings.properties")); getEnunciate().copyFile(new File(getGenerateDir(), "ns2prefix.properties"), new File(webinfClasses, "ns2prefix.properties")); BaseWebAppFragment webappFragment = new BaseWebAppFragment(getName()); webappFragment.setBaseDir(webappDir); WebAppComponent servletComponent = new WebAppComponent(); servletComponent.setName("jersey"); servletComponent.setClassname(EnunciateJerseyServletContainer.class.getName()); TreeMap<String, String> initParams = new TreeMap<String, String>(); initParams.putAll(getServletInitParams()); if (!isUsePathBasedConneg()) { initParams.put(JerseyAdaptedHttpServletRequest.FEATURE_PATH_BASED_CONNEG, Boolean.FALSE.toString()); } if (isUseSubcontext()) { initParams.put(JerseyAdaptedHttpServletRequest.PROPERTY_SERVLET_PATH, getRestSubcontext()); } if (getResourceProviderFactory() != null) { initParams.put(JerseyAdaptedHttpServletRequest.PROPERTY_RESOURCE_PROVIDER_FACTORY, getResourceProviderFactory()); } if (getApplicationClass() != null) { initParams.put("javax.ws.rs.Application", getApplicationClass()); } if (getLoadOnStartup() != null) { servletComponent.setLoadOnStartup(getLoadOnStartup()); } servletComponent.setInitParams(initParams); TreeSet<String> urlMappings = new TreeSet<String>(); for (RootResource rootResource : getModel().getRootResources()) { for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) { String resourceMethodPattern = resourceMethod.getServletPattern(); for (Set<String> subcontextList : ((Map<String, Set<String>>) resourceMethod.getMetaData() .get("subcontexts")).values()) { for (String subcontext : subcontextList) { String servletPattern; if ("".equals(subcontext)) { servletPattern = isUseWildcardServletMapping() ? "/*" : resourceMethodPattern; } else { servletPattern = isUseWildcardServletMapping() ? subcontext + "/*" : subcontext + resourceMethodPattern; } if (urlMappings.add(servletPattern)) { debug("Resource method %s of resource %s to be made accessible by servlet pattern %s.", resourceMethod.getSimpleName(), resourceMethod.getParent().getQualifiedName(), servletPattern); } } } } } if (urlMappings.contains("/*")) { urlMappings.clear(); urlMappings.add("/*"); } else { Iterator<String> iterator = urlMappings.iterator(); while (iterator.hasNext()) { String mapping = iterator.next(); if (!mapping.endsWith("/*") && urlMappings.contains(mapping + "/*")) { iterator.remove(); } } } servletComponent.setUrlMappings(urlMappings); webappFragment.setServlets(Arrays.asList(servletComponent)); getEnunciate().addWebAppFragment(webappFragment); }
From source file:net.spfbl.data.Block.java
public static void clear(String token, String name) { try {/*from w w w. ja v a 2 s .c o m*/ if (SubnetIPv4.isValidIPv4(token)) { String ip = SubnetIPv4.normalizeIPv4(token); if (Block.clearCIDR(ip, 32) != null) { Server.logInfo("false positive BLOCK '" + ip + "/32' detected by '" + name + "'."); } } else if (SubnetIPv6.isValidIPv6(token)) { String ip = SubnetIPv6.normalizeIPv6(token); if (Block.clearCIDR(ip, 64) != null) { Server.logInfo("false positive BLOCK '" + ip + "/64' detected by '" + name + "'."); } } TreeSet<String> blockSet = new TreeSet<String>(); String block; while ((block = Block.find(null, null, token, false, true, true, false)) != null) { if (blockSet.contains(block)) { throw new ProcessException("FATAL BLOCK ERROR " + block); } else if (Block.drop(block)) { Server.logInfo("false positive BLOCK '" + block + "' detected by '" + name + "'."); } blockSet.add(block); } } catch (ProcessException ex) { Server.logError(ex); } }
From source file:net.spfbl.data.Block.java
public static void clear(String userEmail, String ip, String sender, String hostname, String qualifier, String recipient) throws ProcessException { String block;/* w w w .j a va 2 s. com*/ int mask = SubnetIPv4.isValidIPv4(ip) ? 32 : 64; if ((block = Block.clearCIDR(ip, mask)) != null) { if (userEmail == null) { Server.logInfo("false positive BLOCK '" + block + "' detected."); } else { Server.logInfo("false positive BLOCK '" + block + "' detected by '" + userEmail + "'."); } } TreeSet<String> blockSet = new TreeSet<String>(); while ((block = find(userEmail, ip, sender, hostname, qualifier, recipient, false, true, true, false)) != null) { if (blockSet.contains(block)) { throw new ProcessException("FATAL BLOCK ERROR " + block); } else if (dropExact(block)) { if (userEmail == null) { Server.logInfo("false positive BLOCK '" + block + "' detected."); } else { Server.logInfo("false positive BLOCK '" + block + "' detected by '" + userEmail + "'."); } } blockSet.add(block); } }
From source file:org.alfresco.web.forms.xforms.SchemaUtil.java
private static void buildTypeTree(final XSTypeDefinition type, final TreeSet<XSTypeDefinition> descendents, final TreeMap<String, TreeSet<XSTypeDefinition>> typeTree) { if (type == null) { return;//from w w w .ja v a2 s . com } if (LOGGER.isDebugEnabled()) LOGGER.debug("buildTypeTree(" + type.getName() + ", " + descendents.size() + " descendents)"); if (descendents.size() > 0) { TreeSet<XSTypeDefinition> compatibleTypes = typeTree.get(type.getName()); if (compatibleTypes == null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("no compatible types found for " + type.getName() + ", creating a new set"); compatibleTypes = new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER); typeTree.put(type.getName(), compatibleTypes); } if (LOGGER.isDebugEnabled()) LOGGER.debug("adding " + descendents.size() + " descendents to " + type.getName()); compatibleTypes.addAll(descendents); } final XSTypeDefinition parentType = type.getBaseType(); if (parentType == null || type.getTypeCategory() != parentType.getTypeCategory()) { return; } if (type != parentType && parentType.getName() != null && !parentType.getName().equals("anyType")) { TreeSet<XSTypeDefinition> newDescendents = typeTree.get(parentType.getName()); if (newDescendents == null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("type tree doesn't contain " + parentType.getName() + ", creating a new descendant set"); newDescendents = new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER); } if (LOGGER.isDebugEnabled()) LOGGER.debug("adding " + descendents.size() + " descendants to existing " + newDescendents.size() + " descendants of " + parentType.getName()); newDescendents.addAll(descendents); //extension (we only add it to "newDescendants" because we don't want //to have a type descendant to itself, but to consider it for the parent if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { final XSComplexTypeDefinition complexType = (XSComplexTypeDefinition) type; if (complexType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION && !complexType.getAbstract() && !descendents.contains(type)) { if (LOGGER.isDebugEnabled()) LOGGER.debug("adding " + type.getName() + " to existing " + newDescendents.size() + " descendents of " + parentType.getName()); newDescendents.add(type); } } //note: extensions are impossible on simpleTypes ! SchemaUtil.buildTypeTree(parentType, newDescendents, typeTree); } }