Package mil.nga.giat.geowave.accumulo.mapreduce.input

Source Code of mil.nga.giat.geowave.accumulo.mapreduce.input.GeoWaveInputKey

package mil.nga.giat.geowave.accumulo.mapreduce.input;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import mil.nga.giat.geowave.accumulo.mapreduce.GeoWaveKey;
import mil.nga.giat.geowave.index.ByteArrayId;

import org.apache.accumulo.core.data.Key;
import org.apache.hadoop.io.WritableComparator;

/**
* This class encapsulates the unique identifier for GeoWave input data using a
* map-reduce GeoWave input format. The combination of the the adapter ID and
* the data ID should be unique.
*/
public class GeoWaveInputKey extends
    GeoWaveKey
{
  private ByteArrayId dataId;
  private Key accumuloKey;

  protected GeoWaveInputKey() {
    super();
  }

  public GeoWaveInputKey(
      final ByteArrayId adapterId,
      final ByteArrayId dataId ) {
    super(
        adapterId);
    this.dataId = dataId;
  }

  public Key getAccumuloKey() {
    return accumuloKey;
  }

  public void setAccumuloKey(
      final Key accumuloKey ) {
    this.accumuloKey = accumuloKey;
  }

  public ByteArrayId getDataId() {
    return dataId;
  }

  @Override
  public int compareTo(
      final GeoWaveKey o ) {
    final int baseCompare = super.compareTo(o);
    if (baseCompare != 0) {
      return baseCompare;
    }
    if (o instanceof GeoWaveInputKey) {
      final GeoWaveInputKey other = (GeoWaveInputKey) o;
      return WritableComparator.compareBytes(
          dataId.getBytes(),
          0,
          dataId.getBytes().length,
          other.dataId.getBytes(),
          0,
          other.dataId.getBytes().length);
    }
    return 1;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = (prime * result) + ((adapterId == null) ? 0 : adapterId.hashCode());
    result = (prime * result) + ((dataId == null) ? 0 : dataId.hashCode());
    return result;
  }

  @Override
  public boolean equals(
      final Object obj ) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final GeoWaveInputKey other = (GeoWaveInputKey) obj;
    if (adapterId == null) {
      if (other.adapterId != null) {
        return false;
      }
    }
    else if (!adapterId.equals(other.adapterId)) {
      return false;
    }
    if (dataId == null) {
      if (other.dataId != null) {
        return false;
      }
    }
    else if (!dataId.equals(other.dataId)) {
      return false;
    }
    return true;
  }

  @Override
  public void readFields(
      final DataInput input )
      throws IOException {
    super.readFields(input);
    final int dataIdLength = input.readInt();
    final byte[] dataIdBytes = new byte[dataIdLength];
    input.readFully(dataIdBytes);
    dataId = new ByteArrayId(
        dataIdBytes);
  }

  @Override
  public void write(
      final DataOutput output )
      throws IOException {
    super.write(output);
    output.writeInt(dataId.getBytes().length);
    output.write(dataId.getBytes());
  }
}
TOP

Related Classes of mil.nga.giat.geowave.accumulo.mapreduce.input.GeoWaveInputKey

TOP
Copyright © 2018 www.massapi.com. 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.