/**
 *  Copyright (c) 2012, 2016 Sme.UP and others.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *
 * Contributors:
 *   Mattia Rocchi - Initial API and implementation
 */
package org.smeup.sys.il.data.nio;

import org.smeup.sys.il.data.DataSpecial;
import org.smeup.sys.il.data.IntegratedLanguageDataRuntimeException;
import org.smeup.sys.il.data.QDataContext;
import org.smeup.sys.il.data.QDataVisitor;
import org.smeup.sys.il.data.QDecimal;
import org.smeup.sys.il.data.QNumeric;

public abstract class NIODecimalImpl extends NIONumericImpl implements QDecimal {

	private static final long serialVersionUID = 1L;

	private NIODecimalDef decimalDef = null;

	public NIODecimalImpl(QDataContext dataContext, int precision, int scale) {
		super(dataContext);
		
		decimalDef = NIODecimalDef.getInstance(precision, scale);
	}

	protected NIODecimalDef getDecimalDef() {
		return decimalDef;
	}

	@Override
	public final int getLength() {
		return getPrecision();
	}

	@Override
	public final boolean isSigned() {
		return true;
	}

	@Override
	protected final byte[] _toBytes(DataSpecial value) {

		byte[] bytes = null;
		switch (value) {
		case ZERO:
		case ZEROS:
			bytes = getDecimalDef().getZonedInit();
			break;		
		case LOVAL:
			bytes = getDecimalDef().getZonedLoval();
			break;
		case HIVAL:
			bytes = getDecimalDef().getZonedHival();
			break;
		case ON:
		case OFF:
		case BLANK:
		case BLANKS:			
		case NULL:
		case OMIT:
			throw new IntegratedLanguageDataRuntimeException("Unexpected condition 237rvbwe87vb9stf");
		}

		return bytes;
	}
	
	@Override
	public final void accept(QDataVisitor visitor) {
		visitor.visit(this);
	}
	
	@Override
	public final QNumeric qUns() {

		NIONumericImpl number = new NIODecimalPackedImpl(getDataContext(), getPrecision(), getScale(), true);
		if (asShort() > 0)
			number.eval(this);
		else
			number.eval(this.asDouble() * -1);

		return number;
	}
}
@@ -1567,18 +1567,21 @@
 %0A%09%09case 
-ON
+BLANK
 :%0A%09%09case
@@ -1585,20 +1585,79 @@
 ase 
-OFF:
+BLANKS:%09%09%09%0A%09%09%09bytes = getDecimalDef().getZonedInit();%0A%09%09%09break;
 %0A%09%09case 
 BLAN
@@ -1644,37 +1644,34 @@
 %09%09break;%0A%09%09case 
-BLANK
+ON
 :%0A%09%09case BLANKS:
@@ -1663,26 +1663,20 @@
 %0A%09%09case 
-BLANKS:%09%09%09
+OFF:
 %0A%09%09case 

Patch per BLANK su campi numerici