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.openhim.mediator.engine.MediatorRootActor.java

private void processGrizzlyRequest(final Inbox handlerInbox, final ActorRef requestHandler,
        final GrizzlyHTTPRequest request) throws IOException {
    final NIOReader in = request.getRequest().getNIOReader();

    final Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    for (String hdr : request.getRequest().getHeaderNames()) {
        headers.put(hdr, request.getRequest().getHeader(hdr));
    }/*from   w  ww .  java2  s  .c o m*/

    final Map<String, String> params = new HashMap<>();
    for (String param : request.getRequest().getParameterNames()) {
        params.put(param, request.getRequest().getParameter(param));
    }

    in.notifyAvailable(new ReadHandler() {
        final StringWriter bodyBuffer = new StringWriter();
        char[] readBuffer = new char[1024];

        private void read() throws IOException {
            while (in.isReady()) {
                int len = in.read(readBuffer);
                if (len > 0) {
                    bodyBuffer.write(readBuffer, 0, len);
                }
            }
        }

        @Override
        public void onDataAvailable() throws Exception {
            read();
            in.notifyAvailable(this);
        }

        @Override
        public void onError(Throwable throwable) {
            try {
                log.error(throwable, "Error during reading of request body");
                handleResponse(request.getResponseHandle(), 500, "text/plain", throwable.getMessage());
            } catch (IOException ex) {
                log.error(ex, "Error during reading of request body");
            } finally {
                request.getResponseHandle().resume();
            }
        }

        @Override
        public void onAllDataRead() throws Exception {
            try {
                read();
                MediatorHTTPRequest mediatorHTTPRequest = buildMediatorHTTPRequest(requestHandler, request,
                        bodyBuffer.toString(), headers, params);
                handlerInbox.send(requestHandler, mediatorHTTPRequest);
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    });
}

From source file:org.apache.syncope.core.persistence.jpa.content.XMLContentExporter.java

private List<String> sortByForeignKeys(final String dbSchema, final Connection conn,
        final Set<String> tableNames) throws SQLException {

    Set<MultiParentNode<String>> roots = new HashSet<>();

    final DatabaseMetaData meta = conn.getMetaData();

    final Map<String, MultiParentNode<String>> exploited = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    final Set<String> pkTableNames = new HashSet<>();

    for (String tableName : tableNames) {
        MultiParentNode<String> node = exploited.get(tableName);
        if (node == null) {
            node = new MultiParentNode<>(tableName);
            roots.add(node);/* w w  w .  j  ava2 s . co  m*/
            exploited.put(tableName, node);
        }

        pkTableNames.clear();

        ResultSet rs = null;
        try {
            rs = meta.getImportedKeys(conn.getCatalog(), dbSchema, tableName);

            // this is to avoid repetition
            while (rs.next()) {
                pkTableNames.add(rs.getString("PKTABLE_NAME"));
            }
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    LOG.error("While closing tables result set", e);
                }
            }
        }

        for (String pkTableName : pkTableNames) {
            if (!tableName.equalsIgnoreCase(pkTableName)) {
                MultiParentNode<String> pkNode = exploited.get(pkTableName);
                if (pkNode == null) {
                    pkNode = new MultiParentNode<>(pkTableName);
                    roots.add(pkNode);
                    exploited.put(pkTableName, pkNode);
                }

                pkNode.addChild(node);

                if (roots.contains(node)) {
                    roots.remove(node);
                }
            }
        }
    }

    final List<String> sortedTableNames = new ArrayList<>(tableNames.size());
    MultiParentNodeOp.traverseTree(roots, sortedTableNames);

    // remove from sortedTableNames any table possibly added during lookup 
    // but matching some item in this.tablePrefixesToBeExcluded
    sortedTableNames.retainAll(tableNames);

    LOG.debug("Tables after retainAll {}", sortedTableNames);

    Collections.reverse(sortedTableNames);

    return sortedTableNames;
}

From source file:net.landora.video.utils.UIUtils.java

public static String getFirstAvaliableFamily(String... fontFamilies) {
    Map<String, String> families = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (String family : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) {
        families.put(family, family);//from  www  . j a va  2s  . c o  m
    }

    for (String family : fontFamilies) {
        String result = families.get(family);
        if (result != null) {
            return result;
        }
    }

    return null;
}

From source file:com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchUtilities.java

/**
 * Reads headers from the batch starting from the given position.
 *
 * @param iterator batch iterator./*from  w w w  . ja va 2  s . c  o m*/
 * @return Map of header name in header values.
 */
public static Map<String, Collection<String>> readHeaders(final ODataBatchLineIterator iterator) {
    final Map<String, Collection<String>> target = new TreeMap<String, Collection<String>>(
            String.CASE_INSENSITIVE_ORDER);

    readHeaders(iterator, target);
    return target;
}

From source file:de.tor.tribes.util.VillageUtils.java

