[26588] | 1 | package org.honours.collection;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.Collections;
|
---|
| 5 | import java.util.Comparator;
|
---|
| 6 | import java.util.List;
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * A collection information object is used to
|
---|
| 10 | * hold information about a collection during runtime
|
---|
| 11 | * of the system. Replaces the collectionInfo.inf file
|
---|
| 12 | * which was used originally.
|
---|
| 13 | * @author Korii 14/11/2012
|
---|
| 14 | */
|
---|
| 15 | public class CollectionInformation {
|
---|
| 16 |
|
---|
| 17 | private List<String[]> _rows;
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | public CollectionInformation(){
|
---|
| 21 | _rows = new ArrayList<String[]>();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * Add a row containing information about an individual collection
|
---|
| 26 | * item or layer.
|
---|
| 27 | *
|
---|
| 28 | * @param type - Three types: "I" for collection item;
|
---|
| 29 | * "LT" for text layer and "LI" for image layer.
|
---|
| 30 | * @param frameName - name of the frame representing a collection item/layer
|
---|
| 31 | * @param assocfilepath - the assocfilepath value associated with the item.
|
---|
| 32 | */
|
---|
| 33 | public void addRow(String type,String frameName,String assocfilepath){
|
---|
| 34 |
|
---|
| 35 | String[] row = new String[]{type,frameName,assocfilepath};
|
---|
| 36 | _rows.add(row);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public List<String[]> getRows(){
|
---|
| 40 | return _rows;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * Find a row associated with a particular frame.
|
---|
| 45 | * @param frameName
|
---|
| 46 | * @return
|
---|
| 47 | */
|
---|
| 48 | public String[] findRow(String frameName){
|
---|
| 49 |
|
---|
| 50 | String[] result = null;
|
---|
| 51 |
|
---|
| 52 | for(String[] s : _rows){
|
---|
| 53 | if(s[1].equals(frameName))
|
---|
| 54 | result = s;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | return result;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /**
|
---|
| 61 | * Sort the collection information object by
|
---|
| 62 | * assocfilepath
|
---|
| 63 | */
|
---|
| 64 | public void sort(){
|
---|
| 65 | //sort rows by the 3rd index of arrays (assocfilepath)
|
---|
| 66 | Collections.sort(_rows,new Comparator<String[]>(){
|
---|
| 67 | public int compare(String[] s1, String[] s2){
|
---|
| 68 | return s1[2].compareTo(s2[2]);
|
---|
| 69 | }
|
---|
| 70 | });
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | }
|
---|