blob: 526a95f52d4e50c222db05cef46a8cbe52878528 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*******************************************************************************
* Copyright (c) 2010-2019, Tamas Szabo, itemis AG, Gabor Bergmann, IncQuery Labs Ltd.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-v20.html.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package tools.refinery.viatra.runtime.matchers.util.timeline;
import java.util.Collections;
import tools.refinery.viatra.runtime.matchers.util.Direction;
import tools.refinery.viatra.runtime.matchers.util.Signed;
/**
* A timeline which solely consists of one timestamp value, representing a single insertion. Intuitively, a singleton
* timeline always represents a bump which starts at the given timestamp and lasts till plus infinity.
*
* @author Tamas Szabo
* @since 2.4
*/
public class SingletonTimeline<Timestamp extends Comparable<Timestamp>> extends Timeline<Timestamp> {
protected final Timestamp start;
SingletonTimeline(final Timestamp timestamp) {
this.start = timestamp;
}
SingletonTimeline(final Diff<Timestamp> diff) {
if (diff.size() != 1 || diff.get(0).getDirection() == Direction.DELETE) {
throw new IllegalArgumentException("There is only a single (insert) timestamp in the singleton timestamp!");
} else {
this.start = diff.get(0).getPayload();
}
}
@Override
public Signed<Timestamp> getSigned(final int index) {
return new Signed<>(Direction.INSERT, this.getUnsigned(index));
}
@Override
public Timestamp getUnsigned(final int index) {
if (index != 0) {
throw new IllegalArgumentException("There is only a single (insert) timestamp in the singleton timestamp!");
} else {
return this.start;
}
}
@Override
public int size() {
return 1;
}
@Override
public boolean isPresentAtInfinity() {
return true;
}
@Override
public Iterable<Signed<Timestamp>> asChangeSequence() {
return Collections.singletonList(this.getSigned(0));
}
@Override
public boolean isEmpty() {
return false;
}
}
|