/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.anjocaido.groupmanager.utils; import java.util.Comparator; /** * * @author gabrielcouto */ public class StringPermissionComparator implements Comparator { private static StringPermissionComparator instance; public static StringPermissionComparator getInstance() { if (instance == null) { instance = new StringPermissionComparator(); } return instance; } @Override public int compare(final String permA, final String permB) { final boolean ap = permA.startsWith("+"); final boolean bp = permB.startsWith("+"); final boolean am = permA.startsWith("-"); final boolean bm = permB.startsWith("-"); if (ap && bp) { return 0; } if (ap && !bp) { return -1; } if (!ap && bp) { return 1; } if (am && bm) { return 0; } if (am && !bm) { return -1; } if (!am && bm) { return 1; } return permA.compareToIgnoreCase(permB); } }