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

io.druid.timeline.partition.IntegerPartitionChunk Maven / Gradle / Ivy

The newest version!
/*
 * Druid - a distributed column store.
 * Copyright (C) 2012, 2013  Metamarkets Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package io.druid.timeline.partition;

import com.google.common.collect.Ordering;

import java.util.Comparator;

/**
 */
public class IntegerPartitionChunk implements PartitionChunk
{
  Comparator comparator = Ordering.natural().nullsFirst();

  private final Integer start;
  private final Integer end;
  private final int chunkNumber;
  private final T object;

  public static  IntegerPartitionChunk make(Integer start, Integer end, int chunkNumber, T obj)
  {
    return new IntegerPartitionChunk(start, end, chunkNumber, obj);
  }

  public IntegerPartitionChunk(
      Integer start,
      Integer end,
      int chunkNumber,
      T object
  )
  {
    this.start = start;
    this.end = end;
    this.chunkNumber = chunkNumber;
    this.object = object;
  }

  @Override
  public T getObject()
  {
    return object;
  }

  @Override
  public boolean abuts(PartitionChunk chunk)
  {
    if (chunk instanceof IntegerPartitionChunk) {
      IntegerPartitionChunk intChunk = (IntegerPartitionChunk) chunk;

      if (intChunk.isStart()) {
        return false;
      }
      return intChunk.start.equals(end);
    }

    return false;
  }

  @Override
  public boolean isStart()
  {
    return start == null;
  }

  @Override
  public boolean isEnd()
  {
    return end == null;
  }

  @Override
  public int getChunkNumber()
  {
    return chunkNumber;
  }

  @Override
  public int compareTo(PartitionChunk chunk)
  {
    if (chunk instanceof IntegerPartitionChunk) {
      IntegerPartitionChunk intChunk = (IntegerPartitionChunk) chunk;
      return comparator.compare(chunkNumber, intChunk.chunkNumber);
    } else {
      throw new IllegalArgumentException("Cannot compare against something that is not an IntegerPartitionChunk.");
    }
  }

  @Override
  public boolean equals(Object o)
  {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    return compareTo((IntegerPartitionChunk) o) == 0;
  }

  @Override
  public int hashCode()
  {
    int result = start != null ? start.hashCode() : 0;
    result = 31 * result + (end != null ? end.hashCode() : 0);
    result = 31 * result + (object != null ? object.hashCode() : 0);
    return result;
  }

  @Override
  public String toString()
  {
    return "IntegerPartitionChunk{" +
           "start=" + start +
           ", end=" + end +
           ", object=" + object +
           '}';
  }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy