--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.project;\r
+\r
+import java.util.Set;\r
+\r
+import org.simantics.project.features.registry.GroupReference;\r
+\r
+/**\r
+ * Utilities for constructing {@link GroupFilter} instances.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public final class GroupFilters {\r
+\r
+ public static GroupFilter constant(final boolean answer) {\r
+ return new GroupFilter() {\r
+ @Override\r
+ public boolean accept(GroupReference ref) {\r
+ return answer;\r
+ }\r
+ };\r
+ }\r
+\r
+ private static final GroupFilter ACCEPT_ALL = constant(true);\r
+ private static final GroupFilter DENY_ALL = constant(false);\r
+\r
+ public static GroupFilter acceptAll() {\r
+ return ACCEPT_ALL;\r
+ }\r
+\r
+ public static GroupFilter denyAll() {\r
+ return DENY_ALL;\r
+ }\r
+\r
+ /**\r
+ * Constructs a group filter that accepts only equal matches of all the\r
+ * group references provided in the argument set.\r
+ * \r
+ * @param refs the group references to accept\r
+ * @return a filter accepting the specified set of group references\r
+ */\r
+ public static GroupFilter containsEqual(final Set<GroupReference> refs) {\r
+ return new GroupFilter() {\r
+ @Override\r
+ public boolean accept(GroupReference ref) {\r
+ return refs.contains(ref);\r
+ }\r
+ };\r
+ }\r
+\r
+ /**\r
+ * Constructs a group filter that accepts groups that include one or\r
+ * more of the specified groups. Inclusion means that:\r
+ * <ol>\r
+ * <li>group ID's are equal</li>\r
+ * <li>if tested group has a version or version range it must include\r
+ * the version in the group of the specified set</li>\r
+ * </ol>\r
+ * \r
+ * @param refs\r
+ * @return\r
+ */\r
+ public static GroupFilter includesVersion(final Set<GroupReference> refs) {\r
+ return new GroupFilter() {\r
+ @Override\r
+ public boolean accept(GroupReference range) {\r
+ for (GroupReference ref : refs)\r
+ if (range.includes(ref))\r
+ return true;\r
+ return false;\r
+ }\r
+ };\r
+ }\r
+\r
+}\r