Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the previously deprecated metadata object #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 5 additions & 67 deletions src/main/java/io/vlingo/xoom/symbio/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;

public class Metadata implements Comparable<Metadata> {
@Deprecated
public final static Object EmptyObject = new Object() { @Override public String toString() { return "(empty)"; } };

// Object is deprecated and will be removed in future versions. Use the Map of properties instead.
@Deprecated
public final Object object;
public final Map<String, String> properties;
public final String operation;
public final String value;
Expand All @@ -27,21 +21,16 @@ public static Metadata nullMetadata() {
return new Metadata(Collections.emptyMap(), "", "");
}

@Deprecated
public static Metadata withObject(final Object object) {
return new Metadata(object, "", "");
}

public static Metadata withProperties(final Map<String, String> properties) {
return new Metadata(properties, "", "");
}

public static Metadata withOperation(final String operation) {
return new Metadata(EmptyObject, "", operation);
return new Metadata(Collections.emptyMap(), "", operation);
}

public static Metadata withValue(final String value) {
return new Metadata(EmptyObject, value, "");
return new Metadata(Collections.emptyMap(), value, "");
}

public static Metadata with(final String value, final String operation) {
Expand All @@ -61,35 +50,7 @@ public static Metadata with(final Map<String, String> properties, final String v
return new Metadata(properties, value, operation);
}

@Deprecated
public static Metadata with(final Object object, final String value, final String operation) {
return new Metadata(object, value, operation);
}

@Deprecated
public static Metadata with(final Object object, final String value, final Class<?> operationType) {
return with(object, value, operationType, true);
}

@Deprecated
public static Metadata with(final Object object, final String value, final Class<?> operationType, final boolean compact) {
final String operation = compact ? operationType.getSimpleName() : operationType.getName();
return new Metadata(object, value, operation);
}

@Deprecated
public Metadata(final Object object, final String value, final String operation) {
if (object == null) this.object = EmptyObject; else this.object = object;

if (value == null) this.value = ""; else this.value = value;

if (operation == null) this.operation = ""; else this.operation = operation;

this.properties = Collections.emptyMap();
}

public Metadata(final Map<String, String> properties, final String value, final String operation) {
this.object = EmptyObject;

if (properties == null) this.properties = Collections.emptyMap(); else this.properties = properties;

Expand All @@ -106,11 +67,6 @@ public Metadata() {
this(Collections.emptyMap(), "", "");
}

@Deprecated
public boolean hasObject() {
return object != EmptyObject;
}

public boolean hasProperties() {
return !properties.isEmpty();
}
Expand All @@ -127,16 +83,6 @@ public boolean isEmpty() {
return !hasOperation() && !hasValue();
}

@Deprecated
public Object object() {
return object;
}

@Deprecated
public Optional<Object> optionalObject() {
return hasObject() ? Optional.of(object) : Optional.empty();
}

public String operation() {
return operation;
}
Expand All @@ -145,15 +91,8 @@ public String value() {
return value;
}

@Deprecated
@SuppressWarnings("unchecked")
public <T> T typedObject() {
return (T) object;
}

@Override
public int compareTo(final Metadata other) {
if (!this.object.equals(other.object)) return 1;
if (!this.properties.equals(other.properties)) return 1;
return Comparator
.comparing((Metadata m) -> m.value)
Expand All @@ -163,7 +102,7 @@ public int compareTo(final Metadata other) {

@Override
public int hashCode() {
return 31 * value.hashCode() + operation.hashCode() + properties.hashCode() + object.hashCode();
return 31 * value.hashCode() + operation.hashCode() + properties.hashCode();
}

@Override
Expand All @@ -176,13 +115,12 @@ public boolean equals(final Object other) {

return value.equals(otherMetadata.value) &&
operation.equals(otherMetadata.operation) &&
properties.equals(otherMetadata.properties) &&
object.equals(otherMetadata.object);
properties.equals(otherMetadata.properties);
}

@Override
public String toString() {
return getClass().getSimpleName() +
"[value=" + value + " operation=" + operation + " properties=" + properties + " object=" + object + "]";
"[value=" + value + " operation=" + operation + " properties=" + properties + "]";
}
}
13 changes: 2 additions & 11 deletions src/test/java/io/vlingo/xoom/symbio/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ public void testNullMetadata() {
assertFalse(metadata.hasProperties());
}

@Test
@Deprecated
public void testMetadataObject() {
final Object object = new Object();
final Metadata metadata = Metadata.withObject(object);
assertTrue(metadata.hasObject());
assertEquals(object, metadata.object);
assertFalse(metadata.hasValue());
assertFalse(metadata.hasOperation());
}

@Test
public void testMetadataProperties() {
final Map<String, String> properties = new HashMap<String, String>() {{
Expand All @@ -64,6 +53,7 @@ public void testMetadataValue() {
final Metadata metadata = Metadata.withValue("value");
assertTrue(metadata.hasValue());
assertEquals("value", metadata.value);
assertEquals("value", metadata.value());
assertFalse(metadata.hasOperation());
}

Expand All @@ -73,6 +63,7 @@ public void testMetadataOperation() {
assertFalse(metadata.hasValue());
assertTrue(metadata.hasOperation());
assertEquals("op", metadata.operation);
assertEquals("op", metadata.operation());
}

@Test
Expand Down