jaulib v1.3.0
Jau Support Library (C++, Java, ..)
SyncedBitfield.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) 2015 Gothel Software e.K.
5 * Copyright (c) 2015 JogAmp Community.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26package jau.util;
27
28import org.jau.util.Bitfield;
29
30/**
31 * Simple synchronized {@link Bitfield} by wrapping an existing {@link Bitfield}.
32 */
33public class SyncedBitfield implements Bitfield {
34 private final Bitfield impl;
35
36 public SyncedBitfield(final Bitfield impl) {
37 this.impl = impl;
38 }
39
40 @Override
41 public final synchronized int size() {
42 return impl.size();
43 }
44
45 @Override
46 public final synchronized void clearField(final boolean bit) {
47 impl.clearField(bit);
48 }
49
50 @Override
51 public final synchronized int get32(final int lowBitnum, final int length) throws IndexOutOfBoundsException {
52 return impl.get32(lowBitnum, length);
53 }
54
55 @Override
56 public final synchronized void put32(final int lowBitnum, final int length, final int data) throws IndexOutOfBoundsException {
57 impl.put32(lowBitnum, length, data);
58 }
59
60 @Override
61 public final synchronized int copy32(final int srcLowBitnum, final int dstLowBitnum, final int length) throws IndexOutOfBoundsException {
62 return impl.copy32(srcLowBitnum, dstLowBitnum, length);
63 }
64
65 @Override
66 public final synchronized boolean get(final int bitnum) throws IndexOutOfBoundsException {
67 return impl.get(bitnum);
68 }
69
70 @Override
71 public final synchronized boolean put(final int bitnum, final boolean bit) throws IndexOutOfBoundsException {
72 return impl.put(bitnum, bit);
73 }
74
75 @Override
76 public final synchronized void set(final int bitnum) throws IndexOutOfBoundsException {
77 impl.set(bitnum);
78 }
79
80 @Override
81 public final synchronized void clear(final int bitnum) throws IndexOutOfBoundsException {
82 impl.clear(bitnum);
83 }
84
85 @Override
86 public final synchronized boolean copy(final int srcBitnum, final int dstBitnum) throws IndexOutOfBoundsException {
87 return impl.copy(srcBitnum, dstBitnum);
88 }
89
90 @Override
91 public final synchronized int bitCount() {
92 return impl.bitCount();
93 }
94}
Simple synchronized Bitfield by wrapping an existing Bitfield.
SyncedBitfield(final Bitfield impl)
final synchronized int copy32(final int srcLowBitnum, final int dstLowBitnum, final int length)
Copies length bits at position srcLowBitnum to position dstLowBitnum and returning the bits.
final synchronized void clear(final int bitnum)
Clear the bit at position bitnum according to bit.
final synchronized int bitCount()
Returns the number of one bits within this bitfield.
final synchronized boolean copy(final int srcBitnum, final int dstBitnum)
Copies the bit at position srcBitnum to position dstBitnum and returning true if the bit is set,...
final synchronized void clearField(final boolean bit)
Set all bits of this bitfield to the given value bit.
final synchronized int size()
Returns the storage size in bit units, e.g.
final synchronized int get32(final int lowBitnum, final int length)
Returns length bits from this storage, starting with the lowest bit from the storage position lowBitn...
final synchronized boolean put(final int bitnum, final boolean bit)
Set or clear the bit at position bitnum according to bit and return the previous value.
final synchronized void put32(final int lowBitnum, final int length, final int data)
Puts length bits of given data into this storage, starting w/ the lowest bit to the storage position ...
Simple bitfield interface for efficient bit storage access in O(1).
Definition: Bitfield.java:34
boolean get(final int bitnum)
Return true if the bit at position bitnum is set, otherwise false.
void clearField(final boolean bit)
Set all bits of this bitfield to the given value bit.
boolean copy(final int srcBitnum, final int dstBitnum)
Copies the bit at position srcBitnum to position dstBitnum and returning true if the bit is set,...
int copy32(final int srcLowBitnum, final int dstLowBitnum, final int length)
Copies length bits at position srcLowBitnum to position dstLowBitnum and returning the bits.
int size()
Returns the storage size in bit units, e.g.
void clear(final int bitnum)
Clear the bit at position bitnum according to bit.
boolean put(final int bitnum, final boolean bit)
Set or clear the bit at position bitnum according to bit and return the previous value.
int bitCount()
Returns the number of one bits within this bitfield.
void set(final int bitnum)
Set the bit at position bitnum according to bit.
int get32(final int lowBitnum, final int length)
Returns length bits from this storage, starting with the lowest bit from the storage position lowBitn...
void put32(final int lowBitnum, final int length, final int data)
Puts length bits of given data into this storage, starting w/ the lowest bit to the storage position ...