/** * Parses titles if they are in the form Title (Year). The first element is the title, and the second element is the date, both can be null. If the * matcher fails to find the pattern, then the passed in title is set as the first element, which is the title. * * @param title * the title * @return the pair */ public static Pair<String, String> parseTitleAndDateInBrackets(String title) { if (title == null) return new Pair<>(null, null); Pattern p = Pattern.compile("(.*)\\s+\\(?([0-9]{4})\\)?", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(title); if (m.find()) { return new Pair<>(m.group(1), m.group(2)); } return new Pair<>(title, null); }
/** * Adds the header. * * @param key * the key * @param value * the value */ public void addHeader(String key, String value) { if (StringUtils.isBlank(key)) { return; } LOGGER.trace("add HTTP header: " + key + "=" + value); // looks like there is no need for duplicate check since some headers can // occur several times // Typically HTTP headers work like a Map<String, String>: each field has // one value or none. But some headers permit multiple values, like Guava's // Multimap. For example, it's legal and common for an HTTP response to // supply multiple Vary headers. for (int i = headersRequest.size() - 1; i >= 0; i--) { Pair<String, String> header = headersRequest.get(i); if (key.equals(header.first())) { headersRequest.remove(i); } } // and add the new one headersRequest.add(new Pair<>(key, value)); }