Example usage for java.util BitSet set

List of usage examples for java.util BitSet set

Introduction

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

Prototype

public void set(int bitIndex) 

Source Link

Document

Sets the bit at the specified index to true .

Usage

From source file:com.eclecticlogic.pedal.TestPedalDialect.java

@Test
@Transactional/*  w  w  w.jav  a  2  s .c  o  m*/
public void insertTestForCustomTypes() {
    ExoticTypes et = new ExoticTypes();
    et.setLogin("inserter");
    BitSet bs = new BitSet(7);
    bs.set(1);
    bs.set(3);
    bs.set(4);

    et.setCountries(bs);
    et.setAuthorizations(Sets.newHashSet("a", "b", "b", "c"));
    et.setScores(Lists.newArrayList(1L, 2L, 3L));
    et.setGpa(Lists.<Long>newArrayList());
    et.setStatus(Status.ACTIVE);
    et.setCustom("abc");

    entityManager.persist(et);
    entityManager.flush();

    ExoticTypes loaded = entityManager.find(ExoticTypes.class, "inserter");
    Assert.assertNotNull(loaded);
    Assert.assertEquals(loaded.getLogin(), "inserter");
    Assert.assertEquals(loaded.getAuthorizations(), Sets.newHashSet("b", "a", "c"));
    Assert.assertEquals(loaded.getCountries().toString(), "{1, 3, 4}");
    Assert.assertEquals(loaded.getGpa(), Lists.newArrayList());
    Assert.assertEquals(loaded.getScores(), Lists.newArrayList(1L, 2L, 3L));
    Assert.assertEquals(loaded.getStatus(), Status.ACTIVE);
}

From source file:de.upb.wdqa.wdvd.revisiontags.TagDownloaderRevisionData.java

/**
 * Converts the tags to a memory efficient byte[] representation
 *//*  www .  jav a2s.  c o  m*/
private byte[] tagsToBytes(Set<DbTag> tags) {
    BitSet bitSet = new BitSet();

    if (tags != null) {
        for (DbTag tag : tags) {
            bitSet.set(tag.getTagId());
        }
    }

    return bitSet.toByteArray();
}

From source file:com.eclecticlogic.pedal.TestPedalDialect.java

@Test
@Transactional//ww w.  java 2  s. c  o  m
public void testCopyCommand() {
    CopyList<ExoticTypes> list = new CopyList<>();

    // The copy-command can insert 100k of these per second.
    for (int i = 0; i < 10; i++) {
        ExoticTypes et = new ExoticTypes();
        et.setLogin("copyCommand" + i);
        BitSet bs = new BitSet(7);
        bs.set(1);
        bs.set(3);
        bs.set(4);
        et.setCountries(bs);
        et.setAuthorizations(Sets.newHashSet("a", "b", "b", "c"));
        if (i != 9) {
            et.setScores(Lists.newArrayList(1L, 2L, 3L));
        } else {
            et.setScores(Lists.<Long>newArrayList());
        }
        et.setStatus(Status.ACTIVE);
        et.setCustom("this will be made uppercase");
        list.add(et);
    }

    copyCommand.insert(entityManager, list);
    Assert.assertNotNull(entityManager.find(ExoticTypes.class, "copyCommand0"));
    Assert.assertEquals(entityManager.find(ExoticTypes.class, "copyCommand0").getCustom(),
            "THIS WILL BE MADE UPPERCASE");
    Assert.assertNotNull(entityManager.find(ExoticTypes.class, "copyCommand1"));
    Assert.assertEquals(entityManager.find(ExoticTypes.class, "copyCommand0").getAuthorizations(),
            Sets.newHashSet("b", "c", "a"));
}

From source file:org.asoem.greyfish.utils.collect.BitString.java

/**
 * Create a new bit string of given {@code length} with bits set to one at given {@code indices}. The indices might
 * be given//  w  w w. ja v  a  2  s  .  c om
 *
 * @param indices the indices of the bits to set
 * @param length  the length of the bit string to create
 * @return a new bit string of given {@code length}
 */
public static BitString forIndices(final Set<Integer> indices, final int length) {
    if ((double) indices.size() / length < 1.0 / 32) {
        return new IndexSetString(indices, length);
    } else {
        final BitSet bitSet = new BitSet(length);
        for (Integer index : indices) {
            bitSet.set(index);
        }
        return forBitSet(bitSet, length);
    }
}

From source file:org.apache.tez.runtime.library.output.UnorderedKVOutput.java

