| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Arrays |
|
| 0.0;0 |
| 1 | /* | |
| 2 | Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. | |
| 3 | Licensed under the Academic Free License version 3.0 | |
| 4 | */ | |
| 5 | ||
| 6 | package jaggregate; | |
| 7 | ||
| 8 | /** | |
| 9 | * Utility class containing methods that work with arrays. | |
| 10 | * | |
| 11 | * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a> | |
| 12 | * @version $Id: Arrays.java,v 1.3 2008/03/30 03:07:10 pholser Exp $ | |
| 13 | */ | |
| 14 | public class Arrays { | |
| 15 | /** | |
| 16 | * Discourages instantiation. | |
| 17 | * | |
| 18 | * @throws UnsupportedOperationException always | |
| 19 | */ | |
| 20 | 1 | protected Arrays() { |
| 21 | 1 | throw new UnsupportedOperationException(); |
| 22 | } | |
| 23 | ||
| 24 | /** | |
| 25 | * Creates and answers an array containing the given items. | |
| 26 | * <p/> | |
| 27 | * This is a more expressive, less repetitive way to create arrays. For example: | |
| 28 | * <pre><code> | |
| 29 | * Integer[] littlePrimes = arrayWith( 2, 3, 5, 7 ); | |
| 30 | * </code></pre> | |
| 31 | * versus | |
| 32 | * <pre><code> | |
| 33 | * Integer[] littlePrimes = new Integer[] { 2, 3, 5, 7 }; | |
| 34 | * </code></pre> | |
| 35 | * | |
| 36 | * @param <E> the type of the items | |
| 37 | * @param items a variable-length list of items | |
| 38 | * @return the items as an array | |
| 39 | * @throws NullPointerException if the varargs list is {@code null} | |
| 40 | * @throws IllegalArgumentException if the varargs list is of length zero | |
| 41 | * @see <a href="http://www.thenewsbeforethenews.com/2006/05/02/java-5-syntax-tricks-to-keep-you-dry/"> | |
| 42 | * Java 5 syntax tricks to keep you DRY</a> | |
| 43 | */ | |
| 44 | public static <E> E[] arrayWith( E... items ) { | |
| 45 | 189 | if ( items.length == 0 ) |
| 46 | 1 | throw new IllegalArgumentException( "illegal zero-length varargs" ); |
| 47 | ||
| 48 | 187 | return items; |
| 49 | } | |
| 50 | } |