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
46 /***
47 * <p>
48 * Implements support for matching arbitrary dates using a TimePoint supplied
49 * to the constructor. Obviously, this class is not useful in the context of
50 * recurring events, and, perhaps, it is introduction is the begining of a code
51 * smell. :-P
52 * </p>
53 *
54 * <p>
55 * This class is inspired by patterns described in a paper by Martin Fowler
56 * which can be found <a
57 * href="http://martinfowler.com/apsupp/recurring.pdf">here</a>.
58 * </p>
59 *
60 * @author <a href="mlipper@US-ABP.com">Matthew Lipper</a>
61 *
62 * @see <a href="http://martinfowler.com/apsupp/recurring.pdf">Recurring
63 * Events for Calendars</a> by Martin Fowler
64 */
65 public class ArbitraryTimePointTE implements TemporalExpression {
66 private final TimePoint timePoint;
67
68 public ArbitraryTimePointTE(TimePoint aTimePoint) {
69 super();
70
71 if (aTimePoint == null) {
72 throw new NullPointerException("TimePoint argument cannot be null.");
73 }
74
75 timePoint = aTimePoint;
76 }
77
78 /*
79 * (non-Javadoc)
80 *
81 * @see org.chronicj.TemporalExpression#includes(org.chronicj.TimePoint)
82 */
83 public boolean includes(TimePoint arg) {
84 //Adjust to precision
85 if (!timePoint.getDatePrecision().equals(arg.getDatePrecision())) {
86 return timePoint.equals(new TimePoint(arg.getTime(),
87 timePoint.getDatePrecision()));
88 } else {
89 return timePoint.equals(arg);
90 }
91 }
92 }
This page was automatically generated by Maven