blob: 5c0d83678c8b1158fd927bddfb998c46f51a67df (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;
import com.google.common.annotations.Beta;
import java.util.Optional;
/**
* The TestAndSetCondition class represents a test and set condition.
* A test and set condition is an (optional) string representing a
* document selection (cf. document selection language), which is used
* to match a document for test and set. If #isPresent evaluates to false,
* the condition is not present and matches any document.
*
* @author Vegard Sjonfjell
*/
@Beta
public class TestAndSetCondition {
public static final TestAndSetCondition NOT_PRESENT_CONDITION = new TestAndSetCondition();
private final String conditionStr;
public TestAndSetCondition() {
this("");
}
public TestAndSetCondition(String conditionStr) {
this.conditionStr = conditionStr;
}
public String getSelection() { return conditionStr; }
public boolean isPresent() { return !conditionStr.isEmpty(); }
/**
* Maps and optional test and set conditiong string to a TestAndSetCondition.
* If the condition string is not present, a "not present" condition is returned
* @param conditionString test and set conditiong string (document selection)
* @return a TestAndSetCondition representing the condition string or a "not present" condition
*/
public static TestAndSetCondition fromConditionString(Optional<String> conditionString) {
return conditionString
.map(TestAndSetCondition::new)
.orElse(TestAndSetCondition.NOT_PRESENT_CONDITION);
}
}
|