2 * Copyright 2011 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.ipc.invalidation.external.client.types;
19 import com.google.ipc.invalidation.util.Preconditions;
21 import java.util.Arrays;
24 * A class to represent a unique object id that an application can register or
28 public final class ObjectId {
30 /** The invalidation source type. */
31 private final int source;
33 /** The name/unique id for the object. */
34 private final byte[] name;
37 * Creates an object id for the given {@code source} and id {@code name} (does not make a copy of
40 public static ObjectId newInstance(int source, byte[] name) {
41 return new ObjectId(source, name);
44 /** Creates an object id for the given {@code source} and id {@code name}. */
45 private ObjectId(int source, byte[] name) {
46 Preconditions.checkState(source >= 0, "source");
48 this.name = Preconditions.checkNotNull(name, "name");
51 public int getSource() {
55 public byte[] getName() {
60 public boolean equals(Object object) {
65 if (!(object instanceof ObjectId)) {
69 final ObjectId other = (ObjectId) object;
70 if ((source != other.source) || !Arrays.equals(name, other.name)) {
77 public int hashCode() {
78 return source ^ Arrays.hashCode(name);
82 public String toString() {
83 return "Oid: <" + source + ", " + BytesFormatter.toString(name) + ">";