1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27
28 package org.apache.hc.client5.testing.auth;
29
30 import java.util.Arrays;
31 import java.util.Collections;
32 import java.util.List;
33
34 import org.apache.hc.core5.http.NameValuePair;
35 import org.apache.hc.core5.util.LangUtils;
36
37 public final class AuthResult {
38
39 private final boolean success;
40 private final List<NameValuePair> params;
41
42 public AuthResult(final boolean success, final List<NameValuePair> params) {
43 this.success = success;
44 this.params = params != null ? Collections.unmodifiableList(params) : Collections.emptyList();
45 }
46
47 public AuthResult(final boolean success, final NameValuePair... params) {
48 this(success, Arrays.asList(params));
49 }
50
51 public boolean isSuccess() {
52 return success;
53 }
54
55 public boolean hasParams() {
56 return !params.isEmpty();
57 }
58
59 public List<NameValuePair> getParams() {
60 return params;
61 }
62
63 @Override
64 public int hashCode() {
65 int hash = LangUtils.HASH_SEED;
66 hash = LangUtils.hashCode(hash, this.success);
67 return hash;
68 }
69
70 @Override
71 public boolean equals(final Object o) {
72 if (this == o) {
73 return true;
74 }
75 if (o instanceof AuthResult) {
76 final AuthResult that = (AuthResult) o;
77 return this.success == that.success;
78 }
79 return false;
80 }
81
82 @Override
83 public String toString() {
84 final StringBuilder buf = new StringBuilder();
85 buf.append(success);
86 if (!params.isEmpty()) {
87 buf.append(" ").append(params);
88 }
89 return buf.toString();
90 }
91
92 }