Example usage for java.util Comparator Comparator

List of usage examples for java.util Comparator Comparator

Introduction

In this page you can find the example usage for java.util Comparator Comparator.

Prototype

Comparator

Source Link

Usage

From source file:com.googlecode.psiprobe.controllers.datasources.ListAllJdbcResourceGroups.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    List dataSourceGroups = new ArrayList();
    List dataSources = new ArrayList();

    List privateResources = getContainerWrapper().getPrivateDataSources();
    List globalResources = getContainerWrapper().getGlobalDataSources();

    // filter out anything that is not a datasource
    // and use only those datasources that are properly configured
    // as aggregated totals would not make any sense otherwise
    filterValidDataSources(privateResources, dataSources);
    filterValidDataSources(globalResources, dataSources);

    // sort datasources by JDBC URL
    Collections.sort(dataSources, new Comparator() {
        public int compare(Object o1, Object o2) {
            String jdbcURL1 = ((DataSourceInfo) o1).getJdbcURL();
            String jdbcURL2 = ((DataSourceInfo) o2).getJdbcURL();

            // here we rely on the the filter not to add any
            // datasources with a null jdbcUrl to the list

            return jdbcURL1.compareToIgnoreCase(jdbcURL2);
        }//from w  ww.j a v a2  s  . c o  m
    });

    // group datasources by JDBC URL and calculate aggregated totals
    DataSourceInfoGroup dsGroup = null;
    for (Iterator i = dataSources.iterator(); i.hasNext();) {
        DataSourceInfo ds = (DataSourceInfo) i.next();

        if (dsGroup == null || !dsGroup.getJdbcURL().equalsIgnoreCase(ds.getJdbcURL())) {
            dsGroup = new DataSourceInfoGroup(ds);
            dataSourceGroups.add(dsGroup);
        } else {
            dsGroup.addDataSourceInfo(ds);
        }
    }

    return new ModelAndView(getViewName(), "dataSourceGroups", dataSourceGroups);
}

From source file:psiprobe.controllers.datasources.ListAllJdbcResourceGroups.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    List<DataSourceInfoGroup> dataSourceGroups = new ArrayList<>();
    List<DataSourceInfo> dataSources = new ArrayList<>();

    List<ApplicationResource> privateResources = getContainerWrapper().getPrivateDataSources();
    List<ApplicationResource> globalResources = getContainerWrapper().getGlobalDataSources();

    // filter out anything that is not a datasource
    // and use only those datasources that are properly configured
    // as aggregated totals would not make any sense otherwise
    filterValidDataSources(privateResources, dataSources);
    filterValidDataSources(globalResources, dataSources);

    // sort datasources by JDBC URL
    Collections.sort(dataSources, new Comparator<DataSourceInfo>() {
        @Override/*from ww w.ja  va2  s  . co  m*/
        public int compare(DataSourceInfo ds1, DataSourceInfo ds2) {
            String jdbcUrl1 = ds1.getJdbcUrl();
            String jdbcUrl2 = ds2.getJdbcUrl();

            // here we rely on the the filter not to add any datasources with a null jdbcUrl to the list

            return jdbcUrl1.compareToIgnoreCase(jdbcUrl2);
        }
    });

    // group datasources by JDBC URL and calculate aggregated totals
    DataSourceInfoGroup dsGroup = null;
    for (DataSourceInfo ds : dataSources) {
        if (dsGroup == null || !dsGroup.getJdbcUrl().equalsIgnoreCase(ds.getJdbcUrl())) {
            dsGroup = new DataSourceInfoGroup(ds);
            dataSourceGroups.add(dsGroup);
        } else {
            dsGroup.addDataSourceInfo(ds);
        }
    }

    return new ModelAndView(getViewName(), "dataSourceGroups", dataSourceGroups);
}

From source file:org.openmrs.module.htmlformentry19ext.EncounterRoleWidget.java

/**
 * @see org.openmrs.module.htmlformentry.widget.Widget#generateHtml(org.openmrs.module.htmlformentry.FormEntryContext)
 *//*from  ww w .  j a  v  a  2 s  .co m*/
