List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:com.intellij.ide.fileTemplates.FileTemplateUtil.java
public static String[] calculateAttributes(String templateContent, Set<String> propertiesNames, boolean includeDummies) throws ParseException { final Set<String> unsetAttributes = new LinkedHashSet<String>(); final Set<String> definedAttributes = new HashSet<String>(); //noinspection HardCodedStringLiteral SimpleNode template = RuntimeSingleton.parse(new StringReader(templateContent), "MyTemplate"); collectAttributes(unsetAttributes, definedAttributes, template, propertiesNames, includeDummies); for (String definedAttribute : definedAttributes) { unsetAttributes.remove(definedAttribute); }/*from ww w .j av a2s. c o m*/ return ArrayUtil.toStringArray(unsetAttributes); }
From source file:com.vmware.admiral.compute.container.volume.VolumeUtil.java
/** * Creates additional affinity rules between container descriptions which share * local volumes. Each container group should be deployed on a single host. */// w ww . j av a2s . co m public static void applyLocalNamedVolumeConstraints(Collection<ComponentDescription> componentDescriptions) { Map<String, ContainerVolumeDescription> volumes = filterDescriptions(ContainerVolumeDescription.class, componentDescriptions); List<String> localVolumes = volumes.values().stream().filter(v -> DEFAULT_VOLUME_DRIVER.equals(v.driver)) .map(v -> v.name).collect(Collectors.toList()); if (localVolumes.isEmpty()) { return; } Map<String, ContainerDescription> containers = filterDescriptions(ContainerDescription.class, componentDescriptions); // sort containers by local volume: each set is a group of container names // that share a particular local volume List<Set<String>> localVolumeContainers = localVolumes.stream() .map(v -> filterByVolume(v, containers.values())).filter(s -> !s.isEmpty()) .collect(Collectors.toList()); if (localVolumeContainers.isEmpty()) { return; } /** Merge sets of containers sharing local volumes * * C1 C2 C3 C4 C5 C6 * \ /\ / | \ / * L1 L2 L3 L4 * * Input: [C1, C2], [C2, C3], [C4], [C5, C6] * Output: [C1, C2, C3], [C4], [C5, C6] */ localVolumeContainers = mergeSets(localVolumeContainers); Map<String, List<ContainerVolumeDescription>> containerToVolumes = containers.values().stream() .collect(Collectors.toMap(cd -> cd.name, cd -> filterVolumes(cd, volumes.values()))); Map<String, Integer> containerToDriverCount = containerToVolumes.entrySet().stream() .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().stream().map(vd -> vd.driver).collect(Collectors.toSet()).size())); for (Set<String> s : localVolumeContainers) { if (s.size() > 1) { // find the container with highest number of required drivers int max = s.stream().map(cn -> containerToDriverCount.get(cn)) .max((vc1, vc2) -> Integer.compare(vc1, vc2)).get(); Set<String> maxDrivers = s.stream().filter(cn -> containerToDriverCount.get(cn) == max) .collect(Collectors.toSet()); String maxCont = maxDrivers.iterator().next(); s.remove(maxCont); s.stream().forEach(cn -> addAffinity(maxCont, containers.get(cn))); } } }
From source file:com.kibana.multitenancy.plugin.kibana.KibanaSeed.java
public static void setDashboards(String user, Set<String> projects, Set<String> roles, Client esClient, String kibanaIndex, String kibanaVersion) { //GET .../.kibana/index-pattern/_search?pretty=true&fields= // compare results to projects; handle any deltas (create, delete?) //check projects for default and remove for (String project : BLACKLIST_PROJECTS) if (projects.contains(project)) { logger.debug("Black-listed project '{}' found. Not adding as an index pattern", project); projects.remove(project); }/* w w w. j a v a 2 s.c o m*/ Set<String> indexPatterns = getIndexPatterns(user, esClient, kibanaIndex); logger.debug("Found '{}' Index patterns for user", indexPatterns.size()); // Check roles here, if user is a cluster-admin we should add .operations to their project? -- correct way to do this? logger.debug("Checking for '{}' in users roles '{}'", OPERATIONS_ROLES, roles); /*for ( String role : OPERATIONS_ROLES ) if ( roles.contains(role) ) { logger.debug("{} is an admin user", user); projects.add(OPERATIONS_PROJECT); break; }*/ List<String> sortedProjects = new ArrayList<String>(projects); Collections.sort(sortedProjects); if (sortedProjects.isEmpty()) sortedProjects.add(BLANK_PROJECT); logger.debug("Setting dashboards given user '{}' and projects '{}'", user, projects); // If none have been set yet if (indexPatterns.isEmpty()) { create(user, sortedProjects, true, esClient, kibanaIndex, kibanaVersion); //TODO : Currently it is generating wrong search properties when integrated with ES 2.1 //createSearchProperties(user, esClient, kibanaIndex); } else { List<String> common = new ArrayList<String>(indexPatterns); // Get a list of all projects that are common common.retainAll(sortedProjects); sortedProjects.removeAll(common); indexPatterns.removeAll(common); // for any to create (remaining in projects) call createIndices, createSearchmapping?, create dashboard create(user, sortedProjects, false, esClient, kibanaIndex, kibanaVersion); // cull any that are in ES but not in OS (remaining in indexPatterns) remove(user, indexPatterns, esClient, kibanaIndex); common.addAll(sortedProjects); Collections.sort(common); // Set default index to first index in common if we removed the default String defaultIndex = getDefaultIndex(user, esClient, kibanaIndex, kibanaVersion); logger.debug("Checking if '{}' contains '{}'", indexPatterns, defaultIndex); if (indexPatterns.contains(defaultIndex) || StringUtils.isEmpty(defaultIndex)) { logger.debug("'{}' does contain '{}' and common size is {}", indexPatterns, defaultIndex, common.size()); if (common.size() > 0) setDefaultIndex(user, common.get(0), esClient, kibanaIndex, kibanaVersion); } } }
From source file:net.minecraftforge.common.crafting.CraftingHelper.java
private static void init() { conditions.clear();//www . j a v a2 s. c o m ingredients.clear(); recipes.clear(); registerC("forge:mod_loaded", (context, json) -> { String modid = JsonUtils.getString(json, "modid"); return () -> Loader.isModLoaded(modid); }); registerC("minecraft:item_exists", (context, json) -> { String itemName = context.appendModId(JsonUtils.getString(json, "item")); return () -> ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName)); }); registerC("forge:not", (context, json) -> { BooleanSupplier child = CraftingHelper.getCondition(JsonUtils.getJsonObject(json, "value"), context); return () -> !child.getAsBoolean(); }); registerC("forge:or", (context, json) -> { JsonArray values = JsonUtils.getJsonArray(json, "values"); List<BooleanSupplier> children = Lists.newArrayList(); for (JsonElement j : values) { if (!j.isJsonObject()) throw new JsonSyntaxException("Or condition values must be an array of JsonObjects"); children.add(CraftingHelper.getCondition(j.getAsJsonObject(), context)); } return () -> children.stream().anyMatch(BooleanSupplier::getAsBoolean); }); registerC("forge:and", (context, json) -> { JsonArray values = JsonUtils.getJsonArray(json, "values"); List<BooleanSupplier> children = Lists.newArrayList(); for (JsonElement j : values) { if (!j.isJsonObject()) throw new JsonSyntaxException("And condition values must be an array of JsonObjects"); children.add(CraftingHelper.getCondition(j.getAsJsonObject(), context)); } return () -> children.stream().allMatch(c -> c.getAsBoolean()); }); registerC("forge:false", (context, json) -> { return () -> false; }); registerR("minecraft:crafting_shaped", (context, json) -> { String group = JsonUtils.getString(json, "group", ""); //if (!group.isEmpty() && group.indexOf(':') == -1) // group = context.getModId() + ":" + group; Map<Character, Ingredient> ingMap = Maps.newHashMap(); for (Entry<String, JsonElement> entry : JsonUtils.getJsonObject(json, "key").entrySet()) { if (entry.getKey().length() != 1) throw new JsonSyntaxException("Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only)."); if (" ".equals(entry.getKey())) throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol."); ingMap.put(entry.getKey().toCharArray()[0], CraftingHelper.getIngredient(entry.getValue(), context)); } ingMap.put(' ', Ingredient.EMPTY); JsonArray patternJ = JsonUtils.getJsonArray(json, "pattern"); if (patternJ.size() == 0) throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed"); if (patternJ.size() > 3) throw new JsonSyntaxException("Invalid pattern: too many rows, 3 is maximum"); String[] pattern = new String[patternJ.size()]; for (int x = 0; x < pattern.length; ++x) { String line = JsonUtils.getString(patternJ.get(x), "pattern[" + x + "]"); if (line.length() > 3) throw new JsonSyntaxException("Invalid pattern: too many columns, 3 is maximum"); if (x > 0 && pattern[0].length() != line.length()) throw new JsonSyntaxException("Invalid pattern: each row must be the same width"); pattern[x] = line; } NonNullList<Ingredient> input = NonNullList.withSize(pattern[0].length() * pattern.length, Ingredient.EMPTY); Set<Character> keys = Sets.newHashSet(ingMap.keySet()); keys.remove(' '); int x = 0; for (String line : pattern) { for (char chr : line.toCharArray()) { Ingredient ing = ingMap.get(chr); if (ing == null) throw new JsonSyntaxException( "Pattern references symbol '" + chr + "' but it's not defined in the key"); input.set(x++, ing); keys.remove(chr); } } if (!keys.isEmpty()) throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + keys); ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); return new ShapedRecipes(group, pattern[0].length(), pattern.length, input, result); }); registerR("minecraft:crafting_shapeless", (context, json) -> { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ings = NonNullList.create(); for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients")) ings.add(CraftingHelper.getIngredient(ele, context)); if (ings.isEmpty()) throw new JsonParseException("No ingredients for shapeless recipe"); if (ings.size() > 9) throw new JsonParseException("Too many ingredients for shapeless recipe"); ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); return new ShapelessRecipes(group, itemstack, ings); }); registerR("forge:ore_shaped", ShapedOreRecipe::factory); registerR("forge:ore_shapeless", ShapelessOreRecipe::factory); registerI("minecraft:item", (context, json) -> Ingredient.fromStacks(CraftingHelper.getItemStackBasic(json, context))); registerI("minecraft:empty", (context, json) -> Ingredient.EMPTY); registerI("minecraft:item_nbt", (context, json) -> new IngredientNBT(CraftingHelper.getItemStack(json, context))); registerI("forge:ore_dict", (context, json) -> new OreIngredient(JsonUtils.getString(json, "ore"))); }
From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java
private static void validateSonarFile(Document document, Set<Class<?>> modules) { final NodeList rules = document.getElementsByTagName("rule"); for (int position = 0; position < rules.getLength(); position++) { final Node rule = rules.item(position); final Set<Node> children = XmlUtil.getChildrenElements(rule); final String key = SevntuXmlUtil.findElementByTag(children, "key").getTextContent(); final Class<?> module = findModule(modules, key); modules.remove(module); Assert.assertNotNull("Unknown class found in sonar: " + key, module); final String moduleName = module.getName(); final Node name = SevntuXmlUtil.findElementByTag(children, "name"); Assert.assertNotNull(moduleName + " requires a name in sonar", name); Assert.assertFalse(moduleName + " requires a name in sonar", name.getTextContent().isEmpty()); final Node categoryNode = SevntuXmlUtil.findElementByTag(children, "category"); String expectedCategory = module.getCanonicalName(); final int lastIndex = expectedCategory.lastIndexOf('.'); expectedCategory = expectedCategory.substring(expectedCategory.lastIndexOf('.', lastIndex - 1) + 1, lastIndex);//from ww w. jav a2 s . c om Assert.assertNotNull(moduleName + " requires a category in sonar", categoryNode); final Node categoryAttribute = categoryNode.getAttributes().getNamedItem("name"); Assert.assertNotNull(moduleName + " requires a category name in sonar", categoryAttribute); Assert.assertEquals(moduleName + " requires a valid category in sonar", expectedCategory, categoryAttribute.getTextContent()); final Node description = SevntuXmlUtil.findElementByTag(children, "description"); Assert.assertNotNull(moduleName + " requires a description in sonar", description); final Node configKey = SevntuXmlUtil.findElementByTag(children, "configKey"); final String expectedConfigKey = "Checker/TreeWalker/" + key; Assert.assertNotNull(moduleName + " requires a configKey in sonar", configKey); Assert.assertEquals(moduleName + " requires a valid configKey in sonar", expectedConfigKey, configKey.getTextContent()); validateSonarProperties(module, SevntuXmlUtil.findElementsByTag(children, "param")); } for (Class<?> module : modules) { Assert.fail("Module not found in sonar: " + module.getCanonicalName()); } }
From source file:com.centeractive.ws.legacy.SchemaUtils.java
/** * Extracts namespaces - used in tool integrations for mapping.. *//*www . j ava2 s . c om*/ public static Collection<String> extractNamespaces(SchemaTypeSystem schemaTypes, boolean removeDefault) { Set<String> namespaces = new HashSet<String>(); SchemaType[] globalTypes = schemaTypes.globalTypes(); for (int c = 0; c < globalTypes.length; c++) { namespaces.add(globalTypes[c].getName().getNamespaceURI()); } if (removeDefault) { namespaces.removeAll(defaultSchemas.keySet()); namespaces.remove(Constants.SOAP11_ENVELOPE_NS); namespaces.remove(Constants.SOAP_ENCODING_NS); } return namespaces; }
From source file:edu.ku.brc.specify.plugins.CollectionRelPlugin.java
/** * @param collectionRels/*from w w w. j a v a2s. co m*/ * @param colRelToBeRemoved */ public static void removeFromCollectionRel(final Set<CollectionRelationship> collectionRels, final CollectionRelationship colRelToBeRemoved) { for (CollectionRelationship colRel : collectionRels) { if (colRel == colRelToBeRemoved || colRel.getId().equals(colRelToBeRemoved.getId())) { collectionRels.remove(colRel); break; } } }
From source file:Main.java
/** * Reorder a list of elements by another list. Trying to keep absolute order of initial list in alphabetical order * but reorder regarding to provided relative order list. * E.g. initial was [1, 2, 3, 4, 5] - calling reorder with list [2, 5, 4] will generate list * [1, 2, 3, 5, 4]/*w w w. j av a 2 s . c o m*/ * @param elements - initial list * @param order - list describing relative order * @param <T> - Class of comparable object * @return - new reordered list */ public static <T extends Comparable> List<T> mergeReorder(List<T> elements, List<T> order) { if (order.size() == 0) { return elements; } if (elements.size() == 0) { return order; } Set<T> merged = new LinkedHashSet<>(); Set<T> elementsSet = new HashSet<>(elements); int i = 0; int j = 0; T currElement = elements.get(i); T currOrder = order.get(j); while (i < elements.size() || j < order.size()) { if (j >= order.size()) { merged.addAll(elements.subList(i, elements.size())); break; } currElement = i < elements.size() ? elements.get(i) : currElement; currOrder = j < order.size() ? order.get(j) : currOrder; if (currElement.compareTo(currOrder) < 0) { merged.add(currElement); i++; } if (currOrder.compareTo(currElement) < 0 || i >= elements.size()) { if (merged.contains(currOrder)) { merged.remove(currOrder); } if (elementsSet.contains(currOrder)) { merged.add(currOrder); } j++; } if (currElement.compareTo(currOrder) == 0) { merged.add(currElement); i++; j++; } } return new ArrayList<>(merged); }
From source file:biz.netcentric.cq.tools.actool.acls.AceBeanInstallerImpl.java
/** Modifies the privileges so that privileges already covered by actions are removed. This is only a best effort operation as one * action can lead to privileges on multiple nodes. * * @throws RepositoryException */ private static Set<String> removeRedundantPrivileges(Session session, String[] privileges, String[] actions) throws RepositoryException { final CqActions cqActions = new CqActions(session); final Set<String> cleanedPrivileges = new HashSet<String>(); if (privileges == null) { return cleanedPrivileges; }//from w ww . j av a 2s . co m cleanedPrivileges.addAll(Arrays.asList(privileges)); if (actions == null) { return cleanedPrivileges; } for (final String action : actions) { @SuppressWarnings("deprecation") final Set<Privilege> coveredPrivileges = cqActions.getPrivileges(action); for (final Privilege coveredPrivilege : coveredPrivileges) { cleanedPrivileges.remove(coveredPrivilege.getName()); } } return cleanedPrivileges; }
From source file:com.espertech.esper.event.bean.BeanEventType.java
private static void removeJavaLibInterfaces(Set<Class> classes) { for (Class clazz : classes.toArray(new Class[0])) { if (clazz.getName().startsWith("java")) { classes.remove(clazz); }/*from w w w . j a v a2s.c om*/ } }