// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/GraphMemory.java
// public interface GraphMemory {
// 
//     public <R> R get(final String key);
// 
//     public void setIfAbsent(String key, Object value);
// 
//     public long increment(String key, long delta);
// 
//     public long decrement(String key, long delta);
// 
//     public int getIteration();
// 
//     public long getRuntime();
// 
//     public boolean isInitialIteration();
// 
//     /*public void min(String key, double value);
// 
//     public void max(String key, double value);
// 
//     public void avg(String key, double value);
// 
//     public <V> void update(String key, Function<V, V> update, V defaultValue);*/
// 
//     // public Map<String, Object> getCurrentState();
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/VertexProgram.java
// public interface VertexProgram extends Serializable {
// 
//     public enum KeyType {
//         VARIABLE,
//         CONSTANT
//     }
// 
//     /**
//      * The method is called at the beginning of the computation.
//      * The method is global to the GraphComputer and as such, is not called for each vertex.
//      *
//      * @param graphMemory The global GraphMemory of the GraphComputer
//      */
//     public void setup(GraphMemory graphMemory);
// 
//     /**
//      * This method denotes the main body of computation.
//      *
//      * @param vertex      the vertex to execute the VertexProgram on
//      * @param graphMemory the shared state between all vertices in the computation
//      */
//     public void execute(Vertex vertex, GraphMemory graphMemory);
// 
//     /**
//      * The method is called at the end of a round to determine if the computation is complete.
//      * The method is global to the GraphComputer and as such, is not called for each vertex.
//      *
//      * @param graphMemory The global GraphMemory of the GraphComputer
//      * @return whether or not to halt the computation
//      */
//     public boolean terminate(GraphMemory graphMemory);
// 
//     public Map<String, KeyType> getComputeKeys();
// 
// 
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/util/VertexQueryBuilder.java
// public class VertexQueryBuilder extends DefaultVertexQuery {
// 
//     public VertexQueryBuilder() {
//         super(null);
//     }
// 
//     public VertexQueryBuilder has(final String key) {
//         super.has(key);
//         return this;
//     }
// 
//     public VertexQueryBuilder hasNot(final String key) {
//         super.hasNot(key);
//         return this;
//     }
// 
//     public VertexQueryBuilder has(final String key, final Object value) {
//         super.has(key, value);
//         return this;
//     }
// 
//     public VertexQueryBuilder hasNot(final String key, final Object value) {
//         super.hasNot(key, value);
//         return this;
//     }
// 
//     @Deprecated
//     public <T extends Comparable<T>> VertexQueryBuilder has(final String key, final T value, final Query.Compare compare) {
//         return this.has(key, compare, value);
//     }
// 
//     public VertexQueryBuilder has(final String key, final Predicate compare, final Object value) {
//         super.has(key, compare, value);
//         return this;
//     }
// 
//     public <T extends Comparable<?>> VertexQueryBuilder interval(final String key, final T startValue, final T endValue) {
//         super.interval(key, startValue, endValue);
//         return this;
//     }
// 
//     public VertexQueryBuilder direction(final Direction direction) {
//         super.direction(direction);
//         return this;
//     }
// 
//     public VertexQueryBuilder labels(final String... labels) {
//         super.labels(labels);
//         return this;
//     }
// 
//     public VertexQueryBuilder limit(final int limit) {
//         super.limit(limit);
//         return this;
//     }
// 
//     public Iterable<Edge> edges() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Iterable<Vertex> vertices() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Object vertexIds() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public long count() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public VertexQuery build(final Vertex vertex) {
//         VertexQuery query = vertex.query();
//         for (final HasContainer hasContainer : this.hasContainers) {
//             query = query.has(hasContainer.key, hasContainer.predicate, hasContainer.value);
//         }
//         return query.limit(this.limit).labels(this.labels).direction(this.direction);
//     }
// }


import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.furnace.algorithms.vertexcentric.GraphMemory;
import com.tinkerpop.furnace.algorithms.vertexcentric.VertexProgram;
import com.tinkerpop.furnace.util.VertexQueryBuilder;
import java.util.HashMap;
import java.util.Map;
package com.tinkerpop.furnace.algorithms.vertexcentric.programs.ranking;



/**
 * @author Marko A. Rodriguez (http://markorodriguez.com)
 */
public class DegreeRankProgram implements VertexProgram {

    protected VertexQueryBuilder degreeQuery = new VertexQueryBuilder().direction(Direction.IN);
    private static final Map<String, KeyType> computeKeys = new HashMap<String, KeyType>();

    public static final String DEGREE = DegreeRankProgram.class.getName() + ".degree";

    static {
        computeKeys.put(DEGREE, KeyType.CONSTANT);
    }


    protected DegreeRankProgram() {

    }

    public Map<String, KeyType> getComputeKeys() {
        return computeKeys;
    }

    public void setup(final GraphMemory graphMemory) {

    }

    public void execute(final Vertex vertex, final GraphMemory graphMemory) {
        long degree = degreeQuery.build(vertex).count();
        vertex.setProperty(DEGREE, degree);
    }

