1 /*
2 * Copyright (c) 2021 Kaiserpfalz EDV-Service, Roland T. Lichti.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 package de.kaiserpfalzedv.rpg.core.dice.bag;
19
20 import de.kaiserpfalzedv.rpg.core.dice.Die;
21 import lombok.AllArgsConstructor;
22 import lombok.ToString;
23 import lombok.extern.slf4j.Slf4j;
24
25 import jakarta.enterprise.inject.Instance;
26 import jakarta.enterprise.inject.Produces;
27 import jakarta.inject.Inject;
28 import jakarta.inject.Singleton;
29 import java.util.HashSet;
30 import java.util.Set;
31
32 /**
33 * DiceProvider -- Provides a set of dice (better known as dice bag).
34 *
35 * @author klenkes74 {@literal <rlichti@kaiserpfalz-edv.de>}
36 * @since 1.2.0 2021-05-09
37 */
38 @Singleton
39 @AllArgsConstructor(onConstructor = @__(@Inject))
40 @Slf4j
41 @ToString
42 public class DiceProvider {
43 private final Instance<Die> dice;
44
45 @Produces
46 public Set<Die> diceBag() {
47 HashSet<Die> result = new HashSet<>();
48
49 dice.forEach(result::add);
50
51 log.trace("Returning dice bag: {}", result);
52 return result;
53 }
54 }