Exemplo n.º 1
0
 /**
  * This method returns true if set A is a subset of set B
  *
  * @return True if this set is a subset of setB
  */
 public boolean isSubset(Bitset setB) {
   // if one or both sets is null
   if (isNull() || setB.isNull()) return false;
   // if _this_ set has more elements than setB it can't be a subset
   if (cardinality() > setB.cardinality()) return false;
   // temp is all the elements that are both in A and B
   Bitset temp = intersect(setB);
   // if set A is the same as temp, then all elements in A are also in B
   if (equals(temp)) return true;
   else return false;
 }
Exemplo n.º 2
0
  private static Bitset[] createBitsets(
      OutputModelFactory factory, IntervalSet set, boolean useZeroOffset) {
    List<Bitset> bitsetList = new ArrayList<Bitset>();
    for (int ttype : set.toArray()) {
      Bitset current = !bitsetList.isEmpty() ? bitsetList.get(bitsetList.size() - 1) : null;
      if (current == null || ttype > (current.shift + 63)) {
        current = new Bitset();
        if (useZeroOffset && ttype >= 0 && ttype < 63) {
          current.shift = 0;
        } else {
          current.shift = ttype;
        }

        bitsetList.add(current);
      }

      current.ttypes.add(
          factory.getGenerator().target.getTokenTypeAsTargetLabel(factory.getGrammar(), ttype));
    }

    return bitsetList.toArray(new Bitset[bitsetList.size()]);
  }