Java BitSet expand(final BitSet bits, final BitSet add)

Here you can find the source of expand(final BitSet bits, final BitSet add)

Description

Fuses two given BitSets to one by adding the bits of the second at the end of the first BitSet.

License

Open Source License

Parameter

Parameter Description
bits The first BitSet.
add The second BitSet.

Declaration

public static BitSet expand(final BitSet bits, final BitSet add) 

Method Source Code

//package com.java2s;
/**//from  w w  w  .  j  a v  a 2 s.  c o  m
 *  Copyright (C) 2012 Ulrich Viefhaus
 *    This file (ByteUtils.java) is from the package utils which is part of Hashchecker.
 *    Hashchecker is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Hashmaker and Hashviewer is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Hashmaker and Hashviewer.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */

import java.util.BitSet;

public class Main {
    /**
     * Fuses two given BitSets to one by adding the bits of the second at the
     * end of the first BitSet. The length of the result is the added length off
     * both given BitSets.
     * 
     * @param bits
     *            The first BitSet.
     * @param add
     *            The second BitSet.
     */
    public static BitSet expand(final BitSet bits, final BitSet add) {

        final BitSet result = (BitSet) bits.clone();
        int index = result.length();
        for (int i = 0; i < add.length(); i++) {
            if (add.get(i)) {
                result.set(index);
            }
            index++;
        }
        return result;
    }
}

Related

  1. encode(BitSet allowedCharacters, String s, String charset)
  2. encode(BitSet origin, int originBitLength)
  3. encode(String s, BitSet bs)
  4. ensureExclusivity(BitSet bs1, BitSet bs2)
  5. escape(String s, BitSet safeChars)
  6. extractLong(BitSet bitSet, int from, int to)
  7. extractSetBitsMsgFromTxSet(final BitSet txSet)
  8. filter(double[] data, BitSet mask)
  9. filterByIndices(List list, BitSet filter)