blob: 0e7678026e9c34caa1531bc3f47d07576eeec095 (
plain)
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) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
package Ice;
/**
* Manages an optional byte parameter.
**/
public class ByteOptional
{
/**
* The value defaults to unset.
**/
public ByteOptional()
{
_isSet = false;
}
/**
* Sets the value to the given argument.
*
* @param v The initial value.
**/
public ByteOptional(byte v)
{
_value = v;
_isSet = true;
}
/**
* Sets the value to a shallow copy of the given optional.
*
* @param opt The source value.
**/
public ByteOptional(ByteOptional opt)
{
_value = opt._value;
_isSet = opt._isSet;
}
/**
* Obtains the current value.
*
* @return The current value.
* @throws IllegalStateException If the value is not set.
**/
public byte get()
{
if(!_isSet)
{
throw new IllegalStateException("no value is set");
}
return _value;
}
/**
* Sets the value to the given argument.
*
* @param v The new value.
**/
public void set(byte v)
{
_value = v;
_isSet = true;
}
/**
* If the given argument is set, this optional is set to a shallow copy of the argument,
* otherwise this optional is unset.
*
* @param opt The source value.
**/
public void set(ByteOptional opt)
{
_value = opt._value;
_isSet = opt._isSet;
}
/**
* Determines whether the value is set.
*
* @return True if the value is set, false otherwise.
**/
public boolean isSet()
{
return _isSet;
}
/**
* Unsets this value.
**/
public void clear()
{
_isSet = false;
_value = 0;
}
private byte _value;
private boolean _isSet;
}
|