forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
1.9 KiB
116 lines
1.9 KiB
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<KeyClass extends Object>
|
|
{
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private Vector<KeyClass> order = new Vector<KeyClass>();
|
|
|
|
private HashMap<KeyClass, List<Object>> map = new HashMap<KeyClass, List<Object>>();
|
|
|
|
public OrderedMap()
|
|
{
|
|
}
|
|
|
|
public List<Object> getValuesAt( int row )
|
|
{
|
|
return map.get( order.get( row ) );
|
|
}
|
|
|
|
public List<Object> getValues( KeyClass key )
|
|
{
|
|
return map.get( key );
|
|
}
|
|
|
|
public int rows()
|
|
{
|
|
return order.size();
|
|
}
|
|
|
|
public KeyClass getKeyForValue( Object value )
|
|
{
|
|
for( KeyClass key : map.keySet() )
|
|
{
|
|
List<Object> 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<KeyClass> 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<Object> list;
|
|
if( map.containsKey( key ) )
|
|
{
|
|
list = map.get( key );
|
|
}
|
|
else
|
|
{
|
|
list = new ArrayList<Object>();
|
|
order.add( key );
|
|
}
|
|
list.add( value );
|
|
map.put( key, list );
|
|
}
|
|
|
|
public List<Object> remove( Object key )
|
|
{
|
|
order.remove( key );
|
|
return map.remove( key );
|
|
}
|
|
|
|
}
|