Example usage for java.lang String CASE_INSENSITIVE_ORDER

List of usage examples for java.lang String CASE_INSENSITIVE_ORDER

Introduction

In this page you can find the example usage for java.lang String CASE_INSENSITIVE_ORDER.

Prototype

Comparator CASE_INSENSITIVE_ORDER

To view the source code for java.lang String CASE_INSENSITIVE_ORDER.

Click Source Link

Document

A Comparator that orders String objects as by compareToIgnoreCase .

Usage

From source file:org.apache.syncope.client.cli.commands.migrate.MigrateConf.java

private static void copyAttrs(final XMLStreamReader streamReader, final XMLStreamWriter streamWriter,
        final String... but) throws XMLStreamException {

    Set<String> exceptions = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    exceptions.addAll(Arrays.asList(but));
    exceptions.add("id");
    exceptions.add("name");

    for (int i = 0; i < streamReader.getAttributeCount(); i++) {
        String name = streamReader.getAttributeLocalName(i);
        if (!exceptions.contains(name)) {
            streamWriter.writeAttribute(name, streamReader.getAttributeValue(i));
        }//  ww w . j  a v a 2s  . c  o m
    }
}

From source file:org.wisdom.test.http.HttpResponse.java

/**
 * Creates the response./*  w  ww  .j  a  va 2  s.c  o  m*/
 *
 * @param response      the HTTP Client response
 * @param responseClass the class of the response, used to parse the content.
 */
public HttpResponse(org.apache.http.HttpResponse response, Class<T> responseClass) {
    HttpEntity responseEntity = response.getEntity();

    Header[] allHeaders = response.getAllHeaders();
    // Use a case insensitive map to ease the retrieval of headers.
    this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    for (Header header : allHeaders) {
        headers.put(header.getName().toLowerCase(), header.getValue());
    }
    this.code = response.getStatusLine().getStatusCode();

    parseResponseBody(responseClass, responseEntity);
}

From source file:org.ligoj.app.plugin.prov.aws.auth.AWS4SignerBase.java

/**
 * Computes the canonical headers with values for the request. For AWS4, all headers must be included in the signing
 * process.//from   w w w  .j  a  v  a  2s  . c om
 * 
 * @param headers
 *            Current headers.
 * @return Appended headers names and values.
 */
protected String getCanonicalizedHeaderString(final Map<String, String> headers) {
    if (headers.isEmpty()) {
        return "";
    }
    // step1: sort the headers by case-insensitive order
    // step2: form the canonical header:value entries in sorted order.
    // Multiple white spaces in the values should be compressed to a single
    // space.
    return headers.keySet().stream().sorted(String.CASE_INSENSITIVE_ORDER).map(
            key -> key.toLowerCase().replaceAll("\\s+", " ") + ":" + headers.get(key).replaceAll("\\s+", " "))
            .collect(Collectors.joining(LF)) + LF;
}

From source file:com.evolveum.midpoint.web.page.admin.home.dto.AssignmentItemDto.java

@Override
public int compareTo(AssignmentItemDto other) {
    Validate.notNull(other, "Can't compare assignment item dto with null.");

    int value = getIndexOfType(getType()) - getIndexOfType(other.getType());
    if (value != 0) {
        return value;
    }/*from   www.  j ava  2  s  . c  o m*/

    String name1 = getName() != null ? getName() : "";
    String name2 = other.getName() != null ? other.getName() : "";

    return String.CASE_INSENSITIVE_ORDER.compare(name1, name2);
}

From source file:com.michellemay.mappings.MappingsFactory.java

private Mapping createCustomMapping(MappingConfig mappingConfig) {
    if (StringUtils.isBlank(mappingConfig.name)) {
        throw new IllegalArgumentException("Blank mapping name!");
    }/*from   w w w  . j  av  a  2 s. c o  m*/

    Map<String, Locale> curMap = new TreeMap<String, Locale>(
            mappingConfig.casesensitive ? null : String.CASE_INSENSITIVE_ORDER);

    // Inherit all mappings from bases
    if (mappingConfig.extend != null) {
        for (String baseMappingName : mappingConfig.extend) {
            if (StringUtils.isBlank(baseMappingName) || !mappings.containsKey(baseMappingName)) {
                throw new IllegalStateException("Base mapping name '" + baseMappingName + "' does not exists!");
            }
            Mapping baseMapping = mappings.get(baseMappingName);
            baseMapping.getMapping().forEach(curMap::putIfAbsent);
        }
    }

    // Filter out unwanted languages
    if (StringUtils.isNotBlank(mappingConfig.filter)) {
        List<Locale.LanguageRange> priorityList = Locale.LanguageRange.parse(mappingConfig.filter);
        List<Locale> toKeep = Locale.filter(priorityList, curMap.values());
        curMap.entrySet().removeIf(e -> !toKeep.contains(e.getValue()));
    }

    // Add new values
    if (mappingConfig.add != null) {
        mappingConfig.add.forEach((lang, values) -> {
            Locale langLocale = LocaleUtils.toLocale(lang);
            String[] displayValues = values.split(",");
            for (String value : displayValues) {
                String cleanedValue = value.trim();
                if (!cleanedValue.isEmpty()) {
                    curMap.putIfAbsent(cleanedValue, langLocale);
                }
            }
        });
    }

    // Override values
    if (mappingConfig.override != null) {
        mappingConfig.override.forEach((lang, values) -> {
            Locale langLocale = LocaleUtils.toLocale(lang);

            // Remove all existing mappings
            String langTag = langLocale.toLanguageTag();
            curMap.entrySet().removeIf(e -> e.getValue().toLanguageTag().equals(langTag));

            // Add new mappings.
            String[] displayValues = values.split(",");
            for (String value : displayValues) {
                String cleanedValue = value.trim();
                if (!cleanedValue.isEmpty()) {
                    curMap.put(cleanedValue, langLocale);
                }
            }
        });
    }

    return new CustomMapping(mappingConfig.name.trim()).withCaseSensitive(mappingConfig.casesensitive)
            .withMapping(curMap);
}

