This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.io.data.loading.impl;
020
021import org.apache.commons.lang.Validate;
022
023/**
024 * A tuple of an object of type E and an integer index.
025 * Used inside {@link org.apache.reef.io.data.loading.api.EvaluatorToPartitionStrategy} implementations to
026 * mark the partitions associated with each {@link org.apache.hadoop.mapred.InputSplit}
027 *
028 * @param <E>
029 */
030public final class NumberedSplit<E> implements Comparable<NumberedSplit<E>> {
031  private final E entry;
032  private final int index;
033  private final DistributedDataSetPartition partition;
034
035  public NumberedSplit(final E entry, final int index, final DistributedDataSetPartition partition) {
036    Validate.notNull(entry, "Entry cannot be null");
037    Validate.notNull(partition, "Partition cannot be null");
038    this.entry = entry;
039    this.index = index;
040    this.partition = partition;
041  }
042
043  public String getPath() {
044    return partition.getPath();
045  }
046
047  public String getLocation() {
048    return partition.getLocation();
049  }
050
051  public E getEntry() {
052    return entry;
053  }
054
055  public int getIndex() {
056    return index;
057  }
058
059  @Override
060  public String toString() {
061    return "InputSplit-" + partition + "-" + index;
062  }
063
064  @Override
065  public boolean equals(final Object o) {
066    if (this == o) {
067      return true;
068    }
069    if (o == null || getClass() != o.getClass()) {
070      return false;
071    }
072
073    NumberedSplit<?> that = (NumberedSplit<?>) o;
074    return index == that.index;
075  }
076
077  @Override
078  public int hashCode() {
079    return index;
080  }
081
082  @Override
083  public int compareTo(final NumberedSplit<E> o) {
084    if (this.index == o.index) {
085      return 0;
086    }
087    if (this.index < o.index) {
088      return -1;
089    }
090    return 1;
091  }
092}