Fix checkstyle warnings in netconf-cli
[controller.git] / third-party / net.sf.jung2 / src / main / java / edu / uci / ics / jung / algorithms / layout / util / RandomLocationTransformer.java
1 /*
2  * Created on Jul 19, 2005
3  *
4  * Copyright (c) 2005, the JUNG Project and the Regents of the University 
5  * of California
6  * All rights reserved.
7  *
8  * This software is open-source under the BSD license; see either
9  * "license.txt" or
10  * http://jung.sourceforge.net/license.txt for a description.
11  */
12 package edu.uci.ics.jung.algorithms.layout.util;
13
14 import java.awt.Dimension;
15 import java.awt.geom.Point2D;
16 import java.util.Date;
17 import java.util.Random;
18
19 import org.apache.commons.collections15.Transformer;
20
21 /**
22  * Transforms the input type into a random location within
23  * the bounds of the Dimension property.
24  * This is used as the backing Transformer for the LazyMap
25  * for many Layouts,
26  * and provides a random location for unmapped vertices
27  * the first time they are accessed.
28  * 
29  * @author Tom Nelson
30  *
31  * @param <V>
32  */
33 public class RandomLocationTransformer<V> implements Transformer<V,Point2D> {
34
35         Dimension d;
36         Random random;
37     
38     /**
39      * Creates an instance with the specified size which uses the current time 
40      * as the random seed.
41      */
42     public RandomLocationTransformer(Dimension d) {
43         this(d, new Date().getTime());
44     }
45     
46     /**
47      * Creates an instance with the specified dimension and random seed.
48      * @param d
49      * @param seed
50      */
51     public RandomLocationTransformer(final Dimension d, long seed) {
52         this.d = d;
53         this.random = new Random(seed);
54     }
55     
56     public Point2D transform(V v) {
57         return new Point2D.Double(random.nextDouble() * d.width, random.nextDouble() * d.height);
58     }
59 }