Example usage for java.util BitSet get

List of usage examples for java.util BitSet get

Introduction

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

Prototype

public boolean get(int bitIndex) 

Source Link

Document

Returns the value of the bit with the specified index.

Usage

From source file:com.box.restclientv2.httpclientsupport.HttpClientURLEncodedUtils.java

/**
 * Emcode/escape a portion of a URL, to use with the query part ensure {@code plusAsBlank} is true.
 * /*  w ww.ja va  2 s .  co m*/
 * @param content
 *            the portion to decode
 * @param charset
 *            the charset to use
 * @param blankAsPlus
 *            if {@code true}, then convert space to '+' (e.g. for www-url-form-encoded content), otherwise leave as is.
 * @return
 */
private static String urlencode(final String content, final Charset charset, final BitSet safechars,
        final boolean blankAsPlus) {
    if (content == null) {
        return null;
    }
    StringBuilder buf = new StringBuilder();
    ByteBuffer bb = charset.encode(content);
    while (bb.hasRemaining()) {
        int b = bb.get() & 0xff;
        if (safechars.get(b)) {
            buf.append((char) b);
        } else if (blankAsPlus && b == ' ') {
            buf.append('+');
        } else {
            buf.append("%");
            char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX));
            char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
            buf.append(hex1);
            buf.append(hex2);
        }
    }
    return buf.toString();
}

From source file:com.gistlabs.mechanize.util.apache.URLEncodedUtils.java

/**
 * Emcode/escape a portion of a URL, to use with the query part ensure {@code plusAsBlank} is true.
 * /*from w w  w . j a  va2  s.c  om*/
 * @param content the portion to decode
 * @param charset the charset to use
 * @param blankAsPlus if {@code true}, then convert space to '+' (e.g. for www-url-form-encoded content), otherwise leave as is.
 * @return
 */
private static String urlencode(final String content, final Charset charset, final BitSet safechars,
        final boolean blankAsPlus) {
    if (content == null)
        return null;
    StringBuilder buf = new StringBuilder();
    ByteBuffer bb = charset.encode(content);
    while (bb.hasRemaining()) {
        int b = bb.get() & 0xff;
        if (safechars.get(b))
            buf.append((char) b);
        else if (blankAsPlus && b == ' ')
            buf.append('+');
        else {
            buf.append("%");
            char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX));
            char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
            buf.append(hex1);
            buf.append(hex2);
        }
    }
    return buf.toString();
}

From source file:edu.umich.flowfence.service.SandboxManager.java

private static void dumpSandbox(Sandbox sb, BitSet seen) {
    int id = sb.getID();
    String result = String.format("    %s %s package=%s", sb, sb.getTaints(), sb.getAssignedPackage());
    if (seen == null) {
        Log.w(TAG, result + " [LEAKED]");
    } else if (seen.get(id)) {
        Log.w(TAG, result + " [DUPLICATE]");
    } else {//  w ww  .jav a 2 s .c o  m
        Log.v(TAG, result);
        seen.set(id);
    }
}

From source file:de.uni_potsdam.hpi.asg.logictool.helper.BDDHelper.java

public static BDD mergeBDDs(BDD bdd, NetlistVariable replaceVar, BDD replaceBdd, Netlist netlist) {

    Set<NetlistVariable> bddvars = BDDHelper.getVars(bdd, netlist);
    if (!bddvars.contains(replaceVar)) {
        logger.error("ReplaceVar not in Vars");
        return null;
    }/*  ww w  .  ja  v a2s .  c o m*/

    if (bddvars.size() == 1) {
        //         logger.debug("Shortcut");
        //         logger.debug("BDD: " + getFunctionString(bdd, netlist));
        //         logger.debug("ReplBDD: " + getFunctionString(replaceBdd, netlist));
        //         logger.debug("ReplVar: " + replaceVar.getName());
        if (isPos(bdd, replaceVar)) {
            return replaceBdd;
        } else {
            return replaceBdd.not();
        }
        //         return replaceBdd;//.and(netlist.getFac().one());
    }

    SortedSet<NetlistVariable> newinputs = new TreeSet<>();
    newinputs.addAll(bddvars);
    newinputs.addAll(BDDHelper.getVars(replaceBdd, netlist));
    newinputs.remove(replaceVar);
    //      System.out.println("New Inp: " + newinputs.toString());

    BDD retVal = netlist.getFac().zero();
    BitSet b = new BitSet(newinputs.size());
    for (int i = 0; i < Math.pow(2, newinputs.size()); i++) {
        //         System.out.println(i + ": " + BitSetHelper.formatBitset(b, newinputs.size()));
        int index = 0;
        BDD bdd_new = bdd;
        BDD replacBdd_new = replaceBdd;
        BDD minterm = netlist.getFac().one();
        //TODO: xWITH
        for (NetlistVariable var : newinputs) {
            if (b.get(index)) {
                bdd_new = bdd_new.restrict(var.toBDD());
                replacBdd_new = replacBdd_new.restrict(var.toBDD());
                minterm = minterm.and(var.toBDD());
            } else {
                bdd_new = bdd_new.restrict(var.toNotBDD());
                replacBdd_new = replacBdd_new.restrict(var.toNotBDD());
                minterm = minterm.and(var.toNotBDD());
            }
            index++;
        }
        if (replacBdd_new.isZero()) {
            bdd_new = bdd_new.restrict(replaceVar.toNotBDD());
        } else if (replacBdd_new.isOne()) {
            bdd_new = bdd_new.restrict(replaceVar.toBDD());
        } else {
            logger.error("Repl BDD should be one or zero");
        }

        if (bdd_new.isZero()) {

        } else if (bdd_new.isOne()) {
            retVal.orWith(minterm);
        } else {
            logger.error("BDD should be one or zero");
        }

        BitSetHelper.dualNext(b);
    }

    //      if(bddvars.size() == 1) {
    //         logger.debug("RetVal: " + getFunctionString(retVal, netlist));
    //      }

    return retVal;
}

