List of usage examples for java.util BitSet BitSet
public BitSet()
From source file:BitOHoney.java
public static void main(String args[]) { String names[] = { "Java", "Source", "and", "Support" }; BitSet bits = new BitSet(); for (int i = 0, n = names.length; i < n; i++) { if ((names[i].length() % 2) == 0) { bits.set(i);//from ww w. j av a2s . c om } } System.out.println(bits); System.out.println("Size : " + bits.size()); System.out.println("Length: " + bits.length()); for (int i = 0, n = names.length; i < n; i++) { if (!bits.get(i)) { System.out.println(names[i] + " is odd"); } } BitSet bites = new BitSet(); bites.set(0); bites.set(1); bites.set(2); bites.set(3); bites.andNot(bits); System.out.println(bites); }
From source file:NumSeries.java
public static void main(String[] args) { for (int i = 1; i <= months.length; i++) System.out.println("Month # " + i); for (int i = 0; i < months.length; i++) System.out.println("Month " + months[i]); BitSet b = new BitSet(); b.set(0); // January b.set(3); // April for (int i = 0; i < months.length; i++) { if (b.get(i)) System.out.println("Month " + months[i] + " requested"); }//from w w w.ja v a 2 s . co m }
From source file:BitOHoney1.java
public static void main(String args[]) { String names[] = { "Hershey's Kisses", "Nestle's Crunch", "Snickers", "3 Musketeers", "Milky Way", "Twix", "Mr. Goodbar", "Crunchie", "Godiva", "Charleston Chew", "Cadbury's", "Lindt", "Aero", "Hebert", "Toberlone", "Smarties", "LifeSavers", "Riesen", "Goobers", "Raisenettes", "Nerds", "Tootsie Roll", "Sweet Tarts", "Cotton Candy" }; BitSet bits = new BitSet(); for (int i = 0, n = names.length; i < n; i++) { if ((names[i].length() % 2) == 0) { bits.set(i);//from www .j a v a 2 s .co m } } System.out.println(bits); System.out.println("Size : " + bits.size()); System.out.println("Length: " + bits.length()); for (int i = 0, n = names.length; i < n; i++) { if (!bits.get(i)) { System.out.println(names[i] + " is odd"); } } BitSet bites = new BitSet(); bites.set(0); bites.set(1); bites.set(2); bites.set(3); bites.andNot(bits); System.out.println(bites); }
From source file:examples.mail.IMAPImportMbox.java
public static void main(String[] args) throws IOException { if (args.length < 2) { System.err.println(//from w w w. j a v a2s . c o m "Usage: IMAPImportMbox imap[s]://user:password@host[:port]/folder/path <mboxfile> [selectors]"); System.err.println("\tWhere: a selector is a list of numbers/number ranges - 1,2,3-10" + " - or a list of strings to match in the initial From line"); System.exit(1); } final URI uri = URI.create(args[0]); final String file = args[1]; final File mbox = new File(file); if (!mbox.isFile() || !mbox.canRead()) { throw new IOException("Cannot read mailbox file: " + mbox); } String path = uri.getPath(); if (path == null || path.length() < 1) { throw new IllegalArgumentException("Invalid folderPath: '" + path + "'"); } String folder = path.substring(1); // skip the leading / List<String> contains = new ArrayList<String>(); // list of strings to find BitSet msgNums = new BitSet(); // list of message numbers for (int i = 2; i < args.length; i++) { String arg = args[i]; if (arg.matches("\\d+(-\\d+)?(,\\d+(-\\d+)?)*")) { // number,m-n for (String entry : arg.split(",")) { String[] parts = entry.split("-"); if (parts.length == 2) { // m-n int low = Integer.parseInt(parts[0]); int high = Integer.parseInt(parts[1]); for (int j = low; j <= high; j++) { msgNums.set(j); } } else { msgNums.set(Integer.parseInt(entry)); } } } else { contains.add(arg); // not a number/number range } } // System.out.println(msgNums.toString()); // System.out.println(java.util.Arrays.toString(contains.toArray())); // Connect and login final IMAPClient imap = IMAPUtils.imapLogin(uri, 10000, null); int total = 0; int loaded = 0; try { imap.setSoTimeout(6000); final BufferedReader br = new BufferedReader(new FileReader(file)); // TODO charset? String line; StringBuilder sb = new StringBuilder(); boolean wanted = false; // Skip any leading rubbish while ((line = br.readLine()) != null) { if (line.startsWith("From ")) { // start of message; i.e. end of previous (if any) if (process(sb, imap, folder, total)) { // process previous message (if any) loaded++; } sb.setLength(0); total++; wanted = wanted(total, line, msgNums, contains); } else if (startsWith(line, PATFROM)) { // Unescape ">+From " in body text line = line.substring(1); } // TODO process first Received: line to determine arrival date? if (wanted) { sb.append(line); sb.append(CRLF); } } br.close(); if (wanted && process(sb, imap, folder, total)) { // last message (if any) loaded++; } } catch (IOException e) { System.out.println(imap.getReplyString()); e.printStackTrace(); System.exit(10); return; } finally { imap.logout(); imap.disconnect(); } System.out.println("Processed " + total + " messages, loaded " + loaded); }
From source file:Main.java
public static BitSet bitSetOfIndexes(int... indexes) { BitSet bitSet = new BitSet(); for (int index : indexes) { bitSet.set(index);/* w ww. j a va2 s. c om*/ } return bitSet; }
From source file:Main.java
public static BitSet fromByteArray(byte[] bytes) { BitSet bits = new BitSet(); for (int i = 0; i < bytes.length * 8; i++) { if ((bytes[bytes.length - i / 8 - 1] & (1 << (i % 8))) > 0) { bits.set(i);//from w w w . ja va 2 s . c o m } } return bits; }
From source file:Main.java
public static byte[] unencodedSeptetsToEncodedSeptets(byte[] septetBytes) { byte[] txtBytes; byte[] txtSeptets; int txtBytesLen; BitSet bits;// www . j a v a 2s. c om int i, j; txtBytes = septetBytes; txtBytesLen = txtBytes.length; bits = new BitSet(); for (i = 0; i < txtBytesLen; i++) for (j = 0; j < 7; j++) if ((txtBytes[i] & (1 << j)) != 0) bits.set((i * 7) + j); // big diff here int encodedSeptetByteArrayLength = txtBytesLen * 7 / 8 + ((txtBytesLen * 7 % 8 != 0) ? 1 : 0); txtSeptets = new byte[encodedSeptetByteArrayLength]; for (i = 0; i < encodedSeptetByteArrayLength; i++) { for (j = 0; j < 8; j++) { txtSeptets[i] |= (byte) ((bits.get((i * 8) + j) ? 1 : 0) << j); } } return txtSeptets; }
From source file:Main.java
public static BitSet fromByteArray(byte[] bytes) { if (bytes == null) { return new BitSet(); }/*w w w. j a v a2 s . c o m*/ BitSet bits = new BitSet(); for (int i = 0; i < bytes.length * 8; i++) { if ((bytes[(bytes.length) - (i / 8) - 1] & (1 << (i % 8))) > 0) { bits.set(i); } } return bits; }
From source file:Main.java
public static BitSet int2BitSet(int value, int offset) { BitSet bs = new BitSet(); String hex = Integer.toHexString(value); hex2BitSet(bs, hex.getBytes(), offset); return bs;// ww w.j a va2 s.c o m }
From source file:org.terrier.realtime.compression.MemBitSetBuffer.java
/** Constructor (64 bits). */ public MemBitSetBuffer() { buffer = new BitSet(); pointer = 1; position = 1; }