From source file:org.bigmouth.nvwa.utils.url.URLEncoder.java

public static String encode(Object obj, String jointChar, boolean sort, Comparator<String> comparator) {
    StringBuilder rst = new StringBuilder();
    List<String> list = Lists.newArrayList();
    Field[] fields = obj.getClass().getDeclaredFields();
    for (Field field : fields) {
        String fieldName = field.getName();
        String paramName = fieldName;
        if (field.isAnnotationPresent(Argument.class)) {
            paramName = field.getAnnotation(Argument.class).name();
        }/*from  w w  w .java2s.com*/
        String invokeName = StringUtils.join(new String[] { "get", StringUtils.capitalize(fieldName) });
        try {
            Object value = MethodUtils.invokeMethod(obj, invokeName, new Object[0]);
            if (null != value)
                list.add(StringUtils.join(new String[] { paramName, String.valueOf(value) }, "="));
        } catch (NoSuchMethodException e) {
            LOGGER.warn("NoSuchMethod-" + invokeName);
        } catch (IllegalAccessException e) {
            LOGGER.warn("IllegalAccess-" + invokeName);
        } catch (InvocationTargetException e) {
            LOGGER.warn("InvocationTarget-" + invokeName);
        }
    }
    if (sort)
        Collections.sort(list, (null != comparator) ? comparator : String.CASE_INSENSITIVE_ORDER);

    for (String item : list) {
        rst.append(item).append(jointChar);
    }
    return StringUtils.removeEnd(rst.toString(), jointChar);
}

From source file:uk.org.rbc1b.roms.db.common.MergeUtilTest.java

@Test
public void testMergeLeftEmpty() {
    final List<Pair<String, String>> outputs = new ArrayList<Pair<String, String>>();

    MergeUtil.merge(Collections.<String>emptyList(), Arrays.asList("foo"), String.CASE_INSENSITIVE_ORDER,
            new MergeUtil.Callback<String, String>() {
                @Override/*from  w w  w.  j av  a  2s.c  o m*/
                public void output(String leftValue, String rightValue) {
                    outputs.add(new ImmutablePair<String, String>(leftValue, rightValue));
                }
            });

    assertEquals(Arrays.asList(new ImmutablePair<String, String>(null, "foo")), outputs);
}

From source file:org.usergrid.utils.MapUtils.java

/**
 * @param <A>/*w  w w .  j  av  a 2s.  com*/
 * @param <B>
 * @param <C>
 * @param map
 * @param ignore_case
 * @param a
 * @param b
 * @param c
 */
@SuppressWarnings("unchecked")
public static <A, B, C> void addMapMapSet(Map<A, Map<B, Set<C>>> map, boolean ignore_case, A a, B b, C c) {

    Map<B, Set<C>> map_b = map.get(a);
    if (map_b == null) {
        if (ignore_case && (b instanceof String)) {
            map_b = (Map<B, Set<C>>) new TreeMap<String, Set<C>>(String.CASE_INSENSITIVE_ORDER);
        } else {
            map_b = new LinkedHashMap<B, Set<C>>();
        }
        map.put(a, map_b);
    }
    addMapSet(map_b, ignore_case, b, c);
}

From source file:org.carewebframework.cal.api.documents.Document.java

public Collection<String> getTypes() {
    if (types == null) {
        types = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
        CodeableConceptDt dt = reference.getType();
        List<CodingDt> codings = dt == null ? null : dt.getCoding();

        if (codings != null) {
            for (CodingDt coding : codings) {
                String type = coding.getDisplay().toString();

                if (!StringUtils.isEmpty(type)) {
                    types.add(type);/*  w ww  .j a  v  a  2 s  . c  o  m*/
                }
            }

        }
    }

    return types;
}

From source file:cool.pandora.modeller.util.ResourceList.java

/**
 * getResourceList./*from   w w w  .  ja v  a  2s .  co m*/
 *
 * @return resourceList
 */
public ArrayList<String> getResourceList() {
    try {
        final String resource = ModellerClient.doGetContainerResources(this.resourceContainerURI);
        final Model model = ModelFactory.createDefaultModel();
        model.read(new ByteArrayInputStream(resource != null ? resource.getBytes() : new byte[0]), null, "TTL");
        final ArrayList<String> resourceList = getChilden(model);
        resourceList.sort(String.CASE_INSENSITIVE_ORDER);
        return resourceList;
    } catch (final ModellerClientFailedException e) {
        System.out.println(getMessage(e));
    }
    return null;
}