@Override
public synchronized List<Event> close() throws Exception {
    boolean outputGenerated = this.kvWriter.close();

    DataMovementEventPayloadProto.Builder payloadBuilder = DataMovementEventPayloadProto.newBuilder();

    LOG.info("Closing KVOutput: RawLength: " + this.kvWriter.getRawLength() + ", CompressedLength: "
            + this.kvWriter.getCompressedLength());

    if (dataViaEventsEnabled && outputGenerated
            && this.kvWriter.getCompressedLength() <= dataViaEventsMaxSize) {
        LOG.info("Serialzing actual data into DataMovementEvent, dataSize: "
                + this.kvWriter.getCompressedLength());
        byte[] data = this.kvWriter.getData();
        DataProto.Builder dataProtoBuilder = DataProto.newBuilder();
        dataProtoBuilder.setData(ByteString.copyFrom(data));
        dataProtoBuilder.setRawLength((int) this.kvWriter.getRawLength());
        dataProtoBuilder.setCompressedLength((int) this.kvWriter.getCompressedLength());
        payloadBuilder.setData(dataProtoBuilder.build());
    }/* w w  w  . j a  va2 s  .  c  om*/

    // Set the list of empty partitions - single partition on this case.
    if (!outputGenerated) {
        LOG.info("No output was generated");
        BitSet emptyPartitions = new BitSet();
        emptyPartitions.set(0);
        ByteString emptyPartitionsBytesString = TezCommonUtils
                .compressByteArrayToByteString(TezUtilsInternal.toByteArray(emptyPartitions));
        payloadBuilder.setEmptyPartitions(emptyPartitionsBytesString);
    }
    if (outputGenerated) {
        String host = getHost();
        ByteBuffer shuffleMetadata = getContext()
                .getServiceProviderMetaData(ShuffleUtils.SHUFFLE_HANDLER_SERVICE_ID);
        int shufflePort = ShuffleUtils.deserializeShuffleProviderMetaData(shuffleMetadata);
        payloadBuilder.setHost(host);
        payloadBuilder.setPort(shufflePort);
        payloadBuilder.setPathComponent(getContext().getUniqueIdentifier());
    }
    DataMovementEventPayloadProto payloadProto = payloadBuilder.build();

    DataMovementEvent dmEvent = DataMovementEvent.create(0, payloadProto.toByteString().asReadOnlyByteBuffer());
    List<Event> events = Lists.newArrayListWithCapacity(1);
    events.add(dmEvent);
    return events;
}

From source file:uniol.apt.extension.ExtendStateFile.java

private BitSet codeStringToCode(String codeString) {
    BitSet code = new BitSet(codeLength);

    for (int i = 0; i < codeString.length(); i++) {
        if (codeString.charAt(i) == '1') {
            code.set(i);
        }/*from   w  ww  .  j  a  v a 2  s  .  c o m*/
    }

    return code;
}

From source file:org.apache.kylin.cube.gridtable.CuboidToGridTableMappingExt.java

private void init() {
    dynGtDataTypes = Lists.newArrayList();
    dynGtColBlocks = Lists.newArrayList();
    dynDim2gt = Maps.newHashMap();//from  w ww.j  a va 2s .  c  o m
    dynMetrics2gt = Maps.newHashMap();

    int gtColIdx = super.getColumnCount();

    BitSet rtColBlock = new BitSet();
    // dynamic dimensions
    for (TblColRef rtDim : dynDims) {
        dynDim2gt.put(rtDim, gtColIdx);
        dynGtDataTypes.add(rtDim.getType());
        rtColBlock.set(gtColIdx);
        gtColIdx++;
    }
    dynamicDims = new ImmutableBitSet(rtColBlock);

    // dynamic metrics
    for (DynamicFunctionDesc rtFunc : dynFuncs) {
        dynMetrics2gt.put(rtFunc, gtColIdx);
        dynGtDataTypes.add(rtFunc.getReturnDataType());
        rtColBlock.set(gtColIdx);
        gtColIdx++;
    }

    dynGtColBlocks.add(new ImmutableBitSet(rtColBlock));
}

From source file:Randoms.java

/** Return a random BitSet with "size" bits, each having probability p of being true. */
public synchronized BitSet nextBitSet(int size, double p) {
    BitSet bs = new BitSet(size);
    for (int i = 0; i < size; i++)
        if (nextBoolean(p)) {
            bs.set(i);
        }/*from w  ww.j  a v  a 2 s.  c o m*/
    return bs;
}

From source file:com.cloudera.oryx.kmeans.computation.cluster.KSketchIndex.java

private BitSet index(RealVector vec) {
    final double[] prod = new double[projectionBits];

    vec.walkInDefaultOrder(new AbstractRealVectorPreservingVisitor() {
        @Override/*from  w w  w .  ja va 2s .c  o  m*/
        public void visit(int index, double value) {
            for (int j = 0; j < projectionBits; j++) {
                prod[j] += value * projection[index + j * dimensions];
            }
        }
    });

    BitSet bitset = new BitSet(projectionBits);
    for (int i = 0; i < projectionBits; i++) {
        if (prod[i] > 0.0) {
            bitset.set(i);
        }
    }
    return bitset;
}

From source file:nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.chunks.Chunk1_10Type.java

@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
    int chunkX = input.readInt();
    int chunkZ = input.readInt();

    boolean groundUp = input.readBoolean();
    int primaryBitmask = Type.VAR_INT.read(input);
    Type.VAR_INT.read(input);//from   w  w w  .j  a  va  2 s .  co  m

    BitSet usedSections = new BitSet(16);
    ChunkSection1_10[] sections = new ChunkSection1_10[16];
    // Calculate section count from bitmask
    for (int i = 0; i < 16; i++) {
        if ((primaryBitmask & (1 << i)) != 0) {
            usedSections.set(i);
        }
    }

    // Read sections
    for (int i = 0; i < 16; i++) {
        if (!usedSections.get(i))
            continue; // Section not set
        ChunkSection1_10 section = new ChunkSection1_10();
        sections[i] = section;
        section.readBlocks(input);
        section.readBlockLight(input);
        if (world.getEnvironment() == World.Environment.NORMAL) {
            section.readSkyLight(input);
        }
    }

    byte[] biomeData = groundUp ? new byte[256] : null;
    if (groundUp) {
        input.readBytes(biomeData);
    }

    List<CompoundTag> nbtData = Arrays.asList(Type.NBT_ARRAY.read(input));

    // Temp patch for plugins that sent wrong too big chunks TODO find the issue in LibsDisguise and PR it.
    if (input.readableBytes() > 0) {
        byte[] array = new byte[input.readableBytes()];
        input.readBytes(array);
        if (ViaVersion.getInstance().isDebug())
            System.out.println("Found " + array.length + " more bytes than expected while reading the chunk");
    }

    return new Chunk1_10(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
}