ImmutableRangeMap.java 7.85 KB
package com.google.common.collect;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Preconditions;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Nullable;
import nq;
import pn;
import pp;

@Beta
@GwtIncompatible("NavigableMap")
public class ImmutableRangeMap<K extends Comparable<?>, V>
  implements RangeMap<K, V>
{
  private static final ImmutableRangeMap<Comparable<?>, Object> a = new ImmutableRangeMap(ImmutableList.of(), ImmutableList.of());
  private final ImmutableList<Range<K>> b;
  private final ImmutableList<V> c;
  
  ImmutableRangeMap(ImmutableList<Range<K>> paramImmutableList, ImmutableList<V> paramImmutableList1)
  {
    this.b = paramImmutableList;
    this.c = paramImmutableList1;
  }
  
  public static <K extends Comparable<?>, V> Builder<K, V> builder()
  {
    return new Builder();
  }
  
  public static <K extends Comparable<?>, V> ImmutableRangeMap<K, V> copyOf(RangeMap<K, ? extends V> paramRangeMap)
  {
    if ((paramRangeMap instanceof ImmutableRangeMap)) {
      return (ImmutableRangeMap)paramRangeMap;
    }
    Object localObject = paramRangeMap.asMapOfRanges();
    paramRangeMap = new ImmutableList.Builder(((Map)localObject).size());
    ImmutableList.Builder localBuilder = new ImmutableList.Builder(((Map)localObject).size());
    localObject = ((Map)localObject).entrySet().iterator();
    while (((Iterator)localObject).hasNext())
    {
      Map.Entry localEntry = (Map.Entry)((Iterator)localObject).next();
      paramRangeMap.add(localEntry.getKey());
      localBuilder.add(localEntry.getValue());
    }
    return new ImmutableRangeMap(paramRangeMap.build(), localBuilder.build());
  }
  
  public static <K extends Comparable<?>, V> ImmutableRangeMap<K, V> of()
  {
    return a;
  }
  
  public static <K extends Comparable<?>, V> ImmutableRangeMap<K, V> of(Range<K> paramRange, V paramV)
  {
    return new ImmutableRangeMap(ImmutableList.of(paramRange), ImmutableList.of(paramV));
  }
  
  public ImmutableMap<Range<K>, V> asMapOfRanges()
  {
    if (this.b.isEmpty()) {
      return ImmutableMap.of();
    }
    return new pn(new pp(this.b, Range.a), this.c);
  }
  
  public void clear()
  {
    throw new UnsupportedOperationException();
  }
  
  public boolean equals(@Nullable Object paramObject)
  {
    if ((paramObject instanceof RangeMap))
    {
      paramObject = (RangeMap)paramObject;
      return asMapOfRanges().equals(((RangeMap)paramObject).asMapOfRanges());
    }
    return false;
  }
  
  @Nullable
  public V get(K paramK)
  {
    int i = SortedLists.a(this.b, Range.a(), nq.b(paramK), SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_LOWER);
    if (i == -1) {
      return null;
    }
    if (((Range)this.b.get(i)).contains(paramK)) {
      return (V)this.c.get(i);
    }
    return null;
  }
  
  @Nullable
  public Map.Entry<Range<K>, V> getEntry(K paramK)
  {
    int i = SortedLists.a(this.b, Range.a(), nq.b(paramK), SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_LOWER);
    if (i == -1) {
      return null;
    }
    Range localRange = (Range)this.b.get(i);
    if (localRange.contains(paramK)) {
      return Maps.immutableEntry(localRange, this.c.get(i));
    }
    return null;
  }
  
  public int hashCode()
  {
    return asMapOfRanges().hashCode();
  }
  
  public void put(Range<K> paramRange, V paramV)
  {
    throw new UnsupportedOperationException();
  }
  
  public void putAll(RangeMap<K, V> paramRangeMap)
  {
    throw new UnsupportedOperationException();
  }
  
  public void remove(Range<K> paramRange)
  {
    throw new UnsupportedOperationException();
  }
  
  public Range<K> span()
  {
    if (this.b.isEmpty()) {
      throw new NoSuchElementException();
    }
    Range localRange1 = (Range)this.b.get(0);
    Range localRange2 = (Range)this.b.get(this.b.size() - 1);
    return Range.a(localRange1.b, localRange2.c);
  }
  
  public ImmutableRangeMap<K, V> subRangeMap(final Range<K> paramRange)
  {
    if (((Range)Preconditions.checkNotNull(paramRange)).isEmpty()) {
      return of();
    }
    if ((this.b.isEmpty()) || (paramRange.encloses(span()))) {
      return this;
    }
    final int i = SortedLists.a(this.b, Range.b(), paramRange.b, SortedLists.KeyPresentBehavior.FIRST_AFTER, SortedLists.KeyAbsentBehavior.NEXT_HIGHER);
    int j = SortedLists.a(this.b, Range.a(), paramRange.c, SortedLists.KeyPresentBehavior.ANY_PRESENT, SortedLists.KeyAbsentBehavior.NEXT_HIGHER);
    if (i >= j) {
      return of();
    }
    new ImmutableRangeMap(new ImmutableList()
    {
      final boolean a()
      {
        return true;
      }
      
      public final int size()
      {
        return this.a;
      }
    }, this.c.subList(i, j))
    {
      public final ImmutableRangeMap<K, V> subRangeMap(Range<K> paramAnonymousRange)
      {
        if (paramRange.isConnected(paramAnonymousRange)) {
          return jdField_this.subRangeMap(paramAnonymousRange.intersection(paramRange));
        }
        return ImmutableRangeMap.of();
      }
    };
  }
  
  public String toString()
  {
    return asMapOfRanges().toString();
  }
  
  public static final class Builder<K extends Comparable<?>, V>
  {
    private final RangeSet<K> a = TreeRangeSet.create();
    private final RangeMap<K, V> b = TreeRangeMap.create();
    
    public final ImmutableRangeMap<K, V> build()
    {
      Object localObject = this.b.asMapOfRanges();
      ImmutableList.Builder localBuilder1 = new ImmutableList.Builder(((Map)localObject).size());
      ImmutableList.Builder localBuilder2 = new ImmutableList.Builder(((Map)localObject).size());
      localObject = ((Map)localObject).entrySet().iterator();
      while (((Iterator)localObject).hasNext())
      {
        Map.Entry localEntry = (Map.Entry)((Iterator)localObject).next();
        localBuilder1.add(localEntry.getKey());
        localBuilder2.add(localEntry.getValue());
      }
      return new ImmutableRangeMap(localBuilder1.build(), localBuilder2.build());
    }
    
    public final Builder<K, V> put(Range<K> paramRange, V paramV)
    {
      Preconditions.checkNotNull(paramRange);
      Preconditions.checkNotNull(paramV);
      if (!paramRange.isEmpty()) {}
      for (boolean bool = true;; bool = false)
      {
        Preconditions.checkArgument(bool, "Range must not be empty, but was %s", new Object[] { paramRange });
        if (this.a.complement().encloses(paramRange)) {
          break;
        }
        Iterator localIterator = this.b.asMapOfRanges().entrySet().iterator();
        Map.Entry localEntry;
        Range localRange;
        do
        {
          if (!localIterator.hasNext()) {
            break;
          }
          localEntry = (Map.Entry)localIterator.next();
          localRange = (Range)localEntry.getKey();
        } while ((!localRange.isConnected(paramRange)) || (localRange.intersection(paramRange).isEmpty()));
        paramRange = String.valueOf(String.valueOf(paramRange));
        paramV = String.valueOf(String.valueOf(localEntry));
        throw new IllegalArgumentException(paramRange.length() + 47 + paramV.length() + "Overlapping ranges: range " + paramRange + " overlaps with entry " + paramV);
      }
      this.a.add(paramRange);
      this.b.put(paramRange, paramV);
      return this;
    }
    
    public final Builder<K, V> putAll(RangeMap<K, ? extends V> paramRangeMap)
    {
      paramRangeMap = paramRangeMap.asMapOfRanges().entrySet().iterator();
      while (paramRangeMap.hasNext())
      {
        Map.Entry localEntry = (Map.Entry)paramRangeMap.next();
        put((Range)localEntry.getKey(), localEntry.getValue());
      }
      return this;
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/collect/ImmutableRangeMap.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */