Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill another out of date script
[simgrid.git] / contrib / psg / src / peersim / vector / VectCopy.java
1 /*
2  * Copyright (c) 2003-2005 The BISON Project
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  */
18
19 package peersim.vector;
20
21 import peersim.core.*;
22 import peersim.dynamics.*;
23
24 /**
25  * Sets values in a protocol vector by copying the values of another 
26  * protocol vector.
27  * The source is defined by {@value #PAR_SOURCE},
28  * and getter method {@value peersim.vector.VectControl#PAR_GETTER}.
29  * <p>
30  * This dynamics class can copy any primitive field in the source
31  * protocol to any primitive field in the destination protocol,
32  * provided that the former field is associated with a getter method,
33  * while the latter is associated with a setter method.
34  * @see VectControl
35  * @see peersim.vector
36  */
37 public class VectCopy extends VectControl implements  NodeInitializer {
38
39
40 //--------------------------------------------------------------------------
41 //Parameters
42 //--------------------------------------------------------------------------
43
44 /**
45  * The identifier of the protocol to be copied.
46  * The vector values are copied from this vector.
47  * @config
48  */
49 private static final String PAR_SOURCE = "source";
50
51
52 // --------------------------------------------------------------------------
53 // Variables
54 // --------------------------------------------------------------------------
55
56 /** Source getter */
57 private final Getter source;
58
59 //--------------------------------------------------------------------------
60 //Initialization
61 //--------------------------------------------------------------------------
62
63 /**
64  * Standard constructor that reads the configuration parameters.
65  * Invoked by the simulation engine.
66  * @param prefix the configuration prefix for this class
67  */
68 public VectCopy(String prefix)
69 {
70         super(prefix);
71         source = new Getter(prefix,PAR_SOURCE,PAR_GETTER);
72 }
73
74 //--------------------------------------------------------------------------
75 //Method
76 //--------------------------------------------------------------------------
77
78 /**
79  * Sets values in a protocol vector by copying the values of another 
80  * protocol vector. The source is defined by {@value #PAR_SOURCE},
81  * and getter method {@value peersim.vector.VectControl#PAR_GETTER}.
82  * @return always false
83  */
84 public boolean execute() {
85
86         int size = Network.size();
87         for (int i = 0; i < size; i++) {
88                 Number ret = source.get(i);
89                 if(setter.isInteger()) setter.set(i,ret.longValue());
90                 else setter.set(i,ret.doubleValue());
91         }
92
93         return false;
94 }
95
96 //--------------------------------------------------------------------------
97
98 /**
99  * Sets the value by copying the value of another 
100  * protocol. The source is  defined by {@value #PAR_SOURCE},
101  * and getter method {@value peersim.vector.VectControl#PAR_GETTER}.
102  * @param n the node to initialize
103  */
104 public void initialize(Node n) {
105
106         Number ret = source.get(n);
107         if(setter.isInteger()) setter.set(n,ret.longValue());
108         else setter.set(n,ret.doubleValue());
109 }
110
111 //--------------------------------------------------------------------------
112
113 }