blob: ecff096ba7c861208aa00748064d6f4531f51b3d [file] [log] [blame]
lishuai2ddc4692015-07-31 15:15:16 +08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.ovsdb.rfc.jsonrpc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.List;
22import java.util.Objects;
23
24import com.google.common.collect.Lists;
25
26/**
27 * Json Rpc Request information that include id,method,params.
28 */
29public class JsonRpcRequest {
30
31 private final String id;
32 private final String method;
33 private final List<Object> params;
34
35 /**
36 * JsonRpcRequest Constructor.
37 * @param id the id node of request information
38 * @param method the method node of request information
39 */
40 public JsonRpcRequest(String id, String method) {
41 checkNotNull(id, "id cannot be null");
42 checkNotNull(method, "method cannot be null");
43 this.id = id;
44 this.method = method;
45 this.params = Lists.newArrayList();
46 }
47
48 /**
49 * JsonRpcRequest Constructor.
50 * @param id the id node of request information
51 * @param method the method node of request information
52 * @param params the params node of request information
53 */
54 public JsonRpcRequest(String id, String method, List<Object> params) {
55 checkNotNull(id, "id cannot be null");
56 checkNotNull(method, "method cannot be null");
57 checkNotNull(params, "params cannot be null");
58 this.id = id;
59 this.method = method;
60 this.params = params;
61 }
62
63 /**
64 * Returns id.
65 * @return id
66 */
67 public String getId() {
68 return id;
69 }
70
71 /**
72 * Returns method.
73 * @return method
74 */
75 public String getMethod() {
76 return method;
77 }
78
79 /**
80 * Returns params.
81 * @return params
82 */
83 public List<Object> getParams() {
84 return params;
85 }
86
87 @Override
88 public int hashCode() {
89 return Objects.hash(id, method, params);
90 }
91
92 @Override
93 public boolean equals(Object obj) {
94 if (this == obj) {
95 return true;
96 }
97 if (obj instanceof JsonRpcRequest) {
98 final JsonRpcRequest other = (JsonRpcRequest) obj;
99 return Objects.equals(this.id, other.id)
100 && Objects.equals(this.method, other.method)
101 && Objects.equals(this.params, other.params);
102 }
103 return false;
104 }
105
106 @Override
107 public String toString() {
108 return toStringHelper(this).add("id", id).add("method", method)
109 .add("params", params).toString();
110 }
111}