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.example.list; 28 29 import org.perfidix.example.list.Array; 30 31 /** 32 * This is an abstract class for storing elements of any kind in an array-based 33 * list. 34 * 35 * @author BaseX Team 2005-11, BSD License 36 * @author Christian Gruen 37 */ 38 public abstract class ElementList { 39 /** Initial hash capacity. */ 40 public static final int CAP = 1 << 3; 41 /** Resize factor for extending the arrays. */ 42 protected double factor = Array.RESIZE; 43 /** Number of elements. */ 44 protected int size; 45 46 /** 47 * Default constructor. 48 */ 49 protected ElementList() { 50 } 51 52 /** 53 * Returns a new array size. 54 * 55 * @return new array size 56 */ 57 protected final int newSize() { 58 return Array.newSize(size, factor); 59 } 60 61 /** 62 * Returns a new array size that is larger than or equal to the specified 63 * size. 64 * 65 * @param min 66 * minimum size 67 * @return new array size 68 */ 69 protected final int newSize(final int min) { 70 return Math.max(newSize(), min); 71 } 72 73 /** 74 * Returns the number of elements. 75 * 76 * @return number of elements 77 */ 78 public final int size() { 79 return size; 80 } 81 82 /** 83 * Sets the number of elements to the specified value. 84 * 85 * @param s 86 * number of elements 87 */ 88 public final void size(final int s) { 89 size = s; 90 } 91 92 /** 93 * Tests is the container has no elements. 94 * 95 * @return result of check 96 */ 97 public final boolean empty() { 98 return size == 0; 99 } 100 101 /** 102 * Resets the array size. 103 */ 104 public final void reset() { 105 size = 0; 106 } 107 }