Esempio n. 1
0
  public static ComparatorType getByClassName(String className) {

    for (int a = 0; a < values().length; a++) {
      ComparatorType type = values()[a];
      if (type.getClassName().equals(className)) {
        return type;
      }
      if (type.getClassName().equals("org.apache.cassandra.db.marshal." + className)) {
        return type;
      }
    }
    return null;
  }
Esempio n. 2
0
 public WritableByteArrayComparable build() {
   WritableByteArrayComparable comparator;
   switch (ComparatorType.valueOf(type)) {
     case BinaryComparator:
       comparator = new BinaryComparator(Base64.decode(value));
       break;
     case BinaryPrefixComparator:
       comparator = new BinaryPrefixComparator(Base64.decode(value));
       break;
     case BitComparator:
       comparator =
           new BitComparator(Base64.decode(value), BitComparator.BitwiseOp.valueOf(op));
       break;
     case NullComparator:
       comparator = new NullComparator();
       break;
     case RegexStringComparator:
       comparator = new RegexStringComparator(value);
       break;
     case SubstringComparator:
       comparator = new SubstringComparator(value);
       break;
     default:
       throw new RuntimeException("unhandled comparator type: " + type);
   }
   return comparator;
 }
  @Override
  public void writeTo(StreamOutput out) throws IOException {
    out.writeUTF(name);
    out.writeByte(comparatorType.id());
    out.writeVInt(requiredSize);
    out.writeVLong(missing);

    out.writeVInt(entries.size());
    for (IntEntry entry : entries) {
      out.writeInt(entry.term);
      out.writeVInt(entry.count());
    }
  }
  @Override
  public void readFrom(StreamInput in) throws IOException {
    name = in.readUTF();
    comparatorType = ComparatorType.fromId(in.readByte());
    requiredSize = in.readVInt();
    missing = in.readVLong();

    int size = in.readVInt();
    entries = new ArrayList<IntEntry>(size);
    for (int i = 0; i < size; i++) {
      entries.add(new IntEntry(in.readInt(), in.readVInt()));
    }
  }
  @Override
  public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeByte(comparatorType.id());
    out.writeVInt(requiredSize);
    out.writeVLong(missing);
    out.writeVLong(total);

    out.writeVInt(entries.size());
    for (LongEntry entry : entries) {
      out.writeLong(entry.term);
      out.writeVInt(entry.getCount());
    }
  }
Esempio n. 6
0
 public WritableByteArrayComparableModel(WritableByteArrayComparable comparator) {
   String typeName = comparator.getClass().getSimpleName();
   ComparatorType type = ComparatorType.valueOf(typeName);
   this.type = typeName;
   switch (type) {
     case BinaryComparator:
     case BinaryPrefixComparator:
       this.value = Base64.encodeBytes(comparator.getValue());
       break;
     case BitComparator:
       this.value = Base64.encodeBytes(comparator.getValue());
       this.op = ((BitComparator) comparator).getOperator().toString();
       break;
     case NullComparator:
       break;
     case RegexStringComparator:
     case SubstringComparator:
       this.value = Bytes.toString(comparator.getValue());
       break;
     default:
       throw new RuntimeException("unhandled filter type: " + type);
   }
 }