Rework beacon

This commit is contained in:
Christopher Schnick
2021-12-13 15:29:04 +01:00
parent 5356d0d027
commit a523dd210b
18 changed files with 186 additions and 322 deletions

View File

@@ -6,34 +6,51 @@ public class DataSourceId {
public static final char SEPARATOR = ':';
public static DataSourceId create(String collectionName, String entryName) {
if (collectionName == null) {
throw new IllegalArgumentException("Collection name is null");
}
if (collectionName.contains("" + SEPARATOR)) {
throw new IllegalArgumentException("Separator character " + SEPARATOR + " is not allowed in the collection name");
}
if (entryName == null) {
throw new IllegalArgumentException("Collection name is null");
}
if (entryName.contains("" + SEPARATOR)) {
throw new IllegalArgumentException("Separator character " + SEPARATOR + " is not allowed in the entry name");
}
return new DataSourceId(collectionName, entryName);
}
private final String collectionName;
private final String entryName;
@JsonCreator
public DataSourceId(String collectionName, String entryName) {
private DataSourceId(String collectionName, String entryName) {
this.collectionName = collectionName;
this.entryName = entryName;
}
public DataSourceId withEntryName(String newName) {
return new DataSourceId(collectionName, newName);
}
public static DataSourceId fromString(String s) {
if (s == null) {
throw new IllegalArgumentException("String is null");
}
var split = s.split(String.valueOf(SEPARATOR));
if (split.length != 2) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Data source id must contain exactly one " + SEPARATOR);
}
if (split[0].length() == 0) {
throw new IllegalArgumentException("Collection name must not be empty");
}
if (split[1].length() == 0) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Entry name must not be empty");
}
return new DataSourceId(split[0].length() > 0 ? split[0] : null, split[1]);
}
public boolean hasCollection() {
return collectionName != null;
return new DataSourceId(split[0], split[1]);
}
@Override