public static String[] getContinents(Tribe pTribe) {
    if (pTribe == null || pTribe.equals(Barbarians.getSingleton())) {
        return new String[0];
    }//from w w w  .j a v a2  s. co m
    List<String> continents = new ArrayList<>();

    for (Village v : pTribe.getVillageList()) {
        int cont = v.getContinent();
        String sCont = "K" + ((cont < 10) ? "0" + cont : cont);
        if (!continents.contains(sCont)) {
            continents.add(sCont);
        }
    }
    Collections.sort(continents, String.CASE_INSENSITIVE_ORDER);
    return continents.toArray(new String[continents.size()]);
}

From source file:com.genentech.application.calcProps.SDFCalcProps.java

/**
 * Get the list of SD tags that a property produces
 * also gets the tags that are produced by calculators this property depends on aka "required tags"
 * "required tags" are defined in the keepRequiredCalculators field on the XML files
*///from  w ww .  java2 s.c om
private static TreeSet<String> getOutputFields(String prop, Set<Calculator> calculators, boolean verbose) {
    TreeSet<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    for (Calculator calc : calculators) {
        if (calc.getName().equals(prop)) {
            //add tags for calculator
            tags.addAll(calc.getOutputFields());
            if (verbose) {
                tags.addAll(calc.getVerboseFields());
            }
            //get tags for keepRequiredCalculators, recursively
            Set<String> requiredCalcs = calc.getKeepRequiredCalculators();
            for (String c : requiredCalcs) {
                tags.addAll(getOutputFields(c, calculators, verbose));
            }
        }
    }
    return tags;
}

From source file:eu.peppol.as2.MdnMimeMessageInspector.java

public Map<String, String> getMdnFields() {
    Map<String, String> ret = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    try {/*from   w  ww  .j  ava  2  s  .  c o  m*/

        BodyPart bp = getMessageDispositionNotificationPart();
        boolean contentIsBase64Encoded = false;

        //
        // look for base64 transfer encoded MDN's (when Content-Transfer-Encoding is present)
        //
        // Content-Type: message/disposition-notification
        // Content-Transfer-Encoding: base64
        //
        // "Content-Transfer-Encoding not used in HTTP transport Because HTTP, unlike SMTP,
        // does not have an early history involving 7-bit restriction.
        // There is no need to use the Content Transfer Encodings of MIME."
        //
        String[] contentTransferEncodings = bp.getHeader("Content-Transfer-Encoding");
        if (contentTransferEncodings != null && contentTransferEncodings.length > 0) {
            if (contentTransferEncodings.length > 1)
                log.warn("MDN has multiple Content-Transfer-Encoding, we only try the first one");
            String encoding = contentTransferEncodings[0];
            if (encoding == null)
                encoding = "";
            encoding = encoding.trim();
            log.info("MDN specifies Content-Transfer-Encoding : '" + encoding + "'");
            if ("base64".equalsIgnoreCase(encoding)) {
                contentIsBase64Encoded = true;
            }
        }

        Object content = bp.getContent();
        if (content instanceof InputStream) {
            InputStream contentInputStream = (InputStream) content;

            if (contentIsBase64Encoded) {
                log.debug("MDN seems to be base64 encoded, wrapping content stream in Base64 decoding stream");
                contentInputStream = new Base64InputStream(contentInputStream); // wrap in base64 decoding stream
            }

            BufferedReader r = new BufferedReader(new InputStreamReader(contentInputStream));
            while (r.ready()) {
                String line = r.readLine();
                int firstColon = line.indexOf(":"); // "Disposition: ......"
                if (firstColon > 0) {
                    String key = line.substring(0, firstColon).trim(); // up to :
                    String value = line.substring(firstColon + 1).trim(); // skip :
                    ret.put(key, value);
                }
            }
        } else {
            throw new Exception("Unsupported MDN content, expected InputStream found @ " + content.toString());
        }

    } catch (Exception e) {
        throw new IllegalStateException("Unable to retrieve the values from the MDN : " + e.getMessage(), e);
    }
    return ret;
}

From source file:lumbermill.internal.aws.AWSV4SignerImpl.java

