Skip to content
Permalink
Browse files
fix some warnings (#33)
  • Loading branch information
javeme committed Apr 12, 2021
1 parent 3bfed77 commit 7166e4dce9b83da4f400bbaebb1454749f2c99ec
Showing 36 changed files with 130 additions and 121 deletions.
@@ -22,7 +22,7 @@
import com.baidu.hugegraph.computer.core.common.exception.ComputerException;
import com.baidu.hugegraph.computer.core.graph.value.Value;

public interface Aggregator<V extends Value> {
public interface Aggregator<V extends Value<?>> {

/**
* Used by worker to aggregate a new value when compute a vertex, needs to
@@ -37,33 +37,30 @@ public interface Aggregator4Master {
* Register the aggregator with specified name. The name must be unique.
* Used by algorithm's master-computation to register aggregators.
*/
<V extends Value> void registerAggregator(
String name,
Class<? extends Aggregator<V>> aggregatorClass);
void registerAggregator(String name, Class<? extends Aggregator<Value<?>>>
aggregatorClass);

/**
* Register aggregator with specified value type and a combiner which can
* combine values with specified value type. The name must be unique.
* Used by algorithm's master-computation to register aggregators.
*/
<V extends Value> void registerAggregator(
String name,
ValueType type,
Class<? extends Combiner<V>> combinerClass);
void registerAggregator(String name, ValueType type,
Class<? extends Combiner<Value<?>>> combinerClass);

/**
* Set the aggregated value by master-computation. The value will be
* received by workers at next superstep.
* Throws ComputerException if master does not register the aggregator
* with specified name.
*/
<V extends Value> void aggregatedValue(String name, V value);
<V extends Value<?>> void aggregatedValue(String name, V value);

/**
* Get the aggregated value. The aggregated value is aggregated from
* workers at this superstep.
* Throws ComputerException if master does not register the aggregator
* with specified name.
*/
<V extends Value> V aggregatedValue(String name);
<V extends Value<?>> V aggregatedValue(String name);
}
@@ -36,13 +36,13 @@ public interface Aggregator4Worker {
* with specified name.
* @param value The value to be aggregated
*/
<V extends Value> void aggregateValue(String name, V value);
<V extends Value<?>> void aggregateValue(String name, V value);

/**
* Get the aggregated value before a superstep start. The value is
* aggregated by master at previous superstep.
* Throws ComputerException if master does not register the aggregator
* with specified name.
*/
<V extends Value> V aggregatedValue(String name);
<V extends Value<?>> V aggregatedValue(String name);
}
@@ -439,7 +439,7 @@ protected KV getKv() {
}

private static List<byte[]> getResponseValues(GetResponse response) {
List<byte[]> values = new ArrayList((int) response.getCount());
List<byte[]> values = new ArrayList<>((int) response.getCount());
for (KeyValue kv : response.getKvs()) {
values.add(kv.getValue().getBytes());
}
@@ -468,8 +468,8 @@ public V await(long timeout, long logInterval, Runnable logFunc)
while (remaining > 0) {
logInterval = Math.min(remaining, logInterval);
if (this.barrierEvent.await(logInterval)) {
assert result != null;
return result;
assert this.result != null;
return this.result;
} else {
logFunc.run();
}
@@ -31,6 +31,14 @@ default String name() {
return this.getClass().getName();
}

/**
* Combine v1 and v2, return the combined value. The combined value may
* take use v1 or v2. The value of v1 and v2 may be updated. Should not
* use v1 and v2 after combine them.
*/
T combine(T v1, T v2);


public static <T> T combineAll(Combiner<T> combiner, Iterator<T> values) {
if (!values.hasNext()) {
return null;
@@ -41,11 +49,4 @@ public static <T> T combineAll(Combiner<T> combiner, Iterator<T> values) {
}
return result;
}

/**
* Combine v1 and v2, return the combined value. The combined value may
* take use v1 or v2. The value of v1 and v2 may be updated. Should not
* use v1 and v2 after combine them.
*/
T combine(T v1, T v2);
}
@@ -35,9 +35,9 @@ public class MergeNewPropertiesCombiner implements PropertiesCombiner {
public Properties combine(Properties v1, Properties v2) {
E.checkArgumentNotNull(v1, "The combine parameter v1 can't be null");
E.checkArgumentNotNull(v2, "The combine parameter v2 can't be null");
Map<String, Value> v1Map = v1.get();
Map<String, Value> v2Map = v2.get();
for (Map.Entry<String, Value> entry : v2Map.entrySet()) {
Map<String, Value<?>> v1Map = v1.get();
Map<String, Value<?>> v2Map = v2.get();
for (Map.Entry<String, Value<?>> entry : v2Map.entrySet()) {
v1Map.putIfAbsent(entry.getKey(), entry.getValue());
}
return v1;
@@ -35,9 +35,9 @@ public class MergeOldPropertiesCombiner implements PropertiesCombiner {
public Properties combine(Properties v1, Properties v2) {
E.checkArgumentNotNull(v1, "The combine parameter v1 can't be null");
E.checkArgumentNotNull(v2, "The combine parameter v2 can't be null");
Map<String, Value> v1Map = v1.get();
Map<String, Value> v2Map = v2.get();
for (Map.Entry<String, Value> entry : v1Map.entrySet()) {
Map<String, Value<?>> v1Map = v1.get();
Map<String, Value<?>> v2Map = v2.get();
for (Map.Entry<String, Value<?>> entry : v1Map.entrySet()) {
v2Map.putIfAbsent(entry.getKey(), entry.getValue());
}
return v2;
@@ -22,13 +22,14 @@
import com.baidu.hugegraph.computer.core.graph.value.Value;
import com.baidu.hugegraph.util.E;

public class ValueMaxCombiner <T extends Value> implements Combiner<T> {
public class ValueMaxCombiner<T extends Value<?>> implements Combiner<T> {

@Override
@SuppressWarnings("unchecked")
public T combine(T v1, T v2) {
E.checkArgumentNotNull(v1, "The combine parameter v1 can't be null");
E.checkArgumentNotNull(v2, "The combine parameter v2 can't be null");
if (v1.compareTo(v2) >= 0) {
if (((Value<Object>) v1).compareTo(v2) >= 0) {
return v1;
} else {
return v2;
@@ -22,13 +22,14 @@
import com.baidu.hugegraph.computer.core.graph.value.Value;
import com.baidu.hugegraph.util.E;

public class ValueMinCombiner<T extends Value> implements Combiner<T> {
public class ValueMinCombiner<T extends Value<?>> implements Combiner<T> {

@Override
@SuppressWarnings("unchecked")
public T combine(T v1, T v2) {
E.checkArgumentNotNull(v1, "The combine parameter v1 can't be null");
E.checkArgumentNotNull(v2, "The combine parameter v2 can't be null");
if (v1.compareTo(v2) <= 0) {
if (((Value<Object>) v1).compareTo(v2) <= 0) {
return v1;
} else {
return v2;
@@ -24,20 +24,16 @@

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.configuration.MapConfiguration;
import org.slf4j.Logger;

import com.baidu.hugegraph.computer.core.common.exception.ComputerException;
import com.baidu.hugegraph.computer.core.graph.value.ValueType;
import com.baidu.hugegraph.config.ConfigOption;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.TypedOption;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;

public final class Config {

private static final Logger LOG = Log.logger(Config.class);

private final HugeConfig allConfig;
private final HotConfig hotConfig;

@@ -156,7 +152,7 @@ public String getString(String key, String defaultValue) {
* to create object.
*/
public <T> T createObject(ConfigOption<Class<?>> clazzOption) {
Class clazz = this.get(clazzOption);
Class<?> clazz = this.get(clazzOption);
if (clazz == Null.class) {
return null;
}
@@ -39,7 +39,7 @@ public Vertex createVertex() {
return new DefaultVertex();
}

public <V extends Value> Vertex createVertex(Id id, V value) {
public <V extends Value<?>> Vertex createVertex(Id id, V value) {
return new DefaultVertex(id, value);
}

@@ -51,7 +51,7 @@ public Edge createEdge() {
return new DefaultEdge();
}

public <V extends Value> Edge createEdge(Id targetId, V value) {
public <V extends Value<?>> Edge createEdge(Id targetId, V value) {
return new DefaultEdge(targetId, value);
}

@@ -29,14 +29,14 @@
public class DefaultEdge implements Edge {

private Id targetId;
private Value value;
private Value<?> value;
private Properties properties;

public DefaultEdge() {
this(null, null);
}

public DefaultEdge(Id targetId, Value value) {
public DefaultEdge(Id targetId, Value<?> value) {
this.targetId = targetId;
this.value = value;
this.properties = new DefaultProperties();
@@ -54,12 +54,12 @@ public void targetId(Id targetId) {

@Override
@SuppressWarnings("unchecked")
public <V extends Value> V value() {
public <V extends Value<?>> V value() {
return (V) this.value;
}

@Override
public <V extends Value> void value(V value) {
public <V extends Value<?>> void value(V value) {
this.value = value;
}

@@ -30,9 +30,9 @@ public interface Edge extends Recyclable {

void targetId(Id targetId);

<V extends Value> V value();
<V extends Value<?>> V value();

<V extends Value> void value(V value);
<V extends Value<?>> void value(V value);

Properties properties();

@@ -27,23 +27,23 @@

public class DefaultProperties implements Properties {

private final Map<String, Value> keyValues;
private final Map<String, Value<?>> keyValues;

public DefaultProperties() {
this(ComputerContext.instance().graphFactory().createMap());
}

public DefaultProperties(Map<String, Value> keyValues) {
public DefaultProperties(Map<String, Value<?>> keyValues) {
this.keyValues = keyValues;
}

@Override
public Map<String, Value> get() {
public Map<String, Value<?>> get() {
return this.keyValues;
}

@Override
public void put(String key, Value value) {
public void put(String key, Value<?> value) {
this.keyValues.put(key, value);
}

@@ -25,7 +25,7 @@

public interface Properties {

Map<String, Value> get();
Map<String, Value<?>> get();

void put(String key, Value value);
void put(String key, Value<?> value);
}
@@ -32,7 +32,7 @@
import com.baidu.hugegraph.computer.core.io.GraphOutput;
import com.baidu.hugegraph.util.E;

public class ListValue<T extends Value> implements Value<ListValue<T>> {
public class ListValue<T extends Value<?>> implements Value<ListValue<T>> {

private ValueType elemType;
private List<T> values;
@@ -68,17 +68,17 @@ public T get(int index) {
}

public T getLast() {
int index = values.size() - 1;
int index = this.values.size() - 1;
if (index < 0) {
throw new NoSuchElementException("The list value is empty");
}
return this.values.get(index);
}

public ListValue copy() {
List values = ComputerContext.instance().graphFactory().createList();
public ListValue<T> copy() {
List<T> values = ComputerContext.instance().graphFactory().createList();
values.addAll(this.values);
return new ListValue(this.elemType, values);
return new ListValue<>(this.elemType, values);
}

public boolean contains(T obj) {
@@ -148,7 +148,9 @@ public int compareTo(ListValue<T> obj) {
return cmp;
}
for (int i = 0; i < this.size(); i++) {
cmp = this.values.get(i).compareTo(obj.values.get(i));
@SuppressWarnings("unchecked")
Value<Object> self = (Value<Object>) this.values.get(i);
cmp = self.compareTo(obj.values.get(i));
if (cmp != 0) {
return cmp;
}
@@ -161,7 +163,8 @@ public boolean equals(Object obj) {
if (!(obj instanceof ListValue)) {
return false;
}
ListValue other = (ListValue) obj;
@SuppressWarnings("unchecked")
ListValue<T> other = (ListValue<T>) obj;
if (this.elemType != other.elemType) {
return false;
}
@@ -24,13 +24,13 @@

public final class ValueFactory {

public static Value createValue(byte code) {
public static Value<?> createValue(byte code) {
ValueType type = SerialEnum.fromCode(ValueType.class, code);
return createValue(type);
}

// Can reuse Value
public static Value createValue(ValueType type) {
public static Value<?> createValue(ValueType type) {
switch (type) {
case NULL:
return NullValue.get();

0 comments on commit 7166e4d

Please sign in to comment.