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  @Immutable
34  @ParametersAreNonnullByDefault
35  public final class PropertyId implements Serializable {
36    private static final long serialVersionUID = -2614578081057869958L;
37  
38    private final String mpId;
39    private final String namespace;
40    private final String name;
41  
42    /**
43     * Create a new property ID.
44     */
45    public PropertyId(String mpId, String namespace, String name) {
46      this.mpId = RequireUtil.notEmpty(mpId, "mpId");
47      this.namespace = RequireUtil.notEmpty(namespace, "namespace");
48      this.name = RequireUtil.notEmpty(name, "name");
49    }
50  
51    /**
52     * Create a new property ID from the given parameters.
53     */
54    public static PropertyId mk(String mpId, String namespace, String propertyName) {
55      return new PropertyId(mpId, namespace, propertyName);
56    }
57  
58    /**
59     * Create a new property ID from the given parameters.
60     */
61    public static PropertyId mk(String mpId, PropertyName fqn) {
62      return new PropertyId(mpId, fqn.getNamespace(), fqn.getName());
63    }
64  
65    public String getMediaPackageId() {
66      return mpId;
67    }
68  
69    public String getNamespace() {
70      return namespace;
71    }
72  
73    public String getName() {
74      return name;
75    }
76  
77    public PropertyName getFqn() {
78      return PropertyName.mk(namespace, name);
79    }
80  
81    //
82  
83    @Override public int hashCode() {
84      return Objects.hash(mpId, namespace, name);
85    }
86  
87    @Override public boolean equals(Object that) {
88      return (this == that) || (that instanceof PropertyId && eqFields((PropertyId) that));
89    }
90  
91    private boolean eqFields(PropertyId that) {
92      return Objects.equals(mpId, that.mpId)
93          && Objects.equals(namespace, that.namespace)
94          && Objects.equals(name, that.name);
95    }
96  
97    @Override public String toString() {
98      return format("PropertyId(%s, %s, %s)", mpId, namespace, name);
99    }
100 }