From source file:org.lwes.serializer.Deserializer.java

public static Byte[] deserializeNByteArray(DeserializerState state, byte[] bytes) {
    int length = deserializeUINT16(state, bytes);
    BitSet bs = deserializeBitSet(state, bytes);

    Byte[] rtn = new Byte[length];
    for (int i = 0; i < length; i++) {
        if (bs.get(i)) {
            rtn[i] = deserializeBYTE(state, bytes);
        } else {/*from w w w  .j a  v  a  2 s. c o m*/
            rtn[i] = null;
        }
    }
    return rtn;
}

From source file:org.lwes.serializer.Deserializer.java

public static String[] deserializeNStringArray(DeserializerState state, byte[] bytes, short encoding) {
    int length = deserializeUINT16(state, bytes);
    BitSet bs = deserializeBitSet(state, bytes);

    String[] rtn = new String[length];
    for (int i = 0; i < length; i++) {
        if (bs.get(i)) {
            rtn[i] = deserializeSTRING(state, bytes, encoding);
        } else {/*from  w w  w  . j  ava  2s .  c  o  m*/
            rtn[i] = null;
        }
    }
    return rtn;
}

From source file:org.lwes.serializer.Deserializer.java

public static BigInteger[] deserializeNUInt64Array(DeserializerState state, byte[] bytes) {
    int length = deserializeUINT16(state, bytes);
    BitSet bs = deserializeBitSet(state, bytes);

    BigInteger[] rtn = new BigInteger[length];
    for (int i = 0; i < length; i++) {
        if (bs.get(i)) {
            rtn[i] = deserializeUInt64ToBigInteger(state, bytes);
        } else {//from w  w w.j av a 2 s  . c o m
            rtn[i] = null;
        }
    }
    return rtn;
}

From source file:org.lwes.serializer.Deserializer.java

public static Long[] deserializeNUInt32Array(DeserializerState state, byte[] bytes) {
    // get the number of items in the array
    int length = deserializeUINT16(state, bytes); // 2 bytes
    BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case
    Long[] rtn = new Long[length];
    for (int i = 0; i < length; i++) {
        if (bs.get(i)) {
            rtn[i] = deserializeUINT32(state, bytes);
        } else {/*www.j av a2s  . c o  m*/
            rtn[i] = null;
        }
    }
    return rtn;
}

From source file:org.lwes.serializer.Deserializer.java

public static Long[] deserializeNInt64Array(DeserializerState state, byte[] bytes) {
    // get the number of items in the array
    int length = deserializeUINT16(state, bytes); // 2 bytes
    BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case
    Long[] rtn = new Long[length];
    for (int i = 0; i < length; i++) {
        if (bs.get(i)) {
            rtn[i] = deserializeINT64(state, bytes);
        } else {//from ww  w  .  j  a  v a 2  s  .c o  m
            rtn[i] = null;
        }
    }
    return rtn;
}

From source file:org.lwes.serializer.Deserializer.java

public static Float[] deserializeNFloatArray(DeserializerState state, byte[] bytes) {
    // get the number of items in the array
    int length = deserializeUINT16(state, bytes); // 2 bytes
    BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case
    Float[] rtn = new Float[length];
    for (int i = 0; i < length; i++) {
        if (bs.get(i)) {
            rtn[i] = deserializeFLOAT(state, bytes);
        } else {//from  w  w  w .ja v a2s.com
            rtn[i] = null;
        }
    }
    return rtn;
}