diff options
Diffstat (limited to 'subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/timeline/Timelines.java')
-rw-r--r-- | subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/timeline/Timelines.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/timeline/Timelines.java b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/timeline/Timelines.java new file mode 100644 index 00000000..747fda15 --- /dev/null +++ b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/timeline/Timelines.java | |||
@@ -0,0 +1,46 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2019, Tamas Szabo, itemis AG, Gabor Bergmann, IncQuery Labs Ltd. | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.matchers.util.timeline; | ||
10 | |||
11 | import java.util.List; | ||
12 | |||
13 | /** | ||
14 | * Utility class for creating {@link Timeline}s. | ||
15 | * @author Tamas Szabo | ||
16 | * @since 2.4 | ||
17 | */ | ||
18 | public final class Timelines<Timestamp extends Comparable<Timestamp>> { | ||
19 | |||
20 | public static <Timestamp extends Comparable<Timestamp>> Timeline<Timestamp> createEmpty() { | ||
21 | return new CompactTimeline<Timestamp>(); | ||
22 | } | ||
23 | |||
24 | public static <Timestamp extends Comparable<Timestamp>> Timeline<Timestamp> createFrom( | ||
25 | final Diff<Timestamp> diffs) { | ||
26 | if (diffs.size() == 1) { | ||
27 | return new SingletonTimeline<Timestamp>(diffs); | ||
28 | } else { | ||
29 | return new CompactTimeline<Timestamp>(diffs); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | public static <Timestamp extends Comparable<Timestamp>> Timeline<Timestamp> createFrom( | ||
34 | final List<Timestamp> timestamps) { | ||
35 | if (timestamps.size() == 1) { | ||
36 | return new SingletonTimeline<Timestamp>(timestamps.get(0)); | ||
37 | } else { | ||
38 | return new CompactTimeline<Timestamp>(timestamps); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | public static <Timestamp extends Comparable<Timestamp>> Timeline<Timestamp> createFrom(final Timestamp timestamp) { | ||
43 | return new SingletonTimeline<Timestamp>(timestamp); | ||
44 | } | ||
45 | |||
46 | } | ||