|
| 1 | +/* |
| 2 | + * Copyright 2021 the original author or authors. |
| 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 | + * https://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 | +package org.springframework.data.redis.connection; |
| 17 | + |
| 18 | +import org.springframework.lang.NonNull; |
| 19 | +import org.springframework.util.Assert; |
| 20 | +import org.springframework.util.ObjectUtils; |
| 21 | + |
| 22 | +/** |
| 23 | + * Simple {@link NamedNode}. |
| 24 | + * |
| 25 | + * @author Mark Paluch |
| 26 | + * @since 2.5.3 |
| 27 | + */ |
| 28 | +class SentinelMasterId implements NamedNode { |
| 29 | + |
| 30 | + private final String name; |
| 31 | + |
| 32 | + public SentinelMasterId(String name) { |
| 33 | + Assert.hasText(name, "Sentinel Master Id must not be null or empty"); |
| 34 | + this.name = name; |
| 35 | + } |
| 36 | + |
| 37 | + /* |
| 38 | + * (non-Javadoc) |
| 39 | + * @see org.springframework.data.redis.connection.NamedNode#getName() |
| 40 | + */ |
| 41 | + @NonNull |
| 42 | + @Override |
| 43 | + public String getName() { |
| 44 | + return name; |
| 45 | + } |
| 46 | + |
| 47 | + /* |
| 48 | + * (non-Javadoc) |
| 49 | + * @see java.lang.Object#toString() |
| 50 | + */ |
| 51 | + @Override |
| 52 | + public String toString() { |
| 53 | + return getName(); |
| 54 | + } |
| 55 | + |
| 56 | + /* |
| 57 | + * (non-Javadoc) |
| 58 | + * @see java.lang.Object#equals(java.lang.Object) |
| 59 | + */ |
| 60 | + @Override |
| 61 | + public boolean equals(Object o) { |
| 62 | + if (this == o) { |
| 63 | + return true; |
| 64 | + } |
| 65 | + if (!(o instanceof SentinelMasterId)) { |
| 66 | + return false; |
| 67 | + } |
| 68 | + SentinelMasterId that = (SentinelMasterId) o; |
| 69 | + return ObjectUtils.nullSafeEquals(name, that.name); |
| 70 | + } |
| 71 | + |
| 72 | + /* |
| 73 | + * (non-Javadoc) |
| 74 | + * @see java.lang.Object#hashCode() |
| 75 | + */ |
| 76 | + @Override |
| 77 | + public int hashCode() { |
| 78 | + return ObjectUtils.nullSafeHashCode(name); |
| 79 | + } |
| 80 | +} |
0 commit comments