-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from bosch-iot-things/feature/consolidate-enti…
…tytype-resourcetype Feature/consolidate entitytype resourcetype
- Loading branch information
Showing
191 changed files
with
1,828 additions
and
1,912 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
model/base/src/main/java/org/eclipse/ditto/model/base/entity/id/AbstractEntityId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.model.base.entity.id; | ||
|
||
import static org.eclipse.ditto.model.base.common.ConditionChecker.argumentNotEmpty; | ||
import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.eclipse.ditto.model.base.entity.type.EntityType; | ||
|
||
|
||
/** | ||
* Abstract base class for instances of @{code EntityId}. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public abstract class AbstractEntityId implements EntityId { | ||
|
||
private final EntityType entityType; | ||
private final String id; | ||
|
||
/** | ||
* Constructs a new AbstractEntityId object. | ||
* | ||
* @param entityType the entity type. | ||
* @param id the id of the entity. | ||
* @throws NullPointerException if {@code id} or {@code entityType} is {@code null}. | ||
* @throws IllegalArgumentException if {@code id} is empty. | ||
*/ | ||
protected AbstractEntityId(final EntityType entityType, final CharSequence id) { | ||
this.entityType = checkNotNull(entityType, "entityType"); | ||
this.id = argumentNotEmpty(id, "entityId").toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final AbstractEntityId that = (AbstractEntityId) o; | ||
return Objects.equals(id, that.id) && Objects.equals(entityType, that.entityType); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(entityType, id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public EntityType getEntityType() { | ||
return entityType; | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
...base/src/main/java/org/eclipse/ditto/model/base/entity/id/AbstractNamespacedEntityId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.model.base.entity.id; | ||
|
||
import static org.eclipse.ditto.model.base.entity.id.RegexPatterns.NAMESPACE_DELIMITER; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.model.base.entity.type.EntityType; | ||
import org.eclipse.ditto.model.base.entity.validation.EntityIdPatternValidator; | ||
|
||
/** | ||
* Base implementation for namespaced entity IDs which are aware of their entity type. | ||
* <em>Subclasses are required to be immutable.</em> | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
@Immutable | ||
public abstract class AbstractNamespacedEntityId extends AbstractEntityId implements NamespacedEntityId { | ||
|
||
private final String namespace; | ||
private final String name; | ||
|
||
/** | ||
* Constructs a new AbstractNamespacedEntityId object. | ||
* | ||
* @param entityType the entity type to delegate to. | ||
* @param namespace the entity type to delegate to. | ||
* @param name the entity type to delegate to. | ||
* @param shouldValidate the entity type to delegate to. | ||
* @throws NullPointerException if {@code id} or {@code entityType} is {@code null}. | ||
* @throws IllegalArgumentException if {@code id} is empty. | ||
*/ | ||
protected AbstractNamespacedEntityId(final EntityType entityType, final String namespace, final String name, | ||
final boolean shouldValidate) { | ||
super(entityType, shouldValidate ? validate(namespace, name) : namespace + NAMESPACE_DELIMITER + name); | ||
|
||
this.namespace = namespace; | ||
this.name = name; | ||
} | ||
|
||
protected AbstractNamespacedEntityId(final EntityType entityType, @Nullable final CharSequence entityId) { | ||
super(entityType, getNonEmptyEntityId(entityId)); | ||
|
||
final EntityIdPatternValidator validator = EntityIdPatternValidator.getInstance(entityId); | ||
if (validator.isValid()) { | ||
// the given entityId is valid, so we can safely split at NAMESPACE_DELIMITER | ||
final String[] elements = entityId.toString().split(NAMESPACE_DELIMITER, 2); | ||
namespace = elements[0]; | ||
name = elements[1]; | ||
} else { | ||
throw NamespacedEntityIdInvalidException.newBuilder(entityId).build(); | ||
} | ||
} | ||
|
||
private static CharSequence getNonEmptyEntityId(@Nullable final CharSequence entityId) { | ||
if (entityId == null || entityId.toString().isEmpty()) { | ||
throw NamespacedEntityIdInvalidException.newBuilder(entityId).build(); | ||
} | ||
return entityId; | ||
} | ||
|
||
private static String validate(final @Nullable String namespace, final @Nullable String name) { | ||
final String sp = namespace + NAMESPACE_DELIMITER + name; | ||
|
||
if (namespace == null || name == null || !EntityIdPatternValidator.getInstance(sp).isValid()) { | ||
throw NamespacedEntityIdInvalidException.newBuilder(sp).build(); | ||
} | ||
|
||
return sp; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
} |
82 changes: 0 additions & 82 deletions
82
model/base/src/main/java/org/eclipse/ditto/model/base/entity/id/DefaultEntityId.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.