Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
DBTObject.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 * Copyright (c) 2020 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26package jau.direct_bt;
27
28import org.direct_bt.BTObject;
29
30public abstract class DBTObject extends DBTNativeDownlink implements BTObject
31{
32 private final int hashValue;
33
34 /* pp */ static int compHash(final String a, final String b) {
35 // 31 * x == (x << 5) - x
36 final int hash = 31 + a.hashCode();
37 return ((hash << 5) - hash) + b.hashCode();
38 }
39 /* pp */ static int compHash(final int a, final int b) {
40 // 31 * x == (x << 5) - x
41 final int hash = 31 + a;
42 return ((hash << 5) - hash) + b;
43 }
44
45 protected DBTObject(final long nativeInstance, final int hashValue)
46 {
47 super(nativeInstance);
48 this.hashValue = hashValue;
49 }
50
51 @Override
52 public abstract boolean equals(final Object obj);
53
54 @Override
55 public final int hashCode() {
56 return hashValue;
57 }
58
59 @Override
60 protected void finalize()
61 {
62 close();
63 }
64
65 @Override
66 public synchronized void close() {
67 delete();
68 }
69}
DBTObject(final long nativeInstance, final int hashValue)
Definition: DBTObject.java:45
synchronized void close()
Release the native memory associated with this object The object should not be used following a call ...
Definition: DBTObject.java:66
abstract boolean equals(final Object obj)