Skip to content
Permalink
Browse files
improve value interface (#126)
  • Loading branch information
coderzc committed Oct 25, 2021
1 parent 771b14a commit 2442fe66f9d394a44045d2dc3768315e2a6e6c31
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 59 deletions.
@@ -21,7 +21,7 @@

import java.io.IOException;

import javax.ws.rs.NotSupportedException;
import org.apache.commons.lang3.builder.ToStringBuilder;

import com.baidu.hugegraph.computer.core.graph.value.IdList;
import com.baidu.hugegraph.computer.core.graph.value.LongValue;
@@ -59,7 +59,7 @@ public ValueType valueType() {

@Override
public void assign(Value<TriangleCountValue> other) {
throw new NotSupportedException();
throw new UnsupportedOperationException();
}

@Override
@@ -84,16 +84,24 @@ public void write(RandomAccessOutput out) throws IOException {

@Override
public int compareTo(TriangleCountValue other) {
throw new NotSupportedException();
throw new UnsupportedOperationException();
}

@Override
public String toString() {
return new ToStringBuilder(this)
.append("idList", this.idList)
.append("count", this.count)
.toString();
}

@Override
public String string() {
return String.valueOf(this.count);
}

@Override
public Object object() {
throw new NotSupportedException();
public Object value() {
throw new UnsupportedOperationException();
}
}
@@ -21,8 +21,6 @@

import java.io.IOException;

import javax.ws.rs.NotSupportedException;

import com.baidu.hugegraph.computer.core.common.ComputerContext;
import com.baidu.hugegraph.computer.core.graph.GraphFactory;
import com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties;
@@ -52,12 +50,12 @@ public ValueType valueType() {

@Override
public void assign(Value<RingsDetectionValue> other) {
throw new NotSupportedException();
throw new UnsupportedOperationException();
}

@Override
public int compareTo(RingsDetectionValue o) {
throw new NotSupportedException();
throw new UnsupportedOperationException();
}

@Override
@@ -74,7 +72,7 @@ public void write(RandomAccessOutput out) throws IOException {

@Override
public RingsDetectionValue copy() {
throw new NotSupportedException();
throw new UnsupportedOperationException();
}

public IdList path() {
@@ -94,7 +92,7 @@ public void walkEdgeProp(Properties properties) {
}

@Override
public Object object() {
throw new NotSupportedException();
public Object value() {
throw new UnsupportedOperationException();
}
}
@@ -143,7 +143,7 @@ private static Map<String, Object> convertParamsValueToObject(
Map<String, Object> subKv = new HashMap<>();
Map<String, Value<?>> param = entry.getValue();
for (Map.Entry<String, Value<?>> paramItem : param.entrySet()) {
subKv.put(paramItem.getKey(), paramItem.getValue().object());
subKv.put(paramItem.getKey(), paramItem.getValue().value());
}
result.put(entry.getKey(), subKv);
}
@@ -37,7 +37,8 @@ public BooleanValue(boolean value) {
this.value = value;
}

public boolean value() {
@Override
public Boolean value() {
return this.value;
}

@@ -98,9 +99,4 @@ public int hashCode() {
public String toString() {
return String.valueOf(this.value);
}

@Override
public Object object() {
return this.value;
}
}
@@ -59,7 +59,8 @@ public DoubleValue(double value) {
this.value = value;
}

public double value() {
@Override
public Double value() {
return this.value;
}

@@ -120,9 +121,4 @@ public int hashCode() {
public String toString() {
return String.valueOf(this.value);
}

@Override
public Object object() {
return this.value;
}
}
@@ -59,7 +59,8 @@ public FloatValue(float value) {
this.value = value;
}

public float value() {
@Override
public Float value() {
return this.value;
}

@@ -120,9 +121,4 @@ public int hashCode() {
public String toString() {
return String.valueOf(this.value);
}

@Override
public Object object() {
return this.value;
}
}
@@ -59,7 +59,8 @@ public IntValue(int value) {
this.value = value;
}

public int value() {
@Override
public Integer value() {
return this.value;
}

@@ -120,9 +121,4 @@ public int hashCode() {
public String toString() {
return String.valueOf(this.value);
}

@Override
public Object object() {
return this.value;
}
}
@@ -20,8 +20,8 @@
package com.baidu.hugegraph.computer.core.graph.value;

import java.io.IOException;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -225,7 +225,7 @@ public String toString() {
}

@Override
public Object object() {
public List<T> value() {
return this.values;
}
}
@@ -59,7 +59,8 @@ public LongValue(long value) {
this.value = value;
}

public long value() {
@Override
public Long value() {
return this.value;
}

@@ -120,9 +121,4 @@ public int hashCode() {
public String toString() {
return String.valueOf(this.value);
}

@Override
public Object object() {
return this.value;
}
}
@@ -86,7 +86,7 @@ public String toString() {
}

@Override
public Object object() {
public Object value() {
return null;
}
}
@@ -68,6 +68,7 @@ public int compareTo(StringValue other) {
return this.value.compareTo(other.value);
}

@Override
public String value() {
return this.value;
}
@@ -76,11 +77,6 @@ public void value(String value) {
this.value = value;
}

@Override
public Object object() {
return this.value;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof StringValue)) {
@@ -57,5 +57,12 @@ default void checkAssign(Value<T> other) {
/**
* @return value of this object
*/
Object object();
Object value();

/**
* @return result string value of this object
*/
default String string() {
return this.toString();
}
}
@@ -201,7 +201,7 @@ public String toString() {
}

@Override
public Object object() {
public Object value() {
return this.bytes;
}
}
@@ -99,7 +99,7 @@ protected void writeString(String string) throws IOException {
}

protected String constructValueString(Vertex vertex) {
return vertex.value().toString();
return vertex.value().string();
}

public static Path buildPath(String dir, String jobId, int partition) {
@@ -21,8 +21,6 @@

import java.util.Map;

import javax.ws.rs.NotSupportedException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -107,9 +105,9 @@ public void testRunAlgorithm() throws InterruptedException {
public void testTriangleCountValue() {
TriangleCountValue value = new TriangleCountValue();
value.count(10L);
Assert.assertThrows(NotSupportedException.class,
Assert.assertThrows(UnsupportedOperationException.class,
() -> value.assign(null));
Assert.assertThrows(NotSupportedException.class,
Assert.assertThrows(UnsupportedOperationException.class,
() -> value.compareTo(new TriangleCountValue()));

TriangleCountValue copy = (TriangleCountValue) value.copy();
@@ -34,7 +34,7 @@ public void testCombine() {
IntValue value = new IntValue(i);
sum = combiner.combine(sum, value);
}
Assert.assertEquals(55L, sum.value());
Assert.assertEquals(55, sum.value());
}

@Test

0 comments on commit 2442fe6

Please sign in to comment.