当前位置: 首页>>代码示例>>Java>>正文


Java DataConstants.BITS_PER_LONG属性代码示例

本文整理汇总了Java中org.andengine.util.adt.data.constants.DataConstants.BITS_PER_LONG属性的典型用法代码示例。如果您正苦于以下问题:Java DataConstants.BITS_PER_LONG属性的具体用法?Java DataConstants.BITS_PER_LONG怎么用?Java DataConstants.BITS_PER_LONG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.andengine.util.adt.data.constants.DataConstants的用法示例。


在下文中一共展示了DataConstants.BITS_PER_LONG属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LongBackedBitVector

public LongBackedBitVector(final int pSize) throws IllegalArgumentException {
	if (pSize <= 0) {
		throw new IllegalArgumentException("pSize must be > 0.");
	}
	this.mSize = pSize;

	/* Check if bytes perfectly fit into the data fields or if there are some overflow bytes that need special treatment. */
	final boolean perfectDataFit = (pSize % DataConstants.BITS_PER_LONG) == 0;

	final int dataLength;
	if (perfectDataFit) {
		dataLength = pSize / DataConstants.BITS_PER_LONG;
	} else {
		/* Extra field for overflow bytes. */
		dataLength = (pSize / DataConstants.BITS_PER_LONG) + 1;
	}
	this.mData = new long[dataLength];
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:18,代码来源:LongBackedBitVector.java

示例2: getBit

@Override
public int getBit(final int pIndex) throws IllegalArgumentException {
	if (pIndex < 0) {
		throw new IllegalArgumentException("pIndex must be >= 0.");
	}
	if (pIndex >= this.mSize) {
		throw new IllegalArgumentException("pIndex must be < size.");
	}

	final int dataIndex = pIndex / DataConstants.BITS_PER_LONG;
	final int dataOffset = pIndex % DataConstants.BITS_PER_LONG;

	final long dataField = this.mData[dataIndex];

	final int rightShift = DataConstants.BITS_PER_LONG - dataOffset - 1;
	final long dataBit = (dataField >> rightShift) & 0x01;
	final int bit = (int)dataBit;

	return bit;
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:20,代码来源:LongBackedBitVector.java

示例3: getLongBits

@Override
public long getLongBits(final int pIndex, final int pLength) throws IllegalArgumentException {
	/* Sanity checks. */
	if (pIndex < 0) {
		throw new IllegalArgumentException("pIndex must be >= 0.");
	}
	if (pLength < 0) {
		throw new IllegalArgumentException("pLength must be >= 0.");
	}
	if ((pIndex + pLength) > this.mSize) {
		throw new IllegalArgumentException("pIndex + pLength must be <= size.");
	}

	/* Early exit. */
	if (pLength == 0) {
		return 0L;
	}

	final int dataIndex = pIndex / DataConstants.BITS_PER_LONG;
	final int offset = pIndex % DataConstants.BITS_PER_LONG;

	final long data;
	if (offset == 0) {
		data = this.mData[dataIndex];
	} else if ((offset + pLength) <= DataConstants.BITS_PER_LONG) {
		data = this.mData[dataIndex] << offset;
	} else {
		/* Join bits from adjacent data fields. */
		data = (this.mData[dataIndex] << offset) | (this.mData[dataIndex + 1] >>> (DataConstants.BITS_PER_LONG - offset));
	}

	if (pLength == DataConstants.BITS_PER_LONG) {
		return data;
	} else {
		final int rightShift = DataConstants.BITS_PER_LONG - pLength;
		final long mask = 0xFFFFFFFFFFFFFFFFL >>> rightShift;
	final long unmaskedBits = data >> rightShift;
				return unmaskedBits & mask;
	}
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:40,代码来源:LongBackedBitVector.java

示例4: toByteArray

@Override
public byte[] toByteArray() {
	final int byteArrayLength;
	if ((this.mSize % DataConstants.BITS_PER_BYTE) == 0) {
		byteArrayLength = this.mSize / DataConstants.BITS_PER_BYTE;
	} else {
		byteArrayLength = (this.mSize / DataConstants.BITS_PER_BYTE) + 1;
	}

	final byte[] bytes = new byte[byteArrayLength];
	/* Check if bytes perfectly fit into the data fields or if there are some overflow bytes that need special treatment. */
	final boolean perfectDataFit = (this.mSize % DataConstants.BITS_PER_LONG) == 0;

	final long[] data = this.mData;
	final int dataLength = data.length;
	final int lastCompleteDataIndex = (perfectDataFit) ? dataLength - 1 : dataLength - 2;

	int bytesOffset = (lastCompleteDataIndex * DataConstants.BYTES_PER_LONG) + (DataConstants.BYTES_PER_LONG - 1);
	for (int i = lastCompleteDataIndex; i >= 0; i--) {
		final long dataField = data[i];

		bytes[bytesOffset--] = (byte) ((dataField >> 0) & 0xFF);
		bytes[bytesOffset--] = (byte) ((dataField >> 8) & 0xFF);
		bytes[bytesOffset--] = (byte) ((dataField >> 16) & 0xFF);
		bytes[bytesOffset--] = (byte) ((dataField >> 24) & 0xFF);
		bytes[bytesOffset--] = (byte) ((dataField >> 32) & 0xFF);
		bytes[bytesOffset--] = (byte) ((dataField >> 40) & 0xFF);
		bytes[bytesOffset--] = (byte) ((dataField >> 48) & 0xFF);
		bytes[bytesOffset--] = (byte) ((dataField >> 56) & 0xFF);
	}

	/* Put overflow bytes into last data field. */
	if (!perfectDataFit) {
		final int overflowDataIndex = dataLength - 1;
		final long overflowDataField = data[overflowDataIndex];

		final int overflowBytesOffset = overflowDataIndex * DataConstants.BYTES_PER_LONG;

		final int overflowByteCount = bytes.length % DataConstants.BYTES_PER_LONG;
		switch (overflowByteCount) {
			case 7:
				bytes[overflowBytesOffset + 6] = (byte) ((overflowDataField >> 8) & 0xFF);
			case 6:
				bytes[overflowBytesOffset + 5] = (byte) ((overflowDataField >> 16) & 0xFF);
			case 5:
				bytes[overflowBytesOffset + 4] = (byte) ((overflowDataField >> 24) & 0xFF);
			case 4:
				bytes[overflowBytesOffset + 3] = (byte) ((overflowDataField >> 32) & 0xFF);
			case 3:
				bytes[overflowBytesOffset + 2] = (byte) ((overflowDataField >> 40) & 0xFF);
			case 2:
				bytes[overflowBytesOffset + 1] = (byte) ((overflowDataField >> 48) & 0xFF);
			case 1:
				bytes[overflowBytesOffset + 0] = (byte) ((overflowDataField >> 56) & 0xFF);
		}
	}

	return bytes;
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:59,代码来源:LongBackedBitVector.java


注:本文中的org.andengine.util.adt.data.constants.DataConstants.BITS_PER_LONG属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。