org.mentawai.list
Class BaseListData

java.lang.Object
  extended by org.mentawai.list.BaseListData
All Implemented Interfaces:
ListData

public class BaseListData
extends Object
implements ListData

A base implementation for a ListData that will load files and sort. The files should be i18n files inside a given directory (or the default). Sorting is supported and can be by id, by value or by the order they appear in the file.

Author:
Sergio Oliveira

Field Summary
static int ORDER_BY_FILE
          Sort the list according to the order they appear inside the filename (don't sort)
static int ORDER_BY_ID
          Sort the list according to the id (key) values, which can be integers
static int ORDER_BY_STRING_ID
          Sort the list according to the id (key) values, which can be strings
static int ORDER_BY_VALUE
          Sort the list according to item values, which are strings
 
Constructor Summary
BaseListData(String listname)
          Creates a new BaseListData, looking for files inside the default directory "/lists", and using the default sort order ORDER_BY_VALUE.
BaseListData(String listname, int ordertype)
          Creates a new BaseListData, looking for files inside the default directory "/lists".
BaseListData(String listname, int ordertype, String listDir)
          Creates a new BaseListData
 
Method Summary
 String getName()
          The name of this list, for example "genders"
 String getValue(int id)
          Returns the string value of the list data item with the given id with the default locale.
 String getValue(int id, Locale loc)
          Returns the string value of the list data item with the given id in the given locale.
 String getValue(String id)
          Returns the string value for the list data item with the default locale.
 String getValue(String id, Locale loc)
          Given an id and a locale return the list item value.
 List<ListItem> getValues()
          Returns a list of ListItem for the default locale.
 List<ListItem> getValues(Locale loc)
          Return a list of ListItem objects so you can print the whole list for this locale.
 int size()
          The size of the list, for example a "genders" list should have 2 items.
protected  void sort(List<ListItem> list, int ordertype)
          Sort the list acording to the order type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORDER_BY_ID

public static final int ORDER_BY_ID
Sort the list according to the id (key) values, which can be integers

See Also:
Constant Field Values

ORDER_BY_STRING_ID

public static final int ORDER_BY_STRING_ID
Sort the list according to the id (key) values, which can be strings

See Also:
Constant Field Values

ORDER_BY_VALUE

public static final int ORDER_BY_VALUE
Sort the list according to item values, which are strings

See Also:
Constant Field Values

ORDER_BY_FILE

public static final int ORDER_BY_FILE
Sort the list according to the order they appear inside the filename (don't sort)

See Also:
Constant Field Values
Constructor Detail

BaseListData

public BaseListData(String listname,
                    int ordertype,
                    String listDir)
             throws IOException
Creates a new BaseListData

Parameters:
listname - The name of the list
ordertype - How this list should be sorted
listDir - The directory where to look for list files.
Throws:
IOException

BaseListData

public BaseListData(String listname,
                    int ordertype)
             throws IOException
Creates a new BaseListData, looking for files inside the default directory "/lists".

Parameters:
listname - The name of the list
ordertype - How this list should be sorted.
Throws:
IOException

BaseListData

public BaseListData(String listname)
             throws IOException
Creates a new BaseListData, looking for files inside the default directory "/lists", and using the default sort order ORDER_BY_VALUE.

Parameters:
listname - The name of the list
Throws:
IOException
Method Detail

getName

public String getName()
The name of this list, for example "genders"

Specified by:
getName in interface ListData
Returns:
The name of the list.

size

public int size()
The size of the list, for example a "genders" list should have 2 items.

Specified by:
size in interface ListData
Returns:
The size of the list

getValues

public List<ListItem> getValues(Locale loc)
Return a list of ListItem objects so you can print the whole list for this locale.

Specified by:
getValues in interface ListData
Parameters:
loc - The locale of the list
Returns:
a list of ListItem objects

getValues

public List<ListItem> getValues()
Description copied from interface: ListData
Returns a list of ListItem for the default locale. If there is no list for the default locale, then try any locale in order to return a list.

Specified by:
getValues in interface ListData
Returns:
A list of ListItems.

getValue

public String getValue(String id,
                       Locale loc)
Given an id and a locale return the list item value.

Specified by:
getValue in interface ListData
Parameters:
id - The id of the list item
loc - The locale of the list from where to get the value.
Returns:
The value of the list item

getValue

public String getValue(String id)
Description copied from interface: ListData
Returns the string value for the list data item with the default locale. If there is no value for the default locale, use any locale available to return the value.

Specified by:
getValue in interface ListData
Returns:
The string value of the list data item.

getValue

public String getValue(int id)
Description copied from interface: ListData
Returns the string value of the list data item with the given id with the default locale.

Specified by:
getValue in interface ListData
Parameters:
id - The id of the list data item
Returns:
The string value of the list data item

getValue

public String getValue(int id,
                       Locale loc)
Description copied from interface: ListData
Returns the string value of the list data item with the given id in the given locale.

Specified by:
getValue in interface ListData
Parameters:
id - The id of the list data item.
loc - The locale of the list data item.
Returns:
The string value for the list data item.

sort

protected void sort(List<ListItem> list,
                    int ordertype)
Sort the list acording to the order type. If you create another order type, override this method to do the sorting.

Parameters:
list - The list of ListItems to sort.
ordertype - The order type (how to sort)


Copyright © 2013. All Rights Reserved.