Skip to content

Package: InternalUtil

InternalUtil

nameinstructionbranchcomplexitylinemethod
getAddedElements(Collection, Collection)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getElementNames(Set)
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getRemovedElements(Collection, Collection)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.internal.core.util;
15:
16: import java.util.Collection;
17: import java.util.HashSet;
18: import java.util.Set;
19:
20: import org.eclipse.emf.ecp.core.util.ECPElement;
21:
22: /**
23: * @author Eugen Neufeld
24: *
25: */
26: public final class InternalUtil {
27:
28:         private InternalUtil() {
29:         }
30:
31:         /**
32:          * Returns the Set of names of a set of {@link ECPElement ECPElements}.
33:          *
34:          * @param elements the set of elements to get the names for
35:          * @return the set of names of this elements
36:          */
37:         public static Set<String> getElementNames(Set<? extends ECPElement> elements) {
38:                 final Set<String> names = new HashSet<String>();
39:•                for (final ECPElement element : elements) {
40:                         names.add(element.getName());
41:                 }
42:
43:                 return names;
44:         }
45:
46:         /**
47:          * Finds the set of all Elements that are in the new collection but not in the old.
48:          *
49:          * @param oldElements the collection containing the old elements
50:          * @param newElements the collection containing the new elements
51:          * @param <E> the type of the elements
52:          * @return the Set<E> of elements which are only in the newElements collection
53:          */
54:         public static <E> Set<E> getAddedElements(Collection<E> oldElements, Collection<E> newElements) {
55:                 final Set<E> result = new HashSet<E>(newElements);
56:                 result.removeAll(oldElements);
57:                 return result;
58:         }
59:
60:         /**
61:          * Finds the set of all Elements that are in the old collection but not in the new.
62:          *
63:          * @param oldElements the collection containing the old elements
64:          * @param newElements the collection containing the new elements
65:          * @param <E> the type of the elements
66:          * @return the Set<E> of elements which are only in the oldElements collection
67:          */
68:         public static <E> Set<E> getRemovedElements(Collection<E> oldElements, Collection<E> newElements) {
69:                 final Set<E> result = new HashSet<E>(oldElements);
70:                 result.removeAll(newElements);
71:                 return result;
72:         }
73: }