1 /*
2 * This file is part of *** M y C o R e ***
3 * See http://www.mycore.de/ for details.
4 *
5 * MyCoRe is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * MyCoRe is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package org.mycore.common.processing;
20
21 import java.util.Map;
22 import java.util.stream.Stream;
23
24 /**
25 * Defines a collection of coherent {@link MCRProcessable}.
26 *
27 * @author Matthias Eichner
28 */
29 public interface MCRProcessableCollection {
30
31 /**
32 * Returns a human readable name about this registry container.
33 *
34 * @return name of this container
35 */
36 String getName();
37
38 /**
39 * Adds a new {@link MCRProcessable} to this container.
40 *
41 * @param processable the processable to add
42 */
43 void add(MCRProcessable processable);
44
45 /**
46 * Removes a {@link MCRProcessable} from the container.
47 */
48 void remove(MCRProcessable processable);
49
50 /**
51 * Streams all {@link MCRProcessable} registered by this container.
52 *
53 * @return stream of {@link MCRProcessable}
54 */
55 Stream<MCRProcessable> stream();
56
57 /**
58 * Checks if this collection contains any processable.
59 *
60 * @return true if this collection contains at least on processable
61 */
62 boolean isEmpty();
63
64 /**
65 * Returns a map of properties assigned to this processable.
66 *
67 * @return the properties map
68 */
69 Map<String, Object> getProperties();
70
71 /**
72 * A shortcut for getProperties().get(name).
73 *
74 * @param name the name of the property
75 * @return the property value or null
76 */
77 default Object getProperty(String name) {
78 return getProperties().get(name);
79 }
80
81 /**
82 * Returns the property for the given name. The property
83 * will be cast to the specified type. Be aware that a
84 * ClassCastException is thrown if the type does not match.
85 *
86 * @param name name of property
87 * @param type object type of the property
88 * @return the property value or null
89 */
90 @SuppressWarnings("unchecked")
91 default <T> T getPropertyAs(String name, Class<T> type) {
92 Object property = getProperty(name);
93 if (property == null) {
94 return null;
95 }
96 return (T) property;
97 }
98
99 /**
100 * Adds a new listener.
101 *
102 * @param listener the listener to add
103 */
104 void addListener(MCRProcessableCollectionListener listener);
105
106 /**
107 * Removes a listener.
108 *
109 * @param listener the listener to remove
110 */
111 void removeListener(MCRProcessableCollectionListener listener);
112
113 }