Changeset 253


Ignore:
Timestamp:
03/18/10 16:20:42 (14 years ago)
Author:
patdui
Message:
  • return descriptions sorted by default
Location:
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryImpl.java

    r243 r253  
    162162
    163163    public List<ComponentDescription> getComponentDescriptions() {
    164         return new ArrayList(componentDescriptions.values());
     164        List<ComponentDescription> result = new ArrayList(componentDescriptions.values());
     165        Collections.sort(result, ComponentDescription.COMPARE_ON_GROUP_AND_NAME);
     166        return result;
    165167    }
    166168
     
    234236
    235237    public List<ProfileDescription> getProfileDescriptions() {
    236         return new ArrayList(profileDescriptions.values());
     238        List<ProfileDescription> result = new ArrayList(profileDescriptions.values());
     239        Collections.sort(result, ProfileDescription.COMPARE_ON_NAME);
     240        return result;
    237241    }
    238242
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/ComponentDescription.java

    r127 r253  
    11package clarin.cmdi.componentregistry.model;
     2
     3import java.util.Comparator;
    24
    35import javax.xml.bind.annotation.XmlRootElement;
     
    911public class ComponentDescription extends AbstractDescription {
    1012
     13    public static final Comparator<? super ComponentDescription> COMPARE_ON_GROUP_AND_NAME = new Comparator<ComponentDescription>() {
     14        public int compare(ComponentDescription o1, ComponentDescription o2) {
     15            int result=0;
     16            if (o1.getGroupName() != null && o2.getGroupName() != null)
     17                result = o1.getGroupName().compareTo(o2.getGroupName());
     18            if (result == 0) {
     19                if (o1.getName() != null && o2.getName() != null) {
     20                    result = o1.getName().compareTo(o2.getName());
     21                } else {
     22                    result = o1.getId().compareTo(o2.getId());
     23                }
     24            }
     25            return result;
     26        }
     27    };
     28   
    1129    private String groupName;
    1230
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/ProfileDescription.java

    r127 r253  
    11package clarin.cmdi.componentregistry.model;
     2
     3import java.util.Comparator;
    24
    35import javax.xml.bind.annotation.XmlRootElement;
     
    810@XmlRootElement(name = "profileDescription")
    911public class ProfileDescription extends AbstractDescription {
    10    
     12
     13    public static final Comparator<? super ProfileDescription> COMPARE_ON_NAME = new Comparator<ProfileDescription>() {
     14        public int compare(ProfileDescription o1, ProfileDescription o2) {
     15            int result = 0;
     16            if (o1.getName() != null && o2.getName() != null) {
     17                result = o1.getName().compareTo(o2.getName());
     18            } else {
     19                result = o1.getId().compareTo(o2.getId());
     20            }
     21            return result;
     22        }
     23    };
     24
    1125    public static ProfileDescription createNewDescription() {
    12         String id = ComponentRegistry.REGISTRY_ID+"p_" + IdSequence.get();
     26        String id = ComponentRegistry.REGISTRY_ID + "p_" + IdSequence.get();
    1327        ProfileDescription desc = new ProfileDescription();
    1428        desc.setId(id);
Note: See TracChangeset for help on using the changeset viewer.