mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Baseline IrisApi draft before stage-graph redesign
This commit is contained in:
commit
9043d93fbd
91 files changed
+4045
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package com.volmit.resource;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** Case-sensitive namespaced identity. Parsing never supplies an implicit namespace. */
|
||||
public record ResourceId(String namespace, String path) implements Comparable<ResourceId> {
|
||||
public ResourceId {
|
||||
Objects.requireNonNull(namespace, "namespace");
|
||||
Objects.requireNonNull(path, "path");
|
||||
if (!namespace.matches("[a-z0-9_.-]+") || !path.matches("[a-z0-9_./-]+")) {
|
||||
throw new IllegalArgumentException("Invalid resource ID: " + namespace + ":" + path);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResourceId parse(String value) {
|
||||
Objects.requireNonNull(value, "value");
|
||||
int separator = value.indexOf(':');
|
||||
if (separator < 0) throw new IllegalArgumentException("Expected a namespaced ID: " + value);
|
||||
return new ResourceId(value.substring(0, separator), value.substring(separator + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() { return namespace + ":" + path; }
|
||||
|
||||
@Override
|
||||
public int compareTo(ResourceId other) { return toString().compareTo(other.toString()); }
|
||||
}
|
||||
Reference in new issue
Block a user