package siprp.medicina.processo.ui; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; import java.util.Vector; public class OrderedMap { private static final long serialVersionUID = 1L; private Vector order = new Vector(); private HashMap> map = new HashMap>(); public OrderedMap() { } public List getValuesAt( int row ) { return map.get( order.get( row ) ); } public List getValues( KeyClass key ) { return map.get( key ); } public int rows() { return order.size(); } public KeyClass getKeyForValue( Object value ) { for( KeyClass key : map.keySet() ) { List values = map.get( key ); if( value.equals( values )) { return key; }else { for(Object currentValue : values) { if(currentValue.equals(value)) { return key; } } } } return null; } /** * returns the length of the biggest column * * @return */ public int columns() { int result = 0; for( KeyClass key : order ) { result = map.get( key ).size() > result ? map.get( key ).size() : result; } return result; } public KeyClass getFirst() { return order.isEmpty() ? null : order.get( 0 ); } public Set keySet() { return map.keySet(); } public boolean containsKey( KeyClass key ) { return map.containsKey( key ); } public Object getValueAt( int column, int row ) { return this.getValuesAt( row ).get( column ); } public void putLast( KeyClass key, Object value ) { List list; if( map.containsKey( key ) ) { list = map.get( key ); } else { list = new ArrayList(); order.add( key ); } list.add( value ); map.put( key, list ); } public List remove( Object key ) { order.remove( key ); return map.remove( key ); } }