1 // Copyright (C) 2003 - 2012 Philip Aston 2 // All rights reserved. 3 // 4 // This file is part of The Grinder software distribution. Refer to 5 // the file LICENSE which is part of The Grinder distribution for 6 // licensing details. The Grinder distribution is available on the 7 // Internet at http://grinder.sourceforge.net/ 8 // 9 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 12 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 13 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 14 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 15 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 16 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 17 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 18 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 19 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 20 // OF THE POSSIBILITY OF SUCH DAMAGE. 21 22 package net.grinder.console.model; 23 24 import net.grinder.common.Test; 25 import net.grinder.statistics.StatisticsSet; 26 27 28 /** 29 * Snapshot of current test structure that is valid at time of notification. The 30 * test indicies used are numbered between 0 and getNumberOfTests() - 1 and are 31 * not related to the test numbers apart from sharing the same ordering. 32 * 33 * <p> 34 * The test array is immutable, but the statistics may change as new samples are 35 * received. 36 * </p> 37 * 38 * @author Philip Aston 39 * @see SampleModel.Listener#newTests 40 */ 41 public final class ModelTestIndex { 42 43 private final Test[] m_testArray; 44 private final SampleAccumulator[] m_accumulatorArray; 45 46 /** 47 * Default constructor. Public for clients to use as a null model 48 * test index. 49 */ 50 public ModelTestIndex() { 51 m_testArray = new Test[0]; 52 m_accumulatorArray = new SampleAccumulator[0]; 53 } 54 55 ModelTestIndex(Test[] testArray, SampleAccumulator[] accumulatorArray) { 56 m_testArray = testArray; 57 m_accumulatorArray = accumulatorArray; 58 } 59 60 /** 61 * Returns the total number of registered tests. 62 * 63 * @return The number of tests. 64 */ 65 public int getNumberOfTests() { 66 return m_testArray.length; 67 } 68 69 /** 70 * Return a specific test by index. 71 * 72 * @param testIndex The test index. 73 * @return The test. 74 */ 75 public Test getTest(int testIndex) { 76 return m_testArray[testIndex]; 77 } 78 79 /** 80 * Get the cumulative test statistics for a given test. 81 * 82 * @param testIndex The test index. 83 * @return The cumulative statistics. 84 */ 85 public StatisticsSet getCumulativeStatistics(int testIndex) { 86 return m_accumulatorArray[testIndex].getCumulativeStatistics(); 87 } 88 89 /** 90 * Get the last sample statistics for a given test. 91 * 92 * @param testIndex The test index. 93 * @return The last sample statistics. 94 */ 95 public StatisticsSet getLastSampleStatistics(int testIndex) { 96 return m_accumulatorArray[testIndex].getLastSampleStatistics(); 97 } 98 99 SampleAccumulator[] getAccumulatorArray() { 100 return m_accumulatorArray; 101 } 102 }