Package java.util

Examples of java.util.BitSet


        if (str == null)
        {
            return null;
        }

        BitSet set = new BitSet();
        StringTokenizer tokeniser = new StringTokenizer(str.substring(1, str.length()-1), ",");
        while (tokeniser.hasMoreTokens())
        {
            String token = tokeniser.nextToken().trim();
            try
            {
                int position = new Integer(token).intValue();
                set.set(position);
            }
            catch (NumberFormatException nfe)
            {
                throw new NucleusDataStoreException(LOCALISER.msg("016002", str, BitSet.class.getName()), nfe);
            }
View Full Code Here


    public String toString(Object obj)
    {
        String str;
        if (obj instanceof BitSet)
        {
            BitSet set = (BitSet)obj;
            str = set.toString();
        }
        else
        {
            str = (String)obj;
        }
View Full Code Here

  /**
   * Tests for bitsetlogic.
   */
  @Test
  public void testbitsetlogic() throws Exception {
    final BitSet setallfalse = new BitSet(7);
    final BitSet invert = (BitSet) setallfalse.clone();
    assertThat(invert.length(), is(0));

    invert.flip(0, 6);
    assertThat(invert.length(), is(6));
    final BitSet set = new BitSet();
    set.set(3);
    set.set(4);
    set.set(5);
    set.set(7);
    set.set(8);

    final BitSet subset = set.get(2, 6);

    assertFalse(subset.get(0));
    assertTrue(subset.get(1));
    assertTrue(subset.get(2));
    assertTrue(subset.get(3));
    assertFalse(subset.get(4));
    assertFalse(subset.get(5));

    final BitSet subset2 = set.get(2, 8);

    assertFalse(subset2.get(0));
    assertTrue(subset2.get(1));
    assertTrue(subset2.get(2));
    assertTrue(subset2.get(3));
    assertFalse(subset2.get(4));
    assertTrue(subset2.get(5));
    assertFalse(subset2.get(6));

  }
View Full Code Here

   * Tests for rand.
   */
  @Test(timeout = 10000)
  public final void testRand() {

    BitSet gotcha = new BitSet(5);
    gotcha.set(0);
    assertThat(gotcha.cardinality(), is(1));
    gotcha.set(2);
    assertThat(gotcha.cardinality(), is(2));
    gotcha.set(1);
    assertThat(gotcha.cardinality(), is(3));
    gotcha.set(3);
    assertThat(gotcha.cardinality(), is(4));
    gotcha.set(4);
    assertThat(gotcha.cardinality(), is(5));

    gotcha = new BitSet(5);
    int val;
    while (gotcha.cardinality() < 4) {
      val = Direction.rand().get();
      gotcha.set(val);
    }

    assertFalse(gotcha.get(0));
  }
View Full Code Here

    for (int i = 0; i < vocabularySize; i ++) {
      final Word curWord = vocabularyDictionary.get(i);
      curWord.getText().getChars(0, curWord.length(), chs, 0);
      chs[curWord.length()] = (char) -1;
      Beef beef = new Beef(chs, 0, curWord.length() + 1);
      final BitSet bs = new BitSet(curWord.length());
      knife.dissect(new Collector(){
        public void collect(String word, int offset, int end) {
          Hit hit = vocabularyDictionary.search(word, 0, word.length());
          if (hit.isHit() && hit.getWord().length() != curWord.length()) {
            for (int j = offset; j < end; j++) {
              bs.set(j, true);
            }
          }
        }
       
      }, beef, 0);
     
      for (int j = 0; j < curWord.length();j++) {
        if (!bs.get(j)) {
          vocabularyWords[i] = curWord;
          break;
        }
      }
    }
View Full Code Here

        IOBase base = session.getBase();
        FieldsIterator fieldsIterator = objectDataContainer.getActiveFieldsIterator();
        if(fieldsIterator == null){
            return;
        }
        BitSet processedFieldMask = new BitSet();
        FieldRecord record = objectDataContainer.getRecordCache();
        for (int i = 0; fieldsIterator.hasNext(); i++) {
            fieldsIterator.next(record, base);
            Field field = classDescriptor.getFieldForID(record._fieldID, processedFieldMask);
            if (field == null) {
                continue;
            }
            if (field.getType().isPrimitive() && !delayedActivation) {
                try {
                    field.set(instance, record._value);
                } catch (Exception e) {
                    setDefaultValue(instance, field);
                    //TODO add debug level output
                }
                continue;
            }
            if (remainingDepth < 1) {
                continue;
            }
            Object child = TransactionUtils.launchObject(session, record._objectOffset, null, remainingDepth - 1);
            try {
                if(child!=null || JODBConfig.isAllowNullInReflectionSet()){
                    field.set(instance, child);
                }
            } catch (Exception e) {
                setDefaultValue(instance, field);
                //TODO add debug level output
                continue;
            }
        }
        if (!delayedActivation) {
            FieldAndIDRecord[] fields = classDescriptor.getAllFields();
            for (int i = 0; i < fields.length; i++) {//set default values for remaining fields
                if (processedFieldMask.get(i)) {
                    continue;
                }
                setDefaultValue(instance, fields[i]._field);
            }
        }       
View Full Code Here

        //on each bitSet. The AND operator has the affect that only documents
        //that are allowed by every single filter in the filter list will be
        //allowed by this MultiFilter.
        int filterListSize = filterList.size();
        if (filterListSize > 0) {
            BitSet bits = ((Filter)filterList.get(0)).bits(reader);
            for (int i=1; i<filterListSize; i++) {
                bits.and( ((Filter)filterList.get(i)).bits(reader) );
            }
            return bits;
        }
        //There are no filters defined. In this case, we return a new
        //BitSet that will filter out all documents. This is probably the most
        //consistent behavior with the Lucene API. It's also a lot more
        //efficient considering the BitSet implementation.
        else {
            return new BitSet(reader.maxDoc());
        }
    }
View Full Code Here

        searchTerm = new Term(field, value);
    }

    public BitSet bits(IndexReader reader) throws IOException {
        //Create a new BitSet with a capacity equal to the size of the index.
        BitSet bits = new BitSet(reader.maxDoc());
        //Get an enumeration of all the documents that match the specified field
        //value.
        TermDocs matchingDocs = reader.termDocs(searchTerm);
        try {
            while(matchingDocs.next()) {
                bits.set(matchingDocs.doc());
            }
        }
        finally {
            if (matchingDocs != null) {
                matchingDocs.close();
View Full Code Here

 
      // int pos = 0;
      int end = start + length;
      boolean checkWhite = true;
      final int maxCharacter = m_maxCharacter;
      final BitSet specialsMap = m_charInfo.m_specialsMap;
 
      for (int i = start; i < end; i++)
      {
        char ch = chars[i];
 
        if (checkWhite
                && ((ch > 0x20)
                    ||!((ch == 0x20) || (ch == 0x09) || (ch == 0xD)
                        || (ch == 0xA))))
        {
          m_ispreserve = true;
          checkWhite = false;
        }
 
        if ((canConvert(ch) && (!specialsMap.get(ch))) || ('"' == ch))
        {
          lengthClean++;
        }
        else
        {
View Full Code Here

     * @return the escaped string
     * @throws NullPointerException if <code>string</code> is <code>null</code>.
     */
    public static String escape(String string, char escape, boolean isPath) {
        try {
            BitSet validChars = isPath ? URISaveEx : URISave;
            byte[] bytes = string.getBytes("utf-8");
            StringBuffer out = new StringBuffer(bytes.length);
            for (byte aByte : bytes) {
                int c = aByte & 0xff;
                if (validChars.get(c) && c != escape) {
                    out.append((char) c);
                } else {
                    out.append(escape);
                    out.append(hexTable[(c >> 4) & 0x0f]);
                    out.append(hexTable[(c) & 0x0f]);
View Full Code Here

TOP

Related Classes of java.util.BitSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.