All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.db.storage.dynamo.bytes.KeyBytesEncodedLengthCalculator Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.storage.dynamo.bytes;

import com.scalar.db.api.Scan.Ordering.Order;
import com.scalar.db.io.BigIntValue;
import com.scalar.db.io.BlobValue;
import com.scalar.db.io.BooleanValue;
import com.scalar.db.io.DoubleValue;
import com.scalar.db.io.FloatValue;
import com.scalar.db.io.IntValue;
import com.scalar.db.io.Key;
import com.scalar.db.io.TextValue;
import com.scalar.db.io.Value;
import com.scalar.db.io.ValueVisitor;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Map;
import javax.annotation.concurrent.NotThreadSafe;

@NotThreadSafe
public class KeyBytesEncodedLengthCalculator implements ValueVisitor {

  private int length;
  private Map keyOrders;

  @SuppressFBWarnings("EI_EXPOSE_REP2")
  public int calculate(Key key, Map keyOrders) {
    this.keyOrders = keyOrders;
    for (Value value : key) {
      value.accept(this);
    }
    return length;
  }

  @Override
  public void visit(BooleanValue value) {
    length +=
        BytesEncoders.BOOLEAN.encodedLength(
            value, keyOrders.getOrDefault(value.getName(), Order.ASC));
  }

  @Override
  public void visit(IntValue value) {
    length +=
        BytesEncoders.INT.encodedLength(value, keyOrders.getOrDefault(value.getName(), Order.ASC));
  }

  @Override
  public void visit(BigIntValue value) {
    length +=
        BytesEncoders.BIGINT.encodedLength(
            value, keyOrders.getOrDefault(value.getName(), Order.ASC));
  }

  @Override
  public void visit(FloatValue value) {
    length +=
        BytesEncoders.FLOAT.encodedLength(
            value, keyOrders.getOrDefault(value.getName(), Order.ASC));
  }

  @Override
  public void visit(DoubleValue value) {
    length +=
        BytesEncoders.DOUBLE.encodedLength(
            value, keyOrders.getOrDefault(value.getName(), Order.ASC));
  }

  @Override
  public void visit(TextValue value) {
    length +=
        BytesEncoders.TEXT.encodedLength(value, keyOrders.getOrDefault(value.getName(), Order.ASC));
  }

  @Override
  public void visit(BlobValue value) {
    length +=
        BytesEncoders.BLOB.encodedLength(value, keyOrders.getOrDefault(value.getName(), Order.ASC));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy