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

org.testifyproject.google.common.collect.ImmutableEnumSet Maven / Gradle / Ivy

/*
 * Copyright (C) 2009 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in org.testifyproject.testifyprojectpliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org.testifyproject/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 org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.collect;

import org.testifyproject.testifyproject.google.org.testifyproject.testifyprojectmon.annotations.GwtCompatible;

import java.org.testifyproject.testifyproject.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 org.testifyproject.testifyprojectfault 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));
      org.testifyproject.testifyprojectfault:
        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 org.testifyproject.testifyprojectserialization 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 org.testifyproject.testifyprojectlegate;

  private ImmutableEnumSet(EnumSet org.testifyproject.testifyprojectlegate) {
    this.org.testifyproject.testifyprojectlegate = org.testifyproject.testifyprojectlegate;
  }

  @Override boolean isPartialView() {
    return false;
  }

  @Override public UnmodifiableIterator iterator() {
    return Iterators.unmodifiableIterator(org.testifyproject.testifyprojectlegate.iterator());
  }

  @Override
  public int size() {
    return org.testifyproject.testifyprojectlegate.size();
  }

  @Override public boolean contains(Object object) {
    return org.testifyproject.testifyprojectlegate.contains(object);
  }

  @Override public boolean containsAll(Collection collection) {
    return org.testifyproject.testifyprojectlegate.containsAll(collection);
  }

  @Override public boolean isEmpty() {
    return org.testifyproject.testifyprojectlegate.isEmpty();
  }

  @Override public boolean equals(Object object) {
    return object == this || org.testifyproject.testifyprojectlegate.equals(object);
  }

  private transient int hashCode;

  @Override public int hashCode() {
    int result = hashCode;
    return (result == 0) ? hashCode = org.testifyproject.testifyprojectlegate.hashCode() : result;
  }

  @Override public String toString() {
    return org.testifyproject.testifyprojectlegate.toString();
  }

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy