Search in sources :

Example 51 with Collator

use of java.text.Collator in project j2objc by google.

the class CollatorTest method test_collationKeySize.

//    public void test_icuConstantNullorder() throws Exception {
//        assertEquals(android.icu.text.CollationElementIterator.NULLORDER,
//                CollationElementIterator.NULLORDER);
//    }
public void test_collationKeySize() throws Exception {
    // Test to verify that very large collation keys are not truncated.
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < 1024; i++) {
        b.append("0123456789ABCDEF");
    }
    String sixteen = b.toString();
    b.append("_THE_END");
    String sixteenplus = b.toString();
    Collator mColl = Collator.getInstance();
    mColl.setStrength(Collator.PRIMARY);
    byte[] arr = mColl.getCollationKey(sixteen).toByteArray();
    int len = arr.length;
    assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0);
    len--;
    String foo = new String(arr, 0, len, "iso8859-1");
    arr = mColl.getCollationKey(sixteen).toByteArray();
    len = arr.length;
    assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0);
    len--;
    String bar = new String(arr, 0, len, "iso8859-1");
    assertTrue("Collation keys should differ", foo.equals(bar));
}
Also used : Collator(java.text.Collator)

Example 52 with Collator

use of java.text.Collator in project phonegap-facebook-plugin by Wizcorp.

the class GraphObjectAdapter method rebuildSections.

private void rebuildSections() {
    sectionKeys = new ArrayList<String>();
    graphObjectsBySection = new HashMap<String, ArrayList<T>>();
    graphObjectsById = new HashMap<String, T>();
    displaySections = false;
    if (cursor == null || cursor.getCount() == 0) {
        return;
    }
    int objectsAdded = 0;
    cursor.moveToFirst();
    do {
        T graphObject = cursor.getGraphObject();
        if (!filterIncludesItem(graphObject)) {
            continue;
        }
        objectsAdded++;
        String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject);
        if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) {
            sectionKeys.add(sectionKeyOfItem);
            graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<T>());
        }
        List<T> section = graphObjectsBySection.get(sectionKeyOfItem);
        section.add(graphObject);
        graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject);
    } while (cursor.moveToNext());
    if (sortFields != null) {
        final Collator collator = Collator.getInstance();
        for (List<T> section : graphObjectsBySection.values()) {
            Collections.sort(section, new Comparator<GraphObject>() {

                @Override
                public int compare(GraphObject a, GraphObject b) {
                    return compareGraphObjects(a, b, sortFields, collator);
                }
            });
        }
    }
    Collections.sort(sectionKeys, Collator.getInstance());
    displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD;
}
Also used : GraphObject(com.facebook.model.GraphObject) Collator(java.text.Collator)

Example 53 with Collator

use of java.text.Collator in project android by owncloud.

the class AlphanumComparator method compare.

public int compare(OCFile o1, OCFile o2) {
    String s1 = (String) o1.getRemotePath().toLowerCase();
    String s2 = (String) o2.getRemotePath().toLowerCase();
    int thisMarker = 0;
    int thatMarker = 0;
    int s1Length = s1.length();
    int s2Length = s2.length();
    while (thisMarker < s1Length && thatMarker < s2Length) {
        String thisChunk = getChunk(s1, s1Length, thisMarker);
        thisMarker += thisChunk.length();
        String thatChunk = getChunk(s2, s2Length, thatMarker);
        thatMarker += thatChunk.length();
        // If both chunks contain numeric characters, sort them numerically
        int result = 0;
        if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) {
            // Simple chunk comparison by length.
            int thisChunkLength = thisChunk.length();
            result = thisChunkLength - thatChunk.length();
            // If equal, the first different number counts
            if (result == 0) {
                for (int i = 0; i < thisChunkLength; i++) {
                    result = thisChunk.charAt(i) - thatChunk.charAt(i);
                    if (result != 0) {
                        return result;
                    }
                }
            }
        } else {
            Collator collator = Collator.getInstance();
            collator.setStrength(Collator.PRIMARY);
            result = collator.compare(thisChunk, thatChunk);
        }
        if (result != 0)
            return result;
    }
    return s1Length - s2Length;
}
Also used : Collator(java.text.Collator)

Example 54 with Collator

use of java.text.Collator in project SeriesGuide by UweTrottmann.

