summaryrefslogtreecommitdiff
path: root/java/src/Ice/LongOptional.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/Ice/LongOptional.java')
-rw-r--r--java/src/Ice/LongOptional.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/java/src/Ice/LongOptional.java b/java/src/Ice/LongOptional.java
new file mode 100644
index 00000000000..a40c362736f
--- /dev/null
+++ b/java/src/Ice/LongOptional.java
@@ -0,0 +1,106 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2012 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 long parameter.
+ **/
+public class LongOptional
+{
+ /**
+ * The value defaults to unset.
+ **/
+ public LongOptional()
+ {
+ _isSet = false;
+ }
+
+ /**
+ * Sets the value to the given argument.
+ *
+ * @param v The initial value.
+ **/
+ public LongOptional(long v)
+ {
+ _value = v;
+ _isSet = true;
+ }
+
+ /**
+ * Sets the value to a shallow copy of the given optional.
+ *
+ * @param opt The source value.
+ **/
+ public LongOptional(LongOptional opt)
+ {
+ _value = opt._value;
+ _isSet = opt._isSet;
+ }
+
+ /**
+ * Obtains the current value.
+ *
+ * @return The current value.
+ * @throws IllegalStateException If the value is not set.
+ **/
+ public long 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(long 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(LongOptional 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 long _value;
+ private boolean _isSet;
+}