]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.project/src/org/simantics/project/features/registry/GroupReference.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / features / registry / GroupReference.java
index 39dd7edd9368e7a3325fdfd9d052ad4df48dbcb8..6deb4af40170b50be92d905fbbb564e3212dcc27 100644 (file)
-/*******************************************************************************\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.features.registry;\r
-\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-/**\r
- * A reference to a P2 feature group installable unit (IU).\r
- * \r
- * <p>\r
- * Contains an ID and an optional version specifier. If a version is not\r
- * specified, it is <code>null</code>. The version can be either a single\r
- * version or a version range.\r
- * \r
- * <p>\r
- * Serializes to the format <code>ID/version</code>\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class GroupReference implements Comparable<GroupReference> {\r
-\r
-    public static final GroupReference OMNIPRESENT = new GroupReference("omnipresent");\r
-\r
-    private final String id;\r
-    private final String version;\r
-\r
-    /**\r
-     * @return\r
-     */\r
-    public GroupReference withoutVersion() {\r
-        return version == null ? this : new GroupReference(id);\r
-    }\r
-\r
-    /**\r
-     * @param refs\r
-     * @return\r
-     */\r
-    public static Collection<GroupReference> stripVersions(Collection<GroupReference> refs) {\r
-        Set<GroupReference> result = new HashSet<GroupReference>();\r
-        for (GroupReference ref : refs)\r
-            result.add( ref.withoutVersion() );\r
-        return result;\r
-    }\r
-\r
-    /**\r
-     * @param ref\r
-     * @return\r
-     */\r
-    public static GroupReference parse(String ref) {\r
-        // TODO: better validation\r
-        int slash = ref.indexOf('/');\r
-        if (slash >= 0) {\r
-            String id = ref.substring(0, slash);\r
-            String version = ref.substring(slash + 1);\r
-            return new GroupReference(id, version);\r
-        } else {\r
-            return new GroupReference(ref);\r
-        }\r
-    }\r
-\r
-    /**\r
-     * @param id\r
-     */\r
-    public GroupReference(String id) {\r
-        this(id, null);\r
-    }\r
-\r
-    /**\r
-     * @param id\r
-     * @param version\r
-     */\r
-    public GroupReference(String id, String version) {\r
-        if (id == null)\r
-            throw new NullPointerException("null feature bundle id");\r
-        this.id = id;\r
-        this.version = version;\r
-    }\r
-\r
-    /**\r
-     * @return\r
-     */\r
-    public String getId() {\r
-        return id;\r
-    }\r
-\r
-    /**\r
-     * @return\r
-     */\r
-    public String getVersion() {\r
-        return version;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return version != null ? id + "/" + version : id;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + id.hashCode();\r
-        result = prime * result + ((version == null) ? 0 : version.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        GroupReference other = (GroupReference) obj;\r
-        if (!id.equals(other.id))\r
-            return false;\r
-        if (version == null) {\r
-            if (other.version != null)\r
-                return false;\r
-        } else if (!version.equals(other.version))\r
-            return false;\r
-        return true;\r
-    }\r
-\r
-    /**\r
-     * @param obj group reference whose id to compare to this reference's\r
-     * @return <code>true</code> if id's are equal\r
-     */\r
-    public boolean idEquals(GroupReference other) {\r
-        return id.equals(other.id);\r
-    }\r
-\r
-    /**\r
-     * Checks whether this feature reference fulfills the demand imposed by the\r
-     * specified feature reference. Fulfillment implies matching feature ID and\r
-     * a version match or a version range for this feature reference that includes the\r
-     * absolute version in the specified feature reference.\r
-     * \r
-     * @param ref\r
-     * @return\r
-     */\r
-    public boolean includes(GroupReference request) {\r
-        if (!id.equals(request.id))\r
-            return false;\r
-\r
-        if (version == null)\r
-            // Any version will do.\r
-            return true;\r
-\r
-        // TODO: implement version checking\r
-\r
-        // ASSERT: request.version is an absolute version, not a range\r
-\r
-        // If this.version is a absolute version, check that request.version is\r
-        // greater or equal than this.version.\r
-\r
-        // If this.version is a version range, check that the range includes\r
-        // request.version.\r
-\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public int compareTo(GroupReference o) {\r
-        int idDelta = id.compareTo(o.id);\r
-        if (idDelta != 0)\r
-            return idDelta;\r
-\r
-        // TODO: comparability based on version comparability\r
-\r
-        return 0;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.project.features.registry;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A reference to a P2 feature group installable unit (IU).
+ * 
+ * <p>
+ * Contains an ID and an optional version specifier. If a version is not
+ * specified, it is <code>null</code>. The version can be either a single
+ * version or a version range.
+ * 
+ * <p>
+ * Serializes to the format <code>ID/version</code>
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class GroupReference implements Comparable<GroupReference> {
+
+    public static final GroupReference OMNIPRESENT = new GroupReference("omnipresent");
+
+    private final String id;
+    private final String version;
+
+    /**
+     * @return
+     */
+    public GroupReference withoutVersion() {
+        return version == null ? this : new GroupReference(id);
+    }
+
+    /**
+     * @param refs
+     * @return
+     */
+    public static Collection<GroupReference> stripVersions(Collection<GroupReference> refs) {
+        Set<GroupReference> result = new HashSet<GroupReference>();
+        for (GroupReference ref : refs)
+            result.add( ref.withoutVersion() );
+        return result;
+    }
+
+    /**
+     * @param ref
+     * @return
+     */
+    public static GroupReference parse(String ref) {
+        // TODO: better validation
+        int slash = ref.indexOf('/');
+        if (slash >= 0) {
+            String id = ref.substring(0, slash);
+            String version = ref.substring(slash + 1);
+            return new GroupReference(id, version);
+        } else {
+            return new GroupReference(ref);
+        }
+    }
+
+    /**
+     * @param id
+     */
+    public GroupReference(String id) {
+        this(id, null);
+    }
+
+    /**
+     * @param id
+     * @param version
+     */
+    public GroupReference(String id, String version) {
+        if (id == null)
+            throw new NullPointerException("null feature bundle id");
+        this.id = id;
+        this.version = version;
+    }
+
+    /**
+     * @return
+     */
+    public String getId() {
+        return id;
+    }
+
+    /**
+     * @return
+     */
+    public String getVersion() {
+        return version;
+    }
+
+    @Override
+    public String toString() {
+        return version != null ? id + "/" + version : id;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + id.hashCode();
+        result = prime * result + ((version == null) ? 0 : version.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        GroupReference other = (GroupReference) obj;
+        if (!id.equals(other.id))
+            return false;
+        if (version == null) {
+            if (other.version != null)
+                return false;
+        } else if (!version.equals(other.version))
+            return false;
+        return true;
+    }
+
+    /**
+     * @param obj group reference whose id to compare to this reference's
+     * @return <code>true</code> if id's are equal
+     */
+    public boolean idEquals(GroupReference other) {
+        return id.equals(other.id);
+    }
+
+    /**
+     * Checks whether this feature reference fulfills the demand imposed by the
+     * specified feature reference. Fulfillment implies matching feature ID and
+     * a version match or a version range for this feature reference that includes the
+     * absolute version in the specified feature reference.
+     * 
+     * @param ref
+     * @return
+     */
+    public boolean includes(GroupReference request) {
+        if (!id.equals(request.id))
+            return false;
+
+        if (version == null)
+            // Any version will do.
+            return true;
+
+        // TODO: implement version checking
+
+        // ASSERT: request.version is an absolute version, not a range
+
+        // If this.version is a absolute version, check that request.version is
+        // greater or equal than this.version.
+
+        // If this.version is a version range, check that the range includes
+        // request.version.
+
+        return true;
+    }
+
+    @Override
+    public int compareTo(GroupReference o) {
+        int idDelta = id.compareTo(o.id);
+        if (idDelta != 0)
+            return idDelta;
+
+        // TODO: comparability based on version comparability
+
+        return 0;
+    }
+
+}