@Override
public String generateHtml(FormEntryContext context) {
    if (context.getMode() == Mode.VIEW) {
        if (initialValue != null)
            return WidgetFactory.displayValue(initialValue.getName());
        else
            return "";
    }

    List<EncounterRole> roles = Context.getEncounterService().getAllEncounterRoles(true);
    Collections.sort(roles, new Comparator<EncounterRole>() {
        @Override
        public int compare(EncounterRole left, EncounterRole right) {
            return left.getName().compareTo(right.getName());
        }
    });

    StringBuilder sb = new StringBuilder();
    sb.append("<select name=\"" + context.getFieldName(this) + "\">");
    sb.append("\n<option value=\"\">");
    sb.append(Context.getMessageSourceService().getMessage("htmlformentry19ext.chooseAnEncounterRole"));
    sb.append("</option>");

    for (EncounterRole role : roles) {
        sb.append("\n<option ");
        if (initialValue != null && initialValue.equals(role))
            sb.append("selected=\"true\" ");
        sb.append("value=\"" + role.getId() + "\">").append(role.getName()).append("</option>");
    }
    sb.append("</select>");
    return sb.toString();
}

From source file:net.chrissearle.flickrvote.web.account.MyPicsAction.java

@Override
public String execute() throws Exception {
    if (!session.containsKey(FlickrVoteWebConstants.FLICKR_USER_SESSION_KEY)) {
        return "notloggedin";
    }/*from w w  w  .  j  a va 2  s  .  co m*/

    Photographer photographer = (Photographer) session.get(FlickrVoteWebConstants.FLICKR_USER_SESSION_KEY);

    images = new ArrayList<DisplayImage>();

    for (ImageItem image : photographyService.getImagesForPhotographer(photographer.getPhotographerId())) {
        images.add(new DisplayImage(image));
    }

    Collections.sort(images, new Comparator<DisplayImage>() {
        public int compare(DisplayImage o1, DisplayImage o2) {
            return o1.getChallengeTag().compareTo(o2.getChallengeTag());
        }
    });

    return SUCCESS;
}

From source file:com.monits.jpack.codec.ObjectCodec.java

public ObjectCodec(Class<? extends E> struct) {

    this.struct = struct;

    fields = new ArrayList<FieldData>();
    for (Field field : struct.getDeclaredFields()) {
        Encode annotation = field.getAnnotation(Encode.class);
        if (annotation != null) {
            FieldData data = new FieldData();

            data.metadata = annotation;// www  . j ava 2 s. com
            data.codec = (Codec<Object>) CodecFactory.get(field);

            if (data.codec == null) {
                continue;
            }

            data.field = field;
            data.field.setAccessible(true);

            fields.add(data);
        }
    }

    Collections.sort(fields, new Comparator<FieldData>() {

        @Override
        public int compare(FieldData a, FieldData b) {
            return a.metadata.value() - b.metadata.value();
        }

    });
}

From source file:com.appeligo.search.actions.KeywordAlertsPageAction.java

public String execute() throws Exception {

    //Sort keywords alphabetically
    if (log.isDebugEnabled())
        log.debug("=============== GETTING KeywordAlerts for Keyword Alerts page ==========");
    keywordAlerts = new LinkedList<KeywordAlert>(getUser().getLiveKeywordAlerts());
    Collections.sort(keywordAlerts, new Comparator<KeywordAlert>() {
        public int compare(KeywordAlert left, KeywordAlert right) {
            return left.getUserQuery().compareTo(right.getUserQuery());
        }/*  w  ww  . jav  a  2s  .  c o  m*/
    });

    return SUCCESS;
}

From source file:com.github.ipaas.ideploy.plugin.core.Comparetor.java

/**
 *  ??,?//w ww.  j ava  2  s. com
 * 
 * @param pathInfo
 * @param userInfo
 * @return
 */
