View Javadoc
1   /**
2    * Copyright (C) 2003-2014 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
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.
13   *
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/>.
16   **/
17  package org.exoplatform.calendar.service;
18  
19  public class Invitation {
20  
21    private String eventId;
22    
23    private String  participant;
24    
25    private String status;
26  
27    public Invitation(String eventId, String participant, String status) {
28      this.eventId = eventId;
29      this.participant = participant;
30      this.status = status;    
31    }
32  
33    public String getId() {
34      return String.format("%s:%s", eventId, participant);
35    }
36  
37    public String getEventId() {
38      return eventId;
39    }
40  
41    public String getParticipant() {
42      return participant;
43    }
44  
45    public String getStatus() {
46      return status;
47    }
48  
49    @Override
50    public int hashCode() {
51      final int prime = 31;
52      int result = 1;
53      result = prime * result + ((eventId == null) ? 0 : eventId.hashCode());
54      result = prime * result + ((participant == null) ? 0 : participant.hashCode());
55      result = prime * result + ((status == null) ? 0 : status.hashCode());
56      return result;
57    }
58  
59    @Override
60    public boolean equals(Object obj) {
61      if (this == obj)
62        return true;
63      if (obj == null)
64        return false;
65      if (getClass() != obj.getClass())
66        return false;
67      Invitation other = (Invitation) obj;
68      if (eventId == null) {
69        if (other.eventId != null)
70          return false;
71      } else if (!eventId.equals(other.eventId))
72        return false;
73      if (participant == null) {
74        if (other.participant != null)
75          return false;
76      } else if (!participant.equals(other.participant))
77        return false;
78      if (status == null) {
79        if (other.status != null)
80          return false;
81      } else if (!status.equals(other.status))
82        return false;
83      return true;
84    }
85  
86    public static String[] parse(String id) {
87      if (id == null) {
88        throw new IllegalArgumentException("id should not be null");
89      }
90      
91      String[] tmp = id.split(":");
92      if (tmp.length != 2) {
93        throw new IllegalArgumentException("id should be compose of eventId:participantId");
94      }
95      return tmp;
96    }  
97  }