• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google LLC
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.cloud.dns;
18 
19 import static com.google.common.base.Preconditions.checkNotNull;
20 
21 import com.google.cloud.dns.spi.v1.DnsRpc;
22 import com.google.common.base.MoreObjects;
23 import java.io.Serializable;
24 import java.util.Objects;
25 
26 /** A base class for options. */
27 abstract class Option implements Serializable {
28 
29   private static final long serialVersionUID = -5912727967831484228L;
30   private final Object value;
31   private final DnsRpc.Option rpcOption;
32 
Option(DnsRpc.Option rpcOption, Object value)33   Option(DnsRpc.Option rpcOption, Object value) {
34     this.rpcOption = checkNotNull(rpcOption);
35     this.value = value;
36   }
37 
getValue()38   Object getValue() {
39     return value;
40   }
41 
getRpcOption()42   DnsRpc.Option getRpcOption() {
43     return rpcOption;
44   }
45 
46   @Override
equals(Object obj)47   public boolean equals(Object obj) {
48     if (!(obj instanceof Option)) {
49       return false;
50     }
51     Option other = (Option) obj;
52     return Objects.equals(value, other.value) && Objects.equals(rpcOption, other.rpcOption);
53   }
54 
55   @Override
hashCode()56   public int hashCode() {
57     return Objects.hash(value, rpcOption);
58   }
59 
60   @Override
toString()61   public String toString() {
62     return MoreObjects.toStringHelper(this)
63         .add("value", value)
64         .add("rpcOption", rpcOption)
65         .toString();
66   }
67 }
68