<commit_before>/*
*
* Copyright 2008,2009 Newcastle University
*
* This file is part of Workcraft.
*
* Workcraft 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.
*
* Workcraft 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 Workcraft.  If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.workcraft.gui.propertyeditor;

import java.util.HashMap;
import java.util.Map;

public class PropertyDeclaration implements PropertyDescriptor {
	public String name;
	public String getter;
	public String setter;

	public Class<?> cls;
	public Map<String, Object> predefinedValues;
	public Map<Object, String> valueNames;

	private boolean choice;

	public boolean isChoice() {
		return choice;
	}

	public PropertyDeclaration (String name, String getter, String setter, Class<?> cls ) {
		this.name = name;
		this.getter = getter;
		this.setter = setter;
		this.cls = cls;
		this.predefinedValues = null;
		this.valueNames = null;

		choice = false;
	}

	public PropertyDeclaration (String name, String getter, String setter, Class<?> cls, Map<String, Object> predefinedValues) {
		this.name = name;
		this.getter = getter;
		this.setter = setter;
		this.cls = cls;
		this.predefinedValues = predefinedValues;

		valueNames = new HashMap<Object, String>();

		for (String k : predefinedValues.keySet()) {
			valueNames.put(predefinedValues.get(k), k);
		}

		choice = true;
	}

	public Map<Object, String> getChoice() {
		return valueNames;
	}

	public Object getValue(Object owner) {
		try {
			return owner.getClass().getMethod(getter).invoke(owner);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public void setValue(Object owner, Object value) {
		try {
			owner.getClass().getMethod(setter, cls).invoke(owner, value);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public String getName() {
		return name;
	}

	public Class<?> getType() {
		return cls;
	}

	public boolean isWritable() {
		return setter != null;
	}
}<commit_msg>Changed predefined values parameter type to LinkedHashMap to preserve user-specified choice order<commit_after>/*
*
* Copyright 2008,2009 Newcastle University
*
* This file is part of Workcraft.
*
* Workcraft 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.
*
* Workcraft 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 Workcraft.  If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.workcraft.gui.propertyeditor;

import java.util.LinkedHashMap;
import java.util.Map;

public class PropertyDeclaration implements PropertyDescriptor {
	public String name;
	public String getter;
	public String setter;

	public Class<?> cls;
	public Map<String, Object> predefinedValues;
	public Map<Object, String> valueNames;

	private boolean choice;

	public boolean isChoice() {
		return choice;
	}

	public PropertyDeclaration (String name, String getter, String setter, Class<?> cls ) {
		this.name = name;
		this.getter = getter;
		this.setter = setter;
		this.cls = cls;
		this.predefinedValues = null;
		this.valueNames = null;

		choice = false;
	}

	public PropertyDeclaration (String name, String getter, String setter, Class<?> cls, LinkedHashMap<String, Object> predefinedValues) {
		this.name = name;
		this.getter = getter;
		this.setter = setter;
		this.cls = cls;
		this.predefinedValues = predefinedValues;

		valueNames = new LinkedHashMap<Object, String>();

		for (String k : predefinedValues.keySet()) {
			valueNames.put(predefinedValues.get(k), k);
		}

		choice = true;
	}

	public Map<Object, String> getChoice() {
		return valueNames;
	}

	public Object getValue(Object owner) {
		try {
			return owner.getClass().getMethod(getter).invoke(owner);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public void setValue(Object owner, Object value) {
		try {
			owner.getClass().getMethod(setter, cls).invoke(owner, value);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public String getName() {
		return name;
	}

	public Class<?> getType() {
		return cls;
	}

	public boolean isWritable() {
		return setter != null;
	}
}
{'fraction_non_alphanumeric': 0.09874798061389338, 'fraction_numerical': 0.0036348949919224557, 'mean_word_length': 4.122026887280248, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6886182', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1473, 'n_words': 523}