Example usage for java.text Collator getInstance

List of usage examples for java.text Collator getInstance

Introduction

In this page you can find the example usage for java.text Collator getInstance.

Prototype

public static synchronized Collator getInstance() 

Source Link

Document

Gets the Collator for the current default locale.

Usage

From source file:de.blizzy.backup.BackupPlugin.java

public List<LocationProviderDescriptor> getLocationProviders() {
    List<LocationProviderDescriptor> result = new ArrayList<>();
    IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(ID + ".locationProviders"); //$NON-NLS-1$
    IExtension[] extensions = point.getExtensions();
    for (IExtension extension : extensions) {
        for (IConfigurationElement element : extension.getConfigurationElements()) {
            try {
                String name = element.getAttribute("name"); //$NON-NLS-1$
                ILocationProvider locationProvider = (ILocationProvider) element
                        .createExecutableExtension("class"); //$NON-NLS-1$
                result.add(new LocationProviderDescriptor(name, locationProvider));
            } catch (CoreException e) {
                logError("error while creating location provider", e); //$NON-NLS-1$
            }//from w w  w  .jav  a2  s  .c  o m
        }
    }
    Collections.sort(result, new Comparator<LocationProviderDescriptor>() {
        @Override
        public int compare(LocationProviderDescriptor d1, LocationProviderDescriptor d2) {
            if (d1.getLocationProvider() instanceof FileSystemLocationProvider) {
                return -1;
            }
            if (d2.getLocationProvider() instanceof FileSystemLocationProvider) {
                return 1;
            }
            return Collator.getInstance().compare(d1.getName(), d2.getName());
        }
    });
    return result;
}

From source file:org.intermine.install.swing.PreferencesDialog.java

/**
 * Initialise the look and feel choices by reading all the possible look and
 * feel names from <code>preferences.properties</code>, populating the combo
 * box accordingly and highlighting the last selected look and feel.
 */// w  w  w  .j a va  2s  .co m
private void initLookAndFeels() {
    InputStream propsStream = getClass().getResourceAsStream("/org/intermine/install/preferences.properties");
    if (propsStream == null) {
        throw new RuntimeException("The file 'preferences.properties' cannot be found on the class path.");
    }
    properties = new Properties();
    try {
        try {
            properties.load(propsStream);
        } finally {
            propsStream.close();
        }
    } catch (IOException e) {
        logger.warn("Could not load from preferences.properties. The options may be limited.");
    }

    String lookAndFeelNameList = properties.getProperty("lookandfeel.namelist", "Metal");
    String[] lookAndFeelNames = lookAndFeelNameList.split(",");

    Arrays.sort(lookAndFeelNames, Collator.getInstance());

    for (LookAndFeelInfo lf : UIManager.getInstalledLookAndFeels()) {
        installedLookAndFeels.put(lf.getName(), lf);
    }

    for (String lf : lookAndFeelNames) {
        lfComboModel.addElement(lf);
    }

    lfCombo.addActionListener(new LookAndFeelComboListener());

    String lookAndFeel = MineManagerBackingStore.getInstance().getLookAndFeel();

    if (StringUtils.isNotEmpty(lookAndFeel)) {
        lfCombo.setSelectedItem(lookAndFeel);
    }
}

From source file:de.blizzy.rust.lootconfig.LootConfigDump.java

private String formatItems(Category category) {
    return category.Items.stream().sorted((itemSpawn1, itemSpawn2) -> Collator.getInstance()
            .compare(itemSpawn1.item.Shortname, itemSpawn2.item.Shortname)).map(itemSpawn -> {
                if (itemSpawn.Amount > 1) {
                    return String.format("%s x%d", itemSpawn.item.Shortname, itemSpawn.Amount);
                } else {
                    return itemSpawn.item.Shortname;
                }//from   ww  w . j  ava  2 s. c o  m
            }).collect(Collectors.joining(", "));
}

From source file:org.kuali.kfs.sys.DynamicCollectionComparatorTest.java

private <T> boolean isSortedByAscendingOrder(List<T> objectList, String fieldName) throws Exception {
    Collator collator = Collator.getInstance();
    Object tempValue = null;/*from  w w w . ja  v  a2  s .  co m*/
    for (T object : objectList) {
        Object fieldValue = PropertyUtils.getProperty(object, fieldName);

        if (tempValue == null || collator.compare(tempValue, fieldValue) <= 0) {
            tempValue = fieldValue;
        } else {
            return false;
        }
    }
    return true;
}

From source file:io.gravitee.gateway.services.sync.SyncManager.java

