| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractMethodArrangement |
|
| 2.0;2 | ||||
| AbstractMethodArrangement$1 |
|
| 2.0;2 |
| 1 | /** | |
| 2 | * Copyright (c) 2012, University of Konstanz, Distributed Systems Group | |
| 3 | * All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions are met: | |
| 7 | * * Redistributions of source code must retain the above copyright | |
| 8 | * notice, this list of conditions and the following disclaimer. | |
| 9 | * * Redistributions in binary form must reproduce the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer in the | |
| 11 | * documentation and/or other materials provided with the distribution. | |
| 12 | * * Neither the name of the University of Konstanz nor the | |
| 13 | * names of its contributors may be used to endorse or promote products | |
| 14 | * derived from this software without specific prior written permission. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 19 | * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | |
| 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 | */ | |
| 27 | package org.perfidix.element; | |
| 28 | ||
| 29 | import java.util.Collections; | |
| 30 | import java.util.Iterator; | |
| 31 | import java.util.List; | |
| 32 | ||
| 33 | /** | |
| 34 | * This method defines an order for the execution of all methods. A collection | |
| 35 | * with definitly benchmarkable methods is given in, shuffled in a way and | |
| 36 | * returned as an iterator. The kind of shuffling is set by the enum {@link KindOfArrangement}. ordered with | |
| 37 | * the help of inheriting classes. | |
| 38 | * | |
| 39 | * @author Sebastian Graf, University of Konstanz | |
| 40 | */ | |
| 41 | public abstract class AbstractMethodArrangement implements Iterable<BenchmarkElement> { | |
| 42 | ||
| 43 | /** | |
| 44 | * List to hold all benchmarkable elements in the correct order as a base | |
| 45 | * for the iterator. | |
| 46 | */ | |
| 47 | private transient final List<BenchmarkElement> elementList; | |
| 48 | ||
| 49 | /** | |
| 50 | * Constructor which takes all benchmarkable methods. These methods are | |
| 51 | * afterwards shuffled with the help of the implementing class. Note that | |
| 52 | * the elements are fix after the arrangement. | |
| 53 | * | |
| 54 | * @param elements | |
| 55 | * definitly benchmarkable objects. | |
| 56 | */ | |
| 57 | 55 | protected AbstractMethodArrangement(final List<BenchmarkElement> elements) { |
| 58 | 55 | final List<BenchmarkElement> arrangedList = arrangeList(elements); |
| 59 | 55 | this.elementList = Collections.unmodifiableList(arrangedList); |
| 60 | 55 | } |
| 61 | ||
| 62 | /** | |
| 63 | * Method to arrange benchmarkable methods in different orders. | |
| 64 | * | |
| 65 | * @param methods | |
| 66 | * to be arranged | |
| 67 | * @return the arranged methods. | |
| 68 | */ | |
| 69 | protected abstract List<BenchmarkElement> arrangeList(final List<BenchmarkElement> methods); | |
| 70 | ||
| 71 | /** {@inheritDoc} */ | |
| 72 | public final Iterator<BenchmarkElement> iterator() { | |
| 73 | 55 | return this.elementList.iterator(); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Factory method to get the method arrangement for a given set of classes. | |
| 78 | * The kind of arrangement is set by an instance of the enum {@link KindOfArrangement}. | |
| 79 | * | |
| 80 | * @param elements | |
| 81 | * to be benched | |
| 82 | * @param kind | |
| 83 | * for the method arrangement | |
| 84 | * @return the arrangement, mainly an iterator | |
| 85 | */ | |
| 86 | public static final AbstractMethodArrangement getMethodArrangement(final List<BenchmarkElement> elements, | |
| 87 | final KindOfArrangement kind) { | |
| 88 | 55 | AbstractMethodArrangement arrang = null; |
| 89 | 55 | switch (kind) { |
| 90 | case NoArrangement: | |
| 91 | 40 | arrang = new NoMethodArrangement(elements); |
| 92 | 40 | break; |
| 93 | case ShuffleArrangement: | |
| 94 | 5 | arrang = new ShuffleMethodArrangement(elements); |
| 95 | 5 | break; |
| 96 | case SequentialMethodArrangement: | |
| 97 | 10 | arrang = new SequentialMethodArrangement(elements); |
| 98 | 10 | break; |
| 99 | default: | |
| 100 | 0 | throw new IllegalArgumentException("Kind not known!"); |
| 101 | } | |
| 102 | 55 | return arrang; |
| 103 | ||
| 104 | } | |
| 105 | } |