blob: ea727a67aa6e28c356cc9937968034724b7a0d03 (
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
|
/***************************************************************************
* Copyright (c) 2004 - 2008 Eike Stepper, Germany.
* 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.id;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDMetaRange;
import org.eclipse.emf.cdo.common.id.CDOID.Type;
import java.text.MessageFormat;
/**
* @author Eike Stepper
*/
public final class CDOIDMetaRangeImpl implements CDOIDMetaRange
{
private static final long serialVersionUID = 1L;
private CDOID lowerBound;
private int size;
public CDOIDMetaRangeImpl(CDOID lowerBound, int size)
{
if (size < 0)
{
throw new IllegalArgumentException("size < 0");
}
this.lowerBound = lowerBound;
this.size = size;
}
public CDOID getLowerBound()
{
return lowerBound;
}
public CDOID getUpperBound()
{
return size > 0 ? get(size - 1) : null;
}
public CDOID get(int index)
{
if (index < 0 || index >= size)
{
throw new IllegalArgumentException("ids < 0 || ids >= size");
}
if (isTemporary())
{
return new CDOIDTempMetaImpl(((CDOIDTempMetaImpl)lowerBound).getIntValue() + index);
}
return new CDOIDMetaImpl(((CDOIDMetaImpl)lowerBound).getLongValue() + index);
}
public int size()
{
return size;
}
public boolean isEmpty()
{
return size == 0;
}
public boolean contains(CDOID id)
{
if (isTemporary())
{
if (id.getType() != Type.TEMP_META)
{
throw new IllegalArgumentException("id.getType() != Type.TEMP_META");
}
int index = ((CDOIDTempMetaImpl)id).getIntValue() - ((CDOIDTempMetaImpl)lowerBound).getIntValue();
return 0 <= index && index < size;
}
if (id.getType() != Type.META)
{
throw new IllegalArgumentException("id.getType() != Type.META");
}
long index = ((CDOIDMetaImpl)id).getLongValue() - ((CDOIDMetaImpl)lowerBound).getLongValue();
return 0L <= index && index < size;
}
public CDOIDMetaRange increase()
{
return new CDOIDMetaRangeImpl(lowerBound, size + 1);
}
public Type getType()
{
return lowerBound.getType();
}
public boolean isTemporary()
{
return lowerBound.isTemporary();
}
@Override
public String toString()
{
return MessageFormat.format("[{0}:{1}]", lowerBound, getUpperBound());
}
}
|