11d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/*
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2007 The Guava Authors
31d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
41d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License");
51d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * you may not use this file except in compliance with the License.
61d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * You may obtain a copy of the License at
71d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
81d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0
91d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Unless required by applicable law or agreed to in writing, software
111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS,
121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * See the License for the specific language governing permissions and
141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * limitations under the License.
151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */
161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpackage com.google.common.collect;
181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport com.google.common.annotations.Beta;
201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/**
221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Provides equivalent behavior to {@link String#intern} for other immutable
231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * types.
241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @author Kevin Bourrillion
261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 3.0
271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */
281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert@Beta
291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpublic interface Interner<E> {
301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  /**
311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * Chooses and returns the representative instance for any of a collection of
321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * instances that are equal to each other. If two {@linkplain Object#equals
331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * equal} inputs are given to this method, both calls will return the same
341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * instance.  That is, {@code intern(a).equals(a)} always holds, and {@code
351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * intern(a) == intern(b)} if and only if {@code a.equals(b)}. Note that
361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * {@code intern(a)} is permitted to return one instance now and a different
371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * instance later if the original interned instance was garbage-collected.
381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *
391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * <p><b>Warning:</b> do not use with mutable objects.
401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *
411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * @throws NullPointerException if {@code sample} is null
421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   */
431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  E intern(E sample);
441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert}
45