001 /**
002 * Copyright (c) 2010, SIB. All rights reserved.
003 *
004 * SIB (Swiss Institute of Bioinformatics) - http://www.isb-sib.ch Host -
005 * https://sourceforge.net/projects/javaprotlib/
006 *
007 * Redistribution and use in source and binary forms, with or without
008 * modification, are permitted provided that the following conditions are met:
009 * Redistributions of source code must retain the above copyright notice, this
010 * list of conditions and the following disclaimer. Redistributions in binary
011 * form must reproduce the above copyright notice, this list of conditions and
012 * the following disclaimer in the documentation and/or other materials provided
013 * with the distribution. Neither the name of the SIB/GENEBIO nor the names of
014 * its contributors may be used to endorse or promote products derived from this
015 * software without specific prior written permission.
016 *
017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
020 * ARE DISCLAIMED. IN NO EVENT SHALL SIB/GENEBIO BE LIABLE FOR ANY DIRECT,
021 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
024 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027 */
028 package org.expasy.jpl.commons.collection;
029
030
031 import java.util.Set;
032 import org.expasy.jpl.commons.base.Registrable;
033
034
035 /**
036 * A {@code Pool} interface should be implemented by any pool that handles
037 * unique objects.
038 *
039 * @author nikitin
040 *
041 * @param <T> the object type.
042 *
043 * @version 1.0
044 *
045 */
046 public interface Pool<T extends Cachable> extends Register<T> {
047
048 /**
049 * Return true if object exists in pool.
050 *
051 * @param o the object.
052 * @return true if exists.
053 *
054 */
055 boolean isRegistered(T o);
056
057 /**
058 * Get keys of all stored objects.
059 *
060 * @return the key set.
061 */
062 Set<String> getKeys();
063
064 /**
065 * Get values of all stored objects.
066 *
067 * @return the value set.
068 */
069 Set<T> getValues();
070
071 /**
072 * Exception thrown when object already exists in the pool.
073 *
074 * @author nikitin
075 *
076 * @version 1.0
077 *
078 */
079 public static class ObjectAlreadyExistException extends RuntimeException {
080
081 private static final long serialVersionUID = -3173144664053561763L;
082
083 public <T extends Registrable> ObjectAlreadyExistException(T o) {
084 super("object " + o.toString() + " referenced by '" + o.getId()
085 + "' " + "already exists in the pool.");
086 }
087 }
088
089 /**
090 * Exception thrown when key already already reference an object in the
091 * pool.
092 *
093 * @author nikitin
094 *
095 * @version 1.0
096 *
097 */
098 public static class KeyAlreadyExistException extends RuntimeException {
099
100 private static final long serialVersionUID = -3173144664053561763L;
101
102 public KeyAlreadyExistException(String id) {
103 super("key '" + id + "' already references an object in the pool.");
104 }
105 }
106 }