    public boolean terminate(final GraphMemory graphMemory) {
        return true;
    }

// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/GraphMemory.java
// public interface GraphMemory {
// 
//     public <R> R get(final String key);
// 
//     public void setIfAbsent(String key, Object value);
// 
//     public long increment(String key, long delta);
// 
//     public long decrement(String key, long delta);
// 
//     public int getIteration();
// 
//     public long getRuntime();
// 
//     public boolean isInitialIteration();
// 
//     /*public void min(String key, double value);
// 
//     public void max(String key, double value);
// 
//     public void avg(String key, double value);
// 
//     public <V> void update(String key, Function<V, V> update, V defaultValue);*/
// 
//     // public Map<String, Object> getCurrentState();
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/VertexProgram.java
// public interface VertexProgram extends Serializable {
// 
//     public enum KeyType {
//         VARIABLE,
//         CONSTANT
//     }
// 
//     /**
//      * The method is called at the beginning of the computation.
//      * The method is global to the GraphComputer and as such, is not called for each vertex.
//      *
//      * @param graphMemory The global GraphMemory of the GraphComputer
//      */
//     public void setup(GraphMemory graphMemory);
// 
//     /**
//      * This method denotes the main body of computation.
//      *
//      * @param vertex      the vertex to execute the VertexProgram on
//      * @param graphMemory the shared state between all vertices in the computation
//      */
//     public void execute(Vertex vertex, GraphMemory graphMemory);
// 
//     /**
//      * The method is called at the end of a round to determine if the computation is complete.
//      * The method is global to the GraphComputer and as such, is not called for each vertex.
//      *
//      * @param graphMemory The global GraphMemory of the GraphComputer
//      * @return whether or not to halt the computation
//      */
//     public boolean terminate(GraphMemory graphMemory);
// 
//     public Map<String, KeyType> getComputeKeys();
// 
// 
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/util/VertexQueryBuilder.java
// public class VertexQueryBuilder extends DefaultVertexQuery {
// 
//     public VertexQueryBuilder() {
//         super(null);
//     }
// 
//     public VertexQueryBuilder has(final String key) {
//         super.has(key);
//         return this;
//     }
// 
//     public VertexQueryBuilder hasNot(final String key) {
//         super.hasNot(key);
//         return this;
//     }
// 
//     public VertexQueryBuilder has(final String key, final Object value) {
//         super.has(key, value);
//         return this;
//     }
// 
//     public VertexQueryBuilder hasNot(final String key, final Object value) {
//         super.hasNot(key, value);
//         return this;
//     }
// 
//     @Deprecated
//     public <T extends Comparable<T>> VertexQueryBuilder has(final String key, final T value, final Query.Compare compare) {
//         return this.has(key, compare, value);
//     }
// 
//     public VertexQueryBuilder has(final String key, final Predicate compare, final Object value) {
//         super.has(key, compare, value);
//         return this;
//     }
// 
//     public <T extends Comparable<?>> VertexQueryBuilder interval(final String key, final T startValue, final T endValue) {
//         super.interval(key, startValue, endValue);
//         return this;
//     }
// 
//     public VertexQueryBuilder direction(final Direction direction) {
//         super.direction(direction);
//         return this;
//     }
// 
//     public VertexQueryBuilder labels(final String... labels) {
//         super.labels(labels);
//         return this;
//     }
// 
//     public VertexQueryBuilder limit(final int limit) {
//         super.limit(limit);
//         return this;
//     }
// 
//     public Iterable<Edge> edges() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Iterable<Vertex> vertices() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public Object vertexIds() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public long count() {
//         throw new UnsupportedOperationException();
//     }
// 
//     public VertexQuery build(final Vertex vertex) {
//         VertexQuery query = vertex.query();
//         for (final HasContainer hasContainer : this.hasContainers) {
//             query = query.has(hasContainer.key, hasContainer.predicate, hasContainer.value);
//         }
//         return query.limit(this.limit).labels(this.labels).direction(this.direction);
//     }
// }


// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/programs/ranking/DegreeRankProgram.java
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.furnace.algorithms.vertexcentric.GraphMemory;
import com.tinkerpop.furnace.algorithms.vertexcentric.VertexProgram;
import com.tinkerpop.furnace.util.VertexQueryBuilder;
import java.util.HashMap;
import java.util.Map;

package com.tinkerpop.furnace.algorithms.vertexcentric.programs.ranking;



/**
 * @author Marko A. Rodriguez (http://markorodriguez.com)
 */
public class DegreeRankProgram implements VertexProgram {

    protected VertexQueryBuilder degreeQuery = new VertexQueryBuilder().direction(Direction.IN);
    private static final Map<String, KeyType> computeKeys = new HashMap<String, KeyType>();

    public static final String DEGREE = DegreeRankProgram.class.getName() + ".degree";

    static {
        computeKeys.put(DEGREE, KeyType.CONSTANT);
    }


    protected DegreeRankProgram() {

    }

    public Map<String, KeyType> getComputeKeys() {
        return computeKeys;
    }

    public void setup(final GraphMemory graphMemory) {

    }

    public void execute(final Vertex vertex, final GraphMemory graphMemory) {
        long degree = degreeQuery.build(vertex).count();
        vertex.setProperty(DEGREE, degree);
    }

    public boolean terminate(final GraphMemory graphMemory) {
        return true;
    }

    public static Builder create() {