Refactor Argeo API
[gpl/argeo-slc.git] / org.argeo.api.slc / src / org / argeo / api / slc / CategoryNameVersion.java
diff --git a/org.argeo.api.slc/src/org/argeo/api/slc/CategoryNameVersion.java b/org.argeo.api.slc/src/org/argeo/api/slc/CategoryNameVersion.java
new file mode 100644 (file)
index 0000000..afb8121
--- /dev/null
@@ -0,0 +1,25 @@
+package org.argeo.api.slc;
+
+/**
+ * Adds a dimension to {@link NameVersion} by adding an arbitrary category (e.g.
+ * Maven groupId, yum repository ID, etc.)
+ */
+public interface CategoryNameVersion extends NameVersion {
+       /** The category of the component. */
+       String getCategory();
+
+       static CategoryNameVersion parseCategoryNameVersion(String str) {
+               if (str == null || "".equals(str.trim()))
+                       throw new IllegalArgumentException("At least one character required.");
+               String[] arr = str.trim().split(":");
+               if (arr.length > 3)
+                       throw new IllegalArgumentException(str + " does not respect the [category]:[name]:[version] pattern");
+               DefaultCategoryNameVersion res = new DefaultCategoryNameVersion();
+               res.setCategory(arr[0]);
+               if (arr.length > 1)
+                       res.setName(arr[1]);
+               if (arr.length > 2)
+                       res.setVersion(arr[2]);
+               return res;
+       }
+}