View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  package org.opencastproject.assetmanager.api;
22  
23  import static java.lang.String.format;
24  
25  import org.opencastproject.util.RequireUtil;
26  
27  import java.io.Serializable;
28  import java.util.Objects;
29  
30  import javax.annotation.ParametersAreNonnullByDefault;
31  import javax.annotation.concurrent.Immutable;
32  
33  /**
34   * A full qualified property name.
35   */
36  @Immutable
37  @ParametersAreNonnullByDefault
38  public final class PropertyName implements Serializable {
39    private static final long serialVersionUID = -7542245565083273994L;
40  
41    private final String namespace;
42    private final String name;
43  
44    /**
45     * Create a new full qualified property name.
46     */
47    public PropertyName(String namespace, String name) {
48      this.namespace = RequireUtil.notEmpty(namespace, "namespace");
49      this.name = RequireUtil.notEmpty(name, "name");
50    }
51  
52    /**
53     * Create a new full qualified property name.
54     */
55    public static PropertyName mk(String namespace, String name) {
56      return new PropertyName(namespace, name);
57    }
58  
59    /** Return the namespace. */
60    public String getNamespace() {
61      return namespace;
62    }
63  
64    /** Return the namespace local name. */
65    public String getName() {
66      return name;
67    }
68  
69    //
70  
71    @Override public int hashCode() {
72      return Objects.hash(namespace, name);
73    }
74  
75    @Override public boolean equals(Object that) {
76      return (this == that) || (that instanceof PropertyName && eqFields((PropertyName) that));
77    }
78  
79    private boolean eqFields(PropertyName that) {
80      return Objects.equals(namespace, that.namespace) && Objects.equals(name, that.name);
81    }
82  
83    @Override public String toString() {
84      return format("PropertyFqn(%s, %s)", namespace, name);
85    }
86  }