List of usage examples for java.util Collections disjoint
public static boolean disjoint(Collection<?> c1, Collection<?> c2)
From source file:com.kylinolap.metadata.model.cube.CubeDesc.java
public Map<Array<TblColRef>, List<DeriveInfo>> getHostToDerivedInfo(List<TblColRef> rowCols, Collection<TblColRef> wantedCols) { Map<Array<TblColRef>, List<DeriveInfo>> result = new HashMap<Array<TblColRef>, List<DeriveInfo>>(); for (Entry<Array<TblColRef>, List<DeriveInfo>> entry : hostToDerivedMap.entrySet()) { Array<TblColRef> hostCols = entry.getKey(); boolean hostOnRow = rowCols.containsAll(Arrays.asList(hostCols.data)); if (!hostOnRow) continue; List<DeriveInfo> wantedInfo = new ArrayList<DeriveInfo>(); for (DeriveInfo info : entry.getValue()) { if (wantedCols == null || Collections.disjoint(wantedCols, Arrays.asList(info.columns)) == false) // has // any // wanted // columns? wantedInfo.add(info);/*from w w w .j av a2 s.co m*/ } if (wantedInfo.size() > 0) result.put(hostCols, wantedInfo); } return result; }
From source file:org.geppetto.simulation.manager.ExperimentRunThread.java
/** * @param experiment// w ww . j av a2 s . co m * @throws GeppettoInitializationException */ private void init(IExperiment experiment) throws GeppettoInitializationException { try { GeppettoModelAccess modelAccess = new GeppettoModelAccess(runtimeProject.getGeppettoModel()); List<? extends IAspectConfiguration> aspectConfigs = experiment.getAspectConfigurations(); for (IAspectConfiguration aspectConfig : aspectConfigs) { ISimulatorConfiguration simConfig = aspectConfig.getSimulatorConfiguration(); String simulatorId = simConfig.getSimulatorId(); String instancePath = aspectConfig.getInstance(); Pointer pointer = PointerUtility.getPointer(runtimeProject.getGeppettoModel(), instancePath); // We are taking the domain model for the last element of the pointer DomainModel model = PointerUtility.getType(pointer).getDomainModel(); if (simConfig.getConversionServiceId() != null && !simConfig.getConversionServiceId().isEmpty()) { AConversion conversionService = (AConversion) ServiceCreator .getNewServiceInstance(simConfig.getConversionServiceId()); conversionService.setScope(Scope.RUN); conversionService.setProjectId(experiment.getParentProject().getId()); conversionServices.put(instancePath, conversionService); } ASimulator simulator = (ASimulator) ServiceCreator.getNewServiceInstance(simulatorId); simulator.setProjectId(experiment.getParentProject().getId()); simulatorServices.put(instancePath, simulator); simulatorRuntimes.put(instancePath, new SimulatorRuntime()); // get conversion service IConversion conversionService = null; if (simConfig.getConversionServiceId() != null && !simConfig.getConversionServiceId().isEmpty()) { conversionService = this.conversionServices.get(simConfig.getConversionServiceId()); } IModelInterpreter modelService = runtimeProject.getModelInterpreter(pointer); // TODO: Extract formats from model interpreters from within here somehow List<ModelFormat> inputFormats = ServicesRegistry.getModelInterpreterServiceFormats(modelService); List<ModelFormat> outputFormats = ServicesRegistry.getSimulatorServiceFormats(simulator); if (inputFormats == null || inputFormats.isEmpty()) { throw new GeppettoInitializationException( "No supported formats for the model interpreter " + modelService.getName()); } if (outputFormats == null || outputFormats.isEmpty()) { throw new GeppettoInitializationException( "No supported formats for the simulator " + simulator.getName()); } DomainModel iConvertedModel = null; if (conversionService != null) { // Read conversion supported model formats List<ModelFormat> supportedInputFormats = conversionService.getSupportedInputs(); // FIXME: We can pass the model and the input format so it brings back a filtered list of outputs format List<ModelFormat> supportedOutputFormats = conversionService.getSupportedOutputs(); // Check if real model formats and conversion supported model formats match supportedInputFormats.retainAll(inputFormats); supportedOutputFormats.retainAll(outputFormats); // Try to convert until a input-output format combination works for (ModelFormat inputFormat : supportedInputFormats) { if (iConvertedModel == null) { for (ModelFormat outputFormat : supportedOutputFormats) { try { iConvertedModel = conversionService.convert(model, outputFormat, aspectConfig, modelAccess); break; } catch (ConversionException e) { throw new GeppettoInitializationException(e); } } } } } else { // Check format returned by the model interpreter matches with the one accepted by the simulator if (Collections.disjoint(inputFormats, outputFormats) && inputFormats != null && outputFormats != null) { Map<ConversionServiceKey, List<IConversion>> conversionServices = ServicesRegistry .getConversionService(inputFormats, outputFormats); for (Map.Entry<ConversionServiceKey, List<IConversion>> entry : conversionServices .entrySet()) { if (iConvertedModel == null) { // FIXME: Assuming we will only have one conversion service ConversionServiceKey conversionServiceKey = entry.getKey(); for (ModelFormat supportedModelFormat : entry.getValue().get(0) .getSupportedOutputs(model)) { // Verify supported outputs for this model if (supportedModelFormat.equals(conversionServiceKey.getOutputModelFormat())) { ((AConversion) entry.getValue().get(0)).setScope(Scope.RUN); ((AConversion) entry.getValue().get(0)) .setProjectId(experiment.getParentProject().getId()); iConvertedModel = entry.getValue().get(0).convert(model, conversionServiceKey.getOutputModelFormat(), aspectConfig, modelAccess); break; } } } } } } // code to initialize simulator if (simulator != null) { long start = System.currentTimeMillis(); ExperimentState experimentState = runtimeProject.getRuntimeExperiment(experiment) .getExperimentState(); if (iConvertedModel == null) { simulator.initialize(model, aspectConfig, experimentState, this, modelAccess); } else { simulator.initialize(iConvertedModel, aspectConfig, experimentState, this, modelAccess); } long end = System.currentTimeMillis(); logger.info("Finished initializing simulator, took " + (end - start) + " ms "); } else { throw new GeppettoInitializationException( "A simulator for " + instancePath + " already exists, something did not get cleared"); } } } catch (Exception e) { throw new GeppettoInitializationException(e); } }
From source file:org.languagetool.rules.uk.TokenAgreementNounVerbRule.java
static boolean inflectionsOverlap(List<AnalyzedToken> verbTokenReadings, List<AnalyzedToken> nounTokenReadings) { return !Collections.disjoint(getVerbInflections(verbTokenReadings), getNounInflections(nounTokenReadings)); }
From source file:org.artifactory.repo.service.ImportJob.java
private void checkForUnusedSubdirectories() { if (importSettings.isSingleRepoImport()) { return;/*from ww w . j a v a2 s . c o m*/ } Collection<String> directoryNames = collectSubdirectoriesNames(); if (importSettings.isFailIfEmpty() && Collections.disjoint(importSettings.getRepositories(), directoryNames)) { statusHolder.error("The selected directory did not contain any repositories.", log); } else { for (String subDir : directoryNames) { boolean isMetadata = subDir.contains("metadata"); boolean isIndex = subDir.contains("index"); if (!isMetadata && !isIndex && !importSettings.getRepositories().contains(subDir)) { statusHolder.warn("The directory " + subDir + " does not match any repository key.", log); } } } }
From source file:nl.b3p.viewer.util.SelectedContentCache.java
private boolean isAuthorized(JSONObject obj, Set<String> roles, boolean alsoWriters, String authString) throws JSONException { if (obj.has(authString) && obj.getJSONObject(authString).length() != 0) { // Levels only have readers JSONArray readers = obj.getJSONObject(authString).getJSONArray("readers"); if (readers.length() > 0) { Set<String> allowedRoles = new HashSet(); for (int i = 0; i < readers.length(); i++) { if (!readers.isNull(i)) { String reader = readers.getString(i); allowedRoles.add(reader); }//from ww w . j ava 2 s. c om } if (Collections.disjoint(roles, allowedRoles)) { return false; } } if (alsoWriters) { JSONArray writers = obj.getJSONObject(authString).getJSONArray("writers"); if (writers.length() > 0) { Set<String> allowedRoles = new HashSet(); for (int i = 0; i < writers.length(); i++) { String writer = writers.getString(i); allowedRoles.add(writer); } if (Collections.disjoint(roles, allowedRoles)) { return false; } } } } obj.remove(authString); return true; }
From source file:org.apache.ranger.plugin.policyevaluator.RangerDefaultPolicyItemEvaluator.java
@Override public boolean matchUserGroup(String user, Set<String> userGroups) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultPolicyItemEvaluator.matchUserGroup(" + policyItem + ", " + user + ", " + userGroups + ")"); }//from ww w . j a va 2s . com boolean ret = false; if (policyItem != null) { if (!ret && user != null && policyItem.getUsers() != null) { ret = hasCurrentUser || policyItem.getUsers().contains(user); } if (!ret && userGroups != null && policyItem.getGroups() != null) { ret = policyItem.getGroups().contains(RangerPolicyEngine.GROUP_PUBLIC) || !Collections.disjoint(policyItem.getGroups(), userGroups); } } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultPolicyItemEvaluator.matchUserGroup(" + policyItem + ", " + user + ", " + userGroups + "): " + ret); } return ret; }
From source file:org.gvsig.framework.web.service.impl.OGCInfoServiceImpl.java
/** * Recursive method to add list layers get by the WMSServer into tree list * * @param children Represents child layers of parentNode * @param tree Tree of layers/* www .j ava2s. c om*/ * @param crs CRS that must have the layers to add these to the tree * @param parentNode Represents parent layer * @param layersMap Represents the map that contains the layers obtained * @param isCalledByWizard Indicate if the method is called by the wizard */ private void generateWMSChildrenNodes(ArrayList<WMSLayer> children, List<TreeNode> tree, TreeSet<String> listCrs, TreeNode parentNode, Map<String, org.gvsig.framework.web.ogc.WMSLayer> layersMap, WMSInfo wmsInfo) { for (WMSLayer layerChild : children) { // get crs (srs) (belong to layer) Vector crsVector = layerChild.getAllSrs(); // Only get the layers with have crs parameter or if crs is null if (listCrs.isEmpty() || !Collections.disjoint(crsVector, listCrs)) { ArrayList<WMSLayer> layerChildChildren = layerChild.getChildren(); TreeNode layerChildNode = new TreeNode(layerChild.getName()); layerChildNode.setTitle(layerChild.getTitle()); // Get the children and their information if (layerChildChildren.isEmpty()) { layerChildNode.setFolder(false); // Add layer to layer map org.gvsig.framework.web.ogc.WMSLayer wmsLayer = new org.gvsig.framework.web.ogc.WMSLayer(); TreeSet<String> crsSet = new TreeSet<String>(); crsSet.addAll(layerChild.getAllSrs()); wmsLayer.setCrs(crsSet); List<WMSStyle> wmsStyles = createListWMSStyles(layerChild.getStyles()); wmsLayer.setStyles(wmsStyles); wmsLayer.setTitle(layerChild.getTitle()); wmsLayer.setName(layerChild.getName()); layersMap.put(layerChild.getName(), wmsLayer); // add to wmsinfo the layers supported by this layer TreeSet<String> crsSupported = wmsInfo.getCrsSupported(); crsSupported.addAll(layerChild.getAllSrs()); wmsInfo.setCrsSupported(crsSupported); //create one child for each crs of the layer if (listCrs.isEmpty() || listCrs.size() > 1) { for (String crs : crsSet) { if (StringUtils.isNotEmpty(crs) && (listCrs.isEmpty() || listCrs.contains(crs))) { TreeNode crsNode = new TreeNode(crs); crsNode.setHideCheckbox(true); crsNode.setUnselectable(true); crsNode.setIconclass(" "); layerChildNode.addChild(crsNode); } } } } else { layerChildNode.setFolder(true); layerChildNode.setExpanded(true); generateWMSChildrenNodes(layerChildChildren, tree, listCrs, layerChildNode, layersMap, wmsInfo); } parentNode.addChild(layerChildNode); } } }
From source file:main.java.repartition.SimpleTr.java
static double getIncidentSpan(Transaction j, MigrationPlan m) { // Construct A -- for target transaction i Set<Integer> delta_i_A = new HashSet<Integer>(); for (Integer s : m.fromSet) delta_i_A.addAll(m.serverDataSet.get(s)); // Construct b -- for incident transaction j Set<Integer> delta_j_A = new HashSet<Integer>(); for (Integer s : m.fromSet) if (j.getTr_serverSet().containsKey(s)) delta_j_A.addAll(j.getTr_serverSet().get(s)); // Set difference, delta = delta_j_A \ delta_i_A Set<Integer> delta = new HashSet<Integer>(delta_j_A); delta.removeAll(delta_i_A);/* w w w .j ava2 s.c o m*/ HashSet<Integer> psi_delta = new HashSet<Integer>(); for (Entry<Integer, HashSet<Integer>> entry : j.getTr_serverSet().entrySet()) if (!Collections.disjoint(delta, entry.getValue())) // Returns true if the two specified collections have no elements in common. psi_delta.add(entry.getKey()); // Calculate net span improvement for incident transaction j int incident_span = m.fromSet.size() - psi_delta.size(); if (!j.getTr_serverSet().containsKey(m.to)) incident_span -= 1; return (double) (incident_span) * (1 / j.getTr_period()); }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceAdapter.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 resourceId// w w w. j a va 2s. c om * @param value * @param clientId */ public void removeResourceParameter(String resourceId, String value, String clientId) { ResourceParameterKey pk = new ResourceParameterKey(); pk.resourceId = resourceId; pk.value = value; // main parameter ResourceParameter rpdb = resourceParameterRepository.findOne(pk); if (rpdb != null && !rpdb.getClientId().equals(clientId)) { throw new IllegalArgumentException("Can delete only own resource parameters"); } if (rpdb != null) { 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:org.apache.kylin.cube.model.CubeDesc.java
public Map<Array<TblColRef>, List<DeriveInfo>> getHostToDerivedInfo(List<TblColRef> rowCols, Collection<TblColRef> wantedCols) { Map<Array<TblColRef>, List<DeriveInfo>> result = new HashMap<Array<TblColRef>, List<DeriveInfo>>(); for (Entry<Array<TblColRef>, List<DeriveInfo>> entry : hostToDerivedMap.entrySet()) { Array<TblColRef> hostCols = entry.getKey(); boolean hostOnRow = rowCols.containsAll(Arrays.asList(hostCols.data)); if (!hostOnRow) continue; List<DeriveInfo> wantedInfo = new ArrayList<DeriveInfo>(); for (DeriveInfo info : entry.getValue()) { if (wantedCols == null || Collections.disjoint(wantedCols, Arrays.asList(info.columns)) == false) // has any wanted columns? wantedInfo.add(info);//from www .j a v a 2 s. co m } if (wantedInfo.size() > 0) result.put(hostCols, wantedInfo); } return result; }