1 /*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15 package net.sourceforge.basher;
16
17 import java.util.Collection;
18
19 /**
20 * Simple registry where tasks may store objects to be used during runtime.
21 * <b>Warning</b>: This is currenly backed by an in-memory store, which means that heavy use of this may cause
22 * a degradation in performance over time.
23 *
24 * @author Johan Lindquist
25 * @version 1.0
26 */
27 public interface EntityRegistry
28 {
29 /**
30 * Register a certain type as having been created. The <code>entityIdentifier</code> is a key into a collection
31 * of <code>entity</code> instances being held by the <code>EntityRegistry</code>.
32 *
33 * @param entityIdentifier The type of the entity being registered
34 * @param entity The entity being registered
35 */
36 public void register(String entityIdentifier, Object entity);
37
38 /**
39 * Retrieves all registered <code>entity</code> instances for a particular <code>entityIdentifier</code>.
40 *
41 * @param entityIdentifier The entity type to retrive the entity instances for
42 * @return A collection of <code>entity</code>.
43 */
44 public Collection getAllRegistered(String entityIdentifier);
45
46 /**
47 * Retrieves the number of <code>entity</code> instances registered for the specified <code>entityIdentifier</code>.
48 *
49 * @param entityIdentifier The entity type to count
50 * @return The number of instances registered for the specified <code>entityIdentifier</code>.
51 */
52 public long getNumRegistered(String entityIdentifier);
53
54 /**
55 * Retrieves a randomly sized collection of <code>entity</code> instances registered for the specified
56 * <code>entityIdentifier</code>.
57 *
58 * @param entityIdentifier The entity type to generate the random selection from
59 * @param maxSize The maximum number of entity instances in the collection.
60 * @return A collection of <code>entity</code> instances. The size of this collection may be less than
61 * the maxSize specified if there are less entity instances registered than is requested.
62 */
63 public Collection getRandomSelection(String entityIdentifier, int maxSize);
64
65 /**
66 * Retrieves a random <code>entity</code> instance registered for the specified <code>entityIdentifier</code>.
67 *
68 * @param entityIdentifier The entity type to retrieve the instance for.
69 * @return The entity instance or null if none could be found.
70 */
71 public Object getRandom(String entityIdentifier);
72
73 /**
74 * Removes the specified entity from the registry.
75 *
76 * @param entityIdentifier The entity type to remove.
77 * @param entity The entity to remove
78 */
79 public void unregister(String entityIdentifier, Object entity);
80 }