public static String doAtion(PathInfo pathInfo, UserInfo userInfo) {

    if (userInfo.getUrl() == null || userInfo.getUrl().equals("")) {
        ConsoleHandler.error("??");
        return null;
    } else if (userInfo.getEmail() == null || userInfo.getEmail().equals("")) {
        ConsoleHandler.error("????");
        return null;
    } else if (userInfo.getPassword() == null || userInfo.getPassword().equals("")) {
        ConsoleHandler.error("???");
        return null;
    }
    ConsoleHandler.info(":" + userInfo.getEmail());
    ConsoleHandler.info("?:" + pathInfo.getGroupId());

    TreeNode srcRoot = getSrcTree(pathInfo);
    TreeNode targetRoot = getTargetTree(userInfo, pathInfo);
    if (srcRoot != null && targetRoot != null) {
        List<String> result = null;
        if (targetRoot.getChildSet() == null || targetRoot.getChildSet().size() == 0) {
            result = new ArrayList<String>();
            result.add("all");
        } else {
            result = FileTreeNodeComparetor.compare(srcRoot, targetRoot);
        }
        Collections.sort(result, new Comparator<String>() {
            public int compare(String str1, String str2) {
                return str1.compareTo(str2);
            }
        });

        if (result != null && result.size() > 0) {
            ConfigFileFilter filter = new ConfigFileFilter(userInfo.getPatternJsonList());
            result = filter.filterResult(result);
        }

        if (result != null && result.size() > 0) {
            String path = genZipPackage(result, pathInfo);
            ConsoleHandler.info("?  " + path + " ?!");
            return path;
        } else {
            ConsoleHandler.info("?!");
        }
    } else {
        ConsoleHandler.info("???!");
    }
    return null;
}

From source file:ccm.pay2spawn.configurator.HTMLGenerator.java

public static void generate() throws IOException {
    ArrayList<Reward> sortedRewards = new ArrayList<>();
    sortedRewards.addAll(Pay2Spawn.getRewardsDB().getRewards());
    Collections.sort(sortedRewards, new Comparator<Reward>() {
        @Override/*from   w w  w .j a v  a2s. c o m*/
        public int compare(Reward o1, Reward o2) {
            return (int) (o1.getAmount() - o2.getAmount());
        }
    });

    File output = new File(htmlFolder, "index.html");
    String text = readFile(templateIndex);
    int begin = text.indexOf(LOOP_START);
    int end = text.indexOf(LOOP_END);

    FileUtils.writeStringToFile(output, replace(text.substring(0, begin)), false);

    String loop = text.substring(begin + LOOP_START.length(), end);
    for (Reward reward : sortedRewards) {
        Pay2Spawn.getLogger().info("Adding " + reward + " to html file.");
        FileUtils.writeStringToFile(output, replace(loop, reward), true);
    }

    FileUtils.writeStringToFile(output, text.substring(end + LOOP_END.length(), text.length()), true);
}

From source file:com.threewks.thundr.introspection.ClassIntrospector.java

@SuppressWarnings({ "rawtypes" })
public <T> List<Constructor<T>> listConstructors(Class<T> type) {
    ClassDescriptor classDescriptor = new ClassDescriptor(type, true);
    CollectionTransformer<Constructor, Constructor<T>> castAll = Expressive.Transformers
            .transformAllUsing(ClassIntrospector.<Constructor, Constructor<T>>castTransformer());
    List<Constructor<T>> ctors = castAll.from(classDescriptor.getAllCtors(true));
    Collections.sort(ctors, new Comparator<Constructor<T>>() {
        @Override/*w  w  w .j a  v  a  2 s  .  co  m*/
        public int compare(Constructor<T> o1, Constructor<T> o2) {
            Class<?>[] types1 = o1.getParameterTypes();
            Class<?>[] types2 = o2.getParameterTypes();
            int compare = new Integer(types1.length).compareTo(types2.length);
            if (compare == 0) {
                // to keep the outcome consistent, we want to deterministically sort
                for (int i = 0; compare == 0 && i < types1.length; i++) {
                    compare = types1[i].getName().compareTo(types2[i].getName());
                }
            }
            return compare;
        }
    });
    return ctors;
}

From source file:at.meikel.dmrl.webapp.rest.PlayerService.java

@RequestMapping(value = { "/playersByTeam/{teamName}" }, method = RequestMethod.GET)
@ResponseBody/*  www. ja v a  2 s  .  c o  m*/
public List<Player> getPlayersByTeam(@PathVariable String teamName) {
    List<Player> result = null;
    if (server != null) {
        result = server.getRankingList().find(teamName);
    }

    if (result == null) {
        result = new Vector<Player>();
    }

    Collections.sort(result, new Comparator<Player>() {
        @Override
        public int compare(Player p1, Player p2) {
            if (p1 == null) {
                return p2 == null ? 0 : 1;
            } else {
                if (p2 == null) {
                    return -1;
                } else {
                    return (int) Math.signum(p1.getRanglistenwert() - p2.getRanglistenwert());
                }
            }
        }
    });

    return result;
}