/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.struct.scalar;

import divconq.struct.ScalarStruct;

public class AnyStruct extends ScalarStruct {
	protected Object value = null;

	@Override
	public Object getGenericValue() {
		return this.value;
	}
	
	@Override
	public void adaptValue(Object v) {
		this.value = v;
	}

	public Object getValue() {
		return this.value; 
	}
	
	public void setValue(Object v) { 
		this.value = v; 
	}

	@Override
	public Object clone() {
		AnyStruct n = new AnyStruct();
		n.setValue(this.value);
		//n.setName(this.name);
		return n;
	}

	@Override
	public boolean equals(Object obj) {
		return (AnyStruct.comparison(this, obj) == 0);
	}

	@Override
	public int compare(Object y) {
		return AnyStruct.comparison(this, y);
	}
	
	@Override
	public boolean isEmpty() {
		return (this.value == null);
	}

	@Override
	public int hashCode() {
		return (this.value == null) ? 0 : this.value.hashCode();
	}
	
	@Override
	public String toString() {
		return (this.value == null) ? "null" : this.value.toString();
	}

	public static int comparison(Object x, Object y) {
		if ((y == null) && (x == null))
			return 0;

		if (y == null)
			return 1;

		if (x == null)
			return -1;

		return 0;
	}
}
