Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / cacheinvalidation / src / java / com / google / ipc / invalidation / external / client / types / ApplicationClientId.java
1 /*
2  * Copyright 2011 Google Inc.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.ipc.invalidation.external.client.types;
18
19 import com.google.ipc.invalidation.util.Preconditions;
20
21 import java.util.Arrays;
22
23 /**
24  * An identifier for application clients in an application-defined way. I.e., a client name in an
25  * application naming scheme. This is not interpreted by the invalidation system - however, it is
26  * used opaquely to squelch invalidations for the cient causing an update, e.g., if a client C
27  * whose app client id is C.appClientId changes object X and the backend store informs the backend
28  * invalidation sytsem that X was modified by X.appClientId, the invalidation to C can then be
29  * squelched by the invalidation system.
30  *
31  */
32 public final class ApplicationClientId {
33
34   /** The opaque id of the client application. */
35   private final byte[] clientName;
36
37   /**
38    * Creates an application client id for the given {@code clientName} (does not make a copy of the
39    * byte array).
40    */
41   public static ApplicationClientId newInstance(byte[] appClientId) {
42     return new ApplicationClientId(appClientId);
43   }
44
45   /** Creates an application id for the given {@code clientName}. */
46   private ApplicationClientId(byte[] clientName) {
47     this.clientName = Preconditions.checkNotNull(clientName, "clientName");
48   }
49
50   public byte[] getClientName() {
51     return clientName;
52   }
53
54   @Override
55   public boolean equals(Object object) {
56     if (object == this) {
57       return true;
58     }
59
60     if (!(object instanceof ApplicationClientId)) {
61       return false;
62     }
63
64     final ApplicationClientId other = (ApplicationClientId) object;
65     return Arrays.equals(clientName, other.clientName);
66   }
67
68   @Override
69   public int hashCode() {
70     return Arrays.hashCode(clientName);
71   }
72
73   @Override
74   public String toString() {
75     return "AppClientId: <, " + BytesFormatter.toString(clientName) + ">";
76   }
77 }