From 39ba92e7e508b86c0c900c86b8e3f3c27889e636 Mon Sep 17 00:00:00 2001 From: Hou Zhizhen Date: Tue, 2 Feb 2021 16:46:43 +0800 Subject: [PATCH 1/6] add Combiner, DoubleValueSumCombiner, IdValueMinimumCombiner, LongValueSumCombiner --- .../computer/core/combiner/Combiner.java | 30 ++++++++++++++ .../core/combiner/DoubleValueSumCombiner.java | 31 ++++++++++++++ .../core/combiner/IdValueMinimumCombiner.java | 34 +++++++++++++++ .../core/combiner/LongValueSumCombiner.java | 31 ++++++++++++++ .../computer/core/UnitTestSuite.java | 2 + .../core/combiner/CombinerTestSuite.java | 32 +++++++++++++++ .../combiner/DoubleValueSumCombinerTest.java | 40 ++++++++++++++++++ .../combiner/IdValueMinimumCombinerTest.java | 41 +++++++++++++++++++ .../combiner/LongValueSumCombinerTest.java | 39 ++++++++++++++++++ 9 files changed, 280 insertions(+) create mode 100644 computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/Combiner.java create mode 100644 computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombiner.java create mode 100644 computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombiner.java create mode 100644 computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombiner.java create mode 100644 computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java create mode 100644 computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java create mode 100644 computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombinerTest.java create mode 100644 computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombinerTest.java diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/Combiner.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/Combiner.java new file mode 100644 index 000000000..1dc1908df --- /dev/null +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/Combiner.java @@ -0,0 +1,30 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +public interface Combiner { + + /** + * 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); +} diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombiner.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombiner.java new file mode 100644 index 000000000..a01e84dce --- /dev/null +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombiner.java @@ -0,0 +1,31 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import com.baidu.hugegraph.computer.core.graph.value.DoubleValue; + +public class DoubleValueSumCombiner implements Combiner { + + @Override + public DoubleValue combine(DoubleValue v1, DoubleValue v2) { + v2.value(v1.value() + v2.value()); + return v2; + } +} diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombiner.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombiner.java new file mode 100644 index 000000000..7ce08280f --- /dev/null +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombiner.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import com.baidu.hugegraph.computer.core.graph.value.IdValue; + +public class IdValueMinimumCombiner implements Combiner { + + @Override + public IdValue combine(IdValue v1, IdValue v2) { + if (v1.compareTo(v2) <= 0) { + return v1; + } else { + return v2; + } + } +} diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombiner.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombiner.java new file mode 100644 index 000000000..11b3eb1a5 --- /dev/null +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombiner.java @@ -0,0 +1,31 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import com.baidu.hugegraph.computer.core.graph.value.LongValue; + +public class LongValueSumCombiner implements Combiner { + + @Override + public LongValue combine(LongValue v1, LongValue v2) { + v2.value(v1.value() + v2.value()); + return v2; + } +} diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java index 5e229a943..1cb6689bc 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java @@ -26,6 +26,7 @@ import com.baidu.hugegraph.computer.core.allocator.AllocatorTestSuite; import com.baidu.hugegraph.computer.core.bsp.BspTestSuite; +import com.baidu.hugegraph.computer.core.combiner.CombinerTestSuite; import com.baidu.hugegraph.computer.core.common.CommonTestSuite; import com.baidu.hugegraph.computer.core.common.ExceptionTest; import com.baidu.hugegraph.computer.core.config.ComputerOptions; @@ -41,6 +42,7 @@ CommonTestSuite.class, BspTestSuite.class, ExceptionTest.class, + CombinerTestSuite.class, GraphTestSuite.class, IOTestSuite.class, BspTestSuite.class, diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java new file mode 100644 index 000000000..fd6c4aa30 --- /dev/null +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java @@ -0,0 +1,32 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + DoubleValueSumCombinerTest.class, + IdValueMinimumCombinerTest.class, + LongValueSumCombinerTest.class +}) +public class CombinerTestSuite { +} diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java new file mode 100644 index 000000000..e6cc3657f --- /dev/null +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + + +import org.junit.Test; + +import com.baidu.hugegraph.computer.core.graph.value.DoubleValue; +import com.baidu.hugegraph.testutil.Assert; + +public class DoubleValueSumCombinerTest { + + @Test + public void test() { + DoubleValue sum = new DoubleValue(0.0D); + DoubleValueSumCombiner combiner = new DoubleValueSumCombiner(); + for (int i = 1; i <= 10; i++) { + DoubleValue value = new DoubleValue(i); + sum = combiner.combine(sum, value); + } + Assert.assertEquals(55.0D, sum.value(), 0.0D); + } +} diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombinerTest.java new file mode 100644 index 000000000..263661ff9 --- /dev/null +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombinerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import org.junit.Test; + +import com.baidu.hugegraph.computer.core.graph.id.LongId; +import com.baidu.hugegraph.computer.core.graph.value.IdValue; +import com.baidu.hugegraph.testutil.Assert; + +public class IdValueMinimumCombinerTest { + + @Test + public void test() { + LongId longId = new LongId(0); + IdValue min = longId.idValue(); + IdValueMinimumCombiner combiner = new IdValueMinimumCombiner(); + for (int i = 1; i <= 10; i++) { + IdValue value = new LongId(i).idValue(); + min = combiner.combine(min, value); + } + Assert.assertEquals(longId.idValue(), min); + } +} diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombinerTest.java new file mode 100644 index 000000000..a0b8ec0ec --- /dev/null +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/LongValueSumCombinerTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import org.junit.Test; + +import com.baidu.hugegraph.computer.core.graph.value.LongValue; +import com.baidu.hugegraph.testutil.Assert; + +public class LongValueSumCombinerTest { + + @Test + public void test() { + LongValue sum = new LongValue(0L); + LongValueSumCombiner combiner = new LongValueSumCombiner(); + for (int i = 1; i <= 10; i++) { + LongValue value = new LongValue(i); + sum = combiner.combine(sum, value); + } + Assert.assertEquals(55L, sum.value()); + } +} From 132158fc7318b553c6df5a728842dd5a2db03fdf Mon Sep 17 00:00:00 2001 From: Hou Zhizhen Date: Wed, 3 Feb 2021 15:44:17 +0800 Subject: [PATCH 2/6] Value implements Comparable --- .../core/combiner/ValueMaxCombiner.java | 34 ++++++++++++++++ ...mumCombiner.java => ValueMinCombiner.java} | 6 +-- .../core/graph/value/BooleanValue.java | 9 ++++- .../core/graph/value/DoubleValue.java | 9 ++++- .../computer/core/graph/value/FloatValue.java | 9 ++++- .../computer/core/graph/value/IdValue.java | 4 +- .../computer/core/graph/value/IntValue.java | 9 ++++- .../computer/core/graph/value/ListValue.java | 21 +++++++++- .../computer/core/graph/value/LongValue.java | 9 ++++- .../computer/core/graph/value/NullValue.java | 9 ++++- .../computer/core/graph/value/Value.java | 2 +- .../core/combiner/CombinerTestSuite.java | 5 ++- .../core/combiner/ValueMaxCombinerTest.java | 39 +++++++++++++++++++ ...nerTest.java => ValueMinCombinerTest.java} | 16 ++++---- .../computer/core/graph/GraphTestSuite.java | 2 + .../core/graph/value/BooleanValueTest.java | 10 +++++ .../core/graph/value/DoubleValueTest.java | 10 +++++ .../core/graph/value/FloatValueTest.java | 10 +++++ .../core/graph/value/IdValueListListTest.java | 21 ++++++++++ .../core/graph/value/IdValueListTest.java | 16 ++++++++ .../core/graph/value/IdValueTest.java | 38 ++++++++++++++++++ .../core/graph/value/IntValueTest.java | 10 +++++ .../core/graph/value/ListValueTest.java | 14 +++++++ .../core/graph/value/LongValueTest.java | 10 +++++ .../core/graph/value/NullValueTest.java | 7 ++++ 25 files changed, 306 insertions(+), 23 deletions(-) create mode 100644 computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombiner.java rename computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/{IdValueMinimumCombiner.java => ValueMinCombiner.java} (84%) create mode 100644 computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java rename computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/{IdValueMinimumCombinerTest.java => ValueMinCombinerTest.java} (69%) create mode 100644 computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombiner.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombiner.java new file mode 100644 index 000000000..6a59752ef --- /dev/null +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombiner.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import com.baidu.hugegraph.computer.core.graph.value.Value; + +public class ValueMaxCombiner implements Combiner { + + @Override + public T combine(T v1, T v2) { + if (v1.compareTo(v2) >= 0) { + return v1; + } else { + return v2; + } + } +} diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombiner.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombiner.java similarity index 84% rename from computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombiner.java rename to computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombiner.java index 7ce08280f..dcabce56c 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombiner.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombiner.java @@ -19,12 +19,12 @@ package com.baidu.hugegraph.computer.core.combiner; -import com.baidu.hugegraph.computer.core.graph.value.IdValue; +import com.baidu.hugegraph.computer.core.graph.value.Value; -public class IdValueMinimumCombiner implements Combiner { +public class ValueMinCombiner implements Combiner { @Override - public IdValue combine(IdValue v1, IdValue v2) { + public T combine(T v1, T v2) { if (v1.compareTo(v2) <= 0) { return v1; } else { diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java index 7f51e7580..1cf463fb5 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java @@ -23,8 +23,9 @@ import com.baidu.hugegraph.computer.core.io.GraphInput; import com.baidu.hugegraph.computer.core.io.GraphOutput; +import com.baidu.hugegraph.util.E; -public class BooleanValue implements Value { +public class BooleanValue implements Value { public static final BooleanValue TRUE = new BooleanValue(true); public static final BooleanValue FALSE = new BooleanValue(false); @@ -83,4 +84,10 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } + + @Override + public int compareTo(BooleanValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); + return Boolean.compare(this.value, obj.value); + } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java index 7622d87a9..17c63bb2a 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java @@ -23,8 +23,9 @@ import com.baidu.hugegraph.computer.core.io.GraphInput; import com.baidu.hugegraph.computer.core.io.GraphOutput; +import com.baidu.hugegraph.util.E; -public class DoubleValue implements Value { +public class DoubleValue implements Value { private double value; @@ -80,4 +81,10 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } + + @Override + public int compareTo(DoubleValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); + return Double.compare(this.value, obj.value); + } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java index 44f21e406..6d2b34a25 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java @@ -23,8 +23,9 @@ import com.baidu.hugegraph.computer.core.io.GraphInput; import com.baidu.hugegraph.computer.core.io.GraphOutput; +import com.baidu.hugegraph.util.E; -public class FloatValue implements Value { +public class FloatValue implements Value { private float value; @@ -80,4 +81,10 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } + + @Override + public int compareTo(FloatValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); + return Float.compare(this.value, obj.value); + } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java index cc5097a7a..73fd70fb1 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java @@ -32,8 +32,9 @@ import com.baidu.hugegraph.computer.core.io.OptimizedStreamGraphInput; import com.baidu.hugegraph.computer.core.io.StreamGraphInput; import com.baidu.hugegraph.computer.core.util.ByteArrayUtil; +import com.baidu.hugegraph.util.E; -public class IdValue implements Value, Comparable { +public class IdValue implements Value { private byte[] bytes; private int length; @@ -79,6 +80,7 @@ public void write(GraphOutput out) throws IOException { @Override public int compareTo(IdValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); return ByteArrayUtil.compare(this.bytes, this.length, obj.bytes, obj.length); } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java index 835058dff..b8e9f3c1e 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java @@ -23,8 +23,9 @@ import com.baidu.hugegraph.computer.core.io.GraphInput; import com.baidu.hugegraph.computer.core.io.GraphOutput; +import com.baidu.hugegraph.util.E; -public class IntValue implements Value { +public class IntValue implements Value { private int value; @@ -80,4 +81,10 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } + + @Override + public int compareTo(IntValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); + return Integer.compare(this.value, obj.value); + } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java index 441d39ccf..2e2ac111c 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java @@ -31,7 +31,7 @@ import com.baidu.hugegraph.computer.core.io.GraphOutput; import com.baidu.hugegraph.util.E; -public class ListValue implements Value { +public class ListValue implements Value> { private ValueType elemType; private List values; @@ -139,4 +139,23 @@ public String toString() { return String.format("ListValue{elemType=%s" + ", size=%s}", this.elemType, this.values.size()); } + + @Override + public int compareTo(ListValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); + int cmp = this.size() - obj.size(); + if (cmp != 0) { + return cmp; + } else { + for (int i = 0; i < this.size(); i++) { + cmp = this.values.get(i).compareTo(obj.values.get(i)); + if (cmp != 0) { + return cmp; + } else { + // Continue compare next element until to end + } + } + } + return 0; + } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java index 4506ce29c..f7b3c5f0b 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java @@ -23,8 +23,9 @@ import com.baidu.hugegraph.computer.core.io.GraphInput; import com.baidu.hugegraph.computer.core.io.GraphOutput; +import com.baidu.hugegraph.util.E; -public class LongValue implements Value { +public class LongValue implements Value { private long value; @@ -80,4 +81,10 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } + + @Override + public int compareTo(LongValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); + return Long.compare(this.value, obj.value); + } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java index e117dbbae..21f6ef312 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java @@ -23,8 +23,9 @@ import com.baidu.hugegraph.computer.core.io.GraphInput; import com.baidu.hugegraph.computer.core.io.GraphOutput; +import com.baidu.hugegraph.util.E; -public class NullValue implements Value { +public class NullValue implements Value { private static final NullValue INSTANCE = new NullValue(); @@ -67,4 +68,10 @@ public int hashCode() { public String toString() { return ""; } + + @Override + public int compareTo(NullValue obj) { + E.checkArgumentNotNull(obj, "The obj can't be null"); + return 0; + } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/Value.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/Value.java index 5620fd1ee..50c88efb0 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/Value.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/Value.java @@ -22,7 +22,7 @@ import com.baidu.hugegraph.computer.core.io.Readable; import com.baidu.hugegraph.computer.core.io.Writable; -public interface Value extends Writable, Readable { +public interface Value extends Writable, Readable, Comparable { ValueType type(); } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java index fd6c4aa30..8ecb8a68e 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java @@ -25,8 +25,9 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ DoubleValueSumCombinerTest.class, - IdValueMinimumCombinerTest.class, - LongValueSumCombinerTest.class + LongValueSumCombinerTest.class, + ValueMinCombinerTest.class, + ValueMaxCombinerTest.class }) public class CombinerTestSuite { } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java new file mode 100644 index 000000000..f6c02164b --- /dev/null +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.combiner; + +import org.junit.Test; + +import com.baidu.hugegraph.computer.core.graph.value.LongValue; +import com.baidu.hugegraph.testutil.Assert; + +public class ValueMaxCombinerTest { + + @Test + public void test() { + LongValue max = new LongValue(0L); + ValueMaxCombiner combiner = new ValueMaxCombiner(); + for (long i = 1; i <= 10; i++) { + LongValue value = new LongValue(i); + max = combiner.combine(max, value); + } + Assert.assertEquals(new LongValue(10L), max); + } +} diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombinerTest.java similarity index 69% rename from computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombinerTest.java rename to computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombinerTest.java index 263661ff9..3428253d5 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/IdValueMinimumCombinerTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombinerTest.java @@ -21,21 +21,19 @@ import org.junit.Test; -import com.baidu.hugegraph.computer.core.graph.id.LongId; -import com.baidu.hugegraph.computer.core.graph.value.IdValue; +import com.baidu.hugegraph.computer.core.graph.value.LongValue; import com.baidu.hugegraph.testutil.Assert; -public class IdValueMinimumCombinerTest { +public class ValueMinCombinerTest { @Test public void test() { - LongId longId = new LongId(0); - IdValue min = longId.idValue(); - IdValueMinimumCombiner combiner = new IdValueMinimumCombiner(); - for (int i = 1; i <= 10; i++) { - IdValue value = new LongId(i).idValue(); + LongValue min = new LongValue(0L); + ValueMinCombiner combiner = new ValueMinCombiner(); + for (long i = 1; i <= 10; i++) { + LongValue value = new LongValue(i); min = combiner.combine(min, value); } - Assert.assertEquals(longId.idValue(), min); + Assert.assertEquals(new LongValue(0L), min); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/GraphTestSuite.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/GraphTestSuite.java index 2fae84624..ef08de117 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/GraphTestSuite.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/GraphTestSuite.java @@ -35,6 +35,7 @@ import com.baidu.hugegraph.computer.core.graph.value.FloatValueTest; import com.baidu.hugegraph.computer.core.graph.value.IdValueListListTest; import com.baidu.hugegraph.computer.core.graph.value.IdValueListTest; +import com.baidu.hugegraph.computer.core.graph.value.IdValueTest; import com.baidu.hugegraph.computer.core.graph.value.IntValueTest; import com.baidu.hugegraph.computer.core.graph.value.ListValueTest; import com.baidu.hugegraph.computer.core.graph.value.LongValueTest; @@ -51,6 +52,7 @@ IdFactoryTest.class, NullValueTest.class, BooleanValueTest.class, + IdValueTest.class, IntValueTest.class, LongValueTest.class, FloatValueTest.class, diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java index a76a711e2..5e4a9b992 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java @@ -50,4 +50,14 @@ public void test() { public void testReadWrite() throws IOException { assertValueEqualAfterWriteAndRead(new BooleanValue(true)); } + + @Test + public void testCompare() { + BooleanValue value1 = BooleanValue.FALSE; + BooleanValue value2 = BooleanValue.FALSE; + BooleanValue value3 = BooleanValue.TRUE; + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java index a6bd3f9db..84dd3eaec 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java @@ -81,4 +81,14 @@ public void testReadWrite() throws IOException { assertValueEqualAfterWriteAndRead(new DoubleValue(Double.MIN_VALUE)); assertValueEqualAfterWriteAndRead(new DoubleValue(Double.MAX_VALUE)); } + + @Test + public void testCompare() { + DoubleValue value1 = new DoubleValue(123.0D); + DoubleValue value2 = new DoubleValue(123.0D); + DoubleValue value3 = new DoubleValue(321.0D); + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java index ac77aa120..c32ede620 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java @@ -49,4 +49,14 @@ public void test() { public void testReadWrite() throws IOException { assertValueEqualAfterWriteAndRead(new FloatValue(Float.MAX_VALUE)); } + + @Test + public void testCompare() { + FloatValue value1 = new FloatValue(123.0F); + FloatValue value2 = new FloatValue(123.0F); + FloatValue value3 = new FloatValue(321.0F); + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java index 7e599a23c..57ee6e1a6 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java @@ -78,4 +78,25 @@ public void testReadWrite() throws IOException { oldValue.add(listValue); assertValueEqualAfterWriteAndRead(oldValue); } + + @Test + public void testCompare() { + LongId longId1 = new LongId(100L); + LongId longId2 = new LongId(200L); + IdValueList listValue = new IdValueList(); + listValue.add(longId1.idValue()); + listValue.add(longId2.idValue()); + + IdValueListList value1 = new IdValueListList(); + value1.add(listValue); + IdValueListList value2 = new IdValueListList(); + value2.add(listValue); + IdValueListList value3 = new IdValueListList(); + value3.add(listValue); + value3.add(listValue); + + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java index e6b0acf5f..fae262fac 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java @@ -68,4 +68,20 @@ public void testReadWrite() throws IOException { oldValue.add(longId2.idValue()); assertValueEqualAfterWriteAndRead(oldValue); } + + @Test + public void testCompare() { + LongId longId1 = new LongId(100L); + LongId longId2 = new LongId(200L); + IdValueList value1 = new IdValueList(); + value1.add(longId1.idValue()); + IdValueList value2 = new IdValueList(); + value2.add(longId1.idValue()); + IdValueList value3 = new IdValueList(); + value3.add(longId1.idValue()); + value3.add(longId2.idValue()); + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java new file mode 100644 index 000000000..f55145840 --- /dev/null +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017 HugeGraph Authors + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.baidu.hugegraph.computer.core.graph.value; + +import org.junit.Test; + +import com.baidu.hugegraph.computer.core.graph.id.LongId; +import com.baidu.hugegraph.testutil.Assert; + +public class IdValueTest { + + @Test + public void testCompare() { + IdValue value1 = new LongId(123L).idValue(); + IdValue value2 = new LongId(123L).idValue(); + IdValue value3 = new LongId(321L).idValue(); + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value2.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } +} diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java index 291286cac..b39d641e0 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java @@ -49,4 +49,14 @@ public void test() { public void testReadWrite() throws IOException { assertValueEqualAfterWriteAndRead(new IntValue(Integer.MAX_VALUE)); } + + @Test + public void testCompare() { + IntValue value1 = new IntValue(123); + IntValue value2 = new IntValue(123); + IntValue value3 = new IntValue(321); + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java index f49311d9f..a0ff957e6 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java @@ -67,4 +67,18 @@ public void testReadWrite() throws IOException { oldValue.add(new IntValue(200)); assertValueEqualAfterWriteAndRead(oldValue); } + + @Test + public void testCompare() { + ListValue value1 = new ListValue<>(ValueType.INT); + ListValue value2 = new ListValue<>(ValueType.INT); + value1.add(new IntValue(100)); + value2.add(new IntValue(100)); + ListValue value3 = new ListValue<>(ValueType.INT); + value3.add(new IntValue(100)); + value3.add(new IntValue(200)); + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java index d6007a255..ab59503e4 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java @@ -49,4 +49,14 @@ public void test() { public void testReadWrite() throws IOException { assertValueEqualAfterWriteAndRead(new LongValue(Long.MAX_VALUE)); } + + @Test + public void testCompare() { + LongValue value1 = new LongValue(123L); + LongValue value2 = new LongValue(123L); + LongValue value3 = new LongValue(321L); + Assert.assertEquals(0, value1.compareTo(value2)); + Assert.assertTrue(value1.compareTo(value3) < 0); + Assert.assertTrue(value3.compareTo(value1) > 0); + } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValueTest.java index ca0038209..f976a737a 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValueTest.java @@ -43,4 +43,11 @@ public void test() { public void testReadWrite() throws IOException { assertValueEqualAfterWriteAndRead(NullValue.get()); } + + @Test + public void testCompare() { + NullValue value1 = NullValue.get(); + NullValue value2 = NullValue.get(); + Assert.assertEquals(0, value1.compareTo(value2)); + } } From a82a811cf283f490055619716295f842e29462a6 Mon Sep 17 00:00:00 2001 From: Hou Zhizhen Date: Thu, 4 Feb 2021 19:55:42 +0800 Subject: [PATCH 3/6] tiny improve --- .../core/graph/value/BooleanValue.java | 12 +++--- .../core/graph/value/DoubleValue.java | 12 +++--- .../computer/core/graph/value/FloatValue.java | 12 +++--- .../computer/core/graph/value/IdValue.java | 2 +- .../computer/core/graph/value/IntValue.java | 12 +++--- .../computer/core/graph/value/ListValue.java | 38 +++++++++---------- .../computer/core/graph/value/LongValue.java | 12 +++--- .../computer/core/graph/value/NullValue.java | 12 +++--- .../core/graph/value/BooleanValueTest.java | 4 +- .../core/graph/value/DoubleValueTest.java | 4 +- .../core/graph/value/FloatValueTest.java | 4 +- .../core/graph/value/IdValueListListTest.java | 4 +- .../core/graph/value/IdValueListTest.java | 4 +- .../core/graph/value/IdValueTest.java | 4 +- .../core/graph/value/IntValueTest.java | 4 +- .../core/graph/value/ListValueTest.java | 4 +- .../core/graph/value/LongValueTest.java | 4 +- 17 files changed, 74 insertions(+), 74 deletions(-) diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java index 1cf463fb5..925d421c0 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValue.java @@ -67,6 +67,12 @@ public void write(GraphOutput out) throws IOException { out.writeBoolean(this.value); } + @Override + public int compareTo(BooleanValue obj) { + E.checkArgumentNotNull(obj, "The compare argument can't be null"); + return Boolean.compare(this.value, obj.value); + } + @Override public boolean equals(Object obj) { if (!(obj instanceof BooleanValue)) { @@ -84,10 +90,4 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } - - @Override - public int compareTo(BooleanValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); - return Boolean.compare(this.value, obj.value); - } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java index 17c63bb2a..0d0abe721 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValue.java @@ -64,6 +64,12 @@ public void write(GraphOutput out) throws IOException { out.writeDouble(this.value); } + @Override + public int compareTo(DoubleValue obj) { + E.checkArgumentNotNull(obj, "The compare argument can't be null"); + return Double.compare(this.value, obj.value); + } + @Override public boolean equals(Object obj) { if (!(obj instanceof DoubleValue)) { @@ -81,10 +87,4 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } - - @Override - public int compareTo(DoubleValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); - return Double.compare(this.value, obj.value); - } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java index 6d2b34a25..87faab208 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValue.java @@ -64,6 +64,12 @@ public void write(GraphOutput out) throws IOException { out.writeFloat(this.value); } + @Override + public int compareTo(FloatValue obj) { + E.checkArgumentNotNull(obj, "The compare argument can't be null"); + return Float.compare(this.value, obj.value); + } + @Override public boolean equals(Object obj) { if (!(obj instanceof FloatValue)) { @@ -81,10 +87,4 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } - - @Override - public int compareTo(FloatValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); - return Float.compare(this.value, obj.value); - } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java index 73fd70fb1..aea7ab4a6 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValue.java @@ -80,7 +80,7 @@ public void write(GraphOutput out) throws IOException { @Override public int compareTo(IdValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); + E.checkArgumentNotNull(obj, "The compare argument can't be null"); return ByteArrayUtil.compare(this.bytes, this.length, obj.bytes, obj.length); } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java index b8e9f3c1e..336c0e4ec 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValue.java @@ -64,6 +64,12 @@ public void write(GraphOutput out) throws IOException { out.writeInt(this.value); } + @Override + public int compareTo(IntValue obj) { + E.checkArgumentNotNull(obj, "The compare argument can't be null"); + return Integer.compare(this.value, obj.value); + } + @Override public boolean equals(Object obj) { if (!(obj instanceof IntValue)) { @@ -81,10 +87,4 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } - - @Override - public int compareTo(IntValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); - return Integer.compare(this.value, obj.value); - } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java index 2e2ac111c..117edf44a 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java @@ -117,6 +117,25 @@ protected void write(GraphOutput out, boolean writeElemType) } } + @Override + public int compareTo(ListValue obj) { + E.checkArgumentNotNull(obj, "The compare argument can't be null"); + int cmp = this.size() - obj.size(); + if (cmp != 0) { + return cmp; + } else { + for (int i = 0; i < this.size(); i++) { + cmp = this.values.get(i).compareTo(obj.values.get(i)); + if (cmp != 0) { + return cmp; + } else { + // Continue compare next element until to end + } + } + } + return 0; + } + @Override public boolean equals(Object obj) { if (!(obj instanceof ListValue)) { @@ -139,23 +158,4 @@ public String toString() { return String.format("ListValue{elemType=%s" + ", size=%s}", this.elemType, this.values.size()); } - - @Override - public int compareTo(ListValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); - int cmp = this.size() - obj.size(); - if (cmp != 0) { - return cmp; - } else { - for (int i = 0; i < this.size(); i++) { - cmp = this.values.get(i).compareTo(obj.values.get(i)); - if (cmp != 0) { - return cmp; - } else { - // Continue compare next element until to end - } - } - } - return 0; - } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java index f7b3c5f0b..936a236ce 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValue.java @@ -64,6 +64,12 @@ public void write(GraphOutput out) throws IOException { out.writeLong(this.value); } + @Override + public int compareTo(LongValue obj) { + E.checkArgumentNotNull(obj, "The compare argument can't be null"); + return Long.compare(this.value, obj.value); + } + @Override public boolean equals(Object obj) { if (!(obj instanceof LongValue)) { @@ -81,10 +87,4 @@ public int hashCode() { public String toString() { return String.valueOf(this.value); } - - @Override - public int compareTo(LongValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); - return Long.compare(this.value, obj.value); - } } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java index 21f6ef312..4052a4de6 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/NullValue.java @@ -54,6 +54,12 @@ public void read(GraphInput in) throws IOException { // Do nothing } + @Override + public int compareTo(NullValue obj) { + E.checkArgumentNotNull(obj, "The compare argument can't be null"); + return 0; + } + @Override public boolean equals(Object obj) { return obj == INSTANCE || obj instanceof NullValue; @@ -68,10 +74,4 @@ public int hashCode() { public String toString() { return ""; } - - @Override - public int compareTo(NullValue obj) { - E.checkArgumentNotNull(obj, "The obj can't be null"); - return 0; - } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java index 5e4a9b992..4e80c82c5 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/BooleanValueTest.java @@ -57,7 +57,7 @@ public void testCompare() { BooleanValue value2 = BooleanValue.FALSE; BooleanValue value3 = BooleanValue.TRUE; Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java index 84dd3eaec..e4844068b 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/DoubleValueTest.java @@ -88,7 +88,7 @@ public void testCompare() { DoubleValue value2 = new DoubleValue(123.0D); DoubleValue value3 = new DoubleValue(321.0D); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java index c32ede620..e9dabc073 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/FloatValueTest.java @@ -56,7 +56,7 @@ public void testCompare() { FloatValue value2 = new FloatValue(123.0F); FloatValue value3 = new FloatValue(321.0F); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java index 57ee6e1a6..00f225e71 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListListTest.java @@ -96,7 +96,7 @@ public void testCompare() { value3.add(listValue); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java index fae262fac..1c3157dbc 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueListTest.java @@ -81,7 +81,7 @@ public void testCompare() { value3.add(longId1.idValue()); value3.add(longId2.idValue()); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java index f55145840..d971061e2 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IdValueTest.java @@ -32,7 +32,7 @@ public void testCompare() { IdValue value2 = new LongId(123L).idValue(); IdValue value3 = new LongId(321L).idValue(); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value2.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value2.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java index b39d641e0..e715ec9c3 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/IntValueTest.java @@ -56,7 +56,7 @@ public void testCompare() { IntValue value2 = new IntValue(123); IntValue value3 = new IntValue(321); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java index a0ff957e6..f714dab4a 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValueTest.java @@ -78,7 +78,7 @@ public void testCompare() { value3.add(new IntValue(100)); value3.add(new IntValue(200)); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java index ab59503e4..c62caa733 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/graph/value/LongValueTest.java @@ -56,7 +56,7 @@ public void testCompare() { LongValue value2 = new LongValue(123L); LongValue value3 = new LongValue(321L); Assert.assertEquals(0, value1.compareTo(value2)); - Assert.assertTrue(value1.compareTo(value3) < 0); - Assert.assertTrue(value3.compareTo(value1) > 0); + Assert.assertLt(0, value1.compareTo(value3)); + Assert.assertGt(0, value3.compareTo(value1)); } } From 829c0d57da09ecfe4286c3b74ebaca6d8aff7b96 Mon Sep 17 00:00:00 2001 From: Hou Zhizhen Date: Fri, 5 Feb 2021 15:26:50 +0800 Subject: [PATCH 4/6] tiny improve --- .../computer/core/graph/value/ListValue.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java index 117edf44a..bf559b475 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/graph/value/ListValue.java @@ -123,14 +123,11 @@ public int compareTo(ListValue obj) { int cmp = this.size() - obj.size(); if (cmp != 0) { return cmp; - } else { - for (int i = 0; i < this.size(); i++) { - cmp = this.values.get(i).compareTo(obj.values.get(i)); - if (cmp != 0) { - return cmp; - } else { - // Continue compare next element until to end - } + } + for (int i = 0; i < this.size(); i++) { + cmp = this.values.get(i).compareTo(obj.values.get(i)); + if (cmp != 0) { + return cmp; } } return 0; From d34b481e74d72634b48f96cb1bd15314b764633c Mon Sep 17 00:00:00 2001 From: Hou Zhizhen Date: Fri, 5 Feb 2021 16:46:33 +0800 Subject: [PATCH 5/6] tiny improve --- .../com/baidu/hugegraph/computer/core/UnitTestSuite.java | 2 -- .../computer/core/combiner/CombinerTestSuite.java | 8 ++++---- .../core/combiner/DoubleValueSumCombinerTest.java | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java index 1cb6689bc..5d64f4713 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/UnitTestSuite.java @@ -28,7 +28,6 @@ import com.baidu.hugegraph.computer.core.bsp.BspTestSuite; import com.baidu.hugegraph.computer.core.combiner.CombinerTestSuite; import com.baidu.hugegraph.computer.core.common.CommonTestSuite; -import com.baidu.hugegraph.computer.core.common.ExceptionTest; import com.baidu.hugegraph.computer.core.config.ComputerOptions; import com.baidu.hugegraph.computer.core.graph.GraphTestSuite; import com.baidu.hugegraph.computer.core.io.IOTestSuite; @@ -41,7 +40,6 @@ AllocatorTestSuite.class, CommonTestSuite.class, BspTestSuite.class, - ExceptionTest.class, CombinerTestSuite.class, GraphTestSuite.class, IOTestSuite.class, diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java index 8ecb8a68e..53d467e92 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/CombinerTestSuite.java @@ -24,10 +24,10 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - DoubleValueSumCombinerTest.class, - LongValueSumCombinerTest.class, - ValueMinCombinerTest.class, - ValueMaxCombinerTest.class + DoubleValueSumCombinerTest.class, + LongValueSumCombinerTest.class, + ValueMinCombinerTest.class, + ValueMaxCombinerTest.class }) public class CombinerTestSuite { } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java index e6cc3657f..8cd2e14eb 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/DoubleValueSumCombinerTest.java @@ -19,7 +19,6 @@ package com.baidu.hugegraph.computer.core.combiner; - import org.junit.Test; import com.baidu.hugegraph.computer.core.graph.value.DoubleValue; From 2bf9f6e02cd58ecd3233ba2ceafcd24b896404aa Mon Sep 17 00:00:00 2001 From: Hou Zhizhen Date: Fri, 5 Feb 2021 16:57:21 +0800 Subject: [PATCH 6/6] tiny improve --- .../computer/core/combiner/ValueMaxCombinerTest.java | 10 +++++----- .../computer/core/combiner/ValueMinCombinerTest.java | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java index f6c02164b..6b3335e55 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMaxCombinerTest.java @@ -30,10 +30,10 @@ public class ValueMaxCombinerTest { public void test() { LongValue max = new LongValue(0L); ValueMaxCombiner combiner = new ValueMaxCombiner(); - for (long i = 1; i <= 10; i++) { - LongValue value = new LongValue(i); - max = combiner.combine(max, value); - } - Assert.assertEquals(new LongValue(10L), max); + LongValue value1 = new LongValue(1L); + max = combiner.combine(max, value1); + LongValue value2 = new LongValue(2L); + max = combiner.combine(value2, max); + Assert.assertEquals(new LongValue(2L), max); } } diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombinerTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombinerTest.java index 3428253d5..74b09b0ee 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombinerTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/core/combiner/ValueMinCombinerTest.java @@ -30,10 +30,10 @@ public class ValueMinCombinerTest { public void test() { LongValue min = new LongValue(0L); ValueMinCombiner combiner = new ValueMinCombiner(); - for (long i = 1; i <= 10; i++) { - LongValue value = new LongValue(i); - min = combiner.combine(min, value); - } + LongValue value1 = new LongValue(1L); + min = combiner.combine(min, value1); + LongValue value2 = new LongValue(2L); + min = combiner.combine(value2, min); Assert.assertEquals(new LongValue(0L), min); } }