Q:

Comparator for groups of types

I would like to sort array of objects.  Each object has getType() method which returns object type in String. 
I would like to sort my array depending on the type with something like priorities. 
Example: 
Input { A, F, Z, G, E, D, C }

If(type == A or B or C or D) top 
If(type == E) second
If(type == F or G) third
If(differet type) last

Output: { A, C, D, E, F, G, Z }

How should my comparator look like ? 
If I haven't stated my question clear enough, please write a comment, I'll try to explain more briefly the part which is not clear. 

A:

You can declare a priorities hash map:
private static final HashMap<String,Integer> PRIORITIES = new HashMap<String, Integer>();
static{
    PRIORITIES.put("A", 1);
    PRIORITIES.put("B", 1);
    PRIORITIES.put("C", 1);
    PRIORITIES.put("D", 1);
    PRIORITIES.put("E", 2);
    PRIORITIES.put("F", 2);
    PRIORITIES.put("G", 3);
}

Then implement compare method of your Comparator:
private int getPriority(CustomClass obj) {
    if(obj!=null&&PRIORITIES.containsKey(obj.getType())) {
        priority1 = PRIORITIES.get(obj.getType());
    } else {
        priority1 = Integer. MAX_VALUE;
    }
}

@Override
public int compare(CustomClass o1, CustomClass o2) {
    int priority1,priority2;
    priority1 = getPriority(o1);
    priority2 = getPriority(o2);
    return priority1==priority2 ?  0 : (priority1<priority2 ?  -1 : 1);
}

UPDATE: Cleaner approach is to define hashmap in your base class (where getType is declared) and to implement getPriority method: 
public int getPriority() {
    return PRIORITIES.containsKey(getType()) ?  PRIORITIES.get(getType()) : Integer. MAX_VALUE;
}

Then Comparator is obvious: 
@Override
public int compare(CustomClass o1, CustomClass o2) {
    int priority1,priority2;
    priority1 = o1==null ?  Integer. MAX_VALUE : o1.getPriority();
    priority2 = o2==null ?  Integer. MAX_VALUE : o2.getPriority();
    return priority1==priority2 ?  0 : (priority1<priority2 ?  -1 : 1);
}

