List of usage examples for java.util SortedSet retainAll
boolean retainAll(Collection<?> c);
From source file:org.eel.kitchen.jsonschema.keyword.DependenciesKeywordValidator.java
@Override public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) { /*// ww w. j av a2s . co m * Grab the set of property names from the instance */ final Set<String> fields = JacksonUtils.fieldNames(instance); /* * Simple dependencies: first try and see if it applies at all to this * instance. If yes, check that the needed properties are present. */ final SortedSet<String> fieldDeps = Sets.newTreeSet(fields); fieldDeps.retainAll(simple.keySet()); for (final String field : fieldDeps) computeSimpleDep(field, fields, report); /* * Schema dependencies: make a copy of the schemas map and only retain * whatever properties are present in the instance. * * If no schema dependencies, just return. */ final Map<String, JsonNode> schemaDeps = Maps.newHashMap(schemas); schemaDeps.keySet().retainAll(fields); if (schemaDeps.isEmpty()) return; JsonValidator validator; for (final JsonNode subSchema : schemaDeps.values()) { validator = context.newValidator(subSchema); validator.validate(context, report, instance); if (report.hasFatalError()) return; } }
From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java
/** * Retains only the elements that are contained in {@code collection} from * the {@link Set} for the given {@link DeviceProtocolInfoSource}. In other * words, removes all elements that are not contained in {@code collection} * from the {@link Set} for the given {@link DeviceProtocolInfoSource}. * * @param type the {@link DeviceProtocolInfoSource} type. * @param collection a {@link Collection} containing elements to be * retained.//from w ww . j av a 2s . c o m * @return {@code true} if this call resulted in a change. * * @see #remove(ProtocolInfo) * @see #remove(DeviceProtocolInfoSource, ProtocolInfo) * @see #contains(ProtocolInfo) * @see #contains(DeviceProtocolInfoSource, ProtocolInfo) * @see #retainAll(Collection) */ public boolean retainAll(DeviceProtocolInfoSource<?> type, Collection<ProtocolInfo> collection) { setsLock.writeLock().lock(); try { SortedSet<ProtocolInfo> set = protocolInfoSets.get(type); if (set != null && set.retainAll(collection)) { updateImageProfiles(); return true; } return false; } finally { setsLock.writeLock().unlock(); } }
From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java
/** * Retains only the elements that are contained in {@code collection} in all * the {@link DeviceProtocolInfoSource} {@link Set}s. In other words, * removes all elements from all the {@link DeviceProtocolInfoSource} * {@link Set}s that are not contained in {@code collection}. * * @param collection a {@link Collection} containing elements to be * retained.//from w ww . j av a2 s . c om * @return {@code true} if this call resulted in a change. * * @see #remove(ProtocolInfo) * @see #remove(DeviceProtocolInfoSource, ProtocolInfo) * @see #contains(ProtocolInfo) * @see #contains(DeviceProtocolInfoSource, ProtocolInfo) * @see #retainAll(DeviceProtocolInfoSource, Collection) */ public boolean retainAll(Collection<ProtocolInfo> collection) { boolean result = false; setsLock.writeLock().lock(); try { for (SortedSet<ProtocolInfo> set : protocolInfoSets.values()) { result |= set != null && set.retainAll(collection); } if (result) { updateImageProfiles(); } } finally { setsLock.writeLock().unlock(); } return result; }
From source file:com.silverpeas.gallery.servlets.GalleryRequestRouter.java
private Collection<Media> mixedSearch(GallerySessionController gallerySC, Collection<Media> mediaList, List<Integer> alSilverContentIds) throws Exception { ContentManager contentManager = new ContentManager(); // On crait une liste trie d'indexEntry SortedSet<Integer> basicSearchList = new TreeSet<Integer>(); String instanceId;/*from ww w. j a va 2 s . c o m*/ String objectId; List<String> docFeature = new ArrayList<String>(); for (final Media media : mediaList) { instanceId = media.getInstanceId(); objectId = media.getId(); docFeature.add(objectId); docFeature.add(instanceId); } try { // on rcupre le silverContentId partir de la recherche classique basicSearchList = contentManager.getSilverContentId(docFeature); } catch (Exception e) { SilverTrace.info("gallery", "GalleryRequestRouter.mixedSearch", "root.MSG_GEN_EXIT_METHOD"); } // ne garde que les objets communs aux 2 listes basicSearchList - alSilverContentIds // en effet, la liste resultante du PDC n'est pas la meme que celle // labore partir de la recherche classique if (alSilverContentIds != null) { basicSearchList.retainAll(alSilverContentIds); } // la liste basicSearchList ne contient maintenant que les silverContentIds des documents // trouvs // mais ces documents sont galement dans le tableau rsultat de la recherche classique // il faut donc crer une liste de mdias pour afficher le resultat return getMediaBySilverObjectIds(basicSearchList, contentManager, gallerySC); }
From source file:com.stratelia.silverpeas.pdcPeas.servlets.PdcSearchRequestRouter.java
/** * Cette mthode est appelle uniquement lorsque l'utilisateur fait une recherche combinant la * recherche classique la recherche PDC. Elle rcupre dans une liste tous les documents se * trouvant positionns dans le PDC de ie. Puis elle ne garde, que les elements communs entre les * deux listes - celle cre et celle des silvercontentid. Ensuite, elle rcupre les * MatchinIndexEntry correspondant aux rsultats du tri des listes. * * @param ie - le tableau de MatchingIndexEntry trouv par la recherche classique * @return le nouveau tableau de MatchingIndexEntry. *///from w w w . j a v a 2s.c o m private MatchingIndexEntry[] mixedSearch(MatchingIndexEntry[] ie, List<Integer> alSilverContentIds) throws Exception { // On crait une liste trie d'indexEntry SortedSet<Integer> basicSearchList = new TreeSet<Integer>(); List<String> docFeature = new ArrayList<String>(); for (int i = 0; ie != null && i < ie.length; i++) { String instanceId = ie[i].getComponent(); // recupere l'instanceId String objectId = ie[i].getObjectId(); // recupere l'id du document docFeature.add(objectId); docFeature.add(instanceId); } try { // on rcupre le silverContentId partir de la recherche classique basicSearchList = contentManager.getSilverContentId(docFeature); } catch (Exception e) { SilverTrace.info("pdcPeas", "PdcSearchRequestRouteur.mixedSearch", "root.MSG_GEN_EXIT_METHOD"); } // ne garde que les objets communs aux 2 listes basicSearchList - alSilverContentIds // en effet, la liste resultante du PDC n'est pas la meme que celle // labore partir de la recherche classique if (alSilverContentIds != null) { basicSearchList.retainAll(alSilverContentIds); } // la liste basicSearchList ne contient maintenant que les silverContentIds des documents // trouvs // mais ces documents sont galement dans le tableau rsultat de la recherche classique // il faut donc crer un tableau de MatchingIndexEntry pour afficher le resultat List<MatchingIndexEntry> result = new ArrayList<MatchingIndexEntry>(); if (basicSearchList != null && basicSearchList.size() > 0) { // la liste contient bien des rsultats Iterator<Integer> it = basicSearchList.iterator(); for (; it.hasNext();) { int contentId = it.next().intValue(); // on rcupre le silverContentId de la // liste // on rcupre l'internalContentId car nous en avons besoin pour la construction d'un // matchingIndexEntry String internalContentId = contentManager.getInternalContentId(contentId); MatchingIndexEntry mie = getMatchingIndexEntry(ie, internalContentId); if (mie != null) { result.add(mie); } } } Collections.sort(result, ScoreComparator.comparator); return result.toArray(new MatchingIndexEntry[0]); }
From source file:org.jahia.services.content.nodetypes.initializers.TemplatesChoiceListInitializerImpl.java
public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition declaringPropertyDefinition, String param, List<ChoiceListValue> values, Locale locale, Map<String, Object> context) { if (context == null) { return new ArrayList<ChoiceListValue>(); }/*w w w.j av a 2 s . co m*/ JCRNodeWrapper node = (JCRNodeWrapper) context.get("contextNode"); JCRNodeWrapper parentNode = (JCRNodeWrapper) context.get("contextParent"); ExtendedNodeType realNodeType = (ExtendedNodeType) context.get("contextType"); String propertyName = context.containsKey("dependentProperties") ? ((List<String>) context.get("dependentProperties")).get(0) : null; JCRSiteNode site = null; SortedSet<View> views = new TreeSet<View>(); boolean subViews = false; try { if (node != null) { site = node.getResolveSite(); } if (site == null && parentNode != null) { site = parentNode.getResolveSite(); } final List<String> nodeTypeList = new ArrayList<String>(); String nextParam = ""; if (param.contains(",")) { nextParam = StringUtils.substringAfter(param, ","); param = StringUtils.substringBefore(param, ","); } if ("subnodes".equals(param)) { subViews = true; if (propertyName == null) { propertyName = "j:allowedTypes"; } if (context.containsKey(propertyName)) { List<String> types = (List<String>) context.get(propertyName); for (String type : types) { nodeTypeList.add(type); } } else if (node != null && node.hasProperty(propertyName)) { JCRPropertyWrapper property = node.getProperty(propertyName); if (property.isMultiple()) { Value[] types = property.getValues(); for (Value type : types) { nodeTypeList.add(type.getString()); } } else { nodeTypeList.add(property.getValue().getString()); } } else if (node != null && !"j:allowedTypes".equals(propertyName) && node.hasProperty("j:allowedTypes")) { Value[] types = node.getProperty("j:allowedTypes").getValues(); for (Value type : types) { nodeTypeList.add(type.getString()); } } else if (node != null) { // No restrictions get node type list from already existing nodes NodeIterator nodeIterator = node.getNodes(); while (nodeIterator.hasNext()) { Node next = (Node) nodeIterator.next(); String name = next.getPrimaryNodeType().getName(); if (!nodeTypeList.contains(name) && next.isNodeType("jnt:content")) { nodeTypeList.add(name); } } } param = nextParam; } else if ("reference".equals(param)) { if (propertyName == null) { propertyName = Constants.NODE; } if (context.containsKey(propertyName)) { JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(); List<String> refNodeUuids = (List<String>) context.get(propertyName); for (String refNodeUuid : refNodeUuids) { try { JCRNodeWrapper refNode = session.getNodeByUUID(refNodeUuid); nodeTypeList.addAll(refNode.getNodeTypes()); } catch (Exception e) { logger.warn("Referenced node not found to retrieve its nodetype for initializer", e); } } } else if (node != null && node.hasProperty(propertyName)) { try { JCRNodeWrapper refNode = (JCRNodeWrapper) node.getProperty(propertyName).getNode(); nodeTypeList.addAll(refNode.getNodeTypes()); } catch (ItemNotFoundException e) { } } else if (node != null && !Constants.NODE.equals(propertyName) && node.hasProperty(Constants.NODE)) { try { JCRNodeWrapper refNode = (JCRNodeWrapper) node.getProperty(Constants.NODE).getNode(); nodeTypeList.addAll(refNode.getNodeTypes()); } catch (ItemNotFoundException e) { } } param = nextParam; } else if ("mainresource".equals(param)) { JCRNodeWrapper matchingParent; JCRNodeWrapper parent; if (node == null) { parent = (JCRNodeWrapper) context.get("contextParent"); site = parent.getResolveSite(); } else { parent = node.getParent(); } try { while (true) { if (parent.isNodeType("jnt:template")) { matchingParent = parent; break; } parent = parent.getParent(); } if (matchingParent.hasProperty("j:applyOn")) { Value[] vs = matchingParent.getProperty("j:applyOn").getValues(); for (Value v : vs) { nodeTypeList.add(v.getString()); } } } catch (ItemNotFoundException e) { } if (nodeTypeList.isEmpty()) { nodeTypeList.add("jnt:page"); } param = nextParam; } else if (param != null && param.indexOf(":") > 0) { nodeTypeList.add(param); param = nextParam; } else { if (node != null) { nodeTypeList.addAll(node.getNodeTypes()); } else if (realNodeType != null) { nodeTypeList.add(realNodeType.getName()); } } if (nodeTypeList.isEmpty()) { nodeTypeList.add("nt:base"); } SortedSet<ViewWrapper> wrappedViews = new TreeSet<ViewWrapper>(); Set<ViewWrapper> wrappedViewsSet = new HashSet<ViewWrapper>(); for (String s : nodeTypeList) { SortedSet<View> viewsSet = RenderService.getInstance() .getViewsSet(NodeTypeRegistry.getInstance().getNodeType(s), site, "html"); if (!viewsSet.isEmpty()) { // use of wrapper class to get a simpler equals method, based on the key // to keep only views in common between sub nodes for (Iterator<View> iterator = viewsSet.iterator(); iterator.hasNext();) { wrappedViewsSet.add(new ViewWrapper(iterator.next())); } if (subViews && !wrappedViews.isEmpty()) { wrappedViews.retainAll(wrappedViewsSet); } else { wrappedViews.addAll(wrappedViewsSet); } } wrappedViewsSet.clear(); } for (Iterator<ViewWrapper> iterator = wrappedViews.iterator(); iterator.hasNext();) { views.add(iterator.next().getView()); } } catch (RepositoryException e) { logger.error(e.getMessage(), e); } List<ChoiceListValue> vs = new ArrayList<ChoiceListValue>(); for (View view : views) { HashMap<String, Object> map = new HashMap<String, Object>(); fillProperties(map, view.getDefaultProperties()); fillProperties(map, view.getProperties()); boolean isStudio = site != null && site.getPath().startsWith("/modules"); if (isViewVisible(view.getKey(), param, map, isStudio)) { JahiaTemplatesPackage pkg = view.getModule() != null ? view.getModule() : ServicesRegistry.getInstance().getJahiaTemplateManagerService() .getTemplatePackageById(JahiaTemplatesPackage.ID_DEFAULT); String displayName = Messages.get(pkg, declaringPropertyDefinition.getResourceBundleKey() + "." + JCRContentUtils.replaceColon(view.getKey()), locale, view.getKey()); ChoiceListValue c = new ChoiceListValue(displayName, map, new ValueImpl(view.getKey(), PropertyType.STRING, false)); try { final Resource imagePath = pkg.getResource( File.separator + "img" + File.separator + c.getValue().getString() + ".png"); if (imagePath != null && imagePath.exists()) { String s = Jahia.getContextPath(); if (s.equals("/")) { s = ""; } c.addProperty("image", s + (pkg.getRootFolderPath().startsWith("/") ? "" : "/") + pkg.getRootFolderPath() + "/img/" + c.getValue().getString() + ".png"); } } catch (RepositoryException e) { logger.error(e.getMessage(), e); } vs.add(c); } } Collections.sort(vs); return vs; }