List of usage examples for java.util Collections disjoint
public static boolean disjoint(Collection<?> c1, Collection<?> c2)
From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceManager.java
/** * Try to remove the resource parameter and its children. Operation is recursive. * If one of the derived resources is already in use, an exception is thrown. * @param rpId/*from w w w. j ava2s .c o m*/ */ public void removeResourceParameter(Long rpId) { // main parameter ResourceParameter rpdb = resourceParameterRepository.findOne(rpId); if (rpdb != null) { String clientId = rpdb.getClientId(); Set<String> ids = new HashSet<String>(); Set<String> scopes = new HashSet<String>(); // aggregate all derived resource uris Collection<String> uris = findResourceURIs(rpdb).keySet(); for (String uri : uris) { Resource r = resourceRepository.findByResourceUri(uri); if (r != null) { ids.add(r.getResourceId().toString()); scopes.add(r.getResourceUri()); } } ClientDetailsEntity owner = null; // check the resource uri usages for (ClientDetailsEntity cd : clientDetailsRepository.findAll()) { if (cd.getClientId().equals(clientId)) { owner = cd; continue; } if (!Collections.disjoint(cd.getResourceIds(), ids)) { throw new IllegalArgumentException("Resource is in use by other client app."); } } // delete main and its children for (String id : ids) { resourceRepository.delete(Long.parseLong(id)); } if (owner != null) { Set<String> oldScopes = new HashSet<String>(owner.getScope()); oldScopes.removeAll(scopes); owner.setScope(StringUtils.collectionToCommaDelimitedString(oldScopes)); Set<String> oldIds = new HashSet<String>(owner.getResourceIds()); oldIds.removeAll(ids); owner.setResourceIds(StringUtils.collectionToCommaDelimitedString(oldIds)); clientDetailsRepository.save(owner); } resourceParameterRepository.delete(rpdb); } }
From source file:de.appsolve.padelcampus.controller.events.EventsController.java
@RequestMapping(value = { "edit/{eventId}/addpullgame" }, method = POST) public ModelAndView postAddPullGame(HttpServletRequest request, @PathVariable("eventId") Long eventId, @ModelAttribute("Model") AddTeamGame addTeamGame, @RequestParam(value = "redirectUrl", required = false) String redirectUrl, BindingResult bindingResult) {/*from ww w .j a v a2 s .c o m*/ Player user = sessionUtil.getUser(request); if (user == null) { return getLoginView(request, request.getRequestURI()); } Event event = eventDAO.findByIdFetchWithParticipants(eventId); validator.validate(addTeamGame, bindingResult); if (bindingResult.hasErrors()) { return getAddPullGameView(event, addTeamGame); } if (!Collections.disjoint(addTeamGame.getTeams().get(0).getPlayers(), addTeamGame.getTeams().get(1).getPlayers())) { bindingResult.addError(new ObjectError("id", msg.get("ChooseDistinctPlayers"))); return getAddPullGameView(event, addTeamGame); } List<Participant> teams = new ArrayList<>(); teams.add(teamDAO.findOrCreateTeam(addTeamGame.getTeams().get(0).getPlayers())); teams.add(teamDAO.findOrCreateTeam(addTeamGame.getTeams().get(1).getPlayers())); List<Game> eventGames = gameDAO.findByEventWithPlayers(event); for (Game game : eventGames) { if (game.getParticipants().containsAll(teams)) { bindingResult.addError(new ObjectError("id", msg.get("GameAlreadyExists"))); return getAddPullGameView(event, addTeamGame); } } saveGame(event, teams, request); if (!StringUtils.isEmpty(redirectUrl)) { return new ModelAndView("redirect:/" + redirectUrl); } return new ModelAndView("redirect:/events/event/" + event.getId() + "/pullgames"); }
From source file:org.opencms.ade.contenteditor.CmsContentService.java
/** * @see org.opencms.ade.contenteditor.shared.rpc.I_CmsContentService#callEditorChangeHandlers(java.lang.String, org.opencms.acacia.shared.CmsEntity, java.util.Collection, java.util.Collection) *//*from w ww . j av a 2 s . c o m*/ public CmsContentDefinition callEditorChangeHandlers(String entityId, CmsEntity editedLocaleEntity, Collection<String> skipPaths, Collection<String> changedScopes) throws CmsRpcException { CmsContentDefinition result = null; CmsUUID structureId = CmsContentDefinition.entityIdToUuid(editedLocaleEntity.getId()); if (structureId != null) { CmsObject cms = getCmsObject(); CmsResource resource = null; Locale locale = CmsLocaleManager.getLocale(CmsContentDefinition.getLocaleFromId(entityId)); try { resource = cms.readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION); ensureLock(resource); CmsFile file = cms.readFile(resource); CmsXmlContent content = getContentDocument(file, true).clone(); checkAutoCorrection(cms, content); synchronizeLocaleIndependentForEntity(file, content, skipPaths, editedLocaleEntity); for (I_CmsXmlContentEditorChangeHandler handler : content.getContentDefinition().getContentHandler() .getEditorChangeHandlers()) { Set<String> handlerScopes = evaluateScope(handler.getScope(), content.getContentDefinition()); if (!Collections.disjoint(changedScopes, handlerScopes)) { handler.handleChange(cms, content, locale, changedScopes); } } result = readContentDefinition(file, content, entityId, locale, false, null, editedLocaleEntity); } catch (Exception e) { error(e); } } return result; }
From source file:de.appsolve.padelcampus.controller.events.EventsController.java
@RequestMapping(value = { "edit/{eventId}/addfriendlygame" }, method = POST) public ModelAndView postAddFriendlyGame(@PathVariable("eventId") Long eventId, @ModelAttribute("Model") AddTeamGame addTeamGame, @RequestParam(value = "redirectUrl", required = false) String redirectUrl, BindingResult bindingResult, HttpServletRequest request) {// w w w . j a v a 2 s. c o m Player user = sessionUtil.getUser(request); if (user == null) { return getLoginView(request, request.getRequestURI()); } Event event = eventDAO.findByIdFetchWithParticipants(eventId); validator.validate(addTeamGame, bindingResult); if (bindingResult.hasErrors()) { return getAddFriendlyGameView(event, addTeamGame); } if (!Collections.disjoint(addTeamGame.getTeams().get(0).getPlayers(), addTeamGame.getTeams().get(1).getPlayers())) { bindingResult.addError(new ObjectError("id", msg.get("ChooseDistinctPlayers"))); return getAddFriendlyGameView(event, addTeamGame); } List<Participant> teams = new ArrayList<>(); teams.add(teamDAO.findOrCreateTeam(addTeamGame.getTeams().get(0).getPlayers())); teams.add(teamDAO.findOrCreateTeam(addTeamGame.getTeams().get(1).getPlayers())); saveGame(event, teams, request); if (!StringUtils.isEmpty(redirectUrl)) { return new ModelAndView("redirect:/" + redirectUrl); } return new ModelAndView("redirect:/events/event/" + event.getId() + "/pullgames"); }
From source file:org.jahia.services.content.nodetypes.JahiaCndReader.java
private void checkRecursiveInheritance(ExtendedNodeType type, Map<String, ExtendedNodeType> nodeTypeNames, List<String> name) { name.add(type.getName());/*from www.j a va2s .c o m*/ if (!Collections.disjoint(Arrays.asList(type.getDeclaredSupertypeNames()), name)) { hasEncounteredIssuesWithDefinitions = true; parsingErrors.add(name + " invalid supertype: " + type.getName() + " (infinite recursion))"); return; } for (String s : type.getDeclaredSupertypeNames()) { if (nodeTypeNames.containsKey(s)) { checkRecursiveInheritance(nodeTypeNames.get(s), nodeTypeNames, new ArrayList<String>(name)); } } }
From source file:org.onosproject.t3.impl.TroubleshootManager.java
/** * Checks that two hosts are bridged (L2Unicast). * * @param source the source host// w w w.ja va 2s . c om * @param destination the destination host * @return true if bridged. * @throws ConfigException if config can't be properly retrieved */ private boolean areBridged(Host source, Host destination) throws ConfigException { //If the locations is not the same we don't even check vlan or subnets if (Collections.disjoint(source.locations(), destination.locations())) { return false; } if (!source.vlan().equals(VlanId.NONE) && !destination.vlan().equals(VlanId.NONE) && !source.vlan().equals(destination.vlan())) { return false; } InterfaceConfig interfaceCfgH1 = networkConfigService.getConfig(source.location(), InterfaceConfig.class); InterfaceConfig interfaceCfgH2 = networkConfigService.getConfig(destination.location(), InterfaceConfig.class); if (interfaceCfgH1 != null && interfaceCfgH2 != null) { //following can be optimized but for clarity is left as is Interface intfH1 = interfaceCfgH1.getInterfaces().stream().findFirst().get(); Interface intfH2 = interfaceCfgH2.getInterfaces().stream().findFirst().get(); if (source.vlan().equals(VlanId.NONE) && !destination.vlan().equals(VlanId.NONE)) { return intfH1.vlanUntagged().equals(destination.vlan()) || intfH1.vlanNative().equals(destination.vlan()); } if (!source.vlan().equals(VlanId.NONE) && destination.vlan().equals(VlanId.NONE)) { return intfH2.vlanUntagged().equals(source.vlan()) || intfH2.vlanNative().equals(source.vlan()); } if (!intfH1.vlanNative().equals(intfH2.vlanNative())) { return false; } if (!intfH1.vlanUntagged().equals(intfH2.vlanUntagged())) { return false; } List<InterfaceIpAddress> intersection = new ArrayList<>(intfH1.ipAddressesList()); intersection.retainAll(intfH2.ipAddressesList()); if (intersection.size() == 0) { return false; } } return true; }
From source file:org.jamocha.rating.fraj.RatingProvider.java
private double rateBetaWithExistentials(final StatisticsProvider statisticsProvider, final PathNodeFilterSet toRate, final Map<Set<PathFilterList>, List<Pair<List<Set<PathFilterList>>, List<PathFilter>>>> componentToJoinOrder, final Map<Path, Set<PathFilterList>> pathToPreNetworkComponents) { final Set<Path> positiveExistentialPaths = toRate.getPositiveExistentialPaths(); final Set<Path> negativeExistentialPaths = toRate.getNegativeExistentialPaths(); final Set<Set<PathFilterList>> positiveExistentialComponents = new HashSet<>(), negativeExistentialComponents = new HashSet<>(), regularComponents = new HashSet<>(); final Set<Set<PathFilterList>> preNetworkComponents = new HashSet<>(pathToPreNetworkComponents.values()); for (final Set<PathFilterList> preNetworkComponent : preNetworkComponents) { final PathCollector<HashSet<Path>> pathCollector = PathCollector.newHashSet(); preNetworkComponent.forEach(pathCollector::collectAllInLists); final HashSet<Path> paths = pathCollector.getPaths(); if (!Collections.disjoint(paths, positiveExistentialPaths)) { positiveExistentialComponents.add(preNetworkComponent); } else if (!Collections.disjoint(paths, negativeExistentialPaths)) { negativeExistentialComponents.add(preNetworkComponent); } else {//from w w w .ja v a 2 s . com regularComponents.add(preNetworkComponent); } } final Map<Set<PathFilterList>, Data> preNetworkComponentToData = preNetworkComponents.stream() .collect(toMap(Function.identity(), statisticsProvider::getData)); final Map<Set<PathFilterList>, PathFilter> existentialComponentToFilter = componentToJoinOrder.values() .iterator().next().stream().filter(p -> !regularComponents.contains(p.getLeft().iterator().next())) .collect(toMap(p -> p.getLeft().iterator().next(), p -> p.getRight().iterator().next())); final double tupleSize = regularComponents.stream() .mapToDouble(c -> preNetworkComponentToData.get(c).getTupleSize()).sum(); final double tuplesPerPage = statisticsProvider.getPageSize() / tupleSize; final double unfilteredRowCount = calcBetaUnfilteredSize(statisticsProvider, componentToJoinOrder, pathToPreNetworkComponents, regularComponents); final double rowCount = unfilteredRowCount * DoubleStream .concat(positiveExistentialComponents.stream() .mapToDouble(component -> 1 - Math.pow( (1 - statisticsProvider.getJSF(regularComponents, component, existentialComponentToFilter.get(component), pathToPreNetworkComponents)), preNetworkComponentToData.get(component).getRowCount())), negativeExistentialComponents.stream().mapToDouble(component -> Math.pow( (1 - statisticsProvider.getJSF(regularComponents, component, existentialComponentToFilter.get(component), pathToPreNetworkComponents)), preNetworkComponentToData.get(component).getRowCount()))) .reduce(1.0, (a, b) -> a * b); final double xOverUX = rowCount / unfilteredRowCount; // joinsize is needed twice per component, thus pre-calculate it final Map<Set<PathFilterList>, Double> regularComponentToJoinSize = regularComponents.stream() .collect(toMap(Function.identity(), component -> joinSize(statisticsProvider, component, componentToJoinOrder.get(component), positiveExistentialComponents, negativeExistentialComponents, pathToPreNetworkComponents, xOverUX))); // dnrating (30a) final double finsert = xOverUX * regularComponents.stream() .mapToDouble(component -> preNetworkComponentToData.get(component).getFinsert() * regularComponentToJoinSize.get(component)) .sum() + DoubleStream.concat(negativeExistentialComponents.stream().mapToDouble(component -> { final double jsf = statisticsProvider.getJSF(regularComponents, component, existentialComponentToFilter.get(component), pathToPreNetworkComponents); return preNetworkComponentToData.get(component).getFdelete() * rowCount * (jsf / (1 - jsf)); }), positiveExistentialComponents.stream() .mapToDouble(component -> preNetworkComponentToData.get(component).getFinsert() * rowCount * statisticsProvider.getJSF(regularComponents, component, existentialComponentToFilter.get(component), pathToPreNetworkComponents))) .sum(); // dnrating (30b) final double fdelete = DoubleStream.concat( regularComponents.stream().mapToDouble(c -> preNetworkComponentToData.get(c).getFdelete()), DoubleStream.concat(negativeExistentialComponents.stream() .mapToDouble(component -> preNetworkComponentToData.get(component).getFdelete() * rowCount * statisticsProvider.getJSF(regularComponents, component, existentialComponentToFilter.get(component), pathToPreNetworkComponents)), positiveExistentialComponents.stream().mapToDouble(component -> { final double jsf = statisticsProvider.getJSF(regularComponents, component, existentialComponentToFilter.get(component), pathToPreNetworkComponents); return preNetworkComponentToData.get(component).getFinsert() * rowCount * (jsf / (1 - jsf)); }))) .sum(); // publish information to statistics provider { final Set<PathFilterList> filters = new HashSet<>(); componentToJoinOrder.keySet().forEach(filters::addAll); filters.add(toRate); statisticsProvider.setData(filters, new Data(finsert, fdelete, rowCount, tupleSize)); } final double mUxBeta = m(unfilteredRowCount, tuplesPerPage); // dnrating (40) final double runtimeCost = DoubleStream.concat(regularComponents.stream().mapToDouble(component -> { final Data data = preNetworkComponentToData.get(component); return data.getFinsert() * costPosInsVarII(statisticsProvider, component, componentToJoinOrder.get(component), regularComponents, pathToPreNetworkComponents) + data.getFdelete() * (mUxBeta + cardenas(mUxBeta, regularComponentToJoinSize.get(component))); }), Stream.concat(positiveExistentialComponents.stream(), negativeExistentialComponents.stream()) .mapToDouble(component -> { final Data data = preNetworkComponentToData.get(component); return data.getFinsert() * 2 * jc(statisticsProvider, statisticsProvider.getJSF(regularComponents, component, existentialComponentToFilter.get(component), pathToPreNetworkComponents), data, 1) + data.getFdelete() * costNegDelVarII(statisticsProvider, component, componentToJoinOrder.get(component), pathToPreNetworkComponents); })).sum(); final double memoryCost = unfilteredRowCount * (tupleSize + 0.15 * (positiveExistentialComponents.size() + negativeExistentialComponents.size())); return cpuAndMemCostCombiner.applyAsDouble(runtimeCost, memoryCost); }
From source file:gov.nasa.ensemble.core.plan.advisor.view.PlanAdvisorPage.java
private boolean hasNonMarkerViolation(ISelection selection) { Set<EPlanElement> selectedElements = PlanEditorUtil.emfFromSelection(selection); for (ViolationTracker tracker : planAdvisorMember.getViolationTrackers()) { Violation violation = tracker.getViolation(); if (!violation.isCurrentlyViolated() || violation instanceof MarkerViolation) { continue; }//w w w . ja v a2 s . c o m List<? extends EPlanElement> violationElements = violation.getElements(); if (violationElements.isEmpty() || selectedElements.isEmpty() || !Collections.disjoint(violationElements, selectedElements)) { return true; } } return false; }
From source file:de.appsolve.padelcampus.controller.events.EventsController.java
@RequestMapping(value = { "edit/{eventId}/addcommunitygame" }, method = POST) public ModelAndView postAddCommunityGame(HttpServletRequest request, @PathVariable("eventId") Long eventId, @ModelAttribute("Model") AddTeamGame addTeamGame, @RequestParam(value = "redirectUrl", required = false) String redirectUrl, BindingResult bindingResult) {/* www . ja v a 2 s .co m*/ Event event = eventDAO.findByIdFetchWithParticipants(eventId); if (event == null) { throw new ResourceNotFoundException(); } try { Player user = sessionUtil.getUser(request); if (user == null) { return getLoginView(request, request.getRequestURI()); } validator.validate(addTeamGame, bindingResult); if (bindingResult.hasErrors()) { return getAddCommunityGameView(event, addTeamGame); } Team team0 = addTeamGame.getTeams().get(0); Team team1 = addTeamGame.getTeams().get(1); if (team0.getPlayers().size() != 2 || team1.getPlayers().size() != 2) { throw new Exception(msg.get("ChooseTwoPlayersPerTeam")); } if (!Collections.disjoint(team0.getPlayers(), team1.getPlayers())) { throw new Exception(msg.get("ChooseDistinctPlayers")); } if (team0.getCommunity().equals(team1.getCommunity())) { throw new Exception(msg.get("ChooseDistinctCommunities")); } List<Participant> teams = new ArrayList<>(); teams.add(findOrUpdateTeam(team0)); teams.add(findOrUpdateTeam(team1)); List<Game> eventGames = gameDAO.findByEventWithPlayers(event); for (Game game : eventGames) { if (game.getParticipants().containsAll(teams)) { bindingResult.addError(new ObjectError("id", msg.get("GameAlreadyExists"))); return getAddCommunityGameView(event, addTeamGame); } } saveGame(event, teams, request); if (!StringUtils.isEmpty(redirectUrl)) { return new ModelAndView("redirect:/" + redirectUrl); } return new ModelAndView("redirect:/events/event/" + event.getId() + "/communitygames"); } catch (Exception e) { bindingResult.addError(new ObjectError("id", e.getMessage())); return getAddCommunityGameView(event, addTeamGame); } }
From source file:org.metaabm.act.provider.AActItemProvider.java
@SuppressWarnings("unchecked") protected Command createAddCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, Collection<?> collection, int index) { if (feature == MetaABMActPackage.Literals.AACT__SOURCES) { CompoundCommand cmd = new CompoundCommand("Add Source"); SuggestLabelCommand suggestLabelCommand = new SuggestLabelCommand(this, domain, (IID) owner); cmd.append(super.createAddCommand(domain, owner, feature, collection, index)); cmd.append(suggestLabelCommand); return cmd; } else if (feature == MetaABMActPackage.Literals.AACT__TARGETS) { // Don't allow any circular references! AAct source = (AAct) owner;//from w w w . j a v a 2s . c o m if (Collections.disjoint(source.getAllSources(), collection) && !collection.contains(owner)) { CompoundCommand cmd = new CompoundCommand("Add Target"); SuggestLabelCommand suggestLabelCommand = new SuggestLabelCommand(domain, (Collection<IID>) collection); cmd.append(super.createAddCommand(domain, owner, feature, collection, index)); AGroup group = source.getGroup(); if (group != null) { // do not add existing members.. Collection<?> newMembers = new ArrayList<Object>(collection); newMembers.removeAll(group.getMembers()); if (newMembers.size() > 0) { cmd.append(AddCommand.create(domain, group, MetaABMActPackage.Literals.AGROUP__MEMBERS, newMembers)); } } for (Object act : collection) { reassignSelects(domain, cmd, source, (AAct) act); } cmd.append(suggestLabelCommand); return cmd; } else { return UnexecutableCommand.INSTANCE; } } else { return super.createAddCommand(domain, owner, feature, collection, index); } }