Example usage for java.text Collator PRIMARY

List of usage examples for java.text Collator PRIMARY

Introduction

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

Prototype

int PRIMARY

To view the source code for java.text Collator PRIMARY.

Click Source Link

Document

Collator strength value.

Usage

From source file:android.database.DatabaseUtils.java

private static byte[] getCollationKeyInBytes(String name) {
    if (mColl == null) {
        mColl = Collator.getInstance();
        mColl.setStrength(Collator.PRIMARY);
    }/*from ww w  .j  a v  a  2  s . co m*/
    return mColl.getCollationKey(name).toByteArray();
}

From source file:com.all.client.model.predicate.BaseCollatorPredicate.java

private void initialize() {
    rules = ((RuleBasedCollator) Collator.getInstance(Locale.US)).getRules();
    refineRules();//from  w w  w  .ja  v a2 s .c om

    try {
        collator = new RuleBasedCollator(rules);
        collator.setStrength(Collator.PRIMARY);
    } catch (ParseException e) {
        log.error("Error while parsing collator rules [" + rules + "]", e);
    }
}

From source file:com.ecyrd.jspwiki.plugin.AbstractReferralPlugin.java

/**
 * Helper method to initialize the comparator for this page.
 *//*from  w  w w .  j  a  v a 2s.  co  m*/
private void initSorter(WikiContext context, Map params) {
    String order = (String) params.get(PARAM_SORTORDER);
    if (order == null || order.length() == 0) {
        // Use the configured comparator
        m_sorter = context.getEngine().getPageSorter();
    } else if (order.equalsIgnoreCase(PARAM_SORTORDER_JAVA)) {
        // use Java "natural" ordering
        m_sorter = new PageSorter(JavaNaturalComparator.DEFAULT_JAVA_COMPARATOR);
    } else if (order.equalsIgnoreCase(PARAM_SORTORDER_LOCALE)) {
        // use this locale's ordering
        m_sorter = new PageSorter(LocaleComparator.DEFAULT_LOCALE_COMPARATOR);
    } else if (order.equalsIgnoreCase(PARAM_SORTORDER_HUMAN)) {
        // use human ordering
        m_sorter = new PageSorter(HumanComparator.DEFAULT_HUMAN_COMPARATOR);
    } else
        try {
            Collator collator = new RuleBasedCollator(order);
            collator.setStrength(Collator.PRIMARY);
            m_sorter = new PageSorter(new CollatorComparator(collator));
        } catch (ParseException pe) {
            log.info("Failed to parse requested collator - using default ordering", pe);
            m_sorter = context.getEngine().getPageSorter();
        }
}

From source file:org.apache.wiki.plugin.AbstractReferralPlugin.java

/**
 * Helper method to initialize the comparator for this page.
 *//*from   www . ja va  2s  .  c  om*/
private void initSorter(WikiContext context, Map<String, String> params) {
    String order = params.get(PARAM_SORTORDER);
    if (order == null || order.length() == 0) {
        // Use the configured comparator
        m_sorter = context.getEngine().getPageSorter();
    } else if (order.equalsIgnoreCase(PARAM_SORTORDER_JAVA)) {
        // use Java "natural" ordering
        m_sorter = new PageSorter(JavaNaturalComparator.DEFAULT_JAVA_COMPARATOR);
    } else if (order.equalsIgnoreCase(PARAM_SORTORDER_LOCALE)) {
        // use this locale's ordering
        m_sorter = new PageSorter(LocaleComparator.DEFAULT_LOCALE_COMPARATOR);
    } else if (order.equalsIgnoreCase(PARAM_SORTORDER_HUMAN)) {
        // use human ordering
        m_sorter = new PageSorter(HumanComparator.DEFAULT_HUMAN_COMPARATOR);
    } else
        try {
            Collator collator = new RuleBasedCollator(order);
            collator.setStrength(Collator.PRIMARY);
            m_sorter = new PageSorter(new CollatorComparator(collator));
        } catch (ParseException pe) {
            log.info("Failed to parse requested collator - using default ordering", pe);
            m_sorter = context.getEngine().getPageSorter();
        }
}

From source file:com.android.music.PlaylistBrowserFragment.java

private Cursor getPlaylistCursor(AsyncQueryHandler async, String filterstring) {

    StringBuilder where = new StringBuilder();
    where.append(MediaStore.Audio.Playlists.NAME + " != ''");

    // Add in the filtering constraints
    String[] keywords = null;//from  ww  w . ja  v a  2s .  c  o m
    if (filterstring != null) {
        String[] searchWords = filterstring.split(" ");
        keywords = new String[searchWords.length];
        Collator col = Collator.getInstance();
        col.setStrength(Collator.PRIMARY);
        for (int i = 0; i < searchWords.length; i++) {
            keywords[i] = '%' + searchWords[i] + '%';
        }
        for (int i = 0; i < searchWords.length; i++) {
            where.append(" AND ");
            where.append(MediaStore.Audio.Playlists.NAME + " LIKE ?");
        }
    }

    String whereclause = where.toString();

    if (async != null) {
        async.startQuery(0, null, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols, whereclause, keywords,
                MediaStore.Audio.Playlists.NAME);
        return null;
    }
    Cursor c = null;
    c = MusicUtils.query(getActivity(), MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols, whereclause,
            keywords, MediaStore.Audio.Playlists.NAME);

    return mergedCursor(c);
}

From source file:fr.gouv.culture.thesaurus.service.impl.SesameThesaurus.java

