|
26 | 26 | import java.util.HashMap;
|
27 | 27 | import java.util.function.LongUnaryOperator;
|
28 | 28 |
|
29 |
| -public class InitialProbabilityFactory { |
| 29 | +public final class InitialProbabilityFactory { |
30 | 30 |
|
31 |
| - public static InitialProbabilityProvider create(LongUnaryOperator toMappedId, double alpha, SourceNodes sourceNodes) { |
32 |
| - if (sourceNodes == SourceNodes.EMPTY_SOURCE_NODES){ |
| 31 | + private InitialProbabilityFactory() {} |
| 32 | + |
| 33 | + public static InitialProbabilityProvider create( |
| 34 | + LongUnaryOperator toMappedId, |
| 35 | + double alpha, |
| 36 | + SourceNodes sourceNodes |
| 37 | + ) { |
| 38 | + if (sourceNodes == SourceNodes.EMPTY_SOURCE_NODES) { |
33 | 39 | return new GlobalRestartProbability(alpha);
|
34 |
| - } |
35 |
| - else if (sourceNodes instanceof ListSourceNodes){ |
| 40 | + } else if (sourceNodes instanceof ListSourceNodes) { |
36 | 41 | var newSourceNodes = sourceNodes.sourceNodes()
|
37 | 42 | .stream()
|
38 | 43 | .mapToLong(toMappedId::applyAsLong)
|
39 | 44 | .boxed()
|
40 | 45 | .toList();
|
41 | 46 | return new SourceBasedRestartProbabilityList(alpha, newSourceNodes);
|
42 |
| - } |
43 |
| - else if (sourceNodes instanceof MapSourceNodes){ |
| 47 | + } else if (sourceNodes instanceof MapSourceNodes) { |
44 | 48 | var newMap = new HashMap<Long, Double>();
|
45 |
| - for(var entry : ((MapSourceNodes) sourceNodes).map().entrySet()){ |
| 49 | + for (var entry : ((MapSourceNodes) sourceNodes).map().entrySet()) { |
46 | 50 | var newKey = toMappedId.applyAsLong(entry.getKey());
|
47 | 51 | newMap.put(newKey, entry.getValue());
|
48 | 52 | }
|
49 | 53 | return new SourceBasedRestartProbability(alpha, newMap);
|
50 |
| - } |
51 |
| - else { |
52 |
| - throw new IllegalArgumentException("Unsupported source nodes: "); |
| 54 | + } else { |
| 55 | + throw new IllegalArgumentException("Unsupported source nodes type"); |
53 | 56 | }
|
54 | 57 | }
|
55 | 58 | }
|
0 commit comments