1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 2000-2016. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  */
20 package com.ericsson.otp.erlang;
21 
22 // package scope
23 class Link {
24     private final OtpErlangPid local;
25     private final OtpErlangPid remote;
26     private long unlinking = 0;
27     private int hashCodeValue = 0;
28 
Link(final OtpErlangPid local, final OtpErlangPid remote)29     public Link(final OtpErlangPid local, final OtpErlangPid remote) {
30         this.local = local;
31         this.remote = remote;
32         this.unlinking = 0;
33 
34     }
35 
local()36     public OtpErlangPid local() {
37         return local;
38     }
39 
remote()40     public OtpErlangPid remote() {
41         return remote;
42     }
43 
contains(final OtpErlangPid pid)44     public boolean contains(final OtpErlangPid pid) {
45         return local.equals(pid) || remote.equals(pid);
46     }
47 
equals(final OtpErlangPid alocal, final OtpErlangPid aremote)48     public boolean equals(final OtpErlangPid alocal, final OtpErlangPid aremote) {
49         return local.equals(alocal) && remote.equals(aremote)
50                 || local.equals(aremote) && remote.equals(alocal);
51     }
52 
getUnlinking()53     public long getUnlinking() {
54         return this.unlinking;
55     }
56 
setUnlinking(long unlink_id)57     public void setUnlinking(long unlink_id) {
58         this.unlinking = unlink_id;
59     }
60 
61     @Override
hashCode()62     public int hashCode() {
63         if (hashCodeValue == 0) {
64             final OtpErlangObject.Hash hash = new OtpErlangObject.Hash(5);
65             hash.combine(local.hashCode() + remote.hashCode());
66             hashCodeValue = hash.valueOf();
67         }
68         return hashCodeValue;
69     }
70 }
71