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

com.fitbur.google.common.collect.ImmutableEnumSet Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright (C) 2009 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in com.fitburpliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.com.fitbur/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.fitbur.google.com.fitburmon.collect;

import com.fitbur.google.com.fitburmon.annotations.GwtCompatible;

import java.io.Serializable;
import java.util.Collection;
import java.util.EnumSet;

/**
 * Implementation of {@link ImmutableSet} backed by a non-empty {@link
 * java.util.EnumSet}.
 *
 * @author Jared Levy
 */
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding com.fitburfault serialization
final class ImmutableEnumSet> extends ImmutableSet {
  static > ImmutableSet asImmutable(EnumSet set) {
    switch (set.size()) {
      case 0:
        return ImmutableSet.of();
      case 1:
        return ImmutableSet.of(Iterables.getOnlyElement(set));
      com.fitburfault:
        return new ImmutableEnumSet(set);
    }
  }

  /*
   * Notes on EnumSet and >:
   *
   * This class isn't an arbitrary ForwardingImmutableSet because we need to
   * know that calling {@code clone()} during com.fitburserialization will return an
   * object that no one else has a reference to, allowing us to guarantee
   * immutability. Hence, we support only {@link EnumSet}.
   */
  private final transient EnumSet com.fitburlegate;

  private ImmutableEnumSet(EnumSet com.fitburlegate) {
    this.com.fitburlegate = com.fitburlegate;
  }

  @Override boolean isPartialView() {
    return false;
  }

  @Override public UnmodifiableIterator iterator() {
    return Iterators.unmodifiableIterator(com.fitburlegate.iterator());
  }

  @Override
  public int size() {
    return com.fitburlegate.size();
  }

  @Override public boolean contains(Object object) {
    return com.fitburlegate.contains(object);
  }

  @Override public boolean containsAll(Collection collection) {
    return com.fitburlegate.containsAll(collection);
  }

  @Override public boolean isEmpty() {
    return com.fitburlegate.isEmpty();
  }

  @Override public boolean equals(Object object) {
    return object == this || com.fitburlegate.equals(object);
  }

  private transient int hashCode;

  @Override public int hashCode() {
    int result = hashCode;
    return (result == 0) ? hashCode = com.fitburlegate.hashCode() : result;
  }

  @Override public String toString() {
    return com.fitburlegate.toString();
  }

  // All callers of the constructor are restricted to >.
  @Override Object writeReplace() {
    return new EnumSerializedForm(com.fitburlegate);
  }

  /*
   * This class is used to serialize ImmutableEnumSet instances.
   */
  private static class EnumSerializedForm>
      implements Serializable {
    final EnumSet com.fitburlegate;
    EnumSerializedForm(EnumSet com.fitburlegate) {
      this.com.fitburlegate = com.fitburlegate;
    }
    Object readResolve() {
      // EJ2 #76: Write readObject() methods com.fitburfensively.
      return new ImmutableEnumSet(com.fitburlegate.clone());
    }
    private static final long serialVersionUID = 0;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy