Typically takes a list of BitSets and returns a BitSet with the OR of all of them. - Java java.util

Java examples for java.util:BitSet

Description

Typically takes a list of BitSets and returns a BitSet with the OR of all of them.

Demo Code


//package com.java2s;

import java.util.BitSet;
import java.util.Iterator;

public class Main {
    /**//from  w w w  .j  a  v a  2  s. com
     * Typically takes a list of BitSets and returns a BitSet with the OR of all of them.
     * @param bss Any iterable collection of BitSets 
     * @return
     */
    public static BitSet orAll(Iterable<BitSet> bss) {
        if (bss == null)
            throw new IllegalArgumentException("please no null's");
        Iterator<BitSet> iter = bss.iterator();
        if (!iter.hasNext()) // case where no BitSets in bss
            return new BitSet(); // (all bits set to 0)
        BitSet ret = (BitSet) iter.next().clone(); // copy of first BitSet
        for (; iter.hasNext(); ret.or(iter.next()))
            // OR each additional BitSet with ret
            ;
        return ret;
    }
}

Related Tutorials