All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ksc.mission.base.codegen.Property Maven / Gradle / Ivy

package com.ksc.mission.base.codegen;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ksc.mission.base.interfaces.Initializable;
import com.ksc.mission.base.relatedobjects.OwnedObject;

public class Property extends OwnedObject
		implements Initializable, Map  {
	private static final long serialVersionUID = 1L;
	final protected List values = new ArrayList();
	
	protected List getValues() {
		return values;
	}
	
	@Override
	public Property initializeFromStrings(Iterator iterator) {
		while(iterator.hasNext())
			values.add(iterator.next());
		id = getName();
		return this;
}
	@Override
	public int size() {
		return getOwningCollection().header.size();
	}
	@Override
	public boolean isEmpty() {
		return values.isEmpty();
	}
	@Override
	public boolean containsKey(Object key) {
		return getOwningCollection().header.contains(key);
	}
	@Override
	public boolean containsValue(Object value) {
		return values.contains(value);
	}
	@Override
	public String get(Object key) {
		int index = getOwningCollection().indexOf(key);
		if(index == -1)			
			return null;
		else
			return values.get(index);
	}
	
	public String getName() {
		return get("Name");
	}
	
	public String getProperName() {
		String str = getName();
		if(str.isEmpty())
			return str;
		else
			return str.substring(0,0).toUpperCase() + str.substring(1);
	}
	
	
	public String getUpperCase(Object key) {
		return get(key).toUpperCase();
	}

	@Override
	public String put(String key, String value) {
		throw new UnsupportedOperationException("Read Only");
	}
	@Override
	public String remove(Object key) {
		throw new UnsupportedOperationException("Read Only");
	}
	@SuppressWarnings("rawtypes")
	@Override
	public void putAll(Map m) {
		throw new UnsupportedOperationException("Read Only");
	}
	@Override
	public void clear() {
		throw new UnsupportedOperationException("Read Only");
	}

	@Override
	public Set keySet() {
		return getOwningCollection().keySet();
	}
	@Override
	public Collection values() {
		return new ArrayList(values);
	}
	@SuppressWarnings("unlikely-arg-type")
	@Override
	public Set> entrySet() {
		Map map = new HashMap();
		List header = getOwningCollection().getHeader();
		for(String key : header)
			map.put(key,values.get(getOwningCollection().indexOf(key)));
		return map.entrySet();
	}

	public PropertyList getOwningCollection() {
		return (PropertyList) super.getOwningCollection();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy