1 /*
2 * Created on Jul 11, 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 /**
17 * A {@code Transformer<VEPair,Number} that delegates its operation to a
18 * {@code Transformer<E,Number>}. Mainly useful for technical reasons inside
19 * AbstractIterativeScorer; in essence it allows the edge weight instance
20 * variable to be of type <code>VEPair,W</code> even if the edge weight
21 * <code>Transformer</code> only operates on edges.
22 */
23 public class DelegateToEdgeTransformer<V,E> implements
24 Function<VEPair<V,E>,Number>
25 {
26 /**
27 * The Function to which this instance delegates its function.
28 */
29 protected Function<? super E,? extends Number> delegate;
30
31 /**
32 * Creates an instance with the specified delegate Function.
33 * @param delegate the Function to which this instance will delegate
34 */
35 public DelegateToEdgeTransformer(Function<? super E,? extends Number> delegate)
36 {
37 this.delegate = delegate;
38 }
39
40 /**
41 * @see Function#apply(Object)
42 */
43 public Number apply(VEPair<V,E> arg0)
44 {
45 return delegate.apply(arg0.getE());
46 }
47
48 }