<commit_before>/*
 *   This file is part of OpenERPJavaAPI.
 *
 *   OpenERPJavaAPI is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   OpenERPJavaAPI 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 Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with OpenERPJavaAPI.  If not, see <http://www.gnu.org/licenses/>.
 *
 *   Copyright 2011 De Bortoli Wines Pty Limited (Australia)
 */

package com.debortoliwines.openerp.api;

import java.util.ArrayList;
import java.util.HashMap;

/***
 * Provides OpenERP field properties like data types, selection fields etc.
 * @author <NAME>
 *
 */
public class Field {
	
	/**
	 * OpenERP field types.
	 * @author <NAME>
	 *
	 */
	public enum FieldType {
		INTEGER, CHAR, TEXT, BOOLEAN, FLOAT, DATETIME, DATE, MANY2ONE, ONE2MANY, MANY2MANY, SELECTION 
	}
	
	private final String name;
	private final HashMap<String, Object> openERPFieldData;
	
	public Field(String fieldName, HashMap<String, Object> openERPFieldData){
		this.openERPFieldData = openERPFieldData;
		this.name = fieldName;
	}

	/***
	 * Any property not covered by a get function can be fetched using this function
	 * @param propertyName Name of property to fetch, for example 'name'.
	 * @return The value associated with the property if any.
	 */
	public Object getFieldProperty(String propertyName){
		Object value = null;
		
		if (openERPFieldData.containsKey(propertyName))
			value = openERPFieldData.get(propertyName);
		
		return value;
	}

	/**
	 * Get the field name 
	 * @return
	 */
	public String getName() {
		return name;
	}

	/***
	 * Get the field description or label
	 * @return
	 */
	public String getDescription() {
		return (String) getFieldProperty("string");
	}<commit_msg>Added a new function to return state override properties<commit_after>/*
 *   This file is part of OpenERPJavaAPI.
 *
 *   OpenERPJavaAPI is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   OpenERPJavaAPI 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 Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with OpenERPJavaAPI.  If not, see <http://www.gnu.org/licenses/>.
 *
 *   Copyright 2011 De Bortoli Wines Pty Limited (Australia)
 */

package com.debortoliwines.openerp.api;

import java.util.ArrayList;
import java.util.HashMap;

/***
 * Provides OpenERP field properties like data types, selection fields etc.
 * @author <NAME>
 *
 */
public class Field {
	
	/**
	 * OpenERP field types.
	 * @author <NAME>
	 *
	 */
	public enum FieldType {
		INTEGER, CHAR, TEXT, BOOLEAN, FLOAT, DATETIME, DATE, MANY2ONE, ONE2MANY, MANY2MANY, SELECTION 
	}
	
	private final String name;
	private final HashMap<String, Object> openERPFieldData;
	
	public Field(String fieldName, HashMap<String, Object> openERPFieldData){
		this.openERPFieldData = openERPFieldData;
		this.name = fieldName;
	}

	/***
	 * Any property not covered by a get function can be fetched using this function
	 * @param propertyName Name of property to fetch, for example 'name'.
	 * @return The value associated with the property if any.
	 */
	public Object getFieldProperty(String propertyName){
		Object value = null;
		
		if (openERPFieldData.containsKey(propertyName))
			value = openERPFieldData.get(propertyName);
		
		return value;
	}
	
	/**
	 * Gets field property values for every object state 
	 * @return An array of values for all states in the format [state, propvalue]
	 */
	public Object [][] getStateProperties(String propertyName){
		ArrayList<Object[]> stateValues = new ArrayList<Object[]>();
		
		@SuppressWarnings("unchecked")
		HashMap<String, Object> states = (HashMap<String, Object>) getFieldProperty("states");
		
		if (states != null){
			Object[] stateValue = new Object[2];
			for (Object stateKey : states.keySet()){
				stateValue[0] = stateKey.toString();
				
				for (Object stateProperty : (Object[]) states.get(stateKey)){
					Object[] statePropertyArr = (Object[]) stateProperty;
					if (statePropertyArr[0].toString().equals(propertyName)){
						stateValue[1] = statePropertyArr[1];
						stateValues.add(stateValue);
					}
				}
			}
		}
		
		return stateValues.toArray(new Object[0][]);
	}

	/**
	 * Get the field name 
	 * @return
	 */
	public String getName() {
		return name;
	}

	/***
	 * Get the field description or label
	 * @return
	 */
	public String getDescription() {
		return (String) getFieldProperty("string");
	}
{'fraction_non_alphanumeric': 0.09449875407322215, 'fraction_numerical': 0.004216982940387195, 'mean_word_length': 3.6714413607878247, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5003065', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1500, 'n_words': 558}