/** {@inheritDoc} */
@Override/*from  w  w w .j  a v a 2  s .co m*/
public Collection<String> listConceptSchemesProducers(Locale locale) throws BusinessException {
    List<String> producers = new ArrayList<String>();

    RepositoryConnection cnx = null;
    try {
        cnx = this.repository.getConnection();

        TupleQuery query = getSelectQuery(SparqlQueries.ListConceptSchemesProducers.QUERY, cnx);
        TupleQueryResult rs = query.evaluate();

        BindingSet result;
        while (rs.hasNext()) {
            result = rs.next();
            producers.add(this.getValue("organisationName", result));
        }

    } catch (OpenRDFException e) {
        throw new BusinessException(ErrorMessage.SPARQL_CONSTRUCT_FAILED, new Object[] { e.getMessage() }, e);
    } finally {
        if (cnx != null) {
            try {
                cnx.close();
            } catch (Exception e) { /* Ignore... */
            }
        }
    }

    Collator collator = Collator.getInstance(locale);
    collator.setStrength(Collator.PRIMARY);
    Collections.sort(producers, collator);

    if (log.isDebugEnabled()) {
        log.debug("listConceptSchemesProducers: " + producers);
    }

    return producers;
}

From source file:fr.gouv.culture.thesaurus.service.impl.SesameThesaurus.java

/** {@inheritDoc} */
@Override//from   w  w w.  j  a v a 2 s  .c  o m
public Collection<String> listConceptSchemesSubjects(Locale locale) throws BusinessException {
    List<String> subjects = new ArrayList<String>();

    RepositoryConnection cnx = null;
    try {
        cnx = this.repository.getConnection();

        TupleQuery query = getSelectQuery(SparqlQueries.ListConceptSchemesSubjects.QUERY, cnx);
        TupleQueryResult rs = query.evaluate();

        BindingSet result;
        while (rs.hasNext()) {
            result = rs.next();
            String subject = this.getValue("subject", result);
            if (StringUtils.isNotBlank(subject)) {
                subjects.add(subject);
            }
        }
    } catch (OpenRDFException e) {
        throw new BusinessException(ErrorMessage.SPARQL_CONSTRUCT_FAILED, new Object[] { e.getMessage() }, e);
    } finally {
        if (cnx != null) {
            try {
                cnx.close();
            } catch (Exception e) { /* Ignore... */
            }
        }
    }

    Collator collator = Collator.getInstance(locale);
    collator.setStrength(Collator.PRIMARY);
    Collections.sort(subjects, collator);

    if (log.isDebugEnabled()) {
        log.debug("listConceptSchemesSubjects: " + subjects);
    }

    return subjects;
}

From source file:net.pms.dlna.RootFolder.java

private static boolean areNamesEqual(String aThis, String aThat) {
    Collator collator = Collator.getInstance(Locale.getDefault());
    collator.setStrength(Collator.PRIMARY);
    int comparison = collator.compare(aThis, aThat);
    return (comparison == 0);
}

From source file:org.pentaho.platform.web.http.api.resources.services.FileServiceTest.java

public void testDoGetTree() {
    String pathId = ":path:to:file:file1.ext";
    int depth = 1;
    String filter = "*|FOLDERS";
    boolean showHidden = true;
    boolean includeAcls = true;

    // Test 1//from w  w w .  jav a 2s . co m
    doReturn("test").when(fileService).idToPath(anyString());

    RepositoryRequest mockRequest = mock(RepositoryRequest.class);
    doReturn(mockRequest).when(fileService).getRepositoryRequest(anyString(), anyBoolean(), anyInt(),
            anyString());

    RepositoryFileDto mockChildFile = mock(RepositoryFileDto.class);
    doReturn("test").when(mockChildFile).getId();

    RepositoryFileTreeDto mockChildDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockChildFile).when(mockChildDto).getFile();

    List<RepositoryFileTreeDto> mockChildrenDto = new ArrayList<RepositoryFileTreeDto>();
    mockChildrenDto.add(mockChildDto);

    RepositoryFileTreeDto mockTreeDto = mock(RepositoryFileTreeDto.class);
    doReturn(mockChildrenDto).when(mockTreeDto).getChildren();
    doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);

    doReturn(true).when(fileService).isShowingTitle(mockRequest);

    Collator mockCollator = mock(Collator.class);
    doReturn(mockCollator).when(fileService).getCollatorInstance();
    doNothing().when(fileService).sortByLocaleTitle(mockCollator, mockTreeDto);

    Map<String, Serializable> fileMeta = new HashMap<String, Serializable>();
    fileMeta.put(IUnifiedRepository.SYSTEM_FOLDER, new Boolean(false));

    doReturn(fileMeta).when(fileService.repository).getFileMetadata(anyString());

    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);

    verify(fileService, times(1)).idToPath(anyString());
    verify(mockRequest, times(1)).setIncludeAcls(anyBoolean());
    verify(mockCollator, times(1)).setStrength(Collator.PRIMARY);
    verify(fileService, times(1)).sortByLocaleTitle(mockCollator, mockTreeDto);
    verify(mockTreeDto).setChildren(mockChildrenDto);

    // Test 2 - path id is null
    pathId = null;
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);

    verify(fileService, times(1)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(),
            anyString());

    // Test 3 - path id is set to the file utils path separator
    pathId = FileUtils.PATH_SEPARATOR;
    fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);

    verify(fileService, times(2)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(),
            anyString());
}