Example usage for java.util BitSet toLongArray

List of usage examples for java.util BitSet toLongArray

Introduction

In this page you can find the example usage for java.util BitSet toLongArray.

Prototype

public long[] toLongArray() 

Source Link

Document

Returns a new long array containing all the bits in this bit set.

Usage

From source file:Test.java

public static void main(String[] args) {
    BitSet bitSet = new BitSet();
    long[] array = { 1, 2, 3 };
    bitSet = BitSet.valueOf(array);
    System.out.println(bitSet);/*from  w w  w  .  j  a v a  2 s .com*/

    long[] tmp = bitSet.toLongArray();
    for (long number : tmp) {
        System.out.println(number);
    }

    System.out.println(bitSet.previousSetBit(1));
    System.out.println(bitSet.previousClearBit(66));

}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);// www .j  a  v a2 s  .com
    bitset1.set(1);
    bitset1.set(2);

    // print the sets
    System.out.println("Bitset1:" + bitset1);

    System.out.println(Arrays.toString(bitset1.toLongArray()));
}

From source file:be.error.rpi.adc.ObjectStatusReader.java

@Override
public Pair<AdcChannel, ObjectStatusType> apply(final AdcChannel adcChannel) {
    try {/*from   w  w  w.ja  v  a2 s  .co  m*/
        byte readResult[] = adcChannel.getAdc().read(adcChannel);
        BitSet conversion = valueOf(new byte[] { readResult[1], readResult[0] });

        ObjectStatusType objectStatusType = READ_ERROR;

        if (!conversion.get(15)) {
            long[] l = conversion.toLongArray();
            if (l != null && l.length == 1) {
                BigDecimal value = new BigDecimal(l[0]);
                BigDecimal voltage = value.multiply(step).setScale(2, HALF_UP);
                objectStatusType = objectStatusTypeMapper.map(voltage);
            }
        }
        return of(adcChannel, objectStatusType);
    } catch (IOException ioException) {
        logger.error("Could not read from channel", ioException);
        throw new RuntimeException(ioException);
    }
}

From source file:hivemall.ftvec.ranking.ItemPairsSamplingUDTF.java

private void sampleWithoutReplacement(int numPosItems, int numNegItems, @Nonnull final BitSet bitset)
        throws HiveException {
    final BitSet bitsetForPosSampling = bitset;
    final BitSet bitsetForNegSampling = BitSet.valueOf(bitset.toLongArray());

    final int numSamples = Math.max(1, Math.round(numPosItems * samplingRate));
    for (int s = 0; s < numSamples; s++) {
        int nth = _rand.nextInt(numPosItems);
        int i = BitUtils.indexOfSetBit(bitsetForPosSampling, nth);
        if (i == -1) {
            throw new UDFArgumentException("Cannot find a value for " + nth + "-th element in bitset "
                    + bitset.toString() + " where numPosItems = " + numPosItems);
        }/*from   www . j ava 2s.  c  o m*/
        bitsetForPosSampling.set(i, false);
        --numPosItems;

        nth = _rand.nextInt(numNegItems);
        int j = BitUtils.indexOfClearBit(bitsetForNegSampling, nth, maxItemId);
        if (j < 0 || j > maxItemId) {
            throw new UDFArgumentException("j MUST be in [0," + maxItemId + "] but j was " + j);
        }
        bitsetForNegSampling.set(j, true);
        --numNegItems;

        posItemId.set(i);
        negItemId.set(j);
        forward(forwardObjs);

        if (numPosItems <= 0) {
            // cannot draw a positive example anymore
            return;
        } else if (numNegItems <= 0) {
            // cannot draw a negative example anymore
            return;
        }
    }
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.SetAlarmNotificationsCommandExecutor.java

public long alarmFilterLongValue(final AlarmNotifications alarmNotifications) {

    final BitSet bitSet = new BitSet(NUMBER_OF_BITS_IN_ALARM_FILTER);
    final Set<AlarmNotification> notifications = alarmNotifications.getAlarmNotifications();
    for (final AlarmNotification alarmNotification : notifications) {
        bitSet.set(alarmRegisterBitIndexPerAlarmType.get(alarmNotification.getAlarmType()),
                alarmNotification.isEnabled());
    }//from   ww  w  .  ja  va2 s .c  o m

    return bitSet.toLongArray()[0];
}

From source file:ezbake.deployer.impl.Files.java

public static int convertPosixFilePermissionsToTarArchiveEntryMode(Set<PosixFilePermission> permissions) {
    BitSet mode = new BitSet();

    if (permissions.contains(PosixFilePermission.OTHERS_EXECUTE)) {
        mode.set(PosixFilePermission.OTHERS_EXECUTE.ordinal());
    }/*from  w  w w. j  ava 2s  . c o  m*/
    if (permissions.contains(PosixFilePermission.OTHERS_WRITE)) {
        mode.set(PosixFilePermission.OTHERS_WRITE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OTHERS_READ)) {
        mode.set(PosixFilePermission.OTHERS_READ.ordinal());
    }
    if (permissions.contains(PosixFilePermission.GROUP_EXECUTE)) {
        mode.set(PosixFilePermission.GROUP_EXECUTE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.GROUP_WRITE)) {
        mode.set(PosixFilePermission.GROUP_WRITE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.GROUP_READ)) {
        mode.set(PosixFilePermission.GROUP_READ.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OWNER_EXECUTE)) {
        mode.set(PosixFilePermission.OWNER_EXECUTE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OWNER_WRITE)) {
        mode.set(PosixFilePermission.OWNER_WRITE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OWNER_READ)) {
        mode.set(PosixFilePermission.OWNER_READ.ordinal());
    }

    return (int) mode.toLongArray()[0];
}

From source file:org.apache.eagle.alert.engine.serialization.PartitionedEventSerializerTest.java

@Test
public void testBitSet() {
    BitSet bitSet = new BitSet();
    bitSet.set(0, true); // 1
    bitSet.set(1, false); // 0
    bitSet.set(2, true); // 1
    LOG.info("Bit Set Size: {}", bitSet.size());
    LOG.info("Bit Set Byte[]: {}", bitSet.toByteArray());
    LOG.info("Bit Set Byte[]: {}", bitSet.toLongArray());
    LOG.info("BitSet[0]: {}", bitSet.get(0));
    LOG.info("BitSet[1]: {}", bitSet.get(1));
    LOG.info("BitSet[1]: {}", bitSet.get(2));

    byte[] bytes = bitSet.toByteArray();

    BitSet bitSet2 = BitSet.valueOf(bytes);

    LOG.info("Bit Set Size: {}", bitSet2.size());
    LOG.info("Bit Set Byte[]: {}", bitSet2.toByteArray());
    LOG.info("Bit Set Byte[]: {}", bitSet2.toLongArray());
    LOG.info("BitSet[0]: {}", bitSet2.get(0));
    LOG.info("BitSet[1]: {}", bitSet2.get(1));
    LOG.info("BitSet[1]: {}", bitSet2.get(2));

    BitSet bitSet3 = new BitSet();
    bitSet3.set(0, true);/*from w  ww  . j a  v  a2 s .c om*/
    Assert.assertEquals(1, bitSet3.length());

    BitSet bitSet4 = new BitSet();
    bitSet4.set(0, false);
    Assert.assertEquals(0, bitSet4.length());
    Assert.assertFalse(bitSet4.get(1));
    Assert.assertFalse(bitSet4.get(2));
}