public Map<String, String> getSignedHeaders(String uri, String method, Map<String, String> queryParams,
        Map<String, String> headers, Optional<byte[]> payload) {
    final LocalDateTime now = clock.get();
    final AWSCredentials credentials = credentialsProvider.getCredentials();
    final Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    result.putAll(headers);//  ww  w .j a v a2  s . co m
    if (!result.containsKey(DATE)) {
        result.put(X_AMZ_DATE, now.format(BASIC_TIME_FORMAT));
    }
    if (AWSSessionCredentials.class.isAssignableFrom(credentials.getClass())) {
        result.put(SESSION_TOKEN, ((AWSSessionCredentials) credentials).getSessionToken());
    }

    final StringBuilder headersString = new StringBuilder();
    final ImmutableList.Builder<String> signedHeaders = ImmutableList.builder();

    for (Map.Entry<String, String> entry : result.entrySet()) {
        headersString.append(headerAsString(entry)).append(RETURN);
        signedHeaders.add(entry.getKey().toLowerCase());
    }

    final String signedHeaderKeys = JOINER.join(signedHeaders.build());
    final String canonicalRequest = method + RETURN + uri + RETURN + queryParamsString(queryParams) + RETURN
            + headersString.toString() + RETURN + signedHeaderKeys + RETURN
            + toBase16(hash(payload.orElse(EMPTY.getBytes(Charsets.UTF_8))));
    final String stringToSign = createStringToSign(canonicalRequest, now);
    final String signature = sign(stringToSign, now, credentials);
    final String autorizationHeader = AWS4_HMAC_SHA256_CREDENTIAL + credentials.getAWSAccessKeyId() + SLASH
            + getCredentialScope(now) + SIGNED_HEADERS + signedHeaderKeys + SIGNATURE + signature;

    result.put(AUTHORIZATION, autorizationHeader);
    return ImmutableMap.copyOf(result);
}

From source file:edu.ku.brc.specify.ui.db.PickListTableAdapter.java

/**
 * Fills non-Item type PickLists from a Table.
 * @param type the type to be filled/*from  w ww .  j a  va2s  .  c o m*/
 */
protected void fill(final PickListDBAdapterIFace.Type type) {
    if (type != PickListDBAdapterIFace.Type.Item) {
        DBTableInfo tableInfo = DBTableIdMgr.getInstance()
                .getInfoById(DBTableIdMgr.getInstance().getIdByShortName(pickList.getTableName()));
        if (tableInfo != null) {
            DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession();
            try {
                boolean isBasicType = false;
                boolean isFromField = type == PickListDBAdapterIFace.Type.TableField;
                if (isFromField) {
                    DBFieldInfo fi = tableInfo.getFieldByColumnName(pickList.getFieldName());
                    isBasicType = fi != null ? UIHelper.isPrimitiveObjectType(fi.getDataClass()) : false;
                }

                String sqlStr = buildHQL(tableInfo,
                        type == PickListDBAdapterIFace.Type.TableField ? pickList.getFieldName() : null);
                //log.debug(sqlStr);
                if (StringUtils.isNotEmpty(sqlStr)) {
                    List<?> dataList = session.getDataList(sqlStr);
                    if (dataList != null && !dataList.isEmpty()) {
                        if (type == PickListDBAdapterIFace.Type.TableField) {
                            TreeSet<String> values = isBasicType
                                    ? new TreeSet<String>(String.CASE_INSENSITIVE_ORDER)
                                    : null;
                            String formatterStr = isBasicType ? null : pickList.getFormatter();
                            boolean hasFormatter = StringUtils.isNotEmpty(formatterStr);
                            for (Object dataObj : dataList) {
                                if (dataObj instanceof Object[]) {
                                    dataObj = ((Object[]) dataObj)[0];
                                }

                                if (dataObj != null) {
                                    String valStr = hasFormatter ? String.format(formatterStr, dataObj)
                                            : dataObj.toString();
                                    if (isBasicType) {
                                        values.add(valStr);
                                    } else {
                                        items.add(pickList.addItem(valStr, valStr));
                                    }
                                }
                            }

                            if (isBasicType) {
                                for (String v : values) {
                                    items.add(pickList.addItem(v, v));
                                }
                            }
                        } else {
                            for (Object dataObj : dataList) {
                                if (dataObj instanceof Object[]) {
                                    dataObj = ((Object[]) dataObj)[0];
                                }
                                String title;
                                if (pickList.getFormatter() != null) {
                                    title = DataObjFieldFormatMgr.getInstance().format(dataObj,
                                            pickList.getFormatter());
                                } else {
                                    title = ((FormDataObjIFace) dataObj).getIdentityTitle();
                                }
                                items.add(pickList.addItem(title, dataObj));
                            }
                        }

                    } else {
                        // No Data Error
                    }

                } else {
                    log.error("Query String is empty for tableId[" + tableInfo.getTableId() + "]");
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                log.error(ex);
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PickListTableAdapter.class, ex);

            } finally {
                if (session != null) {
                    session.close();
                }
            }

        } else {
            throw new RuntimeException(
                    "Error looking up PickLIst's Table Name [" + pickList.getTableName() + "]");
        }
    }
}

From source file:ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject.java

@Override
public int compareTo(CharacteristicValueObject o) {
    return ComparisonChain.start()
            .compare(category, o.category, Ordering.from(String.CASE_INSENSITIVE_ORDER).nullsLast())
            .compare(taxon, o.taxon, Ordering.from(String.CASE_INSENSITIVE_ORDER).nullsLast())
            .compare(value, o.value, Ordering.from(String.CASE_INSENSITIVE_ORDER).nullsLast())
            .compare(valueUri, o.valueUri, Ordering.from(String.CASE_INSENSITIVE_ORDER).nullsLast()).result();
}