gt: 			double av = ((ScalarElement)a).doubleValue();
context: /*
   * This file is part of the Raster Storage Archive (RSA).
   *
   * The RSA is free software: you can redistribute it and/or modify it under the
   * terms of the GNU General Public License as published by the Free Software
   * Foundation, either version 3 of the License, or (at your option) any later
   * version.
   *
   * The RSA is distributed in the hope that it will be useful, but WITHOUT ANY
   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License along with
   * the RSA.  If not, see <http://www.gnu.org/licenses/>.
   *
   * Copyright 2013 CRCSI - Cooperative Research Centre for Spatial Information
   * http://www.crcsi.com.au/
   */
  
  // THIS IS GENERATED CODE. Do not modify this file. See ElementX_gen.py.
  
  package org.vpac.ndg.query.math;
  
  /**
   * A pixel that stores a double value.
   *
   * <p><img src="doc-files/Element_class.png" /></p>
   *
   * @author Alex Fraser
   */
  public class ElementDouble implements ScalarElement {
  	private double value;
  	private boolean valid;
  
  	/* Components array makes this scalar element look like a vector. */
  	private ElementDouble[] components;
  
  	/**
  	 * Create a new ElementDouble, initalised to zero.
  	 */
  	public ElementDouble() {
  		this((double)0);
  	}
  	/**
  	 * Create a new ElementDouble.
  	 * @param value The initial value for the element.
  	 */
  	public ElementDouble(double value) {
  		this.value = value;
  		this.valid = true;
  		components = new ElementDouble[] { this };
  	}
  	@Override
  	public ElementDouble copy() {
  		ElementDouble res = new ElementDouble(value);
  		res.valid = valid;
  		return res;
  	}
  	@Override
  	public ElementDouble[] getComponents() {
  		return components;
  	}
  	@Override
  	public int size() {
  		return components.length;
  	}
  
  	@Override
  	public boolean isValid() {
  		return valid;
  	}
  	@Override
  	public void setValid(boolean valid) {
  		this.valid = valid;
  	}
  	@Override
  	public void setValid(Element<?> mask) {
  		this.valid = mask.isValid();
  	}
  	@Override
  	public void setValidIfValid(Element<?> mask) {
  		if (mask.isValid())
  			this.valid = true;
  	}
  
  	@Override
  	public Double getValue() {
  		return value;
  	}
  
  	// CASTING
  
  	@Override
  	public ElementDouble set(Element<?> value) {
  		this.value = ((ScalarElement)value).doubleValue();
  		this.valid = value.isValid();
  		return this;
  	}
  	@Override
  	public ElementDouble set(Number value) {
  		this.value = value.doubleValue();
  		this.valid = true;
  		return this;
  	}
  
  	@Override
  	public ElementDouble minimise() {
  		this.value = Double.NEGATIVE_INFINITY;
  		return this;
  	}
  	@Override
  	public ElementDouble maximise() {
  		this.value = Double.POSITIVE_INFINITY;
  		return this;
  	}
  
  	@Override
  	public byte byteValue() {
  		return (byte)value;
  	}
  	@Override
  	public ElementDouble set(byte value) {
  		this.value = (double)value;
  		this.valid = true;
  		return this;
  	}
  	@Override
  	public ElementByte asByte() {
  		ElementByte res = new ElementByte(this.byteValue());
  		res.setValid(valid);
  		return res;
  	}
  
  	@Override
  	public short shortValue() {
  		return (short)value;
  	}
  	@Override
  	public ElementDouble set(short value) {
  		this.value = (double)value;
  		this.valid = true;
  		return this;
  	}
  	@Override
  	public ElementShort asShort() {
  		ElementShort res = new ElementShort(this.shortValue());
  		res.setValid(valid);
  		return res;
  	}
  
  	@Override
  	public int intValue() {
  		return (int)value;
  	}
  	@Override
  	public ElementDouble set(int value) {
  		this.value = (double)value;
  		this.valid = true;
  		return this;
  	}
  	@Override
  	public ElementInt asInt() {
  		ElementInt res = new ElementInt(this.intValue());
  		res.setValid(valid);
  		return res;
  	}
  
  	@Override
  	public long longValue() {
  		return (long)value;
  	}
  	@Override
  	public ElementDouble set(long value) {
  		this.value = (double)value;
  		this.valid = true;
  		return this;
  	}
  	@Override
  	public ElementLong asLong() {
  		ElementLong res = new ElementLong(this.longValue());
  		res.setValid(valid);
  		return res;
  	}
  
  	@Override
  	public float floatValue() {
  		return (float)value;
  	}
  	@Override
  	public ElementDouble set(float value) {
  		this.value = (double)value;
  		this.valid = true;
  		return this;
  	}
  	@Override
  	public ElementFloat asFloat() {
  		ElementFloat res = new ElementFloat(this.floatValue());
  		res.setValid(valid);
  		return res;
  	}
  
  	@Override
  	public double doubleValue() {
  		return value;
  	}
  	@Override
  	public ElementDouble set(double value) {
  		this.value = value;
  		this.valid = true;
  		return this;
  	}
  	@Override
  	public ElementDouble asDouble() {
  		ElementDouble res = new ElementDouble(this.doubleValue());
  		res.setValid(valid);
  		return res;
  	}
  
  	// ARITHMETIC
  
  	@Override
  	public ElementDouble add(long other) {
  		try {
  			value = (double)(value + (double)other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble add(double other) {
  		try {
  			value = (double)(value + other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @throws ClassCastException if other is a vector.
  	 */
  	@Override
  	public ElementDouble add(Element<?> other) {
  		if (!other.isValid()) {
  			this.setValid(false);
  			return this;
  		}
  		try {
  			value = (double)(value + ((ScalarElement)other).doubleValue());
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  
  	@Override
  	public ElementDouble addIfValid(long other, Element<?> mask) {
  		if (!mask.isValid())
  			return this;
  		try {
  			value = (double)(value + (double)other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @throws ClassCastException if mask is a vector.
  	 */
  	@Override
  	public ElementDouble addIfValid(double other, Element<?> mask) {
  		if (!mask.isValid())
  			return this;
  		try {
  			value = (double)(value + other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble addIfValid(Element<?> other) {
  		if (!other.isValid())
  			return this;
  		try {
  			value = (double)(value + ((ScalarElement)other).doubleValue());
  		} catch (ArithmeticException e) {
  			// do nothing.
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble addIfValid(Element<?> other, Element<?> mask) {
  		if (!other.isValid() || !mask.isValid())
  			return this;
  		try {
  			value = (double)(value + ((ScalarElement)other).doubleValue());
  		} catch (ArithmeticException e) {
  			// do nothing.
  		}
  		return this;
  	}
  
  	@Override
  	public ElementDouble addNew(long other) {
  		ElementDouble res = copy();
  		return res.add(other);
  	}
  	@Override
  	public ElementDouble addNew(double other) {
  		ElementDouble res = copy();
  		return res.add(other);
  	}
  	@Override
  	public ElementDouble addNew(Element<?> other) {
  		ElementDouble res = copy();
  		return res.add(other);
  	}
  
  	@Override
  	public ElementDouble addNewIfValid(long other, Element<?> mask) {
  		ElementDouble res = copy();
  		return res.addIfValid(other, mask);
  	}
  	@Override
  	public ElementDouble addNewIfValid(double other, Element<?> mask) {
  		ElementDouble res = copy();
  		return res.addIfValid(other, mask);
  	}
  	@Override
  	public ElementDouble addNewIfValid(Element<?> other) {
  		ElementDouble res = copy();
  		return res.addIfValid(other);
  	}
  	@Override
  	public ElementDouble addNewIfValid(Element<?> other, Element<?> mask) {
  		ElementDouble res = copy();
  		return res.addIfValid(other, mask);
  	}
  
  	@Override
  	public ElementDouble addOf(long a, long b) {
  		try {
  			value = (double)(a + b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble addOf(double a, long b) {
  		try {
  			value = (double)(a + (double)b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble addOf(long a, double b) {
  		try {
  			value = (double)((double)a + b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble addOf(double a, double b) {
  		try {
  			value = (double)((double)a + b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param a This will be converted to double before the operation.
  	 * @throws ClassCastException if a is a vector.
  	 */
  	@Override
  	public ElementDouble addOf(Element<?> a, long b) {
  		try {
  			double av = ((ScalarElement)a).doubleValue();
  			value = (double)(av + b);
  			valid = a.isValid();
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param b This will be converted to double before the operation.
  	 * @throws ClassCastException if b is a vector.
  	 */
  	@Override
  	public ElementDouble addOf(long a, Element<?> b) {
  		try {
  			double bv = ((ScalarElement)b).doubleValue();
  			value = (double)(a + bv);
  			valid = b.isValid();
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param a This will be converted to double before the operation.
  	 * @throws ClassCastException if a is a vector.
  	 */
  	@Override
  	public ElementDouble addOf(Element<?> a, double b) {
  		try {
  			double av = ((ScalarElement)a).doubleValue();
  			value = (double)(av + b);
  			valid = a.isValid();
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param b This will be converted to double before the operation.
  	 * @throws ClassCastException if b is a vector.
  	 */
  	@Override
  	public ElementDouble addOf(double a, Element<?> b) {
  		try {
  			double bv = ((ScalarElement)b).doubleValue();
  			value = (double)(a + bv);
  			valid = b.isValid();
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param a This will be converted to double before the operation.
  	 * @param b This will be converted to double before the operation.
  	 * @throws ClassCastException if a or b are vectors.
  	 */
  	@Override
  	public ElementDouble addOf(Element<?> a, Element<?> b) {
  		try {
  			double av = ((ScalarElement)a).doubleValue();
  			double bv = ((ScalarElement)b).doubleValue();
  			value = (double)(av + bv);
  			valid = b.isValid() && a.isValid();
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  
  	@Override
  	public ElementDouble addOfIfValid(long a, long b, Element<?> mask) {
  		if (mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(double a, long b, Element<?> mask) {
  		if (mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(long a, double b, Element<?> mask) {
  		if (mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(double a, double b, Element<?> mask) {
  		if (mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(Element<?> a, long b) {
  		if (a.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(Element<?> a, long b, Element<?> mask) {
  		if (a.isValid() && mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(long a, Element<?> b) {
  		if (b.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(long a, Element<?> b, Element<?> mask) {
  		if (b.isValid() && mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(Element<?> a, double b) {
  		if (a.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(Element<?> a, double b, Element<?> mask) {
  		if (a.isValid() && mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(double a, Element<?> b) {
  		if (b.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(double a, Element<?> b, Element<?> mask) {
  		if (b.isValid() && mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(Element<?> a, Element<?> b) {
  		if (a.isValid() && b.isValid())
  			addOf(a, b);
  		return this;
  	}
  	@Override
  	public ElementDouble addOfIfValid(Element<?> a, Element<?> b, Element<?> mask) {
  		if (a.isValid() && b.isValid() && mask.isValid())
  			addOf(a, b);
  		return this;
  	}
  
  	@Override
  	public ElementDouble sub(long other) {
  		try {
  			value = (double)(value - (double)other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble sub(double other) {
  		try {
  			value = (double)(value - other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @throws ClassCastException if other is a vector.
  	 */
  	@Override
  	public ElementDouble sub(Element<?> other) {
  		if (!other.isValid()) {
  			this.setValid(false);
  			return this;
  		}
  		try {
  			value = (double)(value - ((ScalarElement)other).doubleValue());
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  
  	@Override
  	public ElementDouble subIfValid(long other, Element<?> mask) {
  		if (!mask.isValid())
  			return this;
  		try {
  			value = (double)(value - (double)other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @throws ClassCastException if mask is a vector.
  	 */
  	@Override
  	public ElementDouble subIfValid(double other, Element<?> mask) {
  		if (!mask.isValid())
  			return this;
  		try {
  			value = (double)(value - other);
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble subIfValid(Element<?> other) {
  		if (!other.isValid())
  			return this;
  		try {
  			value = (double)(value - ((ScalarElement)other).doubleValue());
  		} catch (ArithmeticException e) {
  			// do nothing.
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble subIfValid(Element<?> other, Element<?> mask) {
  		if (!other.isValid() || !mask.isValid())
  			return this;
  		try {
  			value = (double)(value - ((ScalarElement)other).doubleValue());
  		} catch (ArithmeticException e) {
  			// do nothing.
  		}
  		return this;
  	}
  
  	@Override
  	public ElementDouble subNew(long other) {
  		ElementDouble res = copy();
  		return res.sub(other);
  	}
  	@Override
  	public ElementDouble subNew(double other) {
  		ElementDouble res = copy();
  		return res.sub(other);
  	}
  	@Override
  	public ElementDouble subNew(Element<?> other) {
  		ElementDouble res = copy();
  		return res.sub(other);
  	}
  
  	@Override
  	public ElementDouble subNewIfValid(long other, Element<?> mask) {
  		ElementDouble res = copy();
  		return res.subIfValid(other, mask);
  	}
  	@Override
  	public ElementDouble subNewIfValid(double other, Element<?> mask) {
  		ElementDouble res = copy();
  		return res.subIfValid(other, mask);
  	}
  	@Override
  	public ElementDouble subNewIfValid(Element<?> other) {
  		ElementDouble res = copy();
  		return res.subIfValid(other);
  	}
  	@Override
  	public ElementDouble subNewIfValid(Element<?> other, Element<?> mask) {
  		ElementDouble res = copy();
  		return res.subIfValid(other, mask);
  	}
  
  	@Override
  	public ElementDouble subOf(long a, long b) {
  		try {
  			value = (double)(a - b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble subOf(double a, long b) {
  		try {
  			value = (double)(a - (double)b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble subOf(long a, double b) {
  		try {
  			value = (double)((double)a - b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	@Override
  	public ElementDouble subOf(double a, double b) {
  		try {
  			value = (double)((double)a - b);
  			valid = true;
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param a This will be converted to double before the operation.
  	 * @throws ClassCastException if a is a vector.
  	 */
  	@Override
  	public ElementDouble subOf(Element<?> a, long b) {
  		try {
  			double av = ((ScalarElement)a).doubleValue();
  			value = (double)(av - b);
  			valid = a.isValid();
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param b This will be converted to double before the operation.
  	 * @throws ClassCastException if b is a vector.
  	 */
  	@Override
  	public ElementDouble subOf(long a, Element<?> b) {
  		try {
  			double bv = ((ScalarElement)b).doubleValue();
  			value = (double)(a - bv);
  			valid = b.isValid();
  		} catch (ArithmeticException e) {
  			this.setValid(false);
  		}
  		return this;
  	}
  	/**
  	 * @param a This will be converted to double before the operation.
  	 * @throws ClassCastException if a is a vector.
  	 */
  	@Override
  	public ElementDouble subOf(Element<?> a, double b) {
  		try {
  