ImmutableMultiset.java 10.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
package com.google.common.collect;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Ints;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import javax.annotation.Nullable;
import op;
import pl;

@GwtCompatible(emulated=true, serializable=true)
public abstract class ImmutableMultiset<E>
  extends ImmutableCollection<E>
  implements Multiset<E>
{
  private static final ImmutableMultiset<Object> a = new pl(ImmutableMap.of(), 0);
  private transient ImmutableSet<Multiset.Entry<E>> b;
  
  private static <E> ImmutableMultiset<E> a(Multiset<? extends E> paramMultiset)
  {
    return a(paramMultiset.entrySet());
  }
  
  static <E> ImmutableMultiset<E> a(Collection<? extends Multiset.Entry<? extends E>> paramCollection)
  {
    ImmutableMap.Builder localBuilder = ImmutableMap.builder();
    paramCollection = paramCollection.iterator();
    long l = 0L;
    if (paramCollection.hasNext())
    {
      Multiset.Entry localEntry = (Multiset.Entry)paramCollection.next();
      int i = localEntry.getCount();
      if (i <= 0) {
        break label98;
      }
      localBuilder.put(localEntry.getElement(), Integer.valueOf(i));
      l = i + l;
    }
    label98:
    for (;;)
    {
      break;
      if (l == 0L) {
        return of();
      }
      return new pl(localBuilder.build(), Ints.saturatedCast(l));
    }
  }
  
  public static <E> Builder<E> builder()
  {
    return new Builder();
  }
  
  public static <E> ImmutableMultiset<E> copyOf(Iterable<? extends E> paramIterable)
  {
    if ((paramIterable instanceof ImmutableMultiset))
    {
      ImmutableMultiset localImmutableMultiset = (ImmutableMultiset)paramIterable;
      if (!localImmutableMultiset.a()) {
        return localImmutableMultiset;
      }
    }
    if ((paramIterable instanceof Multiset)) {}
    for (paramIterable = Multisets.b(paramIterable);; paramIterable = LinkedHashMultiset.create(paramIterable)) {
      return a(paramIterable);
    }
  }
  
  public static <E> ImmutableMultiset<E> copyOf(Iterator<? extends E> paramIterator)
  {
    LinkedHashMultiset localLinkedHashMultiset = LinkedHashMultiset.create();
    Iterators.addAll(localLinkedHashMultiset, paramIterator);
    return a(localLinkedHashMultiset);
  }
  
  public static <E> ImmutableMultiset<E> copyOf(E[] paramArrayOfE)
  {
    return copyOf(Arrays.asList(paramArrayOfE));
  }
  
  public static <E> ImmutableMultiset<E> of()
  {
    return a;
  }
  
  public static <E> ImmutableMultiset<E> of(E paramE)
  {
    return copyOf(Arrays.asList(new Object[] { paramE }));
  }
  
  public static <E> ImmutableMultiset<E> of(E paramE1, E paramE2)
  {
    return copyOf(Arrays.asList(new Object[] { paramE1, paramE2 }));
  }
  
  public static <E> ImmutableMultiset<E> of(E paramE1, E paramE2, E paramE3)
  {
    return copyOf(Arrays.asList(new Object[] { paramE1, paramE2, paramE3 }));
  }
  
  public static <E> ImmutableMultiset<E> of(E paramE1, E paramE2, E paramE3, E paramE4)
  {
    return copyOf(Arrays.asList(new Object[] { paramE1, paramE2, paramE3, paramE4 }));
  }
  
  public static <E> ImmutableMultiset<E> of(E paramE1, E paramE2, E paramE3, E paramE4, E paramE5)
  {
    return copyOf(Arrays.asList(new Object[] { paramE1, paramE2, paramE3, paramE4, paramE5 }));
  }
  
  public static <E> ImmutableMultiset<E> of(E paramE1, E paramE2, E paramE3, E paramE4, E paramE5, E paramE6, E... paramVarArgs)
  {
    return new Builder().add(paramE1).add(paramE2).add(paramE3).add(paramE4).add(paramE5).add(paramE6).add(paramVarArgs).build();
  }
  
  @GwtIncompatible("not present in emulated superclass")
  protected int a(Object[] paramArrayOfObject, int paramInt)
  {
    Iterator localIterator = entrySet().iterator();
    while (localIterator.hasNext())
    {
      Multiset.Entry localEntry = (Multiset.Entry)localIterator.next();
      Arrays.fill(paramArrayOfObject, paramInt, localEntry.getCount() + paramInt, localEntry.getElement());
      paramInt += localEntry.getCount();
    }
    return paramInt;
  }
  
  public abstract Multiset.Entry<E> a(int paramInt);
  
  @Deprecated
  public final int add(E paramE, int paramInt)
  {
    throw new UnsupportedOperationException();
  }
  
  public boolean contains(@Nullable Object paramObject)
  {
    return count(paramObject) > 0;
  }
  
  public boolean containsAll(Collection<?> paramCollection)
  {
    return elementSet().containsAll(paramCollection);
  }
  
  public ImmutableSet<Multiset.Entry<E>> entrySet()
  {
    ImmutableSet localImmutableSet = this.b;
    Object localObject = localImmutableSet;
    if (localImmutableSet == null) {
      if (!isEmpty()) {
        break label29;
      }
    }
    label29:
    for (localObject = ImmutableSet.of();; localObject = new a((byte)0))
    {
      this.b = ((ImmutableSet)localObject);
      return (ImmutableSet<Multiset.Entry<E>>)localObject;
    }
  }
  
  public boolean equals(@Nullable Object paramObject)
  {
    return Multisets.a(this, paramObject);
  }
  
  public int hashCode()
  {
    return Sets.a(entrySet());
  }
  
  public UnmodifiableIterator<E> iterator()
  {
    new UnmodifiableIterator()
    {
      int a;
      E b;
      
      public final boolean hasNext()
      {
        return (this.a > 0) || (this.c.hasNext());
      }
      
      public final E next()
      {
        if (this.a <= 0)
        {
          Multiset.Entry localEntry = (Multiset.Entry)this.c.next();
          this.b = localEntry.getElement();
          this.a = localEntry.getCount();
        }
        this.a -= 1;
        return (E)this.b;
      }
    };
  }
  
  @Deprecated
  public final int remove(Object paramObject, int paramInt)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public final int setCount(E paramE, int paramInt)
  {
    throw new UnsupportedOperationException();
  }
  
  @Deprecated
  public final boolean setCount(E paramE, int paramInt1, int paramInt2)
  {
    throw new UnsupportedOperationException();
  }
  
  public String toString()
  {
    return entrySet().toString();
  }
  
  Object writeReplace()
  {
    return new c(this);
  }
  
  public static class Builder<E>
    extends ImmutableCollection.Builder<E>
  {
    final Multiset<E> a;
    
    public Builder()
    {
      this(LinkedHashMultiset.create());
    }
    
    Builder(Multiset<E> paramMultiset)
    {
      this.a = paramMultiset;
    }
    
    public Builder<E> add(E paramE)
    {
      this.a.add(Preconditions.checkNotNull(paramE));
      return this;
    }
    
    public Builder<E> add(E... paramVarArgs)
    {
      super.add(paramVarArgs);
      return this;
    }
    
    public Builder<E> addAll(Iterable<? extends E> paramIterable)
    {
      if ((paramIterable instanceof Multiset))
      {
        paramIterable = Multisets.b(paramIterable).entrySet().iterator();
        while (paramIterable.hasNext())
        {
          Multiset.Entry localEntry = (Multiset.Entry)paramIterable.next();
          addCopies(localEntry.getElement(), localEntry.getCount());
        }
      }
      super.addAll(paramIterable);
      return this;
    }
    
    public Builder<E> addAll(Iterator<? extends E> paramIterator)
    {
      super.addAll(paramIterator);
      return this;
    }
    
    public Builder<E> addCopies(E paramE, int paramInt)
    {
      this.a.add(Preconditions.checkNotNull(paramE), paramInt);
      return this;
    }
    
    public ImmutableMultiset<E> build()
    {
      return ImmutableMultiset.copyOf(this.a);
    }
    
    public Builder<E> setCount(E paramE, int paramInt)
    {
      this.a.setCount(Preconditions.checkNotNull(paramE), paramInt);
      return this;
    }
  }
  
  final class a
    extends ImmutableSet<Multiset.Entry<E>>
  {
    private static final long serialVersionUID = 0L;
    
    private a() {}
    
    final boolean a()
    {
      return ImmutableMultiset.this.a();
    }
    
    final ImmutableList<Multiset.Entry<E>> c()
    {
      new op()
      {
        final ImmutableCollection<Multiset.Entry<E>> b()
        {
          return ImmutableMultiset.a.this;
        }
      };
    }
    
    public final boolean contains(Object paramObject)
    {
      if ((paramObject instanceof Multiset.Entry))
      {
        paramObject = (Multiset.Entry)paramObject;
        if (((Multiset.Entry)paramObject).getCount() > 0) {
          break label23;
        }
      }
      label23:
      while (ImmutableMultiset.this.count(((Multiset.Entry)paramObject).getElement()) != ((Multiset.Entry)paramObject).getCount()) {
        return false;
      }
      return true;
    }
    
    public final int hashCode()
    {
      return ImmutableMultiset.this.hashCode();
    }
    
    public final UnmodifiableIterator<Multiset.Entry<E>> iterator()
    {
      return asList().iterator();
    }
    
    public final int size()
    {
      return ImmutableMultiset.this.elementSet().size();
    }
    
    final Object writeReplace()
    {
      return new ImmutableMultiset.b(ImmutableMultiset.this);
    }
  }
  
  static final class b<E>
    implements Serializable
  {
    final ImmutableMultiset<E> a;
    
    b(ImmutableMultiset<E> paramImmutableMultiset)
    {
      this.a = paramImmutableMultiset;
    }
    
    final Object readResolve()
    {
      return this.a.entrySet();
    }
  }
  
  static final class c
    implements Serializable
  {
    private static final long serialVersionUID = 0L;
    final Object[] a;
    final int[] b;
    
    c(Multiset<?> paramMultiset)
    {
      int i = paramMultiset.entrySet().size();
      this.a = new Object[i];
      this.b = new int[i];
      paramMultiset = paramMultiset.entrySet().iterator();
      i = 0;
      while (paramMultiset.hasNext())
      {
        Multiset.Entry localEntry = (Multiset.Entry)paramMultiset.next();
        this.a[i] = localEntry.getElement();
        this.b[i] = localEntry.getCount();
        i += 1;
      }
    }
    
    final Object readResolve()
    {
      LinkedHashMultiset localLinkedHashMultiset = LinkedHashMultiset.create(this.a.length);
      int i = 0;
      while (i < this.a.length)
      {
        localLinkedHashMultiset.add(this.a[i], this.b[i]);
        i += 1;
      }
      return ImmutableMultiset.copyOf(localLinkedHashMultiset);
    }
  }
}


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