List of usage examples for java.util BitSet flip
public void flip(int bitIndex)
From source file:Main.java
public static void main(String[] args) { BitSet bitset1 = new BitSet(8); // assign values to bitset1 bitset1.set(0);/*from w ww . j a v a 2s .c o m*/ bitset1.set(1); bitset1.set(2); System.out.println(bitset1); bitset1.flip(1); System.out.println(bitset1); }
From source file:de.uniba.wiai.lspi.chord.data.ID.java
private static BitSet bitsetArithPwrOf2(final BitSet _bs, final int pwrOf2, final boolean addition) { // The bitset is defined as big-endian unsigned, i.e. (idx 0 is highest bit) final BitSet bs = (BitSet) _bs.clone(); assert (pwrOf2 < kTotalBitLen); for (int i = kTotalBitLen - 1 - pwrOf2; i >= 0; --i) { bs.flip(i); // add/sub for unsigned binary is the same, except we bail if (set == addition) after flip if (bs.get(i) == addition) break; }/* www . j ava 2s . c o m*/ return bs; }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@Test(enabled = true) public void testCopyBitSet() throws Exception { final BitSet bitSet = new BitSet(10); bitSet.flip(2); bitSet.flip(4);//from w w w. j a v a 2s . c om final BitSet copy = _kryo.copy(bitSet); assertDeepEquals(copy, bitSet); }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@Test(enabled = true) public void testBitSet() throws Exception { final BitSet bitSet = new BitSet(10); bitSet.flip(2); bitSet.flip(4);/*from w w w.j ava 2s. c o m*/ final Holder<BitSet> holder = new Holder<BitSet>(bitSet); @SuppressWarnings("unchecked") final Holder<BitSet> deserialized = deserialize(serialize(holder), Holder.class); assertDeepEquals(deserialized, holder); }
From source file:org.apache.carbondata.core.scan.filter.FilterUtil.java
/** * This method will compare the selected data against null values and * flip the bitSet if any null value is found * * @param dimensionColumnPage//from w w w . jav a2s . c om * @param bitSet */ public static void removeNullValues(DimensionColumnPage dimensionColumnPage, BitSet bitSet, byte[] defaultValue) { if (!bitSet.isEmpty()) { if (null != dimensionColumnPage.getNullBits()) { if (!dimensionColumnPage.getNullBits().isEmpty()) { for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) { if (dimensionColumnPage.getNullBits().get(i)) { bitSet.flip(i); } } } } else { for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) { if (dimensionColumnPage.compareTo(i, defaultValue) == 0) { bitSet.flip(i); } } } } }
From source file:org.mycore.imagetiler.MCRImageTest.java
/** * Tests {@link MCRImage#tile()} with various images provided by {@link #setUp()}. * @throws Exception if tiling process fails *///w w w .j av a 2 s. co m @Test public void testTiling() throws Exception { for (final Map.Entry<String, String> entry : pics.entrySet()) { final File file = new File(entry.getValue()); final String derivateID = "derivateID"; final String imagePath = "imagePath/" + FilenameUtils.getName(entry.getValue()); final MCRImage image = new MCRMemSaveImage(file.toPath(), derivateID, imagePath); image.setTileDir(tileDir); final BitSet events = new BitSet(2);//pre and post event image.tile(new MCRTileEventHandler() { @Override public void preImageReaderCreated() { events.flip(0); } @Override public void postImageReaderCreated() { events.flip(1); } }); assertTrue("preImageReaderCreated() was not called", events.get(0)); assertTrue("postImageReaderCreated() was not called", events.get(1)); assertTrue("Tile directory is not created.", Files.exists(tileDir)); final Path iviewFile = MCRImage.getTiledFile(tileDir, derivateID, imagePath); assertTrue("IView File is not created:" + iviewFile, Files.exists(iviewFile)); final MCRTiledPictureProps props = MCRTiledPictureProps.getInstanceFromFile(iviewFile); final int tilesCount; try (final ZipFile iviewImage = new ZipFile(iviewFile.toFile())) { tilesCount = iviewImage.size() - 1; ZipEntry imageInfoXML = iviewImage.getEntry(MCRTiledPictureProps.IMAGEINFO_XML); DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document imageInfo = documentBuilder.parse(iviewImage.getInputStream(imageInfoXML)); String hAttr = Objects.requireNonNull(imageInfo.getDocumentElement().getAttribute("height")); String wAttr = Objects.requireNonNull(imageInfo.getDocumentElement().getAttribute("width")); String zAttr = Objects.requireNonNull(imageInfo.getDocumentElement().getAttribute("zoomLevel")); String tAttr = Objects.requireNonNull(imageInfo.getDocumentElement().getAttribute("tiles")); assertTrue("height must be positive: " + hAttr, Integer.parseInt(hAttr) > 0); assertTrue("width must be positive: " + wAttr, Integer.parseInt(wAttr) > 0); assertTrue("zoomLevel must be zero or positive: " + zAttr, Integer.parseInt(zAttr) >= 0); int iTiles = Integer.parseInt(tAttr); assertEquals(tilesCount, iTiles); } assertEquals(entry.getKey() + ": Metadata tile count does not match stored tile count.", props.getTilesCount(), tilesCount); final int x = props.width; final int y = props.height; assertEquals(entry.getKey() + ": Calculated tile count does not match stored tile count.", MCRImage.getTileCount(x, y), tilesCount); } }