List of usage examples for java.util SortedSet contains
boolean contains(Object o);
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java
@Transactional @Override//from w ww. j av a2s .co m public AvailableSchedule removeFromSchedule(final IScheduleOwner owner, final Set<AvailableBlock> blocksToRemove) { // retrieve existing schedule AvailableSchedule stored = retrieve(owner); // expand it to minimum possible size SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(stored.getAvailableBlocks(), 1); // expand the argument to minimum possible size blocks SortedSet<AvailableBlock> blocksToRemoveExpanded = AvailableBlockBuilder.expand(blocksToRemove, 1); boolean modified = false; for (AvailableBlock toRemove : blocksToRemoveExpanded) { if (expanded.contains(toRemove)) { // remove the specified block boolean result = expanded.remove(toRemove); if (result && !modified) { modified = true; } } } if (modified) { replaceSchedule(owner, expanded); } // retrieve the new complete schedule and return return retrieve(owner); }
From source file:net.sourceforge.subsonic.service.ITunesParser.java
private Map<String, File> parseTracks(List<ITunesPlaylist> playlists) throws Exception { Map<String, File> result = new HashMap<String, File>(); SortedSet<String> trackIds = new TreeSet<String>(); for (ITunesPlaylist playlist : playlists) { trackIds.addAll(playlist.trackIds); }/*from ww w . jav a 2s . c o m*/ InputStream in = new FileInputStream(iTunesXml); try { XMLStreamReader streamReader = inputFactory.createXMLStreamReader(in); String trackId = null; while (streamReader.hasNext()) { int code = streamReader.next(); if (code == XMLStreamReader.START_ELEMENT) { String key = readKey(streamReader); if ("Track ID".equals(key)) { trackId = readNextTag(streamReader); } else if (trackId != null && trackIds.contains(trackId) && "Location".equals(key)) { String location = readNextTag(streamReader); File file = new File(StringUtil.urlDecode(new URL(location).getFile())); result.put(trackId, file); } } } } finally { IOUtils.closeQuietly(in); } return result; }
From source file:org.jclouds.blobstore.integration.internal.StubAsyncBlobStore.java
public Future<? extends ListContainerResponse<? extends ResourceMetadata>> list(final String name, ListContainerOptions... optionsList) { final ListContainerOptions options = (optionsList.length == 0) ? new ListContainerOptions() : optionsList[0];//from w w w . j a va 2 s .c o m return new FutureBase<ListContainerResponse<ResourceMetadata>>() { public ListContainerResponse<ResourceMetadata> get() throws InterruptedException, ExecutionException { final Map<String, Blob> realContents = getContainerToBlobs().get(name); if (realContents == null) throw new ContainerNotFoundException(name); SortedSet<ResourceMetadata> contents = Sets.newTreeSet( Iterables.transform(realContents.keySet(), new Function<String, ResourceMetadata>() { public ResourceMetadata apply(String key) { return copy(realContents.get(key).getMetadata()); } })); if (options.getMarker() != null) { final String finalMarker = options.getMarker(); ResourceMetadata lastMarkerMetadata = Iterables.find(contents, new Predicate<ResourceMetadata>() { public boolean apply(ResourceMetadata metadata) { return metadata.getName().equals(finalMarker); } }); contents = contents.tailSet(lastMarkerMetadata); contents.remove(lastMarkerMetadata); } final String prefix = options.getPath(); if (prefix != null) { contents = Sets.newTreeSet(Iterables.filter(contents, new Predicate<ResourceMetadata>() { public boolean apply(ResourceMetadata o) { return (o != null && o.getName().startsWith(prefix)); } })); } int maxResults = contents.size(); boolean truncated = false; String marker = null; if (options.getMaxResults() != null && contents.size() > 0) { SortedSet<ResourceMetadata> contentsSlice = firstSliceOfSize(contents, options.getMaxResults().intValue()); maxResults = options.getMaxResults(); if (!contentsSlice.contains(contents.last())) { // Partial listing truncated = true; marker = contentsSlice.last().getName(); } else { marker = null; } contents = contentsSlice; } final String delimiter = options.isRecursive() ? null : "/"; if (delimiter != null) { SortedSet<String> commonPrefixes = null; Iterable<String> iterable = Iterables.transform(contents, new CommonPrefixes(prefix != null ? prefix : null, delimiter)); commonPrefixes = iterable != null ? Sets.newTreeSet(iterable) : new TreeSet<String>(); commonPrefixes.remove(CommonPrefixes.NO_PREFIX); contents = Sets.newTreeSet(Iterables.filter(contents, new DelimiterFilter(prefix != null ? prefix : null, delimiter))); Iterables.<ResourceMetadata>addAll(contents, Iterables.transform(commonPrefixes, new Function<String, ResourceMetadata>() { public ResourceMetadata apply(String o) { MutableResourceMetadata md = new MutableResourceMetadataImpl(); md.setType(ResourceType.RELATIVE_PATH); md.setName(o); return md; } })); } return new ListContainerResponseImpl<ResourceMetadata>(contents, prefix, marker, maxResults, truncated); } }; }
From source file:nl.strohalm.cyclos.services.permissions.PermissionServiceImpl.java
private boolean hasPermission(final Group group, final List<Permission> permissions, final Map<Permission, AbstractPermissionCheck.RequiredValuesBean> requiredValues) { boolean result = false; Group groupToCheck;/*from w w w. ja v a 2 s .c o m*/ if (permissions != null) { MemberGroup memberGroup = null; if (group.getNature() == Group.Nature.OPERATOR) { // fetch the operator's owner member group outside the loop final OperatorGroup operatorGroup = fetchService.fetch((OperatorGroup) group, RelationshipHelper.nested(OperatorGroup.Relationships.MEMBER, Element.Relationships.GROUP)); memberGroup = operatorGroup.getMember().getMemberGroup(); } for (Permission permission : permissions) { groupToCheck = group; // When an operator is logged in and the module is member, test the operator's member's permissions if (group.getNature() == Group.Nature.OPERATOR && permission.getModule().getType() == ModuleType.MEMBER) { groupToCheck = memberGroup; } // Get the permissions from the cache Map<Module, SortedSet<Permission>> groupPermissions = ensureGroupPermissions(groupToCheck); SortedSet<Permission> permissionsSet = groupPermissions.get(permission.getModule()); if (permissionsSet != null && permissionsSet.contains(permission)) { // at this point the group has the permission, now we must ensure the permission was granted to the required entities (if any) result = checkRequiredValues(groupToCheck, memberGroup, permission, requiredValues); if (result) { break; } } } } return result; }
From source file:io.wcm.config.core.management.impl.ParameterResolverImpl.java
/** * Apply configured values for given configuration id (except those for which the parameter names are locked on a * higher configuration level)./*from w w w . ja v a 2 s . c o m*/ * @param resolver Resource resolver * @param configurationId Configuration id * @param parameterValues Parameter values * @param ancestorLockedParameterNames Set of locked parameter names on the configuration levels above. * @return Set of locked parameter names on this configuration level combined with the from the levels above. */ private SortedSet<String> applyConfiguredValues(ResourceResolver resolver, String configurationId, Map<String, Object> parameterValues, SortedSet<String> ancestorLockedParameterNames) { // get data from persistence ParameterPersistenceData data = parameterPersistence.getData(resolver, configurationId); // ensure the types provided by persistence are valid Map<String, Object> configuredValues = ensureValidValueTypes(data.getValues()); // put parameter values to map (respect locked parameter names that may be defined on ancestor level) if (!ancestorLockedParameterNames.isEmpty()) { for (Map.Entry<String, Object> entry : configuredValues.entrySet()) { if (!ancestorLockedParameterNames.contains(entry.getKey())) { parameterValues.put(entry.getKey(), entry.getValue()); } } } else { parameterValues.putAll(configuredValues); } // aggregate set of locked parameter names from ancestor levels and this level SortedSet<String> lockedParameterNames = ancestorLockedParameterNames; if (!data.getLockedParameterNames().isEmpty()) { lockedParameterNames = new TreeSet<>(); lockedParameterNames.addAll(ancestorLockedParameterNames); lockedParameterNames.addAll(data.getLockedParameterNames()); } return lockedParameterNames; }
From source file:org.apache.ranger.audit.utils.InMemoryJAASConfiguration.java
private void initialize(Properties properties) { LOG.debug("==> InMemoryJAASConfiguration.initialize()"); int prefixLen = JAAS_CONFIG_PREFIX_PARAM.length(); Map<String, SortedSet<Integer>> jaasClients = new HashMap<>(); for (String key : properties.stringPropertyNames()) { if (key.startsWith(JAAS_CONFIG_PREFIX_PARAM)) { String jaasKey = key.substring(prefixLen); StringTokenizer tokenizer = new StringTokenizer(jaasKey, "."); int tokenCount = tokenizer.countTokens(); if (tokenCount > 0) { String clientId = tokenizer.nextToken(); SortedSet<Integer> indexList = jaasClients.get(clientId); if (indexList == null) { indexList = new TreeSet<Integer>(); jaasClients.put(clientId, indexList); }//from w w w. jav a2 s.com String indexStr = tokenizer.nextToken(); int indexId = isNumeric(indexStr) ? Integer.parseInt(indexStr) : -1; Integer clientIdIndex = Integer.valueOf(indexId); if (!indexList.contains(clientIdIndex)) { indexList.add(clientIdIndex); } } } } for (String jaasClient : jaasClients.keySet()) { for (Integer index : jaasClients.get(jaasClient)) { String keyPrefix = JAAS_CONFIG_PREFIX_PARAM + jaasClient + "."; if (index > -1) { keyPrefix = keyPrefix + String.valueOf(index) + "."; } String keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_NAME_PARAM; String loginModuleName = properties.getProperty(keyParam); if (loginModuleName == null) { LOG.error("Unable to add JAAS configuration for " + "client [" + jaasClient + "] as it is missing param [" + keyParam + "]." + " Skipping JAAS config for [" + jaasClient + "]"); continue; } else { loginModuleName = loginModuleName.trim(); } keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_CONTROL_FLAG_PARAM; String controlFlag = properties.getProperty(keyParam); AppConfigurationEntry.LoginModuleControlFlag loginControlFlag = null; if (controlFlag != null) { controlFlag = controlFlag.trim().toLowerCase(); if (controlFlag.equals("optional")) { loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL; } else if (controlFlag.equals("requisite")) { loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE; } else if (controlFlag.equals("sufficient")) { loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT; } else if (controlFlag.equals("required")) { loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; } else { String validValues = "optional|requisite|sufficient|required"; LOG.warn("Unknown JAAS configuration value for (" + keyParam + ") = [" + controlFlag + "], valid value are [" + validValues + "] using the default value, REQUIRED"); loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; } } else { LOG.warn("Unable to find JAAS configuration (" + keyParam + "); using the default value, REQUIRED"); loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; } Map<String, String> options = new HashMap<>(); String optionPrefix = keyPrefix + JAAS_CONFIG_LOGIN_OPTIONS_PREFIX + "."; int optionPrefixLen = optionPrefix.length(); for (String key : properties.stringPropertyNames()) { if (key.startsWith(optionPrefix)) { String optionKey = key.substring(optionPrefixLen); String optionVal = properties.getProperty(key); if (optionVal != null) { optionVal = optionVal.trim(); try { if (optionKey.equalsIgnoreCase(JAAS_PRINCIPAL_PROP)) { optionVal = SecurityUtil.getServerPrincipal(optionVal, (String) null); } } catch (IOException e) { LOG.warn("Failed to build serverPrincipal. Using provided value:[" + optionVal + "]"); } } options.put(optionKey, optionVal); } } AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName, loginControlFlag, options); if (LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("Adding client: [").append(jaasClient).append("{").append(index).append("}]\n"); sb.append("\tloginModule: [").append(loginModuleName).append("]\n"); sb.append("\tcontrolFlag: [").append(loginControlFlag).append("]\n"); for (String key : options.keySet()) { String val = options.get(key); sb.append("\tOptions: [").append(key).append("] => [").append(val).append("]\n"); } LOG.debug(sb.toString()); } List<AppConfigurationEntry> retList = applicationConfigEntryMap.get(jaasClient); if (retList == null) { retList = new ArrayList<AppConfigurationEntry>(); applicationConfigEntryMap.put(jaasClient, retList); } retList.add(entry); } } LOG.debug("<== InMemoryJAASConfiguration.initialize()"); }
From source file:org.apache.atlas.security.InMemoryJAASConfiguration.java
private void initialize(Properties properties) { LOG.debug("==> InMemoryJAASConfiguration.initialize()"); int prefixLen = JAAS_CONFIG_PREFIX_PARAM.length(); Map<String, SortedSet<Integer>> jaasClients = new HashMap<>(); for (String key : properties.stringPropertyNames()) { if (key.startsWith(JAAS_CONFIG_PREFIX_PARAM)) { String jaasKey = key.substring(prefixLen); StringTokenizer tokenizer = new StringTokenizer(jaasKey, "."); int tokenCount = tokenizer.countTokens(); if (tokenCount > 0) { String clientId = tokenizer.nextToken(); SortedSet<Integer> indexList = jaasClients.get(clientId); if (indexList == null) { indexList = new TreeSet<>(); jaasClients.put(clientId, indexList); }/*from w ww . j a va 2 s.c om*/ String indexStr = tokenizer.nextToken(); int indexId = isNumeric(indexStr) ? Integer.parseInt(indexStr) : -1; Integer clientIdIndex = Integer.valueOf(indexId); if (!indexList.contains(clientIdIndex)) { indexList.add(clientIdIndex); } } } } for (String jaasClient : jaasClients.keySet()) { for (Integer index : jaasClients.get(jaasClient)) { String keyPrefix = JAAS_CONFIG_PREFIX_PARAM + jaasClient + "."; if (index > -1) { keyPrefix = keyPrefix + String.valueOf(index) + "."; } String keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_NAME_PARAM; String loginModuleName = properties.getProperty(keyParam); if (loginModuleName == null) { LOG.error( "Unable to add JAAS configuration for client [{}] as it is missing param [{}]. Skipping JAAS config for [{}]", jaasClient, keyParam, jaasClient); continue; } else { loginModuleName = loginModuleName.trim(); } keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_CONTROL_FLAG_PARAM; String controlFlag = properties.getProperty(keyParam); AppConfigurationEntry.LoginModuleControlFlag loginControlFlag = null; if (controlFlag != null) { controlFlag = controlFlag.trim().toLowerCase(); switch (controlFlag) { case "optional": loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL; break; case "requisite": loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE; break; case "sufficient": loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT; break; case "required": loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; break; default: String validValues = "optional|requisite|sufficient|required"; LOG.warn( "Unknown JAAS configuration value for ({}) = [{}], valid value are [{}] using the default value, REQUIRED", keyParam, controlFlag, validValues); loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; break; } } else { LOG.warn("Unable to find JAAS configuration ({}); using the default value, REQUIRED", keyParam); loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; } Map<String, String> options = new HashMap<>(); String optionPrefix = keyPrefix + JAAS_CONFIG_LOGIN_OPTIONS_PREFIX + "."; int optionPrefixLen = optionPrefix.length(); for (String key : properties.stringPropertyNames()) { if (key.startsWith(optionPrefix)) { String optionKey = key.substring(optionPrefixLen); String optionVal = properties.getProperty(key); if (optionVal != null) { optionVal = optionVal.trim(); try { if (optionKey.equalsIgnoreCase(JAAS_PRINCIPAL_PROP)) { optionVal = SecurityUtil.getServerPrincipal(optionVal, (String) null); } } catch (IOException e) { LOG.warn("Failed to build serverPrincipal. Using provided value:[{}]", optionVal); } } options.put(optionKey, optionVal); } } AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName, loginControlFlag, options); if (LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); sb.append("Adding client: [").append(jaasClient).append("{").append(index).append("}]\n"); sb.append("\tloginModule: [").append(loginModuleName).append("]\n"); sb.append("\tcontrolFlag: [").append(loginControlFlag).append("]\n"); for (String key : options.keySet()) { String val = options.get(key); sb.append("\tOptions: [").append(key).append("] => [").append(val).append("]\n"); } LOG.debug(sb.toString()); } List<AppConfigurationEntry> retList = applicationConfigEntryMap.get(jaasClient); if (retList == null) { retList = new ArrayList<>(); applicationConfigEntryMap.put(jaasClient, retList); } retList.add(entry); } } LOG.debug("<== InMemoryJAASConfiguration.initialize({})", applicationConfigEntryMap); }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * Create 2 adjacent blocks with different visitor limits. * Pass them into combine, assert they come out as 2 separate blocks. * /*from www . ja v a 2 s. co m*/ * @throws Exception */ @Test public void testCombineMismatchedVisitorLimit() throws Exception { AvailableBlock block1 = AvailableBlockBuilder.createBlock("20091007-1200", "20091007-1230", 10); AvailableBlock block2 = AvailableBlockBuilder.createBlock("20091007-1230", "20091007-1300", 9); SortedSet<AvailableBlock> smallBlocks = new TreeSet<AvailableBlock>(); smallBlocks.add(block1); smallBlocks.add(block2); SortedSet<AvailableBlock> resultCombined = AvailableBlockBuilder.combine(smallBlocks); assertEquals(resultCombined.size(), 2); assertTrue(resultCombined.contains(block1)); assertTrue(resultCombined.contains(block2)); }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * Create 2 adjacent blocks with different meeting locations. * Pass them into combine, assert they come out as 2 separate blocks. * @throws Exception// w w w . j a v a 2 s . c o m */ @Test public void testCombineMismatchedMeetingLocation() throws Exception { AvailableBlock block1 = AvailableBlockBuilder.createBlock("20091007-1200", "20091007-1230", 1, "alternate location"); AvailableBlock block2 = AvailableBlockBuilder.createBlock("20091007-1230", "20091007-1300", 1, null); SortedSet<AvailableBlock> smallBlocks = new TreeSet<AvailableBlock>(); smallBlocks.add(block1); smallBlocks.add(block2); SortedSet<AvailableBlock> resultCombined = AvailableBlockBuilder.combine(smallBlocks); assertEquals(resultCombined.size(), 2); assertTrue(resultCombined.contains(block1)); assertTrue(resultCombined.contains(block2)); }
From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java
/** * Returns {@code true} if any of the {@link DeviceProtocolInfoSource} * {@link Set}s contains the specified element. * * @param protocolInfo the element whose presence is to be tested. * @return {@code true} if any of the {@link DeviceProtocolInfoSource} * {@link Set}s contains the specified element {@code false} * otherwise.//from w w w . ja va 2 s .co m */ public boolean contains(ProtocolInfo protocolInfo) { setsLock.readLock().lock(); try { for (SortedSet<ProtocolInfo> set : protocolInfoSets.values()) { if (set != null && set.contains(protocolInfo)) { return true; } } } finally { setsLock.readLock().unlock(); } return false; }