gt: 										(c=='C'&&(c2==' '||c2=='C'))||(c=='R'&&c2=='R')) {
context: package com.res.java.lib;
  /*****************************************************************************
  Copyright 2009 Venkat Krishnamurthy
  This file is part of RES.
  
  RES 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.
  
  RES 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 RES.  If not, see <http://www.gnu.org/licenses/>.
  
  @author VenkatK mailto: open.cobol.to.java at gmail.com
  ******************************************************************************/
  
  import java.math.BigDecimal;
  import java.math.RoundingMode;
  import java.text.DecimalFormat;
  import java.util.ArrayList;
  import java.util.regex.Pattern;
  
  import com.res.java.lib.exceptions.InvalidCobolFormatException;
  
  public class FieldFormat {
  
  	private String name=null;
  	private String picture=null;
  	
  	private DecimalFormat numberFormat=null;
  
  	private DecimalFormat getNumberFormat() {
  		return numberFormat;
  	}
  
  	private void setNumberFormat(DecimalFormat numberFormat) {
  		this.numberFormat = numberFormat;
  	}
  	
  	private char[] javaFormat=null;
  	
  	private char[] getJavaFormat() {
  		return javaFormat;
  	}
  
  	private void setJavaFormat(char[] javaFormat) {
  		this.javaFormat = javaFormat;
  	}
  	private FieldFormatData sym=new FieldFormatData();
  	
  	public boolean isSigned() {
  		return sym.isSigned;
  	}
  
  	public void setSigned(boolean isSigned) {
  		this.sym.isSigned = isSigned;
  	}
  
  	public boolean isFloating() {
  		return false;
  	}
  
  	public void setFloating(boolean isFloating) {
  		//this.sym.isFloating = isFloating;
  	}
  
  	public boolean isPointer() {
  		return false;
  	}
  
  	public void setPointer(boolean isPointer) {
  		//this.isPointer = isPointer;
  	}
  
  	//private boolean isPointer=false;
  
  	public boolean isBlankWhenZero() {
  		return sym.isBlankWhenZero;
  	}
  
  	public void setBlankWhenZero(boolean blankWhenZero) {
  		this.sym.isBlankWhenZero = blankWhenZero;
  	}
  
  	public boolean isJustifiedRight() {
  		return sym.isJustifiedRight;
  	}
  
  	public void setJustifiedRight(boolean justifiedRight) {
  		this.sym.isJustifiedRight = justifiedRight;
  	}
  
  	public boolean isSignSeperate() {
  		return sym.isSignSeparate;
  	}
  
  	public void setSignSeperate(boolean signSeperate) {
  		this.sym.isSignSeparate = signSeperate;
  	}
  
  	public boolean isSignTrailing() {
  		return !sym.isSignLeading;
  	}
  
  	public void setSignTrailing(boolean signTrailing) {
  		this.sym.isSignLeading = !signTrailing;
  	}
  
  	public String getName() {
  		return name;
  	}
  
  	public void setName(String name) {
  		this.name = name;
  	}
  
  	public String getPicture() {
  		return picture;
  	}
  
  	public void setPicture(String picture) {
  		this.picture = picture;
  	}
  	
  	public void setDataCategory(byte dataCategory) {
  		if(this.sym!=null)
  			this.sym.dataCategory = dataCategory;
  	}
  
  	public byte getDataCategory() {
  		if(this.sym!=null)
  			return this.sym.dataCategory;
  		else 
  			return -1;
  	}
  	public void setScaled(boolean isScaled) {
  		this.isScaled = isScaled;
  	}
  
  	public boolean isScaled() {
  		return isScaled;
  	}
  
  	private boolean isScaled=false;
  
  	public FieldFormat(String pictureVal) {
  		sym=new FieldFormatData();
  		sym.type=FieldFormat.verifyCobolPicture(pictureVal);
  		setDataCategory(dataCategoryTemp);
  		setPicture(pictureVal);
  		getJavaFormat(pictureVal);
  	}
  	
  	public FieldFormat(String nameVal, String pictureVal) {
  		sym=new FieldFormatData();
  		sym.type=FieldFormat.verifyCobolPicture(pictureVal);
  		setDataCategory(dataCategoryTemp);
  		setName(nameVal);setPicture(pictureVal);
  		getJavaFormat(pictureVal);
  	}
  	public FieldFormat(String nameVal, String pictureVal, boolean bwz) {
  		this(nameVal,pictureVal);
  		this.setBlankWhenZero(bwz);
  	}
  
  	public FieldFormat(String nameVal, String pictureVal, boolean bwz,boolean just, boolean signSep, boolean trail) {
  		sym=new FieldFormatData();
  		sym.type=FieldFormat.verifyCobolPicture(pictureVal);
  		sym.dataCategory=FieldFormat.dataCategoryTemp;
  		setName(nameVal);setPicture(pictureVal);
  		this.setBlankWhenZero(bwz);this.setJustifiedRight(just);
  		this.setSignSeperate(signSep);this.setSignTrailing(trail);
  		getJavaFormat(pictureVal);
  	}
  	
  	private String blankWhenZero(String num) {
  		//if(!this.sym.isSigned)
  			//return num;
  		String ret="";
  		if(num.matches("[0\\.\\+\\-\\$ ]*")) {
  			for(int i=0;i<getJavaFormat().length;++i)
  				ret+=' ';
  			return ret;
  		}
  		return num;
  	}
  	
  	private String suppressLeadingZeros(String num) {
  		String ret="";String ret2;int i;
  		if(num.trim().length()>0) {
  			if(num.length()==getJavaFormat().length) {//Is this check always true for correct format?
  				boolean isLeading=true;
  				char prev=' ';char c=' ';
  				//Blank out the leading zeros
  				for(i=0;i<num.length();++i) {
  					c=getJavaFormat()[i];
  					char c2=num.charAt(i);
  					if(((c=='Z'&&c2=='0')||(prev=='Z'&&c==','&&c2==','))&&isLeading) {
  						ret+=' ';
  						prev='Z';
  						continue;
  					}
  					else 
  						if(((c=='*'&&c2=='0')||(prev=='*'&&c==','&&c2==','))&&isLeading) {
  							ret+='*';
  							prev='*';
  							continue;
  						}
  						else if(c=='.') {
  							ret+=c2;
  							break;
  						}
  						else 
  							if(c=='$'||c=='S'||(c=='B'&&(c2==' '||c2=='B'))||(c=='D'&&(c2==' '||c2=='D'))||
  									(c=='C'&&(c2==' '||c2=='C'))||(c=='R'&&c2=='R')) {
  								ret+=c2;
  								continue;
  							}
  							else if(c=='.') break;
  					
  					isLeading=false;
  					ret+=c2;
  				}
  				ret2=ret;//save
  				ret="";
  				//Blank out trailing zeros
  				if(c=='.') {
  					boolean isTrailing=true;
  					for(i=num.length()-1;i>=0;--i) {
  						c=getJavaFormat()[i];
  						char c2=num.charAt(i);
  						if(((c=='Z'&&c2=='0')||(prev=='Z'&&c==','&&c2==','))&&isTrailing) {
  							ret=' '+ret;
  							prev='Z';
  							continue;
  						}
  						else 
  							if(((c=='*'&&c2=='0')||(prev=='*'&&c==','&&c2==','))&&isTrailing) {
  								ret='*'+ret;
  								prev='*';
  								continue;
  							}
  							else if(c=='.') {
  								break;
  							}
  							else 
  								if(c=='$'||c=='S'||(c=='B'&&(c2==' '||c2=='B'))||(c=='D'&&(c2==' '||c2=='D'))||
  