JOAL v2.6.0-rc-20250706
JOAL, OpenAL® API Binding for Java™ (public API).
ALContextKey.java
Go to the documentation of this file.
1/**
2 * Copyright 2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.openal;
29
30import com.jogamp.common.util.HashUtil;
31
32/**
33 * Implementing {@link #equals(Object)} based on the native address
34 * and {@link #hashCode()} on the {@link HashUtil#getAddrHash32_EqualDist(long)} with same native address.
35 * <p>
36 * Both, the native address and its hash code values are cached.
37 * </p>
38 */
39public class ALContextKey {
40 static final ALC alc = ALFactory.getALC();
41 private final ALCcontext alCtx;
42 private final long nativeAddress;
43 private final int hashCodeValue;
44
45 /** Creates an instance using the current context as key. */
46 public ALContextKey( final ALCcontext context ) {
47 if( null == context ) {
48 throw new IllegalArgumentException("null context");
49 }
50 // alCtx = alc.alcGetCurrentContext();
51 alCtx = context;
52 if( null != alCtx ) {
53 nativeAddress = alCtx.getDirectBufferAddress();
54 hashCodeValue = HashUtil.getAddrHash32_EqualDist(nativeAddress);
55 } else {
56 nativeAddress = 0;
57 hashCodeValue = 0;
58 }
59 }
60
61 public ALCcontext getContext() { return alCtx; }
62
63 @Override
64 public boolean equals(final Object o) {
65 if( this == o ) {
66 return true;
67 }
68 if( !(o instanceof ALContextKey) ) {
69 return false;
70 }
71 final ALContextKey o2 = (ALContextKey)o;
72 return nativeAddress == o2.nativeAddress;
73 }
74 @Override
75 public int hashCode() {
76 return hashCodeValue;
77 }
78
79 @Override
80 public String toString() {
81 return "ALContextKey[alCtx hash 0x"+Integer.toHexString(System.identityHashCode(alCtx))+
82 ", native[ptr 0x"+Long.toHexString(nativeAddress)+", hash 0x"+Integer.toHexString(hashCodeValue)+"]]";
83 }
84}
final long getDirectBufferAddress()
Returns the native address of the underlying native ByteBuffer getBuffer().
Definition: ALCcontext.java:62
Implementing equals(Object) based on the native address and hashCode() on the HashUtil#getAddrHash32_...
ALContextKey(final ALCcontext context)
Creates an instance using the current context as key.
boolean equals(final Object o)
This class provides factory methods for generating AL and ALC objects.
Definition: ALFactory.java:62
static ALC getALC()
Get the default ALC object.
Definition: ALFactory.java:136