List of usage examples for com.google.common.collect LinkedListMultimap removeAll
@Override
public List<V> removeAll(@Nullable Object key)
The returned list is immutable and implements java.util.RandomAccess .
From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java
@SuppressWarnings("ConstantConditions") public static void updateSubscriptionCategoryTitleAt(final Context context, final String category, final String newTitle, final int position) { final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context); final String title = getSubscriptionTitleAt(context, position); final List<String> values = subscriptions.get(title); final boolean newCategory = !values.get(0).equals(category); if (newCategory || !newTitle.equals(title)) { if (newCategory) { final List<String> newValues = new ArrayList<>(subscriptions.removeAll(title)); newValues.set(0, category);// w ww.jav a 2 s . c om subscriptions.putAll(newTitle, newValues); } else { subscriptions.putAll(newTitle, subscriptions.removeAll(title)); } saveSubscriptions(context, subscriptions); updateCurrentFeedPosition(context, newTitle); } }
From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java
public static boolean unsubscribe(final Context context, final List<String> titles) { final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context); if (subscriptions.asMap().size() < 2) { saveSubscriptions(context, null); putCurrentFeedPosition(context, 0); putPreviousFeedPosition(context, 0); return false; }/*from w ww . j a v a2 s . c o m*/ final String currentTitle = getCurrentFeedTitle(context); for (final String title : titles) { subscriptions.removeAll(title); } if (subscriptions.isEmpty()) { saveSubscriptions(context, null); putCurrentFeedPosition(context, 0); putPreviousFeedPosition(context, 0); return false; } saveSubscriptions(context, subscriptions); if (subscriptions.containsKey(currentTitle)) { updateCurrentFeedPosition(context, currentTitle); return false; } return true; }
From source file:org.splevo.diffing.match.HierarchicalStrategyResourceMatcher.java
/** * Create matches for the left and right candidates. A match is only created if a pair is the * best match for both sides.// www . j a v a 2 s .c o m * * Internally, indexes are build to identify the total number of matches and the best matches * for both candidate lists. * * @param leftCandidates * The left candidates to search matches for. * @param rightCandidates * The right candidates to search matches for. * @param mappings * The list of mappings to fill. */ private void matchBestMatches(List<Resource> leftCandidates, List<Resource> rightCandidates, List<MatchResource> mappings) { // index for a fast lookup of the highest match score for a resource. HashMap<Resource, Integer> bestMatchCountIndex = new HashMap<Resource, Integer>(); // mappings for a resource to it's best matches // This is implemented as multimap to support renaming and derived copies. // in such a case, an original resource might map two times: // To the still existing same class as well as the modified, derived copy // see SPLEVO-181 for details {@link https://sdqbuild.ipd.kit.edu/jira/browse/SPLEVO-181} LinkedListMultimap<Resource, Resource> bestMatchIndexLeft = LinkedListMultimap.create(); LinkedListMultimap<Resource, Resource> bestMatchIndexRight = LinkedListMultimap.create(); for (Resource leftRes : leftCandidates) { for (Resource rightRes : rightCandidates) { int matchCount = getMatchingSegmentsPathOnly(leftRes, rightRes); if (!bestMatchCountIndex.containsKey(leftRes) || bestMatchCountIndex.get(leftRes) < matchCount) { bestMatchCountIndex.put(leftRes, matchCount); bestMatchIndexLeft.removeAll(leftRes); bestMatchIndexLeft.put(leftRes, rightRes); } else if (bestMatchCountIndex.get(leftRes) == matchCount) { bestMatchCountIndex.put(leftRes, matchCount); bestMatchIndexLeft.put(leftRes, rightRes); } if (!bestMatchCountIndex.containsKey(rightRes) || bestMatchCountIndex.get(rightRes) < matchCount) { bestMatchCountIndex.put(rightRes, matchCount); bestMatchIndexRight.removeAll(rightRes); bestMatchIndexRight.put(rightRes, leftRes); } else if (bestMatchCountIndex.get(rightRes) == matchCount) { bestMatchCountIndex.put(rightRes, matchCount); bestMatchIndexRight.put(rightRes, leftRes); } } } List<MatchResource> bestMatches = createMatchElementsForBestMatches(bestMatchCountIndex, bestMatchIndexLeft); mappings.addAll(bestMatches); }
From source file:org.onos.yangtools.yang.data.impl.schema.transform.base.parser.BaseDispatcherParser.java
/** * can return null only if you override ParsingStrategy and explicitely return null * @param elements//from www.j a v a2 s . c o m * @param schema * @return */ @Nullable @Override public N parse(final Iterable<E> elements, final S schema) { checkAtLeastOneNode(schema, elements); DataContainerNodeBuilder<P, N> containerBuilder = getBuilder(schema); // Map child nodes to QName LinkedListMultimap<QName, E> mappedChildElements = mapChildElements(elements); // Map child nodes from Augments Map<QName, AugmentationSchema> mappedAugmentChildNodes = mapChildElementsFromAugments(schema); LinkedListMultimap<AugmentationSchema, E> augmentsToElements = LinkedListMultimap.create(); // Map child nodes from choices Map<QName, ChoiceSchemaNode> mappedChoiceChildNodes = mapChildElementsFromChoices(schema); LinkedListMultimap<ChoiceSchemaNode, E> choicesToElements = LinkedListMultimap.create(); Map<QName, String> attributes = getAttributes(elements.iterator().next()); if (containerBuilder instanceof AttributesBuilder) { final int size = Iterables.size(elements); Preconditions.checkArgument(size == 1, "Unexpected number of elements: %s, should be 1 for: %s", size, schema); ((AttributesBuilder<?>) containerBuilder).withAttributes(attributes); } //parse keys first if (schema instanceof ListSchemaNode) { for (QName qname : ((ListSchemaNode) schema).getKeyDefinition()) { if (mappedChildElements.get(qname.withoutRevision()).isEmpty()) { continue; } DataSchemaNode childSchema = getSchemaForChild(schema, qname); List<E> childrenForQName = mappedChildElements.removeAll(qname.withoutRevision()); DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChildNode = getDispatcher() .dispatchChildElement(childSchema, childrenForQName); if (optionalChildNode != null) { containerBuilder.withChild(optionalChildNode); } } } //stage attribues for strategy before going deeper in the recursion buildingStrategy.prepareAttributes(attributes, containerBuilder); // process Child nodes for (QName childPartialQName : mappedChildElements.keySet()) { DataSchemaNode childSchema = getSchemaForChild(schema, childPartialQName); //with strict parsing an exception would be already thrown, with nonstrict we want to ignore this node if (childSchema == null) { continue; } List<E> childrenForQName = mappedChildElements.get(childPartialQName); // Augment if (isMarkedAs(mappedAugmentChildNodes, childSchema.getQName())) { AugmentationSchema augmentationSchema = mappedAugmentChildNodes.get(childSchema.getQName()); augmentsToElements.putAll(augmentationSchema, childrenForQName); // Choices } else if (isMarkedAs(mappedChoiceChildNodes, childSchema.getQName())) { ChoiceSchemaNode choiceSchema = mappedChoiceChildNodes.get(childSchema.getQName()); choicesToElements.putAll(choiceSchema, childrenForQName); // Regular child nodes } else { DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChildNode = getDispatcher() .dispatchChildElement(childSchema, childrenForQName); if (optionalChildNode != null) { containerBuilder.withChild(optionalChildNode); } } } // TODO ordering is not preserved for choice and augment elements for (ChoiceSchemaNode choiceSchema : choicesToElements.keySet()) { DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChild = getDispatcher() .dispatchChildElement(choiceSchema, choicesToElements.get(choiceSchema)); if (optionalChild != null) { containerBuilder.withChild(optionalChild); } } for (AugmentationSchema augmentSchema : augmentsToElements.keySet()) { Set<DataSchemaNode> realChildSchemas = getRealSchemasForAugment(schema, augmentSchema); EffectiveAugmentationSchema augSchemaProxy = new EffectiveAugmentationSchema(augmentSchema, realChildSchemas); DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChild = getDispatcher() .dispatchChildElement(augSchemaProxy, augmentsToElements.get(augmentSchema)); if (optionalChild != null) { containerBuilder.withChild(optionalChild); } } return buildingStrategy.build(containerBuilder); }
From source file:org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.BaseDispatcherParser.java
/** * can return null only if you override ParsingStrategy and explicitely return null * @param elements elements to be parsed into NormalizedNode * @param schema schema belonging to the type N of NormalizedNode * @return child of DataContainerNode as a result of parsing list of E elements with schema S *///from www . ja v a 2 s. c om @Nullable @Override public N parse(final Iterable<E> elements, final S schema) { checkAtLeastOneNode(schema, elements); DataContainerNodeBuilder<P, N> containerBuilder = getBuilder(schema); // Map child nodes to QName LinkedListMultimap<QName, E> mappedChildElements = mapChildElements(elements); // Map child nodes from Augments Map<QName, AugmentationSchema> mappedAugmentChildNodes = mapChildElementsFromAugments(schema); LinkedListMultimap<AugmentationSchema, E> augmentsToElements = LinkedListMultimap.create(); // Map child nodes from choices Map<QName, ChoiceSchemaNode> mappedChoiceChildNodes = mapChildElementsFromChoices(schema); LinkedListMultimap<ChoiceSchemaNode, E> choicesToElements = LinkedListMultimap.create(); Map<QName, String> attributes = getAttributes(elements.iterator().next()); if (containerBuilder instanceof AttributesBuilder) { final int size = Iterables.size(elements); Preconditions.checkArgument(size == 1, "Unexpected number of elements: %s, should be 1 for: %s", size, schema); ((AttributesBuilder<?>) containerBuilder).withAttributes(attributes); } //parse keys first if (schema instanceof ListSchemaNode) { for (QName qname : ((ListSchemaNode) schema).getKeyDefinition()) { final QName noRev = qname.withoutRevision(); if (mappedChildElements.get(noRev).isEmpty()) { continue; } DataSchemaNode childSchema = getSchemaForChild(schema, qname); List<E> childrenForQName = mappedChildElements.removeAll(noRev); DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChildNode = getDispatcher() .dispatchChildElement(childSchema, childrenForQName); if (optionalChildNode != null) { containerBuilder.withChild(optionalChildNode); } } } //stage attribues for strategy before going deeper in the recursion buildingStrategy.prepareAttributes(attributes, containerBuilder); // process Child nodes for (QName childPartialQName : mappedChildElements.keySet()) { DataSchemaNode childSchema = getSchemaForChild(schema, childPartialQName); //with strict parsing an exception would be already thrown, with nonstrict we want to ignore this node if (childSchema == null) { continue; } List<E> childrenForQName = mappedChildElements.get(childPartialQName); // Augment if (isMarkedAs(mappedAugmentChildNodes, childSchema.getQName())) { AugmentationSchema augmentationSchema = mappedAugmentChildNodes.get(childSchema.getQName()); augmentsToElements.putAll(augmentationSchema, childrenForQName); // Choices } else if (isMarkedAs(mappedChoiceChildNodes, childSchema.getQName())) { ChoiceSchemaNode choiceSchema = mappedChoiceChildNodes.get(childSchema.getQName()); choicesToElements.putAll(choiceSchema, childrenForQName); // Regular child nodes } else { DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChildNode = getDispatcher() .dispatchChildElement(childSchema, childrenForQName); if (optionalChildNode != null) { containerBuilder.withChild(optionalChildNode); } } } // TODO ordering is not preserved for choice and augment elements for (ChoiceSchemaNode choiceSchema : choicesToElements.keySet()) { DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChild = getDispatcher() .dispatchChildElement(choiceSchema, choicesToElements.get(choiceSchema)); if (optionalChild != null) { containerBuilder.withChild(optionalChild); } } for (AugmentationSchema augmentSchema : augmentsToElements.keySet()) { Set<DataSchemaNode> realChildSchemas = getRealSchemasForAugment(schema, augmentSchema); EffectiveAugmentationSchema augSchemaProxy = new EffectiveAugmentationSchema(augmentSchema, realChildSchemas); DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChild = getDispatcher() .dispatchChildElement(augSchemaProxy, augmentsToElements.get(augmentSchema)); if (optionalChild != null) { containerBuilder.withChild(optionalChild); } } return buildingStrategy.build(containerBuilder); }