From 87dd7c34c576bb7817f7a2fbf502fc331f407901 Mon Sep 17 00:00:00 2001 From: bdew Date: Tue, 12 Aug 2014 12:41:10 +0300 Subject: [PATCH] Added DataSlotOption --- src/net/bdew/lib/data/DataSlotOption.scala | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/net/bdew/lib/data/DataSlotOption.scala diff --git a/src/net/bdew/lib/data/DataSlotOption.scala b/src/net/bdew/lib/data/DataSlotOption.scala new file mode 100644 index 0000000..74394be --- /dev/null +++ b/src/net/bdew/lib/data/DataSlotOption.scala @@ -0,0 +1,46 @@ +/* + * Copyright (c) bdew, 2013 - 2014 + * https://github.com/bdew/bdlib + * + * This mod is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt + */ + +package net.bdew.lib.data + +import net.bdew.lib.data.base.DataSlotVal + +abstract class DataSlotOption[T] extends DataSlotVal[Option[T]] { + override var cval: Option[T] = None + + def set(v: T) { + if (v == null) sys.error("Null should never be used with DataSlotOption") + cval = Some(v) + } + + def unset() { + cval = None + } + + override def isSame(v: Option[T]) = { + if (v == null) sys.error("Null should never be used with DataSlotOption") + super.isSame(v) + } + override def :=(that: Option[T]) = { + if (that == null) sys.error("Null should never be used with DataSlotOption") + super.:=(that) + } + override def :!=(that: Option[T]) = { + if (that == null) sys.error("Null should never be used with DataSlotOption") + super.:!=(that) + } + override def :==(that: Option[T]) = { + if (that == null) sys.error("Null should never be used with DataSlotOption") + super.:==(that) + } + override def update(v: Option[T]) = { + if (v == null) sys.error("Null should never be used with DataSlotOption") + super.update(v) + } +}