Repository: giraph
Updated Branches:
  refs/heads/trunk add1d4f07 -> 77f8a075c


http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/map/package-info.java
----------------------------------------------------------------------
diff --git 
a/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/map/package-info.java
 
b/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/map/package-info.java
new file mode 100644
index 0000000..295ef8c
--- /dev/null
+++ 
b/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/map/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+/**
+ * Reducers for collecting map of objects.
+ */
+package org.apache.giraph.block_app.reducers.map;

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/package-info.java
----------------------------------------------------------------------
diff --git 
a/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/package-info.java
 
b/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/package-info.java
new file mode 100644
index 0000000..145f3dc
--- /dev/null
+++ 
b/giraph-block-app/src/main/java/org/apache/giraph/block_app/reducers/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+/**
+ * Common reducer utilities for Block Applications
+ */
+package org.apache.giraph.block_app.reducers;

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-block-app/src/main/java/org/apache/giraph/function/TripleFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-block-app/src/main/java/org/apache/giraph/function/TripleFunction.java 
b/giraph-block-app/src/main/java/org/apache/giraph/function/TripleFunction.java
new file mode 100644
index 0000000..b7609ca
--- /dev/null
+++ 
b/giraph-block-app/src/main/java/org/apache/giraph/function/TripleFunction.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.apache.giraph.function;
+
+import java.io.Serializable;
+
+/**
+ * Function:
+ * (F1, F2, F3) -> T
+ *
+ * @param <F1> First argument type
+ * @param <F2> Second argument type
+ * @param <F3> Third argument type
+ * @param <T> Result type
+ */
+public interface TripleFunction<F1, F2, F3, T> extends Serializable {
+
+  /**
+   * Returns the result of applying this function to given
+   * {@code input1}, {@code input2} and {@code input3}.
+   *
+   * The returned object may or may not be a new instance,
+   * depending on the implementation.
+   */
+  T apply(F1 input1, F2 input2, F3 input3);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.java
 
b/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.java
new file mode 100644
index 0000000..ad1ca8e
--- /dev/null
+++ 
b/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.giraph.function.primitive;
+
+import java.io.Serializable;
+
+/**
+ * Primitive specialization of Function:
+ * (F) -> double
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2DoubleFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   */
+  double apply(T value);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.java
 
b/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.java
new file mode 100644
index 0000000..b1a653f
--- /dev/null
+++ 
b/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.giraph.function.primitive;
+
+import java.io.Serializable;
+
+/**
+ * Primitive specialization of Function:
+ * (F) -> float
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2FloatFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   */
+  float apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.java
 
b/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.java
new file mode 100644
index 0000000..5300250
--- /dev/null
+++ 
b/giraph-block-app/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.giraph.function.primitive;
+
+import java.io.Serializable;
+
+/**
+ * Primitive specialization of Function:
+ * (F) -> long
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2LongFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   */
+  long apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-block-app/src/test/java/org/apache/giraph/block_app/reducers/array/ObjectStripingTest.java
----------------------------------------------------------------------
diff --git 
a/giraph-block-app/src/test/java/org/apache/giraph/block_app/reducers/array/ObjectStripingTest.java
 
b/giraph-block-app/src/test/java/org/apache/giraph/block_app/reducers/array/ObjectStripingTest.java
new file mode 100644
index 0000000..5e4eb11
--- /dev/null
+++ 
b/giraph-block-app/src/test/java/org/apache/giraph/block_app/reducers/array/ObjectStripingTest.java
@@ -0,0 +1,58 @@
+package org.apache.giraph.block_app.reducers.array;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import 
org.apache.giraph.block_app.reducers.array.HugeArrayUtils.ObjectStriping;
+import org.junit.Test;
+
+public class ObjectStripingTest {
+
+  private void testStriping(int size, int splits) {
+    ObjectStriping striping = new ObjectStriping(size, splits);
+
+    int numPerSplit = size / splits;
+
+    int prevSplitIndex = 0;
+    int prevInsideIndex = -1;
+
+    assertEquals(0, striping.getSplitStart(0));
+
+    for (int i = 0; i < size; i++) {
+      int splitIndex = striping.getSplitIndex(i);
+      int insideIndex = striping.getInsideIndex(i);
+
+
+      if (prevInsideIndex + 1 == striping.getSplitSize(prevSplitIndex)) {
+        assertEquals(i, striping.getSplitStart(splitIndex));
+        assertEquals(splitIndex, prevSplitIndex + 1);
+        assertEquals(insideIndex, 0);
+      } else {
+        assertEquals(splitIndex, prevSplitIndex);
+        assertEquals(insideIndex, prevInsideIndex + 1);
+      }
+
+      int splitSize = striping.getSplitSize(splitIndex);
+      if (splitSize != numPerSplit && splitSize != numPerSplit + 1) {
+        fail(splitSize + " " + numPerSplit);
+      }
+      prevSplitIndex = splitIndex;
+      prevInsideIndex = insideIndex;
+    }
+
+    assertEquals(prevSplitIndex + 1, splits);
+    assertEquals(prevInsideIndex + 1, striping.getSplitSize(prevSplitIndex));
+  }
+
+  @Test
+  public void test() {
+    testStriping(5, 5);
+    testStriping(6, 5);
+    testStriping(7, 5);
+    testStriping(9, 5);
+    testStriping(10, 5);
+    testStriping(100, 5);
+    testStriping(101, 5);
+    testStriping(104, 5);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/pom.xml
----------------------------------------------------------------------
diff --git a/giraph-core/pom.xml b/giraph-core/pom.xml
index 4719a5d..e98741e 100644
--- a/giraph-core/pom.xml
+++ b/giraph-core/pom.xml
@@ -503,6 +503,10 @@ under the License.
       <artifactId>commons-io</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/reducers/impl/KryoWrappedReduceOperation.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/reducers/impl/KryoWrappedReduceOperation.java
 
b/giraph-core/src/main/java/org/apache/giraph/reducers/impl/KryoWrappedReduceOperation.java
new file mode 100644
index 0000000..7dd9bc0
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/reducers/impl/KryoWrappedReduceOperation.java
@@ -0,0 +1,86 @@
+/*
+ * 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 org.apache.giraph.reducers.impl;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.giraph.reducers.ReduceOperation;
+import org.apache.giraph.writable.kryo.KryoWritableWrapper;
+
+/**
+ * Reduce operation which wraps reduced value in KryoWritableWrapper,
+ * so we don't need to worry about it being writable
+ *
+ * @param <S> Single value type
+ * @param <R> Reduced value type
+ */
+public abstract class KryoWrappedReduceOperation<S, R>
+    implements ReduceOperation<S, KryoWritableWrapper<R>> {
+  /**
+   * Look at ReduceOperation.reduce.
+   *
+   * @param reduceInto Partial value into which to reduce and store the result
+   * @param valueToReduce Single value to be reduced
+   */
+  public abstract void reduce(R reduceInto, S valueToReduce);
+
+  /**
+   * Look at ReduceOperation.reduceMerge.
+   *
+   * @param reduceInto Partial value into which to reduce and store the result
+   * @param valueToReduce Partial value to be reduced
+   */
+  public abstract void reduceMerge(R reduceInto, R valueToReduce);
+
+  /**
+   * Look at ReduceOperation.createValue.
+   *
+   * @return Neutral value
+   */
+  public abstract R createValue();
+
+  @Override
+  public final KryoWritableWrapper<R> createInitialValue() {
+    return new KryoWritableWrapper<>(createValue());
+  }
+
+  @Override
+  public final KryoWritableWrapper<R> reduce(
+      KryoWritableWrapper<R> wrapper, S value) {
+    reduce(wrapper.get(), value);
+    return wrapper;
+  }
+
+  @Override
+  public final KryoWritableWrapper<R> reduceMerge(
+      KryoWritableWrapper<R> wrapper,
+      KryoWritableWrapper<R> wrapperToReduce) {
+    reduceMerge(wrapper.get(), wrapperToReduce.get());
+    return wrapper;
+  }
+
+  @Override
+  public void write(DataOutput dataOutput) throws IOException {
+  }
+
+  @Override
+  public void readFields(DataInput dataInput) throws IOException {
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/DoubleDoubleWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/DoubleDoubleWritable.java
 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/DoubleDoubleWritable.java
new file mode 100644
index 0000000..0433642
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/DoubleDoubleWritable.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import org.apache.hadoop.io.DoubleWritable;
+
+/** Double-double Pair Writable */
+public class DoubleDoubleWritable
+        extends PairWritable<DoubleWritable, DoubleWritable> {
+  /** Constructor */
+  public DoubleDoubleWritable() {
+    super(new DoubleWritable(), new DoubleWritable());
+  }
+
+  /**
+   * Constructor
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public DoubleDoubleWritable(double left, double right) {
+    super(new DoubleWritable(left), new DoubleWritable(right));
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntDoubleWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntDoubleWritable.java
 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntDoubleWritable.java
new file mode 100644
index 0000000..36ae908
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntDoubleWritable.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import org.apache.hadoop.io.DoubleWritable;
+import org.apache.hadoop.io.IntWritable;
+
+/** Int-Double Pair Writable */
+public class IntDoubleWritable
+    extends PairWritable<IntWritable, DoubleWritable> {
+  /** Constructor */
+  public IntDoubleWritable() {
+    super(new IntWritable(), new DoubleWritable());
+  }
+
+  /**
+   * Constructor
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public IntDoubleWritable(int left, double right) {
+    super(new IntWritable(left), new DoubleWritable(right));
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntIntWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntIntWritable.java
 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntIntWritable.java
new file mode 100644
index 0000000..c41812b
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntIntWritable.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import org.apache.hadoop.io.IntWritable;
+
+/** Int-Int Pair Writable */
+public class IntIntWritable
+    extends PairWritable<IntWritable, IntWritable> {
+  /** Constructor */
+  public IntIntWritable() {
+    super(new IntWritable(), new IntWritable());
+  }
+
+  /**
+   * Constructor
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public IntIntWritable(int left, int right) {
+    super(new IntWritable(left), new IntWritable(right));
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntLongWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntLongWritable.java
 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntLongWritable.java
new file mode 100644
index 0000000..2d8d1df
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/IntLongWritable.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
+
+/** Int-Long Pair Writable */
+public class IntLongWritable
+    extends PairWritable<IntWritable, LongWritable> {
+  /** Constructor */
+  public IntLongWritable() {
+    super(new IntWritable(), new LongWritable());
+  }
+
+  /**
+   * Constructor
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public IntLongWritable(int left, long right) {
+    super(new IntWritable(left), new LongWritable(right));
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongDoubleWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongDoubleWritable.java
 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongDoubleWritable.java
new file mode 100644
index 0000000..2a86b1c
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongDoubleWritable.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import org.apache.hadoop.io.DoubleWritable;
+import org.apache.hadoop.io.LongWritable;
+
+/** Long-Double Pair Writable */
+public class LongDoubleWritable
+    extends PairWritable<LongWritable, DoubleWritable> {
+  /** Constructor */
+  public LongDoubleWritable() {
+    super(new LongWritable(), new DoubleWritable());
+  }
+
+  /**
+   * Constructor
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public LongDoubleWritable(long left, double right) {
+    super(new LongWritable(left), new DoubleWritable(right));
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongIntWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongIntWritable.java
 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongIntWritable.java
new file mode 100644
index 0000000..e5b923c
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongIntWritable.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
+
+/** Long-Int Pair Writable */
+public class LongIntWritable
+    extends PairWritable<LongWritable, IntWritable> {
+  /** Constructor */
+  public LongIntWritable() {
+    super(new LongWritable(), new IntWritable());
+  }
+
+  /**
+   * Constructor
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public LongIntWritable(long left, int right) {
+    super(new LongWritable(left), new IntWritable(right));
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongLongWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongLongWritable.java
 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongLongWritable.java
new file mode 100644
index 0000000..37105d8
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/LongLongWritable.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import org.apache.hadoop.io.LongWritable;
+
+/** Long-Long Pair Writable */
+public class LongLongWritable
+    extends PairWritable<LongWritable, LongWritable> {
+  /** Constructor */
+  public LongLongWritable() {
+    super(new LongWritable(), new LongWritable());
+  }
+
+  /**
+   * Constructor
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public LongLongWritable(long left, long right) {
+    super(new LongWritable(left), new LongWritable(right));
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/PairWritable.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/PairWritable.java 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/PairWritable.java
new file mode 100644
index 0000000..62f294f
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/PairWritable.java
@@ -0,0 +1,113 @@
+/*
+ * 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 org.apache.giraph.writable.tuple;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.hadoop.io.Writable;
+
+/**
+ * Pair Writable class, that knows types upfront and can deserialize itself.
+ *
+ * PairWritable knows types, as instances are passed through constructor, and
+ * are references are immutable (values themselves are mutable).
+ *
+ * Child classes specify no-arg constructor that passes concrete types in.
+ *
+ * Extends Pair, not ImmutablePair, since later class is final. Code is
+ * copied from it.
+ *
+ * @param <L> Type of the left element
+ * @param <R> Type of the right element
+ */
+public class PairWritable<L extends Writable, R extends Writable>
+    extends Pair<L, R> implements Writable {
+  /** Left object */
+  private final L left;
+  /** Right object */
+  private final R right;
+
+  /**
+   * Create a new pair instance.
+   *
+   * @param left  the left value
+   * @param right  the right value
+   */
+  public PairWritable(L left, R right) {
+    this.left = left;
+    this.right = right;
+  }
+
+  /**
+   * <p>
+   * Obtains an immutable pair of from two objects inferring
+   * the generic types.</p>
+   *
+   * <p>This factory allows the pair to be created using inference to
+   * obtain the generic types.</p>
+   *
+   * @param <L> the left element type
+   * @param <R> the right element type
+   * @param left  the left element, may be null
+   * @param right  the right element, may be null
+   * @return a pair formed from the two parameters, not null
+   */
+  public static <L extends Writable, R extends Writable>
+  PairWritable<L, R> of(L left, R right) {
+    return new PairWritable<L, R>(left, right);
+  }
+
+  @Override
+  public final L getLeft() {
+    return left;
+  }
+
+  @Override
+  public final R getRight() {
+    return right;
+  }
+
+  /**
+   * <p>Throws {@code UnsupportedOperationException}.</p>
+   *
+   * <p>This pair is immutable, so this operation is not supported.</p>
+   *
+   * @param value  the value to set
+   * @return never
+   * @throws UnsupportedOperationException as this operation is not supported
+   */
+  @Override
+  public final R setValue(R value) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public final void write(DataOutput out) throws IOException {
+    left.write(out);
+    right.write(out);
+  }
+
+  @Override
+  public final void readFields(DataInput in) throws IOException {
+    left.readFields(in);
+    right.readFields(in);
+  }
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/giraph-core/src/main/java/org/apache/giraph/writable/tuple/package-info.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/writable/tuple/package-info.java 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/package-info.java
new file mode 100644
index 0000000..e44efd8
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/writable/tuple/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+/**
+ * Writable tuple utilities
+ */
+package org.apache.giraph.writable.tuple;

http://git-wip-us.apache.org/repos/asf/giraph/blob/77f8a075/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index eb4f2f7..ceca219 100644
--- a/pom.xml
+++ b/pom.xml
@@ -293,6 +293,7 @@ under the License.
     <dep.commons-logging.version>1.1.1</dep.commons-logging.version>
     <dep.commons-io.version>2.1</dep.commons-io.version>
     <dep.commons-net.version>3.1</dep.commons-net.version>
+    <dep.commons-lang3.version>3.4</dep.commons-lang3.version>
     <dep.facebook-swift.version>0.14.0</dep.facebook-swift.version>
     <dep.fasterxml-jackson.version>2.1.2</dep.fasterxml-jackson.version>
     <dep.fastutil.version>6.5.4</dep.fastutil.version>
@@ -1618,6 +1619,11 @@ under the License.
         <version>${dep.commons-logging.version}</version>
       </dependency>
       <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-lang3</artifactId>
+        <version>${dep.commons-lang3.version}</version>
+      </dependency>
+      <dependency>
         <groupId>com.facebook.thirdparty.yourkit-api</groupId>
         <artifactId>yjp-controller-api-redist</artifactId>
         <version>${dep.yourkit-api.version}</version>

Reply via email to