Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 58d0e01a010890c95ae09c954d10d25ca33b0036 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * Copyright (c) 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.internal.ui.history;

/**
 * @author Eike Stepper
 */
public final class Segment
{
  private final Track track;

  private final Branch branch;

  private final Commit mergeSource;

  private boolean complete;

  private long firstVisualTime;

  private long firstCommitTime;

  private long lastCommitTime;

  private Segment previousInTrack;

  private Segment nextInTrack;

  private Segment previousInBranch;

  private Segment nextInBranch;

  public Segment(Track track, Branch branch, Commit mergeSource)
  {
    this.track = track;
    this.branch = branch;
    this.mergeSource = mergeSource;
  }

  public Net getNet()
  {
    return track.getNet();
  }

  public Track getTrack()
  {
    return track;
  }

  public Branch getBranch()
  {
    return branch;
  }

  public Commit getMergeSource()
  {
    return mergeSource;
  }

  public boolean isMerge()
  {
    return mergeSource != null;
  }

  public boolean isComplete()
  {
    return complete;
  }

  public long getFirstVisualTime()
  {
    return firstVisualTime;
  }

  public long getFirstCommitTime()
  {
    return firstCommitTime;
  }

  public long getLastCommitTime()
  {
    return lastCommitTime;
  }

  public Segment getPreviousInTrack()
  {
    return previousInTrack;
  }

  public Segment getNextInTrack()
  {
    return nextInTrack;
  }

  public Segment getPreviousInBranch()
  {
    return previousInBranch;
  }

  public Segment getNextInBranch()
  {
    return nextInBranch;
  }

  public boolean containsCommitTime(long time)
  {
    return time >= firstCommitTime && time <= lastCommitTime;
  }

  public boolean containsVisualTime(long time)
  {
    return time >= getFirstVisualTime() && time <= lastCommitTime;
  }

  @Override
  public String toString()
  {
    return "Segment[" + branch + " --> " + track + "]";
  }

  void adjustVisualTime(long time, boolean complete)
  {
    if (isMerge())
    {
      firstVisualTime = firstCommitTime;
      this.complete = true;
    }
    else
    {
      if (firstVisualTime == 0 || time < firstVisualTime)
      {
        firstVisualTime = time;
      }
    }

    this.complete |= complete;
  }

  void adjustCommitTimes(long time)
  {
    adjustVisualTime(time, false);
    if (firstCommitTime == 0)
    {
      firstCommitTime = time;
      lastCommitTime = time;
    }
    else if (time < firstCommitTime)
    {
      firstCommitTime = time;
    }
    else if (time > lastCommitTime)
    {
      lastCommitTime = time;
    }
  }

  void setPreviousInTrack(Segment previousInTrack)
  {
    this.previousInTrack = previousInTrack;
  }

  void setNextInTrack(Segment nextInTrack)
  {
    this.nextInTrack = nextInTrack;
  }

  void setPreviousInBranch(Segment previousInBranch)
  {
    this.previousInBranch = previousInBranch;
  }

  void setNextInBranch(Segment nextInBranch)
  {
    this.nextInBranch = nextInBranch;
  }
}

Back to the top