Repository: giraph
Updated Branches:
  refs/heads/trunk e4aa99d3f -> a927450aa


http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Int2ObjFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Int2ObjFunction.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Int2ObjFunction.java
new file mode 100644
index 0000000..973c41b
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Int2ObjFunction.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.function.primitive;
+
+import java.io.Serializable;
+
+/**
+ * Primitive specialization of Function:
+ * (int) -> T
+ *
+ * @param <T> Result type
+ */
+public interface Int2ObjFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * The returned object may or may not be a new instance,
+   * depending on the implementation.
+   *
+   * @param input input
+   * @return result
+   */
+  T apply(int input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntConsumer.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntConsumer.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntConsumer.java
new file mode 100644
index 0000000..f47ab74
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntConsumer.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (int) -> void
+ */
+public interface IntConsumer extends Serializable {
+  /**
+   * Applies this function to {@code input}
+   *
+   * @param input input
+   */
+  void apply(int input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntSupplier.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntSupplier.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntSupplier.java
new file mode 100644
index 0000000..c71b6d6
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/IntSupplier.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:
+ * () -> int
+ */
+public interface IntSupplier extends Serializable {
+  /**
+   * Retrieves an int value.
+   *
+   * @return result
+   */
+  int get();
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/LongConsumer.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/LongConsumer.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/LongConsumer.java
new file mode 100644
index 0000000..6ad9f80
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/LongConsumer.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (long) -> void
+ */
+public interface LongConsumer extends Serializable {
+  /**
+   * Applies this function to {@code input}
+   *
+   * @param input input
+   */
+  void apply(long input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2BooleanFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2BooleanFunction.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2BooleanFunction.java
new file mode 100644
index 0000000..0e39fca
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2BooleanFunction.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.function.primitive;
+
+import java.io.Serializable;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (T) -> boolean
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2BooleanFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * @param input input
+   * @return result
+   */
+  boolean apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2ByteFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2ByteFunction.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2ByteFunction.java
new file mode 100644
index 0000000..88d1ed3
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2ByteFunction.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.function.primitive;
+
+import java.io.Serializable;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (T) -> byte
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2ByteFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * @param input input
+   * @return result
+   */
+  byte apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.java
new file mode 100644
index 0000000..11b0fdf
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2DoubleFunction.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.function.primitive;
+
+import java.io.Serializable;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (T) -> double
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2DoubleFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * @param input input
+   * @return result
+   */
+  double apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.java
new file mode 100644
index 0000000..01fb8bc
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2FloatFunction.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.function.primitive;
+
+import java.io.Serializable;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (T) -> float
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2FloatFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * @param input input
+   * @return result
+   */
+  float apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2IntFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2IntFunction.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2IntFunction.java
new file mode 100644
index 0000000..628c45e
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2IntFunction.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.function.primitive;
+
+import java.io.Serializable;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (T) -> int
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2IntFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * @param input input
+   * @return result
+   */
+  int apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.java
new file mode 100644
index 0000000..4933523
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/Obj2LongFunction.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.function.primitive;
+
+import java.io.Serializable;
+
+// AUTO-GENERATED class via class:
+// org.apache.giraph.generate.GeneratePrimitiveClasses
+
+/**
+ * Primitive specialization of Function:
+ * (T) -> long
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2LongFunction<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * @param input input
+   * @return result
+   */
+  long apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/PrimitiveRefs.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/PrimitiveRefs.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/PrimitiveRefs.java
new file mode 100644
index 0000000..c83676f
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/PrimitiveRefs.java
@@ -0,0 +1,137 @@
+/*
+ * 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;
+
+/**
+ * Convenience classes holding primitive values - a reference
+ * to a mutable value.
+ * For use when lambdas need to mutate capturing primitive local variable.
+ * (since lambdas cannot capture and modify local variables)
+ */
+public interface PrimitiveRefs {
+
+  // Have public field for convenience, since classes have no logic inside
+  // CHECKSTYLE: stop VisibilityModifierCheck
+
+  /**
+   * Convenience class holding int value,
+   * for use when lambdas need to mutate capturing int local variable.
+   */
+  public class IntRef {
+    /** value */
+    public int value;
+
+    /**
+     * Constructor
+     * @param value initial value
+     */
+    public IntRef(int value) {
+      this.value = value;
+    }
+  }
+
+  /**
+   * Convenience class holding long value,
+   * for use when lambdas need to mutate capturing long local variable.
+   */
+  public class LongRef {
+    /** value */
+    public long value;
+
+    /**
+     * Constructor
+     * @param value initial value
+     */
+    public LongRef(long value) {
+      this.value = value;
+    }
+  }
+
+  /**
+   * Convenience class holding int value,
+   * for use when lambdas need to mutate capturing int local variable.
+   */
+  public class ShortRef {
+    /** value */
+    public short value;
+
+    /**
+     * Constructor
+     * @param value initial value
+     */
+    public ShortRef(short value) {
+      this.value = value;
+    }
+  }
+
+
+  /**
+   * Convenience class holding float value,
+   * for use when lambdas need to mutate capturing float local variable.
+   */
+  public class FloatRef {
+    /** value */
+    public float value;
+
+    /**
+     * Constructor
+     * @param value initial value
+     */
+    public FloatRef(float value) {
+      this.value = value;
+    }
+  }
+
+  /**
+   * Convenience class holding double value,
+   * for use when lambdas need to mutate capturing double local variable.
+   */
+  public class DoubleRef {
+    /** value */
+    public double value;
+
+    /**
+     * Constructor
+     * @param value initial value
+     */
+    public DoubleRef(double value) {
+      this.value = value;
+    }
+  }
+
+  /**
+   * Convenience class holding object values,
+   * for use when lambdas need to mutate capturing object local variable.
+   *
+   * <O> object
+   */
+  public class ObjRef<O> {
+    /** value */
+    public O value;
+
+    /**
+     * Constructor
+     * @param value initial value
+     */
+    public ObjRef(O value) {
+      this.value = value;
+    }
+  }
+
+  // CHECKSTYLE: resume VisibilityModifierCheck
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/primitive/package-info.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/primitive/package-info.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/package-info.java
new file mode 100644
index 0000000..fdf40ff
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/primitive/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+/**
+ * Primitive specializations of interfaces from org.apache.giraph.function
+ * package.
+ */
+package org.apache.giraph.function.primitive;

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/vertex/ConsumerWithVertex.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/vertex/ConsumerWithVertex.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/ConsumerWithVertex.java
new file mode 100644
index 0000000..3b6ba0e
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/ConsumerWithVertex.java
@@ -0,0 +1,51 @@
+/*
+ * 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.vertex;
+
+import java.io.Serializable;
+
+import org.apache.giraph.function.PairConsumer;
+import org.apache.giraph.graph.Vertex;
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
+
+
+/**
+ * Function:
+ * (vertex, T) -> void
+ *
+ * A class that can consume objects of a single type, when given a vertex.
+ *
+ * @param <I> Vertex id type
+ * @param <V> Vertex value type
+ * @param <E> Edge value type
+ * @param <T> Argument type
+ */
+@SuppressWarnings("rawtypes")
+public interface ConsumerWithVertex<I extends WritableComparable,
+    V extends Writable, E extends Writable, T>
+    extends PairConsumer<Vertex<I, V, E>, T>, Serializable  {
+  /**
+   * Applies this function to {@code vertex} and {@code input}
+   *
+   * @param vertex Vertex
+   * @param value Value
+   */
+  @Override
+  void apply(Vertex<I, V, E> vertex, T value);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/vertex/FunctionWithVertex.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/vertex/FunctionWithVertex.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/FunctionWithVertex.java
new file mode 100644
index 0000000..e7552c9
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/FunctionWithVertex.java
@@ -0,0 +1,56 @@
+/*
+ * 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.vertex;
+
+import java.io.Serializable;
+
+import org.apache.giraph.function.PairFunction;
+import org.apache.giraph.graph.Vertex;
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
+
+/**
+ * Function:
+ * (vertex, F) -> T
+ *
+ * Determines an output value based on a vertex and an input value.
+ *
+ * @param <I> Vertex id type
+ * @param <V> Vertex value type
+ * @param <E> Edge value type
+ * @param <F> Argument type
+ * @param <T> Result type
+ */
+@SuppressWarnings("rawtypes")
+public interface FunctionWithVertex<I extends WritableComparable,
+    V extends Writable, E extends Writable, F, T>
+    extends PairFunction<Vertex<I, V, E>, F, T>, Serializable {
+  /**
+   * Returns the result of applying this function to given
+   * {@code vertex} and {@code input}.
+   *
+   * The returned object may or may not be a new instance,
+   * depending on the implementation.
+   *
+   * @param vertex Vertex
+   * @param input Input
+   * @return result
+   */
+  @Override
+  T apply(Vertex<I, V, E> vertex, F input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/vertex/SupplierFromVertex.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/vertex/SupplierFromVertex.java
 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/SupplierFromVertex.java
new file mode 100644
index 0000000..bf2a4b1
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/SupplierFromVertex.java
@@ -0,0 +1,52 @@
+/*
+ * 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.vertex;
+
+import java.io.Serializable;
+
+import org.apache.giraph.graph.Vertex;
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
+
+/**
+ * Function:
+ * (vertex) -> T
+ *
+ * A class that can supply objects of a single type, when given a vertex.
+ *
+ * (doesn't extend Function<Vertex<I, V, E>, T>, because of different
+ * method names)
+ *
+ * @param <I> Vertex id type
+ * @param <V> Vertex value type
+ * @param <E> Edge value type
+ * @param <T> Result type
+ */
+@SuppressWarnings("rawtypes")
+public interface SupplierFromVertex<I extends WritableComparable,
+    V extends Writable, E extends Writable, T> extends Serializable {
+  /**
+   * Retrieves an instance of the appropriate type, given a vertex.
+   * The returned object may or may not be a new instance,
+   * depending on the implementation.
+   *
+   * @param vertex Vertex
+   * @return result
+   */
+  T get(Vertex<I, V, E> vertex);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/main/java/org/apache/giraph/function/vertex/package-info.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/main/java/org/apache/giraph/function/vertex/package-info.java 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/package-info.java
new file mode 100644
index 0000000..bd5b019
--- /dev/null
+++ 
b/giraph-core/src/main/java/org/apache/giraph/function/vertex/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 for interfaces representing functions additionally
+ * performed on vertex values.
+ */
+package org.apache.giraph.function.vertex;

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java
----------------------------------------------------------------------
diff --git 
a/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java
 
b/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java
new file mode 100644
index 0000000..95896f6
--- /dev/null
+++ 
b/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java
@@ -0,0 +1,185 @@
+/*
+ * 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.generate;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import freemarker.core.ParseException;
+import freemarker.template.Configuration;
+import freemarker.template.MalformedTemplateNameException;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateExceptionHandler;
+import freemarker.template.TemplateNotFoundException;
+
+/**
+ * <p>Code generation utility that generates set of classes from a template 
files.
+ * Templates are found in giraph-core/template/ folder.
+ * If you want to add new generation, look at the main function, and add a call
+ * to appropriate generate* function.</p>
+ *
+ * <p>Templates are using freemarker template format, which given
+ * template file and map of String->Object replacements generates
+ * new file.</p>
+ * Main rules:
+ * <ul>
+ * <li><code>${something}</code> gets replaced with value of 
<code>map.get("something")</code></li>
+ * <li><code>${obj.method}</code> gets replaced with value of 
<code>map.get("obj").getMethod()</code></li>
+ * </ul>
+ * More description about template format can be found at:
+ * <a 
href="http://freemarker.org/docs/dgui_quickstart_template.html";>tutorial</a>
+ */
+public class GeneratePrimitiveClasses {
+  // No Short since there is no ShortWritable for some reason
+  public static enum PrimitiveType {
+    BOOLEAN("Boolean", false, false, false),
+    BYTE("Byte", true, false, false),
+    INT("Int", "Integer", true, true, false),
+    LONG("Long", true, true, false),
+    FLOAT("Float", true, false, true),
+    DOUBLE("Double", true, false, true);
+
+    private final String name;
+    private final String boxed;
+    private final boolean numeric;
+    private final boolean id;
+    private final boolean floating;
+
+    private PrimitiveType(String name, String boxed, boolean numeric, boolean 
id, boolean floating) {
+      this.name = name;
+      this.boxed = boxed;
+      this.numeric = numeric;
+      this.id = id;
+      this.floating = floating;
+    }
+
+    private PrimitiveType(String name, boolean numeric, boolean id, boolean 
floating) {
+      this(name, name, numeric, id, floating);
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public String getCamel() {
+      return name;
+    }
+
+    public String getLower() {
+      return name.toLowerCase();
+    }
+
+    public String getBoxed() {
+      return boxed;
+    }
+
+    public boolean isNumeric() {
+      return numeric;
+    }
+
+    public boolean isId() {
+      return id;
+    }
+
+    public boolean isFloating() {
+      return floating;
+    }
+  }
+
+  public static void main(String[] args) throws Exception {
+    /* Create and adjust the configuration singleton */
+    Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
+    cfg.setDirectoryForTemplateLoading(new File("templates"));
+    cfg.setDefaultEncoding("UTF-8");
+    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
+
+    generateForAll(
+        cfg,
+        EnumSet.allOf(PrimitiveType.class),
+        "TypeConsumer.java",
+        "src/main/java/org/apache/giraph/function/primitive/%sConsumer.java");
+
+    generateForAll(
+        cfg,
+        EnumSet.allOf(PrimitiveType.class),
+        "Obj2TypeFunction.java",
+        
"src/main/java/org/apache/giraph/function/primitive/Obj2%sFunction.java");
+
+//    generateForAll(
+//        cfg,
+//        EnumSet.allOf(PrimitiveType.class),
+//        "TypeTypeOps.java",
+//        "src/main/java/org/apache/giraph/types/ops/%sTypeOps.java");
+//
+//    generateForAll(
+//        cfg,
+//        EnumSet.allOf(PrimitiveType.class),
+//        "WTypeArrayList.java",
+//        
"src/main/java/org/apache/giraph/types/ops/collections/array/W%sArrayList.java");
+
+    EnumSet<PrimitiveType> ids = EnumSet.noneOf(PrimitiveType.class);
+    for (PrimitiveType type : PrimitiveType.values()) {
+      if (type.isId()) {
+        ids.add(type);
+      }
+    }
+  }
+
+  /**
+   * Generate a set of files from a template, one for each type in the passed 
set,
+   * where added entry for "type" to that object is added, on top of default 
entries.
+   */
+  private static void generateForAll(Configuration cfg, EnumSet<PrimitiveType> 
types,
+      String template, String outputPattern) throws TemplateNotFoundException, 
MalformedTemplateNameException, ParseException, FileNotFoundException, 
IOException, TemplateException {
+    for (PrimitiveType type : types) {
+      Map<String, Object> props = defaultMap();
+      props.put("type", type);
+      generateAndWrite(cfg, props,
+          template,
+          String.format(outputPattern, type.getCamel()));
+    }
+  }
+
+  /** Generate a single file from a template, replacing mappings from given 
properties */
+  private static void generateAndWrite(Configuration cfg, Map<String, Object> 
props,
+      String template, String outputFile)
+          throws TemplateNotFoundException, MalformedTemplateNameException, 
ParseException,
+          IOException, FileNotFoundException, TemplateException {
+    Template temp = cfg.getTemplate(template);
+    Writer out = new OutputStreamWriter(new FileOutputStream(outputFile));
+    temp.process(props, out);
+    out.close();
+  }
+
+  public static Map<String, Object> defaultMap() {
+    Map<String, Object> props = new HashMap<>();
+    props.put("generated_message", GENERATED_MESSAGE);
+    return props;
+  }
+
+  private static final String GENERATED_MESSAGE =
+      "// AUTO-GENERATED class via class:\n// " + 
GeneratePrimitiveClasses.class.getName();
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/templates/Obj2TypeFunction.java
----------------------------------------------------------------------
diff --git a/giraph-core/templates/Obj2TypeFunction.java 
b/giraph-core/templates/Obj2TypeFunction.java
new file mode 100644
index 0000000..b256283
--- /dev/null
+++ b/giraph-core/templates/Obj2TypeFunction.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+${generated_message}
+
+/**
+ * Primitive specialization of Function:
+ * (T) -> ${type.lower}
+ *
+ * @param <T> Argument type
+ */
+public interface Obj2${type.camel}Function<T> extends Serializable {
+  /**
+   * Returns the result of applying this function to given {@code input}.
+   *
+   * @param input input
+   * @return result
+   */
+  ${type.lower} apply(T input);
+}

http://git-wip-us.apache.org/repos/asf/giraph/blob/a927450a/giraph-core/templates/TypeConsumer.java
----------------------------------------------------------------------
diff --git a/giraph-core/templates/TypeConsumer.java 
b/giraph-core/templates/TypeConsumer.java
new file mode 100644
index 0000000..9bea280
--- /dev/null
+++ b/giraph-core/templates/TypeConsumer.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+${generated_message}
+
+/**
+ * Primitive specialization of Function:
+ * (${type.lower}) -> void
+ */
+public interface ${type.camel}Consumer extends Serializable {
+  /**
+   * Applies this function to {@code input}
+   *
+   * @param input input
+   */
+  void apply(${type.lower} input);
+}

Reply via email to