blob: 18b7a7937e82e58f7ac0f448a09f4bb77efbcb25 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*****************************************************************************
* Copyright (c) 2014 Christian W. Damus and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christian W. Damus - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.utils;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import com.google.common.base.Predicate;
/**
* Useful Guava {@link Predicate}s for working with EMF models.
*/
public class EMFPredicates {
private EMFPredicates() {
super();
}
/**
* Obtains a predicate testing that an EMF object is not a proxy. It is formulated this
* way on the expectation that usually one would want to filter for objects that aren't
* proxies. Otherwise, just do {@code Predicates.not(EMFPredicates.notProxy())}.
*
* @return a predicate that matches EMF objects that are not proxies
*
* @see EObject#eIsProxy()
*/
public static Predicate<EObject> notProxy() {
return new Predicate<EObject>() {
@Override
public boolean apply(EObject input) {
return (input != null) && !input.eIsProxy();
}
};
}
/**
* Obtains a predicate testing that a resource is loaded.
*
* @return an is-loaded predicate
*
* @see Resource#isLoaded()
*/
public static Predicate<Resource> isLoaded() {
return new Predicate<Resource>() {
@Override
public boolean apply(Resource input) {
return (input != null) && input.isLoaded();
}
};
}
}
|