| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| NaturallySortedCollection |
|
| 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 | * Represents a variable-sized collection of objects whose elements are ordered based on | |
| 10 | * the natural ordering of its elements, as defined by the interface {@link Comparable}. | |
| 11 | * Elements may be added, removed, or inserted, and can be accessed using external | |
| 12 | * integer keys. | |
| 13 | * | |
| 14 | * @param <E> a restriction on the types of elements that may be included in the | |
| 15 | * collection | |
| 16 | * | |
| 17 | * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a> | |
| 18 | * @version $Id: NaturallySortedCollection.java,v 1.2 2008/03/26 18:00:33 pholser Exp $ | |
| 19 | */ | |
| 20 | public class NaturallySortedCollection<E extends Comparable<? super E>> | |
| 21 | extends SortedCollection<E> { | |
| 22 | ||
| 23 | private static final long serialVersionUID = -1L; | |
| 24 | ||
| 25 | /** | |
| 26 | * Creates an empty naturally sorted collection. | |
| 27 | */ | |
| 28 | public NaturallySortedCollection() { | |
| 29 | 421 | super( Comparing.<E>byNaturalOrdering() ); |
| 30 | 421 | } |
| 31 | ||
| 32 | /** | |
| 33 | * Creates a naturally sorted collection containing the elements from the given | |
| 34 | * collection. | |
| 35 | * | |
| 36 | * @param newElements the elements to add to the new collection | |
| 37 | * @throws NullPointerException if {@code newElements} is {@code null} | |
| 38 | */ | |
| 39 | public NaturallySortedCollection( Collection<? extends E> newElements ) { | |
| 40 | 12 | super( Comparing.<E>byNaturalOrdering(), newElements ); |
| 41 | 11 | } |
| 42 | ||
| 43 | /** | |
| 44 | * Creates a naturally sorted collection containing the elements from the given | |
| 45 | * array. | |
| 46 | * | |
| 47 | * @param newElements the elements to add to the new collection | |
| 48 | * @throws NullPointerException if {@code newElements} is {@code null} | |
| 49 | */ | |
| 50 | public NaturallySortedCollection( E... newElements ) { | |
| 51 | 202 | super( Comparing.<E>byNaturalOrdering(), newElements ); |
| 52 | 201 | } |
| 53 | ||
| 54 | /** | |
| 55 | * Creates a naturally sorted collection containing the elements from the given | |
| 56 | * iterable. | |
| 57 | * | |
| 58 | * @param newElements the elements to add to the new collection | |
| 59 | * @throws NullPointerException if {@code newElements} is {@code null} | |
| 60 | */ | |
| 61 | public NaturallySortedCollection( Iterable<? extends E> newElements ) { | |
| 62 | 2 | super( Comparing.<E>byNaturalOrdering(), newElements ); |
| 63 | 1 | } |
| 64 | ||
| 65 | /** | |
| 66 | * Creates an empty naturally sorted collection. | |
| 67 | * | |
| 68 | * @param <T> the type of elements to add to the new sorted collection | |
| 69 | * @return a new sorted collection | |
| 70 | */ | |
| 71 | public static <T extends Comparable<? super T>> | |
| 72 | NaturallySortedCollection<T> emptyNaturallySortedCollection() { | |
| 73 | 1 | return new NaturallySortedCollection<T>(); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Creates a naturally sorted collection containing the elements from the given | |
| 78 | * collection. | |
| 79 | * | |
| 80 | * @param <T> the type of elements to add to the new sorted collection | |
| 81 | * @param newElements the elements to add to the new collection | |
| 82 | * @return a new sorted collection | |
| 83 | * @throws NullPointerException if {@code newElements} is {@code null} | |
| 84 | */ | |
| 85 | public static <T extends Comparable<? super T>> | |
| 86 | NaturallySortedCollection<T> naturallySortedCollectionFrom( | |
| 87 | Collection<? extends T> newElements ) { | |
| 88 | ||
| 89 | 11 | return new NaturallySortedCollection<T>( newElements ); |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Creates a naturally sorted collection containing the elements from the given | |
| 94 | * array. | |
| 95 | * | |
| 96 | * @param <T> the type of elements to add to the new sorted collection | |
| 97 | * @param newElements the elements to add to the new collection | |
| 98 | * @return a new sorted collection | |
| 99 | * @throws NullPointerException if {@code newElements} is {@code null} | |
| 100 | */ | |
| 101 | public static <T extends Comparable<? super T>> | |
| 102 | NaturallySortedCollection<T> naturallySortedCollectionWith( T... newElements ) { | |
| 103 | 193 | return new NaturallySortedCollection<T>( newElements ); |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * Creates a naturally sorted collection containing the elements from the given | |
| 108 | * iterable. | |
| 109 | * | |
| 110 | * @param <T> the type of elements to add to the new sorted collection | |
| 111 | * @param newElements the elements to add to the new collection | |
| 112 | * @return a new sorted collection | |
| 113 | * @throws NullPointerException if {@code newElements} is {@code null} | |
| 114 | */ | |
| 115 | public static <T extends Comparable<? super T>> | |
| 116 | NaturallySortedCollection<T> naturallySortedCollectionFrom( | |
| 117 | Iterable<? extends T> newElements ) { | |
| 118 | ||
| 119 | 1 | return new NaturallySortedCollection<T>( newElements ); |
| 120 | } | |
| 121 | } |