IndirectBoolean.java
1 /* 2 * Copyright (C) 2022 github.com/REAndroid 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 package com.reandroid.arsc.item; 17 18 public class IndirectBoolean implements BooleanReference{ 19 20 private final BlockItem blockItem; 21 private final int byteOffset; 22 private final int bitIndex; 23 24 public IndirectBoolean(BlockItem blockItem, int byteOffset, int bitIndex) { 25 this.blockItem = blockItem; 26 this.byteOffset = byteOffset; 27 this.bitIndex = bitIndex; 28 } 29 30 @Override 31 public boolean get() { 32 return BlockItem.getBit(blockItem.getBytesInternal(), byteOffset, bitIndex); 33 } 34 @Override 35 public void set(boolean value) { 36 BlockItem.putBit(blockItem.getBytesInternal(), byteOffset, bitIndex, value); 37 } 38 @Override 39 public String toString() { 40 return Boolean.toString(get()); 41 } 42 }