Java BitSet mapToBitSet(Map map, String key)

Here you can find the source of mapToBitSet(Map map, String key)

Description

Parses a string representation of a BitSet into a BitSet7 object.

License

Open Source License

Parameter

Parameter Description
map The map to read the BitSet string from.
key The map key that points to the BitSet string.

Return

The parsed BitSet7 object.

Declaration

public static BitSet mapToBitSet(Map<String, String> map, String key) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.BitSet;
import java.util.Map;

public class Main {
    /**//w w  w  .  ja  v a 2  s  .c  om
     * Parses a string representation of a BitSet into a BitSet7 object. Used for loading circuit state from file.
     * @param map The map to read the BitSet string from.
     * @param key The map key that points to the BitSet string.
     * @return The parsed BitSet7 object.
     */
    public static BitSet mapToBitSet(Map<String, String> map, String key) {
        String sbits = map.get(key);
        if (sbits == null)
            return null;
        else
            return stringToBitSet(sbits);
    }

    /**
     * Converts a string into a BitSet. 
     * The first character is the most significant bit. 
     * a '1' character is converted to true. 
     * Every other character is converted to false.
     * 
     * @param sbits The string to convert.
     * @return BitSet representing the binary value.
     */
    public static BitSet stringToBitSet(String sbits) {
        BitSet bits = new BitSet(sbits.length());

        for (int i = sbits.length() - 1; i >= 0; i--) {
            bits.set(sbits.length() - 1 - i, (sbits.charAt(i) == '1'));
        }

        return bits;
    }
}

Related

  1. isSubset(BitSet subsetToTest, BitSet supersetToTest)
  2. isSubSet(BitSet x, BitSet y)
  3. longFrom(final BitSet bitSet)
  4. longToBitSet(long bits)
  5. longToBitSet(long value)
  6. max(BitSet bits)
  7. members(BitSet set)
  8. nextClearBitModulo(int index, int poolSize, BitSet bitSet)
  9. not(BitSet bitSets)