LinkedHashMultimap.java 11.6 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 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
package com.google.common.collect;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Nullable;
import nb;
import nj;
import oo;
import oq;

@GwtCompatible(emulated=true, serializable=true)
public final class LinkedHashMultimap<K, V>
  extends nb<K, V>
{
  @GwtIncompatible("java serialization not supported")
  private static final long serialVersionUID = 1L;
  @VisibleForTesting
  transient int a = 2;
  private transient a<K, V> b;
  
  private LinkedHashMultimap(int paramInt1, int paramInt2)
  {
    super(new LinkedHashMap(paramInt1));
    nj.a(paramInt2, "expectedValuesPerKey");
    this.a = paramInt2;
    this.b = new a(null, null, 0, null);
    b(this.b, this.b);
  }
  
  private static <K, V> void b(a<K, V> parama1, a<K, V> parama2)
  {
    parama1.h = parama2;
    parama2.g = parama1;
  }
  
  private static <K, V> void b(c<K, V> paramc1, c<K, V> paramc2)
  {
    paramc1.b(paramc2);
    paramc2.a(paramc1);
  }
  
  public static <K, V> LinkedHashMultimap<K, V> create()
  {
    return new LinkedHashMultimap(16, 2);
  }
  
  public static <K, V> LinkedHashMultimap<K, V> create(int paramInt1, int paramInt2)
  {
    return new LinkedHashMultimap(Maps.a(paramInt1), Maps.a(paramInt2));
  }
  
  public static <K, V> LinkedHashMultimap<K, V> create(Multimap<? extends K, ? extends V> paramMultimap)
  {
    LinkedHashMultimap localLinkedHashMultimap = create(paramMultimap.keySet().size(), 2);
    localLinkedHashMultimap.putAll(paramMultimap);
    return localLinkedHashMultimap;
  }
  
  @GwtIncompatible("java.io.ObjectInputStream")
  private void readObject(ObjectInputStream paramObjectInputStream)
    throws IOException, ClassNotFoundException
  {
    paramObjectInputStream.defaultReadObject();
    this.b = new a(null, null, 0, null);
    b(this.b, this.b);
    this.a = paramObjectInputStream.readInt();
    int j = paramObjectInputStream.readInt();
    LinkedHashMap localLinkedHashMap = new LinkedHashMap(Maps.a(j));
    int i = 0;
    Object localObject1;
    while (i < j)
    {
      localObject1 = paramObjectInputStream.readObject();
      localLinkedHashMap.put(localObject1, a(localObject1));
      i += 1;
    }
    j = paramObjectInputStream.readInt();
    i = 0;
    while (i < j)
    {
      localObject1 = paramObjectInputStream.readObject();
      Object localObject2 = paramObjectInputStream.readObject();
      ((Collection)localLinkedHashMap.get(localObject1)).add(localObject2);
      i += 1;
    }
    a(localLinkedHashMap);
  }
  
  @GwtIncompatible("java.io.ObjectOutputStream")
  private void writeObject(ObjectOutputStream paramObjectOutputStream)
    throws IOException
  {
    paramObjectOutputStream.defaultWriteObject();
    paramObjectOutputStream.writeInt(this.a);
    paramObjectOutputStream.writeInt(keySet().size());
    Iterator localIterator = keySet().iterator();
    while (localIterator.hasNext()) {
      paramObjectOutputStream.writeObject(localIterator.next());
    }
    paramObjectOutputStream.writeInt(size());
    localIterator = entries().iterator();
    while (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      paramObjectOutputStream.writeObject(localEntry.getKey());
      paramObjectOutputStream.writeObject(localEntry.getValue());
    }
  }
  
  final Collection<V> a(K paramK)
  {
    return new b(paramK, this.a);
  }
  
  final Set<V> a()
  {
    return new LinkedHashSet(this.a);
  }
  
  public final void clear()
  {
    super.clear();
    b(this.b, this.b);
  }
  
  public final Set<Map.Entry<K, V>> entries()
  {
    return super.entries();
  }
  
  final Iterator<V> f()
  {
    return Maps.b(g());
  }
  
  final Iterator<Map.Entry<K, V>> g()
  {
    new Iterator()
    {
      LinkedHashMultimap.a<K, V> a = LinkedHashMultimap.a(LinkedHashMultimap.this).h;
      LinkedHashMultimap.a<K, V> b;
      
      public final boolean hasNext()
      {
        return this.a != LinkedHashMultimap.a(LinkedHashMultimap.this);
      }
      
      public final void remove()
      {
        if (this.b != null) {}
        for (boolean bool = true;; bool = false)
        {
          Preconditions.checkState(bool, "no calls to next() since the last call to remove()");
          LinkedHashMultimap.this.remove(this.b.getKey(), this.b.getValue());
          this.b = null;
          return;
        }
      }
    };
  }
  
  public final Set<V> replaceValues(@Nullable K paramK, Iterable<? extends V> paramIterable)
  {
    return super.replaceValues(paramK, paramIterable);
  }
  
  public final Collection<V> values()
  {
    return super.values();
  }
  
  @VisibleForTesting
  static final class a<K, V>
    extends oq<K, V>
    implements LinkedHashMultimap.c<K, V>
  {
    final int a;
    @Nullable
    a<K, V> b;
    LinkedHashMultimap.c<K, V> c;
    LinkedHashMultimap.c<K, V> d;
    a<K, V> g;
    a<K, V> h;
    
    a(@Nullable K paramK, @Nullable V paramV, int paramInt, @Nullable a<K, V> parama)
    {
      super(paramV);
      this.a = paramInt;
      this.b = parama;
    }
    
    public final LinkedHashMultimap.c<K, V> a()
    {
      return this.c;
    }
    
    public final void a(LinkedHashMultimap.c<K, V> paramc)
    {
      this.c = paramc;
    }
    
    final boolean a(@Nullable Object paramObject, int paramInt)
    {
      return (this.a == paramInt) && (Objects.equal(getValue(), paramObject));
    }
    
    public final LinkedHashMultimap.c<K, V> b()
    {
      return this.d;
    }
    
    public final void b(LinkedHashMultimap.c<K, V> paramc)
    {
      this.d = paramc;
    }
  }
  
  @VisibleForTesting
  final class b
    extends Sets.f<V>
    implements LinkedHashMultimap.c<K, V>
  {
    @VisibleForTesting
    LinkedHashMultimap.a<K, V>[] a;
    private final K c;
    private int d = 0;
    private int e = 0;
    private LinkedHashMultimap.c<K, V> f;
    private LinkedHashMultimap.c<K, V> g;
    
    b(int paramInt)
    {
      this.c = paramInt;
      this.f = this;
      this.g = this;
      int i;
      this.a = new LinkedHashMultimap.a[oo.a(i, 1.0D)];
    }
    
    public final LinkedHashMultimap.c<K, V> a()
    {
      return this.g;
    }
    
    public final void a(LinkedHashMultimap.c<K, V> paramc)
    {
      this.g = paramc;
    }
    
    public final boolean add(@Nullable V paramV)
    {
      int i = oo.a(paramV);
      int j = i & this.a.length - 1;
      LinkedHashMultimap.a locala = this.a[j];
      for (Object localObject = locala; localObject != null; localObject = ((LinkedHashMultimap.a)localObject).b) {
        if (((LinkedHashMultimap.a)localObject).a(paramV, i)) {
          return false;
        }
      }
      paramV = new LinkedHashMultimap.a(this.c, paramV, i, locala);
      LinkedHashMultimap.a(this.g, paramV);
      LinkedHashMultimap.a(paramV, this);
      LinkedHashMultimap.a(LinkedHashMultimap.a(LinkedHashMultimap.this).g, paramV);
      LinkedHashMultimap.a(paramV, LinkedHashMultimap.a(LinkedHashMultimap.this));
      this.a[j] = paramV;
      this.d += 1;
      this.e += 1;
      if (oo.a(this.d, this.a.length))
      {
        localObject = new LinkedHashMultimap.a[this.a.length * 2];
        this.a = ((LinkedHashMultimap.a[])localObject);
        i = localObject.length;
        for (paramV = this.f; paramV != this; paramV = paramV.b())
        {
          locala = (LinkedHashMultimap.a)paramV;
          j = locala.a & i - 1;
          locala.b = localObject[j];
          localObject[j] = locala;
        }
      }
      return true;
    }
    
    public final LinkedHashMultimap.c<K, V> b()
    {
      return this.f;
    }
    
    public final void b(LinkedHashMultimap.c<K, V> paramc)
    {
      this.f = paramc;
    }
    
    public final void clear()
    {
      Arrays.fill(this.a, null);
      this.d = 0;
      for (LinkedHashMultimap.c localc = this.f; localc != this; localc = localc.b()) {
        LinkedHashMultimap.a((LinkedHashMultimap.a)localc);
      }
      LinkedHashMultimap.a(this, this);
      this.e += 1;
    }
    
    public final boolean contains(@Nullable Object paramObject)
    {
      int i = oo.a(paramObject);
      for (LinkedHashMultimap.a locala = this.a[(this.a.length - 1 & i)]; locala != null; locala = locala.b) {
        if (locala.a(paramObject, i)) {
          return true;
        }
      }
      return false;
    }
    
    public final Iterator<V> iterator()
    {
      new Iterator()
      {
        LinkedHashMultimap.c<K, V> a = LinkedHashMultimap.b.a(LinkedHashMultimap.b.this);
        LinkedHashMultimap.a<K, V> b;
        int c = LinkedHashMultimap.b.b(LinkedHashMultimap.b.this);
        
        private void a()
        {
          if (LinkedHashMultimap.b.b(LinkedHashMultimap.b.this) != this.c) {
            throw new ConcurrentModificationException();
          }
        }
        
        public final boolean hasNext()
        {
          a();
          return this.a != LinkedHashMultimap.b.this;
        }
        
        public final V next()
        {
          if (!hasNext()) {
            throw new NoSuchElementException();
          }
          LinkedHashMultimap.a locala = (LinkedHashMultimap.a)this.a;
          Object localObject = locala.getValue();
          this.b = locala;
          this.a = locala.d;
          return (V)localObject;
        }
        
        public final void remove()
        {
          a();
          if (this.b != null) {}
          for (boolean bool = true;; bool = false)
          {
            Preconditions.checkState(bool, "no calls to next() since the last call to remove()");
            LinkedHashMultimap.b.this.remove(this.b.getValue());
            this.c = LinkedHashMultimap.b.b(LinkedHashMultimap.b.this);
            this.b = null;
            return;
          }
        }
      };
    }
    
    public final boolean remove(@Nullable Object paramObject)
    {
      int i = oo.a(paramObject);
      int j = i & this.a.length - 1;
      Object localObject2 = null;
      LinkedHashMultimap.a locala;
      for (Object localObject1 = this.a[j]; localObject1 != null; localObject1 = locala)
      {
        if (((LinkedHashMultimap.a)localObject1).a(paramObject, i))
        {
          if (localObject2 == null) {
            this.a[j] = ((LinkedHashMultimap.a)localObject1).b;
          }
          for (;;)
          {
            LinkedHashMultimap.a((LinkedHashMultimap.c)localObject1);
            LinkedHashMultimap.a((LinkedHashMultimap.a)localObject1);
            this.d -= 1;
            this.e += 1;
            return true;
            ((LinkedHashMultimap.a)localObject2).b = ((LinkedHashMultimap.a)localObject1).b;
          }
        }
        locala = ((LinkedHashMultimap.a)localObject1).b;
        localObject2 = localObject1;
      }
      return false;
    }
    
    public final int size()
    {
      return this.d;
    }
  }
  
  static abstract interface c<K, V>
  {
    public abstract c<K, V> a();
    
    public abstract void a(c<K, V> paramc);
    
    public abstract c<K, V> b();
    
    public abstract void b(c<K, V> paramc);
  }
}


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