|
| 1 | +/* |
| 2 | + * Copyright 2014 NAVER Corp. |
| 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.navercorp.pinpoint.web.applicationmap.link; |
| 18 | + |
| 19 | +import com.navercorp.pinpoint.common.trace.ServiceType; |
| 20 | +import com.navercorp.pinpoint.web.vo.Application; |
| 21 | + |
| 22 | +import java.util.Objects; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author emeroad |
| 26 | + */ |
| 27 | +public final class LinkKey { |
| 28 | + private final Application from; |
| 29 | + private final Application to; |
| 30 | + |
| 31 | + private int hash; |
| 32 | + |
| 33 | + public LinkKey(Application from, Application to) { |
| 34 | + this.from = Objects.requireNonNull(from, "from"); |
| 35 | + this.to = Objects.requireNonNull(to, "to"); |
| 36 | + } |
| 37 | + |
| 38 | + public static LinkKey of(String fromApplication, ServiceType fromServiceType, String toApplication, ServiceType toServiceType) { |
| 39 | + Application from = new Application(fromApplication, fromServiceType); |
| 40 | + Application to = new Application(toApplication, toServiceType); |
| 41 | + return new LinkKey(from, to); |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + public Application getFrom() { |
| 46 | + return from; |
| 47 | + } |
| 48 | + |
| 49 | + public Application getTo() { |
| 50 | + return to; |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + @Override |
| 55 | + public boolean equals(Object o) { |
| 56 | + if (this == o) return true; |
| 57 | + if (o == null || getClass() != o.getClass()) return false; |
| 58 | + |
| 59 | + LinkKey linkKey = (LinkKey) o; |
| 60 | + |
| 61 | + if (!from.equals(linkKey.from)) return false; |
| 62 | + return to.equals(linkKey.to); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public int hashCode() { |
| 67 | + final int hash = this.hash; |
| 68 | + if (hash != 0) { |
| 69 | + return hash; |
| 70 | + } |
| 71 | + int result = from.hashCode(); |
| 72 | + result = 31 * result + to.hashCode(); |
| 73 | + this.hash = result; |
| 74 | + return result; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public String toString() { |
| 79 | + return "LinkKey{" |
| 80 | + + from + " -> " + to + |
| 81 | + '}'; |
| 82 | + } |
| 83 | +} |
0 commit comments