1 package org.jscsi.target.settings.entry;
2
3
4 import org.jscsi.target.TargetServer;
5 import org.jscsi.target.settings.KeySet;
6 import org.jscsi.target.settings.NegotiationStatus;
7 import org.jscsi.target.settings.NegotiationType;
8 import org.jscsi.target.settings.NumericalResultFunction;
9 import org.jscsi.target.settings.NumericalValueRange;
10 import org.jscsi.target.settings.SingleNumericalValue;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public final class NumericalEntry extends Entry {
32
33
34
35
36 private final NumericalValueRange protocolValueRange;
37
38
39
40
41 private final int negotiationValue;
42
43
44
45
46 private final NumericalResultFunction resultFunction;
47
48
49
50
51
52
53 private final boolean zeroMeansDontCare;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public NumericalEntry (final KeySet keySet, final NegotiationType negotiationType, final Use use, final NegotiationStatus negotiationStatus, final int negotiationValue, final NumericalValueRange protocolValueRange, final NumericalResultFunction resultFunction, final Integer defaultValue, final boolean zeroMeansDontCare) {
72 super(keySet, negotiationType, use, negotiationStatus, defaultValue);
73 this.protocolValueRange = protocolValueRange;
74 this.negotiationValue = negotiationValue;
75 this.resultFunction = resultFunction;
76 this.zeroMeansDontCare = zeroMeansDontCare;
77 }
78
79 @Override
80 protected boolean inProtocolValueRange (final Object values) {
81
82 final int val = (Integer) values;
83 if (zeroMeansDontCare && val == 0)
84
85 return true;
86 return protocolValueRange.contains(val);
87 }
88
89 @Override
90 protected Object parseOffer (final TargetServer target, final String values) {
91
92 return SingleNumericalValue.parseSingleNumericValue(values).getValue();
93 }
94
95 @Override
96 protected void processDeclaration (final Object values) {
97
98 final int val = (Integer) values;
99 if (zeroMeansDontCare && val == 0)
100 value = negotiationValue;
101 else
102 value = values;
103 }
104
105 @Override
106 protected String processNegotiation (final Object values) {
107
108 final int val = (Integer) values;
109 if (zeroMeansDontCare && val == 0)
110 value = negotiationValue;
111 else
112
113 value = resultFunction.getResult(negotiationValue, val);
114 return value.toString();
115 }
116
117 @Override
118 public Integer getIntegerValue () {
119 return (Integer) value;
120 }
121
122 @Override
123 public Entry copy () {
124 final NumericalEntry e = new NumericalEntry(keySet, negotiationType, use, negotiationStatus, negotiationValue, protocolValueRange, resultFunction, (Integer) value, zeroMeansDontCare);
125 e.alreadyNegotiated = this.alreadyNegotiated;
126 return e;
127 }
128 }