1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.project;
16 import org.simantics.project.features.registry.GroupReference;
19 * Utilities for constructing {@link GroupFilter} instances.
21 * @author Tuukka Lehtonen
23 public final class GroupFilters {
25 public static GroupFilter constant(final boolean answer) {
26 return new GroupFilter() {
28 public boolean accept(GroupReference ref) {
34 private static final GroupFilter ACCEPT_ALL = constant(true);
35 private static final GroupFilter DENY_ALL = constant(false);
37 public static GroupFilter acceptAll() {
41 public static GroupFilter denyAll() {
46 * Constructs a group filter that accepts only equal matches of all the
47 * group references provided in the argument set.
49 * @param refs the group references to accept
50 * @return a filter accepting the specified set of group references
52 public static GroupFilter containsEqual(final Set<GroupReference> refs) {
53 return new GroupFilter() {
55 public boolean accept(GroupReference ref) {
56 return refs.contains(ref);
62 * Constructs a group filter that accepts groups that include one or
63 * more of the specified groups. Inclusion means that:
65 * <li>group ID's are equal</li>
66 * <li>if tested group has a version or version range it must include
67 * the version in the group of the specified set</li>
73 public static GroupFilter includesVersion(final Set<GroupReference> refs) {
74 return new GroupFilter() {
76 public boolean accept(GroupReference range) {
77 for (GroupReference ref : refs)
78 if (range.includes(ref))