Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 24d5769b3a3eb9a2075451e06e9e12acd7fba38a (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
/*
 * Copyright (c) 2011, 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.common.revision;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.revision.CDORevisable;
import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
import org.eclipse.emf.cdo.internal.common.branch.CDOBranchVersionImpl;

import org.eclipse.net4j.util.ObjectUtil;

import java.text.MessageFormat;

/**
 * @author Eike Stepper
 */
public class CDORevisableImpl extends CDOBranchVersionImpl implements CDORevisable
{
  private long timeStamp;

  private long revised;

  public CDORevisableImpl(CDOBranch branch, int version, long timeStamp, long revised)
  {
    super(branch, version);
    this.timeStamp = timeStamp;
    this.revised = revised;
  }

  public CDORevisableImpl(CDORevisable source)
  {
    super(source.getBranch(), source.getVersion());
    timeStamp = source.getTimeStamp();
    revised = source.getRevised();
  }

  public CDORevisableImpl(CDOBranch branch, int version)
  {
    super(branch, version);
  }

  public long getTimeStamp()
  {
    return timeStamp;
  }

  public long getRevised()
  {
    return revised;
  }

  @Override
  public int hashCode()
  {
    return ObjectUtil.hashCode(timeStamp) ^ ObjectUtil.hashCode(revised) ^ super.hashCode();
  }

  @Override
  public boolean equals(Object obj)
  {
    if (obj == this)
    {
      return true;
    }

    if (obj instanceof CDORevisable)
    {
      CDORevisable that = (CDORevisable)obj;
      return timeStamp == that.getTimeStamp() && revised == that.getRevised() && getBranch().equals(that.getBranch()) && getVersion() == that.getVersion();
    }

    return false;
  }

  @Override
  public String toString()
  {
    return MessageFormat.format("{0}v{1}[{2}-{3}]", getBranch().getID(), getVersion(), CDOCommonUtil.formatTimeStamp(timeStamp),
        CDOCommonUtil.formatTimeStamp(revised));
  }
}

Back to the top