Allow an instance of PropertyName to be set to an arbitrary value.
[acal.git] / src / com / morphoss / acal / davacal / RecurrenceId.java
blob9cf6e0735c05a8c424bd45e26e5a3b60b27f5028
1 /*
2 * Copyright (C) 2011 Morphoss Ltd
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com.morphoss.acal.davacal;
21 import java.util.Comparator;
23 import com.morphoss.acal.acaltime.AcalDateTime;
25 public class RecurrenceId extends AcalProperty implements Comparable<RecurrenceId>{
27 public final AcalDateTime when;
28 public final boolean andFuture;
30 protected RecurrenceId(String name, String value, String[] paramsBlob) {
31 super(name,value,paramsBlob);
32 when = AcalDateTime.fromIcalendar(getValue(),getParam("VALUE"), getParam("TZID"));
33 andFuture = (getParam("RANGE") != null && getParam("RANGE").equalsIgnoreCase("THISANDFUTURE"));
36 public static RecurrenceId fromString(String blob) {
37 AcalProperty ret = AcalProperty.fromString(blob);
38 if ( ret instanceof RecurrenceId ) return (RecurrenceId) ret;
39 throw new IllegalArgumentException();
42 public int compareTo(RecurrenceId another) {
43 if ( when.before(another.when) ) return -1;
44 else if ( when.after(another.when) ) return 1;
45 return 0;
48 public static Comparator<VComponent> getVComponentComparatorByRecurrenceId() {
49 return new VComponentComparatorByRecurrenceId();
52 public boolean equals(RecurrenceId rid) {
53 if ( when == null && rid.when == null ) return true;
54 return when.equals(rid.when);
57 public boolean notAfter(RecurrenceId rid) {
58 if ( rid.andFuture && !when.after(rid.when) ) return true;
59 return when.equals(rid.when);
62 public static class VComponentComparatorByRecurrenceId implements Comparator<VComponent> {
64 public int compare(VComponent a, VComponent b) {
65 RecurrenceId recA = (RecurrenceId)a.getProperty("RECURRENCE-ID");
66 RecurrenceId recB = (RecurrenceId)b.getProperty("RECURRENCE-ID");
67 return recA.compareTo(recB);