View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License. 
18   */
19  package org.apache.creadur.whisker.model;
20  
21  import java.util.Map;
22  
23  /**
24   * Describes a group or individual with responsibility for 
25   * upstream distributions.
26   */
27  public class Organisation implements Comparable<Organisation> {
28  
29      /** Identifies this group or individual with responsibility. */
30      private final String id;
31      /** A name for this group or individual suitable for presentation. */
32      private final String name;
33      /** A locator for the home of this group or individual. */
34      private final String url;
35  
36      /**
37       * Constructs an instance.
38       * @param id identifies this group or individual 
39       * with responsibility for 
40       * upstream distributions, not null
41       * @param name a name for this group or individual 
42       * suitable for presentation, not null
43       * @param url a locator for the home of this group 
44       * or individual, not null
45       */
46      public Organisation(final String id, final String name, final String url) {
47          super();
48          this.id = id;
49          this.name = name;
50          this.url = url;
51      }
52  
53      /**
54       * Stores this organisation by id.
55       * @param organisationsById not null
56       * @return this organisation
57       */
58      public Organisation storeIn(
59              final Map<String, Organisation> organisationsById) {
60          organisationsById.put(this.id, this);
61          return this;
62      }
63  
64      /**
65       * Gets a name for this group or individual 
66       * suitable for presentation.
67       * @return not null
68       */
69      public String getName() {
70          return this.name;
71      }
72  
73      /**
74       * Gets a locator for the home of this group 
75       * or individual.
76       * @return not null
77       */
78      public String getURL() {
79          return this.url;
80      }
81  
82      /**
83       * Gets an identifier for this group or individual 
84       * with responsibility for 
85       * upstream distributions.
86       * @return not null
87       */
88      public String getId() {
89          return this.id;
90      }
91  
92      @Override
93      public int hashCode() {
94          final int prime = 31;
95          int result = 1;
96          result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
97          return result;
98      }
99  
100     @Override
101     public boolean equals(final Object obj) {
102         if (this == obj) {
103             return true;
104         }
105         if (obj == null) {
106             return false;
107         }
108         if (getClass() != obj.getClass()) {
109             return false;
110         }
111         final Organisation other = (Organisation) obj;
112         if (this.id == null) {
113             if (other.id != null) {
114                 return false;
115             }
116         } else if (!this.id.equals(other.id)) {
117             return false;
118         }
119         return true;
120     }
121 
122     /**
123      * @see java.lang.Comparable#compareTo(java.lang.Object)
124      */
125     public int compareTo(final Organisation other) {
126         final int nameDifference = getName().compareTo(other.getName());
127         return nameDifference == 0 ? getId().compareTo(other.getId())
128                 : nameDifference;
129     }
130 
131     @Override
132     public String toString() {
133         return "Organisation [id=" + this.id + ", name=" + this.name + ", url="
134                 + this.url + "]";
135     }
136 }