private boolean hasMatchingTags(Api api) {
    final Optional<List<String>> optTagList = gatewayConfiguration.shardingTags();

    if (optTagList.isPresent()) {
        List<String> tagList = optTagList.get();
        if (api.getTags() != null) {
            final List<String> inclusionTags = tagList.stream().map(String::trim)
                    .filter(tag -> !tag.startsWith("!")).collect(Collectors.toList());

            final List<String> exclusionTags = tagList.stream().map(String::trim)
                    .filter(tag -> tag.startsWith("!")).map(tag -> tag.substring(1))
                    .collect(Collectors.toList());

            if (inclusionTags.stream().filter(exclusionTags::contains).count() > 0) {
                throw new IllegalArgumentException("You must not configure a tag to be included and excluded");
            }/*from   w w w  .jav  a  2 s .  c om*/

            final boolean hasMatchingTags = inclusionTags.stream()
                    .anyMatch(tag -> api.getTags().stream().anyMatch(apiTag -> {
                        final Collator collator = Collator.getInstance();
                        collator.setStrength(Collator.NO_DECOMPOSITION);
                        return collator.compare(tag, apiTag) == 0;
                    })) || (!exclusionTags.isEmpty() && exclusionTags.stream()
                            .noneMatch(tag -> api.getTags().stream().anyMatch(apiTag -> {
                                final Collator collator = Collator.getInstance();
                                collator.setStrength(Collator.NO_DECOMPOSITION);
                                return collator.compare(tag, apiTag) == 0;
                            })));

            if (!hasMatchingTags) {
                logger.info("The API {} has been ignored because not in configured tags {}", api.getName(),
                        tagList);
            }
            return hasMatchingTags;
        }
        logger.info("Tags {} are configured on gateway instance but not found on the API {}", tagList,
                api.getName());
        return false;
    }
    // no tags configured on this gateway instance
    return true;
}

From source file:ro.nextreports.designer.persistence.FileReportPersistence.java

public List<File> getReportFiles(String folderPath) {
    List<File> result = new ArrayList<File>();
    DataSourceManager manager = DefaultDataSourceManager.getInstance();
    DataSource ds = manager.getConnectedDataSource();
    if (ds != null) {
        File file = new File(folderPath);
        File[] files = file.listFiles();
        if (files != null) {
            for (int i = 0, size = files.length; i < size; i++) {
                int index = files[i].getName().indexOf(REPORT_EXTENSION_SEPARATOR + REPORT_EXTENSION);
                if (index != -1) {
                    if (files[i].getName().endsWith(REPORT_EXTENSION_SEPARATOR + REPORT_EXTENSION)) {
                        result.add(files[i]);
                    }//from  w  w w.  j  av  a 2s  .c  om
                } else {
                    if (file.isDirectory()) {
                        result.add(files[i]);
                    }
                }
            }
        }
    }
    Collections.sort(result, new Comparator<File>() {
        public int compare(File o1, File o2) {
            if ((o1.isDirectory() && o2.isDirectory()) || (o1.isFile() && o2.isFile())) {
                return Collator.getInstance().compare(o1.getName(), o2.getName());
            } else {
                if (o1.isDirectory()) {
                    return -1;
                } else {
                    return 1;
                }
            }
        }
    });
    return result;
}

From source file:org.n52.io.response.ParameterOutput.java

@Override
public int compare(Collator collator, ParameterOutput o) {
    if (collator == null) {
        collator = Collator.getInstance();
    }//from  w  ww . j a v  a 2  s.  c o  m
    return collator.compare(getLabel().toLowerCase(), o.getLabel().toLowerCase());
}

From source file:de.blizzy.rust.lootconfig.LootConfigDump.java

private String formatBlueprints(Category category) {
    return category.Blueprints.stream()
            .sorted((blueprintSpawn1, blueprintSpawn2) -> Collator.getInstance()
                    .compare(blueprintSpawn1.item.Shortname, blueprintSpawn2.item.Shortname))
            .peek(blueprintSpawn -> {
                if (blueprintSpawn.item == null) {
                    throw new IllegalStateException("blueprint spawn without item");
                }//from w w w .jav  a  2  s  .  c  o  m
            }).map(blueprintSpawn -> blueprintSpawn.item.Shortname).collect(Collectors.joining(", "));
}

From source file:org.kuali.kfs.sys.DynamicCollectionComparatorTest.java

private <T> boolean isSortedByDescendingOrder(List<T> objectList, String fieldName) throws Exception {
    Collator collator = Collator.getInstance();
    Object tempValue = null;/*from  www  .  j a v a2 s . c  o  m*/

    int count = 0;
    for (T object : objectList) {
        Object fieldValue = PropertyUtils.getProperty(object, fieldName);

        if (count == 0) {
            tempValue = fieldValue;
            count++;
        } else if (tempValue == null && fieldValue == null) {
            tempValue = fieldValue;
        } else if (tempValue == null) {
            return false;
        } else if (fieldValue == null) {
            tempValue = fieldValue;
        } else if (collator.compare(tempValue, fieldValue) >= 0) {
            tempValue = fieldValue;
        } else {
            return false;
        }
    }

    return true;
}

From source file:pt.webdetails.cdf.dd.CdfTemplates.java

private void loadFiles(final File[] jsonFiles, final JSONArray result, final String type)
        throws FileNotFoundException, IOException {

    Arrays.sort(jsonFiles, new Comparator<File>() {
        private Collator c = Collator.getInstance();

        public int compare(final File f1, final File f2) {
            return c.compare(f1.getName(), f2.getName());
        }//from w ww. j a  v a 2s.c o m
    });

    for (int i = 0; i < jsonFiles.length; i++) {
        final JSONObject template = new JSONObject();
        final File image = new File(jsonFiles[i].getAbsolutePath().replace(".cdfde", ".png"));
        final String imgResourcePath = image.exists() ? RESOURCE_TEMPLATE_DIR + image.getName() : UNKNOWN_IMAGE;
        template.put("img", imgResourcePath);
        template.put("type", type);
        FileInputStream cdfdeFile = null;
        try {
            cdfdeFile = new FileInputStream(jsonFiles[i]);
            template.put("structure", JsonUtils.readJsonFromInputStream(cdfdeFile));
            result.add(template);
        } finally {
            IOUtils.closeQuietly(cdfdeFile);
        }

    }
}