1 /*
2 * Created on Jul 18, 2008
3 *
4 * Copyright (c) 2008, The JUNG Authors
5 *
6 * All rights reserved.
7 *
8 * This software is open-source under the BSD license; see either
9 * "license.txt" or
10 * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
11 */
12 package edu.uci.ics.jung.algorithms.scoring.util;
13
14 import com.google.common.base.Function;
15
16 import edu.uci.ics.jung.algorithms.scoring.VertexScorer;
17
18 /**
19 * A Function convenience wrapper around VertexScorer.
20 */
21 public class VertexScoreTransformer<V, S> implements Function<V, S>
22 {
23 /**
24 * The VertexScorer instance that provides the values returned by <code>transform</code>.
25 */
26 protected VertexScorer<V,S> vs;
27
28 /**
29 * Creates an instance based on the specified VertexScorer.
30 * @param vs the VertexScorer which will retrieve the score for each vertex
31 */
32 public VertexScoreTransformer(VertexScorer<V,S> vs)
33 {
34 this.vs = vs;
35 }
36
37 /**
38 * @param v the vertex whose score is being returned
39 * @return the score for this vertex.
40 */
41 public S apply(V v)
42 {
43 return vs.getVertexScore(v);
44 }
45
46 }