the class MovieLocalizationDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.dialog_localization, container, false);
    unbinder = ButterKnife.bind(this, view);
    buttonOk.setText(android.R.string.ok);
    buttonOk.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    adapter = new LocalizationAdapter(onItemClickListener);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    updateButtonText();
    buttonLanguage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setListVisible(true);
            new Thread(new Runnable() {

                @Override
                public void run() {
                    String[] languageCodes = getContext().getResources().getStringArray(R.array.languageCodesMovies);
                    List<LocalizationAdapter.LocalizationItem> items = new ArrayList<>(languageCodes.length);
                    for (String languageCode : languageCodes) {
                        // example: "en-US"
                        String languageDisplayName = new Locale(languageCode.substring(0, 2), languageCode.substring(3)).getDisplayName();
                        items.add(new LocalizationAdapter.LocalizationItem(languageCode, languageDisplayName));
                    }
                    final Collator collator = Collator.getInstance();
                    Collections.sort(items, new Comparator<LocalizationAdapter.LocalizationItem>() {

                        @Override
                        public int compare(LocalizationAdapter.LocalizationItem left, LocalizationAdapter.LocalizationItem right) {
                            return collator.compare(left.displayText, right.displayText);
                        }
                    });
                    EventBus.getDefault().postSticky(new ItemsLoadedEvent(items, 0));
                }
            }).run();
        }
    });
    buttonRegion.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setListVisible(true);
            new Thread(new Runnable() {

                @Override
                public void run() {
                    String[] regionCodes = Locale.getISOCountries();
                    List<LocalizationAdapter.LocalizationItem> items = new ArrayList<>(regionCodes.length);
                    for (String regionCode : regionCodes) {
                        // example: "en-US"
                        String displayCountry = new Locale("", regionCode).getDisplayCountry();
                        items.add(new LocalizationAdapter.LocalizationItem(regionCode, displayCountry));
                    }
                    final Collator collator = Collator.getInstance();
                    Collections.sort(items, new Comparator<LocalizationAdapter.LocalizationItem>() {

                        @Override
                        public int compare(LocalizationAdapter.LocalizationItem left, LocalizationAdapter.LocalizationItem right) {
                            return collator.compare(left.displayText, right.displayText);
                        }
                    });
                    EventBus.getDefault().postSticky(new ItemsLoadedEvent(items, 1));
                }
            }).run();
        }
    });
    return view;
}
Also used : Locale(java.util.Locale) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Collator(java.text.Collator) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(android.support.annotation.Nullable)

Example 55 with Collator

use of java.text.Collator in project EnrichmentMapApp by BaderLab.

the class LegendPanel method updateEdgeColorPanel.

private void updateEdgeColorPanel(EnrichmentMap map) {
    JPanel p = getEdgeColorPanel();
    CyNetworkView netView = options.getNetworkView();
    VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
    JComponent[][] entries = null;
    if (map != null) {
        Dimension iconSize = new Dimension(LEGEND_ICON_SIZE, LEGEND_ICON_SIZE / 2);
        if (map.getParams().getCreateDistinctEdges()) {
            VisualMappingFunction<?, Paint> mf = style.getVisualMappingFunction(BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);
            if (mf instanceof DiscreteMapping) {
                DiscreteMapping<?, Paint> dm = (DiscreteMapping<?, Paint>) mf;
                final Collator collator = Collator.getInstance();
                Map<Object, Paint> dmMap = new TreeMap<>((Object o1, Object o2) -> {
                    return collator.compare("" + o1, "" + o2);
                });
                dmMap.putAll(dm.getAll());
                dmMap.remove(Columns.EDGE_DATASET_VALUE_COMPOUND);
                if (!map.hasSignatureDataSets())
                    dmMap.remove(Columns.EDGE_DATASET_VALUE_SIG);
                if (dmMap.size() > 0) {
                    entries = new JComponent[dmMap.size()][2];
                    int i = 0;
                    for (Entry<?, Paint> e : dmMap.entrySet()) {
                        Color color = null;
                        if (e.getValue() instanceof Color)
                            color = (Color) e.getValue();
                        JLabel iconLabel = createColorLabel(color, iconSize);
                        JLabel descLabel = new JLabel("" + e.getKey());
                        if (Columns.EDGE_DATASET_VALUE_SIG.equals(e.getKey()))
                            descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                        entries[i++] = new JComponent[] { iconLabel, descLabel };
                    }
                }
            }
        }
        if (entries == null) {
            int rows = map.hasSignatureDataSets() ? 2 : 1;
            entries = new JComponent[rows][2];
            {
                JLabel iconLabel = createColorLabel(Colors.COMPOUND_EDGE_COLOR, iconSize);
                JLabel descLabel = new JLabel(Columns.EDGE_DATASET_VALUE_COMPOUND);
                descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                entries[0] = new JComponent[] { iconLabel, descLabel };
            }
            if (rows == 2) {
                JLabel iconLabel = createColorLabel(Colors.SIG_EDGE_COLOR, iconSize);
                JLabel descLabel = new JLabel(Columns.EDGE_DATASET_VALUE_SIG);
                descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                entries[1] = new JComponent[] { iconLabel, descLabel };
            }
        }
    }
    updateStyleLegendPanel(entries, p);
}
Also used : JPanel(javax.swing.JPanel) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Paint(java.awt.Paint) TreeMap(java.util.TreeMap) Paint(java.awt.Paint) Collator(java.text.Collator) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Aggregations

Collator (java.text.Collator)70 ArrayList (java.util.ArrayList)14 RuleBasedCollator (java.text.RuleBasedCollator)8 HashMap (java.util.HashMap)7 Comparator (java.util.Comparator)5 List (java.util.List)5 GraphObject (com.facebook.model.GraphObject)4 Context (android.content.Context)3 InputMethodInfo (android.view.inputmethod.InputMethodInfo)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 Locale (java.util.Locale)3 Entry (java.util.Map.Entry)3 SharedPreferences (android.content.SharedPreferences)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageInfo (android.content.pm.PackageInfo)2 DBObject (com.mongodb.DBObject)2 SMSException (com.sun.identity.sm.SMSException)2 ServiceSchema (com.sun.identity.sm.ServiceSchema)2 AutoPilot (com.ximpleware.AutoPilot)2