01: /*
02: * This file or a portion of this file is licensed under the terms of
03: * the Globus Toolkit Public License, found in file GTPL, or at
04: * http://www.globus.org/toolkit/download/license.html. This notice must
05: * appear in redistributions of this file, with or without modification.
06: *
07: * Redistributions of this Software, with or without modification, must
08: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
09: * some other similar material which is provided with the Software (if
10: * any).
11: *
12: * Copyright 1999-2004 University of Chicago and The University of
13: * Southern California. All rights reserved.
14: */
15: package org.griphyn.cPlanner.selector.transformation;
16:
17: import org.griphyn.cPlanner.selector.TransformationSelector;
18:
19: import org.griphyn.cPlanner.common.LogManager;
20:
21: import java.util.ArrayList;
22: import java.util.List;
23:
24: /**
25: * This implemenation of the TCSelector selects a random
26: * TransformationCatalogEntry from a List of entries.
27: *
28: * @author Gaurang Mehta
29: * @version $Revision: 50 $
30: */
31: public class Random extends TransformationSelector {
32: public Random() {
33: }
34:
35: /**
36: * This method randomly selects one of the records from numerous valid
37: * Transformation Catalog Entries returned by the TCMapper.
38: *
39: * @param tcentries List TransformationCatalogEntry objects returned by the TCMapper.
40: * @return TransformationCatalogEntry Single TransformationCatalogEntry object
41: */
42: public List getTCEntry(List tcentries) {
43: int no_of_entries = tcentries.size();
44: int recSelected = new Double(Math.random() * no_of_entries)
45: .intValue();
46: String message = "Random TC Record selected is "
47: + (recSelected + 1) + " amongst " + no_of_entries
48: + " possible";
49: mLogger.log(message, LogManager.DEBUG_MESSAGE_LEVEL);
50: List result = new ArrayList(1);
51: result.add(tcentries.get(recSelected));
52: return result;
53: }
54:
55: }
|