View Javadoc

1   /*
2    * Copyright 2004 Carlos Sanchez.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.oness.common.model.temporal;
17  
18  import java.util.ArrayList;
19  import java.util.Calendar;
20  import java.util.Collection;
21  import java.util.Collections;
22  import java.util.Comparator;
23  import java.util.Iterator;
24  
25  import org.apache.commons.beanutils.BeanComparator;
26  
27  /***
28   * @author Carlos Sanchez
29   * @version $Revision: 1.3 $
30   */
31  public class TemporalValueUtil {
32  
33      private static final int START_DATE = 0, END_DATE = 1;
34  
35  //    public static Collection update(
36  //        TemporalValue old,
37  //        TemporalValue updated,
38  //        Collection values)
39  //        throws NonContinuousDataException {
40  //
41  //        if ((old.getTransactionTime().getEnd() == null)
42  //            && (updated.getTransactionTime().getEnd() != null))
43  //            throw new NonContinuousDataException();
44  //
45  //        if ((old.getTransactionTime().getStart() == null)
46  //            && (updated.getTransactionTime().getStart() != null))
47  //            throw new NonContinuousDataException();
48  //
49  //        /* 1 Delete objects whose startDate is between the old and the updated startDate */
50  //        if ((old.getTransactionTime().getStart() != null)
51  //            && (updated.getTransactionTime().getStart() != null)) {
52  //            deleteBetween(
53  //                old.getTransactionTime().getStart(),
54  //                updated.getTransactionTime().getStart(),
55  //                values,
56  //                START_DATE);
57  //            TemporalValue previous =
58  //                (TemporalValue) Collections.max(values, getStartComparator());
59  //            previous.getTransactionTime().setEnd(
60  //                updated.getTransactionTime().getStart());
61  //        }
62  //
63  //        /* 3 Delete objects whose endDate is between the old and the updated endDate */
64  //        if ((old.getTransactionTime().getStart() != null)
65  //            && (updated.getTransactionTime().getStart() != null)) {
66  //            deleteBetween(
67  //                old.getTransactionTime().getEnd(),
68  //                updated.getTransactionTime().getEnd(),
69  //                values,
70  //                END_DATE);
71  //            TemporalValue next =
72  //                (TemporalValue) Collections.max(values, getEndComparator());
73  //            next.getTransactionTime().setStart(
74  //                updated.getTransactionTime().getEnd());
75  //        }
76  //
77  //        return values;
78  //    }
79  //
80  //    public static Collection deleteBetween(
81  //        Date c1,
82  //        Date c2,
83  //        Collection values,
84  //        int type) {
85  //        Date first, last;
86  //
87  //        if (c1.after(c2)) {
88  //            first = c2;
89  //            last = c1;
90  //        } else {
91  //            first = c1;
92  //            last = c2;
93  //        }
94  //
95  //        Collection c = new ArrayList();
96  //        Iterator iter = values.iterator();
97  //        while (iter.hasNext()) {
98  //            TemporalValue element = (TemporalValue) iter.next();
99  //            if (type == START_DATE) {
100 //                if ((element.getTransactionTime().getStart().after(first))
101 //                    && (element.getTransactionTime().getStart().before(last))) {
102 //                    element.getTransactionTime().setEnd(
103 //                        new Date(Calendar.getInstance()));
104 //                    c.add(element);
105 //                }
106 //            } else if (type == END_DATE) {
107 //                if ((element.getTransactionTime().getEnd().after(first))
108 //                    && (element.getTransactionTime().getEnd().before(last))) {
109 //                    element.getTransactionTime().setEnd(
110 //                        new Date(Calendar.getInstance()));
111 //                    c.add(element);
112 //                }
113 //            }
114 //        }
115 //        return c;
116 //    }
117 //
118 //    public static Comparator getStartComparator() {
119 //        return new BeanComparator("start.time");
120 //    }
121 //
122 //    public static Comparator getEndComparator() {
123 //        return new BeanComparator("end.time");
124 //    }
125 
126 }