• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 /*
19  * $Id$
20  */
21 
22 /*
23  *
24  * OutputNameManager.java
25  *
26  */
27 package org.apache.qetest;
28 
29 /**
30  * Simple utility class to manage tests with multiple output names.
31  * <p>Starts with a base name and extension, and returns
32  * nextName()s like:<pre>
33  * baseName_<i>1</i>.ext
34  * baseName_<i>2</i>.ext
35  * baseName_<i>3</i>.ext
36  * ...<pre>
37  * @author Shane_Curcuru@lotus.com
38  * @version $Id$
39  */
40 public class OutputNameManager
41 {
42 
43     // defaults are provided for everything for the terminally lazy
44 
45     /** NEEDSDOC Field extension          */
46     protected String extension = ".out";
47 
48     /** NEEDSDOC Field baseName          */
49     protected String baseName = "OutputFile";
50 
51     /** NEEDSDOC Field currentName          */
52     protected String currentName = "currentUnset";
53 
54     /** NEEDSDOC Field previousName          */
55     protected String previousName = "previousUnset";
56 
57     /** NEEDSDOC Field counter          */
58     protected int counter = 0;
59 
60     /** NEEDSDOC Field SEPARATOR          */
61     public static final String SEPARATOR = "_";
62 
63     /**
64      * Construct with just a basename.
65      *
66      * @param base basename of file; defaults counter, extension
67      */
OutputNameManager(String base)68     public OutputNameManager(String base)
69     {
70         baseName = base;
71     }
72 
73     /**
74      * Construct with a basename and extension.
75      *
76      * @param base basename of file; defaults counter
77      * @param ext extension to use instead of .out
78      */
OutputNameManager(String base, String ext)79     public OutputNameManager(String base, String ext)
80     {
81         baseName = base;
82         extension = ext;
83     }
84 
85     /**
86      * Construct with a basename, extension, and set the counter.
87      *
88      * @param base basename of file; defaults counter
89      * @param ext extension to use instead of .out
90      * @param ctr number to start output counting from
91      */
OutputNameManager(String base, String ext, int ctr)92     public OutputNameManager(String base, String ext, int ctr)
93     {
94 
95         baseName = base;
96         extension = ext;
97 
98         setCounter(ctr);
99     }
100 
101     /** Reset the counter to zero and update current, previous names. */
reset()102     public void reset()
103     {
104 
105         previousName = currentName;
106         currentName = null;
107         counter = 0;  // Set to 0 since we always call nextOutName() first
108     }
109 
110     /**
111      * Increment counter and get next name.
112      *
113      * @return the next name in the series
114      */
nextName()115     public String nextName()
116     {
117 
118         setCounter(counter + 1);  // Updates names
119 
120         return currentName();
121     }
122 
123     /**
124      * Just get the current name.
125      *
126      * @return our current output name
127      */
currentName()128     public String currentName()
129     {
130         return currentName;
131     }
132 
133     /**
134      * Get the previous name, even past a reset().
135      *
136      * @return last name we calculated
137      */
previousName()138     public String previousName()
139     {
140         return previousName;
141     }
142 
143     /**
144      * Get the current counter number.
145      *
146      * @return counter
147      */
currentCounter()148     public int currentCounter()
149     {
150         return counter;
151     }
152 
153     /**
154      * Set the current counter number, including names.
155      *
156      * @param ctr new counter number to set
157      */
setCounter(int ctr)158     public void setCounter(int ctr)
159     {
160         counter = ctr;
161         previousName = currentName;
162         currentName = baseName + SEPARATOR + counter + extension;
163     }
164 }  // end of class OutputNameManager
165 
166