View Javadoc
1   /*
2    * Created on Aug 5, 2007
3    *
4    * Copyright (c) 2007, 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.util;
13  
14  import java.util.Map;
15  
16  
17  /**
18   * A <code>SettableTransformer</code> that operates on an underlying <code>Map</code> instance.
19   * Similar to <code>MapTransformer</code>.
20   * 
21   * @author Joshua O'Madadhain
22   */
23  public class MapSettableTransformer<I, O> implements SettableTransformer<I, O>
24  {
25      protected Map<I,O> map;
26      
27      /**
28       * Creates an instance based on <code>m</code>.
29       * @param m the map on which this instance is based
30       */
31      public MapSettableTransformer(Map<I,O> m)
32      {
33          this.map = m;
34      }
35  
36      public O apply(I input)
37      {
38          return map.get(input);
39      }
40  
41      public void set(I input, O output)
42      {
43          map.put(input, output);
44      }
45  }