Here you can find the source of insertBits(BitSet fromSet, int insertBefore, int count)
Parameter | Description |
---|---|
fromSet | The BitSet into which bit positions are to be inserted. |
insertBefore | The index above which the new bit positions are to be created. |
count | The number of new bit positions to be created. |
public static BitSet insertBits(BitSet fromSet, int insertBefore, int count)
//package com.java2s; /*//w w w .j ava 2 s. c o m * This is a class containing various static utility methods. * * Copyright (C) 1999 Thomas Studer * mailto:tstuder@datacomm.ch * http://www.datacomm.ch/tstuder * * This class is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This class 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this class; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.BitSet; public class Main { /** * Insert a range of bit positions into a BitSet. * * @return A Copy of 'fromSet' with bits in the specified range * inserted (in cleared state). * @param fromSet The BitSet into which bit positions are to be inserted. * @param insertBefore The index above which the new bit positions are to * be created. * @param count The number of new bit positions to be created. */ public static BitSet insertBits(BitSet fromSet, int insertBefore, int count) { BitSet newSet = new BitSet(fromSet.size() + count); for (int i = 0; i < insertBefore; i++) { if (fromSet.get(i)) newSet.set(i); } for (int i = insertBefore; i < fromSet.size(); i++) { if (fromSet.get(i)) newSet.set(i + count); } return newSet; } }