Ejemplo n.º 1
0
  public void andNot(BitSet set) {
    // a & !a is false
    if (this == set) {
      // all falses result in an empty BitSet
      clear();
      return;
    }

    // trim the second set to avoid extra work
    trimToSize(array);
    int length = array.length();

    // truth table
    //
    // case | a | b | !b | a & !b | change?
    // 1 | false | false | true | false | a is already false
    // 2 | false | true | false | false | a is already false
    // 3 | true | false | true | true | a is already true
    // 4 | true | true | false | false | set a to false
    //
    // we only need to change something in case 4
    // whenever b is true, a should be false, so iterate over set b
    int index = 0;
    while ((index = nextSetWord(set.array, index)) != -1) {
      setWord(array, index, getWord(array, index) & ~set.array.get(index));
      if (++index >= length) {
        // nothing further will affect anything
        break;
      }
    }
  }
Ejemplo n.º 2
0
  public void and(BitSet set) {
    // a & a is just a
    if (this == set) {
      return;
    }

    // trim the second set to avoid extra work
    trimToSize(set.array);

    // check if the length is longer than otherLength
    int otherLength = set.array.length();
    if (array.length() > otherLength) {
      // shrink the array, effectively ANDing those bits to false
      setLengthWords(array, otherLength);
    }

    // truth table
    //
    // case | a | b | a & b | change?
    // 1 | false | false | false | a is already false
    // 2 | false | true | false | a is already false
    // 3 | true | false | false | set a to false
    // 4 | true | true | true | a is already true
    //
    // we only need to change something in case 3, so iterate over set a
    int index = 0;
    while ((index = nextSetWord(array, index)) != -1) {
      setWord(array, index, array.get(index) & getWord(set.array, index));
      index++;
    }
  }
Ejemplo n.º 3
0
 private int[] jsArrayIntegerToIntArray(JsArrayInteger values) {
   int len = values.length();
   int[] vals = new int[len];
   for (int i = 0; i < len; i++) {
     vals[i] = values.get(i);
   }
   return vals;
 }
Ejemplo n.º 4
0
 public final Date getDate(String key) {
   String type = getType(key);
   if ("number".equals(type)) {
     return new Date(getLong(key));
   } else if ("date".equals(type)) {
     return getNativeDate(key);
   } else if ("string".equals(type)) {
     // DateTimeFormat dtf = DateTimeFormat.getFormat(Defaults.getDateFormat());
     // return dtf.parse(get(key));
   } else if ("array".equals(type)) {
     JsArrayInteger jsAray = getNativeValue(key).cast();
     Date date = new Date();
     date.setYear(jsAray.get(0));
     date.setMonth(jsAray.get(1));
     date.setDate(jsAray.get(2));
     if (jsAray.length() > 3) {
       date.setHours(jsAray.get(3));
       date.setMinutes(jsAray.get(4));
       date.setSeconds(jsAray.get(5));
     }
     return date;
   }
   return null;
 }
Ejemplo n.º 5
0
 public int size() {
   // the number of bytes that can fit without using "more" memory
   return bitIndex(array.length());
 }