From e874a1a193d16232eed497e5d868b2200dd50fd9 Mon Sep 17 00:00:00 2001 From: Pierre-Charles David Date: Fri, 5 Apr 2024 18:00:21 +0200 Subject: [PATCH] [146] Remove Guava dependency in oes.ecore.extender Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/146 Signed-off-by: Pierre-Charles David --- .../META-INF/MANIFEST.MF | 3 +- .../accessor/CompositeMetamodelExtender.java | 33 ++++++------ .../accessor/EcoreMetamodelDescriptor.java | 23 ++------ .../ecore/EcoreIntrinsicExtender.java | 52 +++++++++++-------- .../accessor/ecore/PackageRegistryIndex.java | 36 ++++++++----- .../AbstractPermissionAuthority.java | 17 +++--- .../ecore/extender/tool/api/ModelUtils.java | 10 ++-- .../tool/internal/ReferencesResolver.java | 24 +++------ 8 files changed, 91 insertions(+), 107 deletions(-) diff --git a/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF index 92b0946bfb..6c6128f7db 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF @@ -6,8 +6,7 @@ Bundle-Version: 7.4.3.qualifier Bundle-Vendor: %providerName Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.emf.ecore.xmi;bundle-version="2.8.1", - org.eclipse.emf.edit;bundle-version="2.8.0", - com.google.guava;bundle-version="27.0" + org.eclipse.emf.edit;bundle-version="2.8.0" Export-Package: org.eclipse.sirius.ecore.extender.business.api.accessor;version="3.0.0", org.eclipse.sirius.ecore.extender.business.api.accessor.exception;version="3.0.0", org.eclipse.sirius.ecore.extender.business.api.permission;version="2.0.4", diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java index 9c8e679750..fb92ef6699 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -18,6 +18,9 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.stream.StreamSupport; import org.eclipse.emf.common.util.AbstractTreeIterator; import org.eclipse.emf.common.util.TreeIterator; @@ -27,10 +30,6 @@ import org.eclipse.sirius.ecore.extender.business.internal.common.ExtenderDescriptor; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; - /** * Aggregate more {@link IMetamodelExtender}'s using a priority system. * @@ -185,6 +184,7 @@ public String eContainingFeatureName(final EObject instance) { return null; } + @Override public Iterator eContents(final EObject root) { final List> iterators = new ArrayList<>(); @@ -195,11 +195,12 @@ public Iterator eContents(final EObject root) { } } if (!iterators.isEmpty()) { - return Iterators.concat(iterators.iterator()); + return iterators.stream() + .flatMap(iterator -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)) + .iterator(); } return Collections. emptyList().iterator(); } - /** * Check whether the given instance should block the eAllContent browsing or * not. @@ -238,7 +239,7 @@ public EObject eDelete(EObject objectToRemove, ECrossReferenceAdapter xref, ERef @Override public Collection eRemoveInverseCrossReferences(EObject eObject, ECrossReferenceAdapter xref, EReferencePredicate isReferencesToIgnorePredicate) { - Collection impactedEObjects = new LinkedHashSet(); + Collection impactedEObjects = new LinkedHashSet<>(); for (final IMetamodelExtender extender : getActivatedExtenders()) { impactedEObjects.addAll(extender.eRemoveInverseCrossReferences(eObject, xref, isReferencesToIgnorePredicate)); } @@ -336,7 +337,9 @@ public Iterator getContributedAttributeNames(final EObject next) { for (final IMetamodelExtender extender : getActivatedExtenders()) { iterators.add(extender.getContributedAttributeNames(next)); } - return Iterators.concat(iterators.iterator()); + return iterators.stream() + .flatMap(iterator -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)) + .iterator(); } @Override @@ -345,8 +348,9 @@ public Iterator getContributedReferenceNames(final EObject instance) { for (final IMetamodelExtender extender : getActivatedExtenders()) { iterators.add(extender.getContributedReferenceNames(instance)); } - return Iterators.concat(iterators.iterator()); - + return iterators.stream() + .flatMap(iterator -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)) + .iterator(); } @Override @@ -477,12 +481,7 @@ public void deactivate() { */ protected synchronized Iterable getActivatedExtenders() { if (activeExtenders == null) { - activeExtenders = Iterables.filter(extenders, new Predicate() { - @Override - public boolean apply(IMetamodelExtender extender) { - return extender.isActive(); - } - }); + activeExtenders = () -> extenders.stream().filter(IMetamodelExtender::isActive).iterator(); } return activeExtenders; } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java index 12d7183d3b..b3976a2272 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,11 +12,11 @@ *******************************************************************************/ package org.eclipse.sirius.ecore.extender.business.api.accessor; +import java.util.Objects; + import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; -import com.google.common.base.Objects; - /** * A descriptors for EPackages. * @@ -75,11 +75,6 @@ private boolean isInPlugin(final EPackage package1) { return false; } - /** - * {@inheritDoc} - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -89,25 +84,17 @@ public int hashCode() { return result; } - /** - * {@inheritDoc} - * - * @see java.lang.Object#equals(java.lang.Object) - */ // CHECKSTYLE:OFF @Override public boolean equals(Object obj) { - if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } - - final EcoreMetamodelDescriptor other = (EcoreMetamodelDescriptor) obj; - - return ePackage == other.ePackage && Objects.equal(nsURI, other.nsURI); + EcoreMetamodelDescriptor other = (EcoreMetamodelDescriptor) obj; + return ePackage == other.ePackage && Objects.equals(nsURI, other.nsURI); // CHECKSTYLE:ON } } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java index 3491d791bf..f3ebd99bcb 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,12 +15,17 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EEnum; import org.eclipse.emf.ecore.EEnumLiteral; @@ -39,13 +44,6 @@ import org.eclipse.sirius.ecore.extender.business.api.accessor.MetamodelDescriptor; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.base.Predicates; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; - /** * This metamodel Extender accesses the intrinsic data of an EObject. * @@ -58,9 +56,9 @@ public class EcoreIntrinsicExtender extends AbstractMetamodelExtender { private static final String AQL_SEPARATOR = "::"; //$NON-NLS-1$ - private static PackageRegistryIndex platformIndex = new PackageRegistryIndex(EPackage.Registry.INSTANCE, Predicates. alwaysTrue()); + private static PackageRegistryIndex platformIndex = new PackageRegistryIndex(EPackage.Registry.INSTANCE, p -> true); - private Multimap viewpointIndex = HashMultimap.create(); + private Map> viewpointIndex = new HashMap<>(); private Collection lastDescriptors; @@ -377,12 +375,19 @@ public void init(final ResourceSet set) { } private void addTypesToSiriusIndex(final EPackage value) { - for (EClass cur : Iterables.filter(value.getEClassifiers(), EClass.class)) { - viewpointIndex.put(cur.getName(), cur); - viewpointIndex.put(value.getName() + EcoreIntrinsicExtender.SEPARATOR + cur.getName(), cur); - viewpointIndex.put(value.getName() + EcoreIntrinsicExtender.AQL_SEPARATOR + cur.getName(), cur); + for (EClassifier eClassifier : value.getEClassifiers()) { + if (eClassifier instanceof EClass cur) { + addToIndex(cur.getName(), cur); + addToIndex(value.getName() + EcoreIntrinsicExtender.SEPARATOR + cur.getName(), cur); + addToIndex(value.getName() + EcoreIntrinsicExtender.AQL_SEPARATOR + cur.getName(), cur); + } } } + + private void addToIndex(String key, EClass eClass) { + viewpointIndex.putIfAbsent(key, new ArrayList<>()); + viewpointIndex.get(key).add(eClass); + } @Override public boolean isExtension(final EObject next) { @@ -390,7 +395,7 @@ public boolean isExtension(final EObject next) { } private Iterator getEClassesFromName(final String name) { - return Iterators.concat(viewpointIndex.get(name).iterator(), platformIndex.getEClassesFromName(name).iterator()); + return Stream.concat(viewpointIndex.getOrDefault(name, List.of()).stream(), platformIndex.getEClassesFromName(name).stream()).iterator(); } private EClass findFirstEClassFromName(final String name) { @@ -400,7 +405,7 @@ private EClass findFirstEClassFromName(final String name) { } return null; } - + /** * Create a new instance. * @@ -439,21 +444,22 @@ public boolean preventFromBrowsing(final EObject root) { @Override public void updateMetamodels(final Collection metamodelDescriptors) { - final Collection metamodelDescriptorsCopy = Sets.newLinkedHashSet(metamodelDescriptors); + final Collection metamodelDescriptorsCopy = new LinkedHashSet<>(metamodelDescriptors); if (lastDescriptors != null) { metamodelDescriptorsCopy.removeAll(lastDescriptors); } final Iterator it = metamodelDescriptorsCopy.iterator(); while (it.hasNext()) { final Object obj = it.next(); - if (obj instanceof EcoreMetamodelDescriptor) { - final EPackage pak = ((EcoreMetamodelDescriptor) obj).resolve(); + if (obj instanceof EcoreMetamodelDescriptor descriptor) { + final EPackage pak = descriptor.resolve(); if (pak != null) { addTypesToSiriusIndex(pak); - Iterator subPack = Iterators.filter(pak.eAllContents(), EPackage.class); - while (subPack.hasNext()) { - addTypesToSiriusIndex(subPack.next()); - } + pak.eAllContents().forEachRemaining(eObject -> { + if (eObject instanceof EPackage subPack) { + addTypesToSiriusIndex(subPack); + } + }); } } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java index 5953111a3b..661e57414d 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -14,15 +14,15 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EPackage; -import com.google.common.base.Predicate; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; - /** * Index for all EClasses defined in a package registry. * @@ -37,7 +37,7 @@ public class PackageRegistryIndex { private final Predicate packageFilter; - private final Multimap index = HashMultimap.create(); + private final Map> index = new HashMap<>(); private boolean initializedDescriptors; @@ -99,22 +99,30 @@ private void indexTypesFromRegistry(boolean descriptors) { * @return all the indexed classes with a matching name. */ public Collection getEClassesFromName(String name) { - Collection result = index.get(name); + Collection result = index.getOrDefault(name, List.of()); if (Boolean.valueOf(System.getProperty("org.eclipse.sirius.enableUnsafeOptimisations", "false")) && result.isEmpty() && !initializedDescriptors) { //$NON-NLS-1$ //$NON-NLS-2$ indexTypesFromRegistry(true); initializedDescriptors = true; - result = index.get(name); + result = index.getOrDefault(name, List.of()); } return result; } private void indexTypesFrom(EPackage value) { - if (packageFilter.apply(value)) { - for (EClass cur : Iterables.filter(value.getEClassifiers(), EClass.class)) { - index.put(cur.getName(), cur); - index.put(value.getName() + SEPARATOR + cur.getName(), cur); - index.put(value.getName() + AQL_SEPARATOR + cur.getName(), cur); + if (packageFilter.test(value)) { + for (EClassifier classifier : value.getEClassifiers()) { + if (classifier instanceof EClass cur) { + addToIndex(cur.getName(), cur); + addToIndex(value.getName() + SEPARATOR + cur.getName(), cur); + addToIndex(value.getName() + AQL_SEPARATOR + cur.getName(), cur); + } } } } + + private void addToIndex(String key, EClass eClass) { + index.putIfAbsent(key, new ArrayList<>()); + index.get(key).add(eClass); + } + } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java index 48d9b28402..efa9c56d6b 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,17 +15,15 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.ConcurrentMap; +import java.util.Set; +import java.util.WeakHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Collectors; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener; import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority; -import com.google.common.collect.MapMaker; - /** * A basic permission authority which will manage a list of listeners. * @@ -40,7 +38,7 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit protected List listeners = new CopyOnWriteArrayList(); /** the locked objects. */ - protected ConcurrentMap lockedObjects = new MapMaker().concurrencyLevel(4).weakKeys().makeMap(); + protected Set lockedObjects = Collections.newSetFromMap(new WeakHashMap()); /** * Check if an object is locked or not. @@ -50,7 +48,7 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit * @return true if is locked, false otherwise */ protected boolean isLocked(final EObject eObject) { - return lockedObjects.containsKey(eObject); + return lockedObjects.contains(eObject); } /** @@ -60,7 +58,7 @@ protected boolean isLocked(final EObject eObject) { * the locked instance */ protected void storeAsLockedAndNotify(final EObject eObject) { - lockedObjects.put(eObject, true); + lockedObjects.add(eObject); for (IAuthorityListener listener : listeners) { listener.notifyIsLocked(eObject); } @@ -68,8 +66,7 @@ protected void storeAsLockedAndNotify(final EObject eObject) { @Override public List getLockedObjects() { - List lockedEObjects = lockedObjects.keySet().stream().filter(EObject.class::isInstance).map(EObject.class::cast).collect(Collectors.toList()); - return Collections.unmodifiableList(lockedEObjects); + return lockedObjects.stream().filter(EObject.class::isInstance).map(EObject.class::cast).toList(); } /** diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java index d577d9e7dc..d528b16719 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Obeo. + * Copyright (c) 2006, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -49,8 +49,6 @@ import org.eclipse.sirius.ecore.extender.tool.internal.ReferencesResolver; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.collect.Iterators; - /** * Utility class for model loading/saving and serialization. * @@ -506,12 +504,12 @@ public static void resolveAll(final Resource res, boolean recursive) { if (res != null && res.getResourceSet() != null) { cachedIDsResources = ModelUtils.cachedEObjectIDs(res.getResourceSet()); } - List resourcesBeforeResolveAll = new ArrayList(res.getResourceSet().getResources()); + List resourcesBeforeResolveAll = new ArrayList<>(res.getResourceSet().getResources()); EcoreUtil.resolveAll(res); if (recursive) { - List resourcesAfterResolveAll = new ArrayList(res.getResourceSet().getResources()); + List resourcesAfterResolveAll = new ArrayList<>(res.getResourceSet().getResources()); // Remove the known resources - Iterators.removeAll(resourcesAfterResolveAll.iterator(), resourcesBeforeResolveAll); + resourcesAfterResolveAll.removeAll(resourcesBeforeResolveAll); for (Resource resource : resourcesAfterResolveAll) { resolveAll(resource, recursive); } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java index f2f8f99fd3..7b32237081 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.function.Predicate; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; @@ -29,9 +30,6 @@ import org.eclipse.sirius.ecore.extender.business.internal.Messages; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterators; - /** * Class responsible for resolving some references. * @@ -52,13 +50,8 @@ public class ReferencesResolver { * @param set * resource set to resolve. */ - public ReferencesResolver(ResourceSet set, final EReferencePredicate filter) { - this.filter = new Predicate() { - @Override - public boolean apply(EReference input) { - return filter.apply(input); - } - }; + public ReferencesResolver(ResourceSet set, EReferencePredicate filter) { + this.filter = filter::apply; this.set = set; } @@ -97,10 +90,7 @@ private void doResolveAll(Resource resource) { } private void resolveCrossReferences(EObject eObject) { - Iterator it = Iterators.filter(eObject.eClass().getEAllReferences().iterator(), filter); - while (it.hasNext()) { - eObject.eGet(it.next()); - } + eObject.eClass().getEAllReferences().stream().filter(filter).forEach(eObject::eGet); } /** @@ -116,12 +106,12 @@ public static List prepareResolveAll(final ResourceSet set, final IPer if (authority != null) { authority.setListening(false); } - final List cachedIdsResources = new LinkedList(); + final List cachedIdsResources = new LinkedList<>(); Iterator iterResources = set.getResources().iterator(); while (iterResources.hasNext()) { final Resource resource = iterResources.next(); if (resource instanceof ResourceImpl && ((ResourceImpl) resource).getIntrinsicIDToEObjectMap() == null) { - ((ResourceImpl) resource).setIntrinsicIDToEObjectMap(new HashMap()); + ((ResourceImpl) resource).setIntrinsicIDToEObjectMap(new HashMap<>()); cachedIdsResources.add(resource); } }