KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > isac > plugins > httpmatrix10 > tools > MatrixDescription


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF
20 *
21 * Contact: clif@objectweb.org
22 */

23 package org.objectweb.clif.isac.plugins.httpmatrix10.tools;
24
25 /**
26  * This class is a matrix description
27  *
28  * @author JC Meillaud
29  * @author A Peyrard
30  */

31 public class MatrixDescription {
32     private double[][] matrix ;
33     private String JavaDoc[] urls ;
34     private double[] waiting_times ;
35     private int[] nbHitBeforeEnding ;
36     private int size ;
37     
38     /**
39      * Construtor, build a new matrix description
40      * The matrix is a square matrix
41      * @param number Size of the matrix
42      */

43     public MatrixDescription(int number) {
44         // init all the tables
45
this.matrix = new double[number][number] ;
46         this.urls = new String JavaDoc[number] ;
47         this.waiting_times = new double[number] ;
48         this.nbHitBeforeEnding = new int[number] ;
49         // init the size
50
this.size = number ;
51     }
52     
53     /**
54      * Set the cell Aij in the matrix
55      * @param i The X-axis value of the cell
56      * @param j The Y-axis value of the cell
57      * @param value of the cell
58      * @return true if the sell has been set, else false
59      */

60     public boolean setCell(int i, int j, double value) {
61         // check if the coord are right
62
if (i <= size && j <= size) {
63             // set the value
64
matrix[i][j] = value ;
65             return true ;
66         }
67         else
68             // the cell was not found
69
return false ;
70     }
71     
72     /**
73      * Get the cell value Aij
74      * @param i The X-axis value of the cell
75      * @param j The Y-axis value of the cell
76      * @return The cell value
77      */

78     public double getCell(int i, int j) {
79         // check if the coord are right
80
if (i <= size && j <= size) {
81             // get the value
82
return matrix[i][j] ;
83         }
84         else
85             return -1 ;
86     }
87
88     /**
89      * Set an url
90      * @param n The number of the url to be set
91      * @param url The url to be set
92      * @return True if the url has been set
93      */

94     public boolean setUrl(int n, String JavaDoc url) {
95         if (n <= size) {
96             urls[n] = new String JavaDoc(url) ;
97             return true ;
98         }
99         else
100             return false ;
101     }
102     
103     /**
104      * Get an url
105      * @param n The number of the url
106      * @return The url
107      */

108     public String JavaDoc getUrl(int n) {
109         if (n <= size) {
110             return urls[n] ;
111         }
112         else
113             return null ;
114     }
115     
116     /**
117      * Set a waiting time
118      * @param n The number of the waiting time to be set
119      * @param time The waiting time to be set
120      * @return True if the waiting time has been set
121      */

122     public boolean setWaitingTime(int n, double waiting_time) {
123         if (n <= size) {
124             waiting_times[n] = waiting_time ;
125             return true ;
126         }
127         else
128             return false ;
129     }
130     
131     /**
132      * Get a waiting time
133      * @param n The number of the waiting time
134      * @return The waiting time
135      */

136     public double getWaitingTime(int n) {
137         if (n <= size) {
138             return waiting_times[n] ;
139         }
140         else
141             return -1 ;
142     }
143     
144     /**
145      * Set a value of the ending table, 0 means what the link is not a ending link
146      * @param n the number of the link
147      * @param nbB the number of hit to this link before ending
148      * @return True if the number have been set
149      */

150     public boolean setNbHitBeforeEnding(int n, int nbB) {
151         if (n<=size) {
152             nbHitBeforeEnding[n] = nbB ;
153             return true;
154         }
155         return false ;
156     }
157     
158     /**
159      * Get a value of the ending table
160      * @param n the number of the link
161      * @return The number of hits before ending for this link
162      */

163     public int getNbHitBeforeEnding(int n) {
164         if (n<=size) {
165             return nbHitBeforeEnding[n];
166         }
167         return -1;
168     }
169     
170     /**
171      * @return Returns the size.
172      */

173     public int getSize() {
174         return size;
175     }
176     
177     /**
178      * @param size The size to set.
179      */

180     public void setSize(int size) {
181         this.size = size;
182     }
183     
184     /**
185      * Implementation of the method toString
186      * used in the debug of the class
187      */

188     public String JavaDoc toString() {
189         String JavaDoc result = "** Matrix Description : \n" ;
190         result = result.concat("-size=" + this.size + "\n") ;
191         for (int i=0;i<this.size;i++) {
192             result = result.concat("url"+i+"="+this.urls[i]+"\n") ;
193             result = result.concat(" waiting_time=" + waiting_times[i]+"\n") ;
194         }
195         for (int i=0;i<this.size;i++) {
196             for (int j=0;j<this.size;j++) {
197                 result = result.concat(this.matrix[i][j]+" ") ;
198             }
199             result = result.concat("\n") ;
200         }
201         return result ;
202     }
203 }
Popular Tags