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
|
/*******************************************************************************
* Copyright (c) 2013 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.orcs.core.ds;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
import org.eclipse.osee.framework.core.enums.LoadLevel;
import org.eclipse.osee.framework.jdk.core.util.Strings;
public final class OptionsUtil {
private OptionsUtil() {
// Utility method
}
private static final int TRANSACTION_SENTINEL = -1;
private static final String FROM_TRANSACTION = "from.transaction";
private static final String INCLUDE_DELETED = "include.deleted";
private static final String LOAD_LEVEL = "load.level";
public static Options createBranchOptions() {
Options options = new Options();
setIncludeDeleted(options, false);
setLoadLevel(options, LoadLevel.SHALLOW);
return options;
}
public static Options createOptions() {
Options options = new Options();
setIncludeDeleted(options, false);
setHeadTransaction(options);
setLoadLevel(options, LoadLevel.SHALLOW);
return options;
}
public static void reset(Options options) {
setIncludeDeleted(options, false);
setHeadTransaction(options);
setLoadLevel(options, LoadLevel.SHALLOW);
}
public static boolean areDeletedIncluded(Options options) {
return options.getBoolean(INCLUDE_DELETED);
}
public static void setIncludeDeleted(Options options, boolean enabled) {
options.put(INCLUDE_DELETED, enabled);
}
public static DeletionFlag getIncludeDeleted(Options options) {
boolean includeDeleted = areDeletedIncluded(options);
return DeletionFlag.allowDeleted(includeDeleted);
}
public static LoadLevel getLoadLevel(Options options) {
String level = options.get(LOAD_LEVEL);
LoadLevel loadLevel = LoadLevel.SHALLOW;
if (Strings.isValid(level)) {
loadLevel = LoadLevel.valueOf(level);
}
return loadLevel;
}
public static void setLoadLevel(Options options, LoadLevel loadLevel) {
options.put(LOAD_LEVEL, loadLevel.name());
}
public static void setFromTransaction(Options options, int transactionId) {
int transactionToSet = transactionId;
if (transactionToSet < -1) {
transactionToSet = TRANSACTION_SENTINEL;
}
options.put(FROM_TRANSACTION, transactionToSet);
}
public static int getFromTransaction(Options options) {
int transactionId = TRANSACTION_SENTINEL;
if (!options.isEmpty(FROM_TRANSACTION)) {
transactionId = options.getInt(FROM_TRANSACTION);
}
if (transactionId < -1) {
transactionId = TRANSACTION_SENTINEL;
}
return transactionId;
}
public static void setHeadTransaction(Options options) {
setFromTransaction(options, TRANSACTION_SENTINEL);
}
public static boolean isHeadTransaction(Options options) {
return TRANSACTION_SENTINEL == getFromTransaction(options);
}
public static boolean isHistorical(Options options) {
return !isHeadTransaction(options);
}
}
|