View Javadoc
1 /* 2 * ==================================================================== The 3 * Apache Software License, Version 1.1 4 * 5 * Copyright (c) 2003 Digital Clash LLC. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 1. 9 * Redistributions of source code must retain the above copyright notice, this 10 * list of conditions and the following disclaimer. 2. Redistributions in 11 * binary form must reproduce the above copyright notice, this list of 12 * conditions and the following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 3. The end-user documentation 14 * included with the redistribution, if any, must include the following 15 * acknowledgment: "This product includes software developed by the ChronicJ 16 * team (http://www.chronicj.org/)." Alternately, this acknowledgment may 17 * appear in the software itself, if and wherever such third-party 18 * acknowledgments normally appear. 4. The names "ChronicJ" and "Digital Clash" 19 * not be used to endorse or promote products derived from this software 20 * without prior written permission. For written permission, please contact 21 * info@digitalclash.com. 5. Products derived from this software may not be 22 * called "ChronicJ", "Digital Clash", nor may "ChronicJ" or "Digital Clash" 23 * appear in their name, without prior written permission of Digital Clash LLC. 24 * 25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 27 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28 * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 * ==================================================================== This 36 * product includes software developed by the by the Apache Software Foundation 37 * (http://www.apache.org/). 38 * ==================================================================== 39 */ 40 package org.chronicj.impl; 41 42 import org.chronicj.TemporalExpression; 43 import org.chronicj.TimePoint; 44 45 import java.util.ArrayList; 46 import java.util.Iterator; 47 import java.util.List; 48 49 50 /*** 51 * <p> 52 * Abstract base class for allowing temporal expressions to be composed of 1.. 53 * other temporal expressions which can then be used in set expressions. 54 * </p> 55 * 56 * <p> 57 * This class is based directly on patterns described in a paper by Martin 58 * Fowler which can be found <a 59 * href="http://martinfowler.com/apsupp/recurring.pdf">here</a>. 60 * </p> 61 * 62 * @author <a href="mlipper@US-ABP.com">Matthew Lipper</a> 63 * 64 * @see <a href="http://martinfowler.com/apsupp/recurring.pdf">Recurring 65 * Events for Calendars</a> by Martin Fowler 66 */ 67 abstract class CollectionTE implements TemporalExpression { 68 private final List expressions; 69 70 /*** 71 * Creates an instance of a CollectionTE 72 */ 73 CollectionTE() { 74 super(); 75 expressions = new ArrayList(); 76 } 77 78 /* 79 * @see org.chronicj.TemporalExpression#includes(org.chronicj.TimePoint) 80 */ 81 public abstract boolean includes(TimePoint aTimePoint); 82 83 /*** 84 * Getter for expressions. 85 * 86 * @return a List of temporal expression which compose this expression 87 */ 88 public List getExpressions() { 89 return expressions; 90 } 91 92 /*** 93 * Adds a TemporalExpression to be processed as part of the composition of 94 * this TemporalExpression. 95 * 96 * @param anExpression 97 * the TemporalExpression to add 98 * 99 * @return a CollectionTE reference to the current instance (<code>this</code>), 100 * enabling easier syntax for building expressions 101 */ 102 public CollectionTE add(TemporalExpression anExpression) { 103 expressions.add(anExpression); 104 105 return this; 106 } 107 108 /*** 109 * Getter for querying whether this (abstract) expression has been 110 * configured with any actual expressions. 111 * 112 * @return true if 1 or more TemporalExpression has been added to this 113 * CollectionTE 114 */ 115 public boolean containsExpressions() { 116 //expressions is final and initialized in ctor, it should never be 117 // null 118 return expressions.size() > 0; 119 } 120 121 /* 122 * (non-Javadoc) 123 * 124 * @see java.lang.Object#toString() 125 */ 126 public String toString() { 127 StringBuffer result = new StringBuffer(); 128 int count = 0; 129 130 for (Iterator iter = expressions.iterator(); iter.hasNext(); count++) { 131 if (count == 0) { 132 result.append(iter.next()); 133 } else { 134 result.append(" " + iter.next()); 135 } 136 } 137 138 return result.toString(); 139 } 140 }

This page was automatically generated by Maven