Here you can find the source of bitSetToMap(Map
Parameter | Description |
---|---|
map | A Map object to store the bit set in. |
key | The map key in which to store the bit set. |
bits | The bit set that will be stored in the map. |
length | Number of bits to store. |
public static Map<String, String> bitSetToMap(Map<String, String> map, String key, BitSet bits, int length)
//package com.java2s; //License from project: Open Source License import java.util.BitSet; import java.util.Map; public class Main { /**//from w ww. j a v a 2 s.c o m * Stores a BitSet object as a string in a map. Used for state persistence. * Basically converts the BitSet into a string of "1" and "0" according to its bit values. * * @param map A Map object to store the bit set in. * @param key The map key in which to store the bit set. * @param bits The bit set that will be stored in the map. * @param length Number of bits to store. * @return The same map object as the parameter. */ public static Map<String, String> bitSetToMap(Map<String, String> map, String key, BitSet bits, int length) { map.put(key, bitSetToString(bits, length)); return map; } /** * Converts a BitSet to String * @param bits * @param length * @return */ public static String bitSetToString(BitSet bits, int length) { String sbits = ""; for (int i = length - 1; i >= 0; i--) sbits += (bits.get(i) ? "1" : "0"); return sbits; } }