Example usage for java.util AbstractMap.SimpleEntry AbstractMap.SimpleEntry

List of usage examples for java.util AbstractMap.SimpleEntry AbstractMap.SimpleEntry

Introduction

In this page you can find the example usage for java.util AbstractMap.SimpleEntry AbstractMap.SimpleEntry.

Prototype

public SimpleEntry(K key, V value) 

Source Link

Document

Creates an entry representing a mapping from the specified key to the specified value.

Usage

From source file:org.kuali.rice.core.impl.security.PropertySuppressionServiceImpl.java

private static <K, V> Map.Entry<K, V> entry(K key, V value) {
    return new AbstractMap.SimpleEntry<K, V>(key, value);
}

From source file:org.apache.metron.dataloads.extractor.csv.CSVExtractor.java

private static Map.Entry<String, Integer> getColumnMapEntry(String column, int i) {
    if (column.contains(":")) {
        Iterable<String> tokens = Splitter.on(':').split(column);
        String col = Iterables.getFirst(tokens, null);
        Integer pos = Integer.parseInt(Iterables.getLast(tokens));
        return new AbstractMap.SimpleEntry<>(col, pos);
    } else {//from  ww w . j  a  v a2  s  .  c  o m
        return new AbstractMap.SimpleEntry<>(column, i);
    }

}

From source file:com.agileapes.couteau.http.io.impl.ImmutableHttpRequest.java

public ImmutableHttpRequest(URI uri, HttpRequestMethod method, HttpEntity data, List<HttpHeader> headers,
        RequestConfig requestConfig) {//from w ww.ja v a 2 s .  com
    this.method = method;
    this.uri = uri;
    this.data = data;
    this.headers = headers == null ? Collections.<HttpHeader>emptyList()
            : with(headers).transform(new Transformer<HttpHeader, HttpHeader>() {
                @Override
                public HttpHeader map(HttpHeader input) {
                    return new ImmutableHttpHeader(input.getName(), input.getValue());
                }
            }).list();
    this.config = requestConfig;
    parameters = new HashMap<String, String>();
    final List<Map.Entry<String, String>> entries = with(
            (this.uri.getQuery() == null ? "" : this.uri.getQuery()).split("&"))
                    .transform(new Transformer<String, Map.Entry<String, String>>() {
                        @Override
                        public Map.Entry<String, String> map(String input) {
                            final String[] strings = input.split("=", 2);
                            return new AbstractMap.SimpleEntry<String, String>(strings[0],
                                    strings.length > 1 ? strings[1] : "");
                        }
                    }).list();
    for (Map.Entry<String, String> entry : entries) {
        parameters.put(entry.getKey(), entry.getValue());
    }
}

From source file:com.orange.servicebroker.staticcreds.stories.get_syslog_drain_url.CreateLogDrainServiceBindingTest.java

@Test
public void create_service_binding_with_static_syslog_drain_url_set_at_service_level() throws Exception {
    given().syslog_drain_url_set_in_catalog(
            service_broker_properties_with_syslog_drain_url_at_service_level_with_requires_field_set());
    when().cloud_controller_requests_to_create_a_service_instance_binding_for_plan_id("dev-id");
    then().it_should_be_returned_with_syslog_drain_url(
            new CreateServiceInstanceAppBindingResponse().withSyslogDrainUrl("syslog://log.example.com:5000")
                    .withCredentials(Collections.unmodifiableMap(
                            Stream.of(new AbstractMap.SimpleEntry<>("URI", "http://my-api.org"))
                                    .collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue())))));
}

From source file:crawl.BasicCrawler.java

/**
 * This function is called when a page is fetched and ready to be processed
 * by your program.//from ww w .j  av a 2  s  .c  om
 */
@Override
public void visit(Page page) {
    pagecount++;
    System.out.printf("pagecount is %d\n", pagecount);

    //if(tokengen==null) tokengen = new tokenGen();
    boolean pagemod = false;
    int docid = page.getWebURL().getDocid();
    String url = page.getWebURL().getURL();
    String domain = page.getWebURL().getDomain();
    String path = page.getWebURL().getPath();
    String subDomain = page.getWebURL().getSubDomain();
    String parentUrl = page.getWebURL().getParentUrl();
    String anchor = page.getWebURL().getAnchor();

    logger.debug("Docid: {}", docid);
    logger.info("URL: {}", url);
    logger.debug("Domain: '{}'", domain);
    logger.debug("Sub-domain: '{}'", subDomain);
    logger.debug("Path: '{}'", path);
    logger.debug("Parent page: {}", parentUrl);
    logger.debug("Anchor text: {}", anchor);

    if (page.getParseData() instanceof HtmlParseData) {

        HtmlParseData htmlParseData = (HtmlParseData) page.getParseData();
        String text = htmlParseData.getText();
        String title = htmlParseData.getTitle();
        Map<String, String> metaTags = htmlParseData.getMetaTags();

        //filestorage.insertURLPage(url,text);
        AbstractMap.SimpleEntry<String, String> test = new AbstractMap.SimpleEntry<String, String>(url, text);
        //System.out.println(test.getKey()+" "+test.getValue());
        pages.add(test);
        titleList.add(title);
        metaTagList.add(metaTags);
        anchorList.add(anchor);
        //commit into DB for every 20 pages

        if (pagecount % 500 == 0) {
            System.out.println("**********Inserting**********************");
            filestorage.insertURLPage(pages, titleList, anchorList, metaTagList);
            pages.clear();
            titleList.clear();
            metaTagList.clear();
            anchorList.clear();
            System.out.println("**********Insert complete****************");
        }

        String html = htmlParseData.getHtml();
        Set<WebURL> links = htmlParseData.getOutgoingUrls();

        logger.debug("Text length: {}", text.length());
        logger.debug("Html length: {}", html.length());
        logger.debug("Number of outgoing links: {}", links.size());
    }

    Header[] responseHeaders = page.getFetchResponseHeaders();
    if (responseHeaders != null) {
        logger.debug("Response headers:");
        for (Header header : responseHeaders) {
            logger.debug("\t{}: {}", header.getName(), header.getValue());
        }
    }
    logger.debug("=============");
}

From source file:com.orange.servicebroker.staticcreds.stories.get_syslog_drain_url.CreateLogDrainServiceBindingTest.java

@Test
public void create_service_binding_with_static_syslog_drain_url_set_at_service_plan_level() throws Exception {
    given().syslog_drain_url_set_in_catalog(
            service_broker_properties_with_syslog_drain_url_at_service_plan_level_with_requires_field_set());
    when().cloud_controller_requests_to_create_a_service_instance_binding_for_plan_id("dev-id");
    then().it_should_be_returned_with_syslog_drain_url(
            new CreateServiceInstanceAppBindingResponse().withSyslogDrainUrl("syslog://log.dev.com:5000")
                    .withCredentials(Collections.unmodifiableMap(
                            Stream.of(new AbstractMap.SimpleEntry<>("URI", "http://my-api.org"))
                                    .collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue())))));
}

From source file:com.servioticy.dispatcher.jsonprocessors.JsonPathReplacer.java

public JsonPathReplacer(String str, ObjectMapper mapper, Set<String> excludedDocIds) {
    this.mapper = mapper;
    this.jsonPaths = new TreeMap<Integer, LinkedList<Map.Entry<String, JsonPath>>>();
    this.str = str;

    // compile JsonPaths on the String
    for (int firstIndex = 0; firstIndex < this.str.length();) {
        firstIndex = this.str.indexOf("{", firstIndex);

        if (firstIndex == -1) {
            break;
        }//w ww  . j  av  a  2s . c o m
        if ((firstIndex != 0) && (this.str.charAt(firstIndex - 1) == '\\')) {
            firstIndex++;
            continue;
        }

        int lastIndex;
        for (lastIndex = firstIndex; lastIndex < this.str.length(); lastIndex++) {
            lastIndex = this.str.indexOf("}", lastIndex);
            if (lastIndex == -1) {
                break;
            }
            // Ignore if escaped.
            if (this.str.charAt(lastIndex - 1) == '\\') {
                lastIndex++;
                continue;
            }
            break;
        }
        if (lastIndex == -1) {
            break;
        }

        String jsonPath = this.str.substring(firstIndex + 1, lastIndex);
        String jsonId = "";
        // Check that right after the '{' char there is the '$' character (may be spaces in between). Then get
        //   the substring between the '$' and the '.' and use it as JSON id.
        int iDollar = jsonPath.indexOf("$");
        int endJsonId = jsonPath.indexOf('.', iDollar);
        endJsonId = endJsonId != -1 ? endJsonId : jsonPath.length();
        if (iDollar == -1) {
            firstIndex = lastIndex;
            continue;
        }

        //         // Exclude jsonIds
        //         
        //         if(excludedDocIds.contains(jsonId)){
        //            firstIndex++;
        //            continue;
        //         }

        // Change the index of the JsonPaths already existing in positions further than firstIndex.
        // Also, if any of those JsonPaths are before lastIndex, ignore it.
        //         int indexOffset = (lastIndex-1) - (firstIndex+1);
        //         boolean recJsonPath = false;

        // If there is a jsonId, extract it from the jsonPath and make the jsonPath 'standard'
        if (iDollar + 1 != endJsonId) {
            jsonId = jsonPath.substring(iDollar + 1, endJsonId);
            jsonPath = deleteSubstring(jsonPath, iDollar + 1, endJsonId);
        }

        // Escape \\{ and \\}
        unescapeChar(jsonPath, '{');
        unescapeChar(jsonPath, '}');
        JsonPath jp;
        try {
            jp = JsonPath.compile(jsonPath);
        } catch (java.lang.IllegalArgumentException e) {
            // If the detected JsonPath is invalid for any reason, simply ignore it.
            firstIndex++;
            continue;
        }

        //         // jpstr.jsonPaths is ordered by key.
        //         for(Entry<Integer, LinkedList<Entry<String, JsonPath>>> currentJpList : this.jsonPaths.entrySet()){
        //            if(currentJpList.getKey() > firstIndex){
        //               if(currentJpList.getKey() <= lastIndex){
        //                  recJsonPath = true;
        //                  break;
        //               }
        //               int newIndex = currentJpList.getKey() - indexOffset;
        //               if(this.jsonPaths.get(newIndex) != null){
        //                  this.jsonPaths.get(newIndex).addAll(currentJpList.getValue());
        //               }
        //               else{
        //                  this.jsonPaths.put(newIndex, currentJpList.getValue());
        //               }
        //               this.jsonPaths.remove(currentJpList.getKey());
        //            }
        //         }
        //         if(recJsonPath){
        //            firstIndex++;
        //            continue;
        //         }
        LinkedList<Entry<String, JsonPath>> jplist = new LinkedList<Entry<String, JsonPath>>();
        jplist.add(new AbstractMap.SimpleEntry<String, JsonPath>(jsonId, jp));

        if (this.jsonPaths.get(firstIndex) != null) {
            this.jsonPaths.get(firstIndex).addAll(jplist);
        } else {
            this.jsonPaths.put(firstIndex, jplist);
        }

        this.str = deleteSubstring(this.str, firstIndex, lastIndex + 1);
    }
    // Escape \\{ and \\}
    unescapeChar(this.str, '{');
    unescapeChar(this.str, '}');
}

From source file:org.apache.metron.maas.service.callback.LaunchContainer.java

private Map.Entry<String, LocalResource> localizeResource(FileStatus status) {
    URL url = ConverterUtils.getYarnUrlFromURI(status.getPath().toUri());
    LocalResource resource = LocalResource.newInstance(url, LocalResourceType.FILE,
            LocalResourceVisibility.APPLICATION, status.getLen(), status.getModificationTime());
    String name = status.getPath().getName();
    return new AbstractMap.SimpleEntry<>(name, resource);
}

From source file:io.klerch.alexa.tellask.util.resource.YamlReader.java

@SuppressWarnings("unchecked")
private List<String> getPhrasesForIntent(final String intentName, final Integer index) {
    Validate.notBlank(intentName, "Intent name is null or empty.");
    // return list of utterances if already read out and saved to local list
    final List<Object> contents = phrases.entrySet().stream().filter(k -> k.getKey().equals(intentName))
            .findFirst()/*from  w w  w .  j ava 2  s .c o m*/
            // otherwise load utterances from resource of utterance reader
            .orElse(new AbstractMap.SimpleEntry<>(intentName, loadUtterances(intentName))).getValue();
    // cache the result
    phrases.putIfAbsent(intentName, contents);

    final List<String> utterances = new ArrayList<>();

    if (contents.size() > index) {
        // group node assumed to be an array list
        final Object assumedUtteranceCollection = contents.get(index);

        if (assumedUtteranceCollection instanceof ArrayList) {
            // parse each phrase as string and add to return collection
            ((ArrayList) assumedUtteranceCollection).stream().map(resolveMultiPhrases).map(resolvePlaceholders)
                    .forEach(utterance -> utterances.add(String.valueOf(utterance)));
        } else if (assumedUtteranceCollection instanceof String) {
            utterances.add(String.valueOf(assumedUtteranceCollection));
        }
    }
    return utterances;
}

From source file:org.wikipedia.citolytics.cpa.types.WikiDocument.java

private void extractLinks() {
    outLinks = new ArrayList<>();

    // [[Zielartikel|alternativer Text]]
    // [[Artikelname]]
    // [[#Wikilink|Wikilink]]
    Pattern p = Pattern.compile("\\[\\[(.*?)((\\||#).*?)?\\]\\]");

    String text = raw; //.toLowerCase();

    // strip "see also" section
    text = stripSeeAlsoSection(text);//from   ww w  .ja  va2s. co  m

    /* Remove all interwiki links */
    Pattern p2 = Pattern.compile("\\[\\[(\\w\\w\\w?|simple)(-[\\w-]*)?:(.*?)\\]\\]");
    text = p2.matcher(text).replaceAll("");
    Matcher m = p.matcher(text);

    while (m.find()) {
        if (m.groupCount() >= 1) {
            target = m.group(1).trim();

            if (target.length() > 0 && !target.contains("<") && !target.contains(">")
                    && startsNotWith(target.toLowerCase(), listOfStopPatterns)) {
                // First char is not case sensitive
                target = org.apache.commons.lang.StringUtils.capitalize(target);
                outLinks.add(new AbstractMap.SimpleEntry<>(target, m.start()));
            }
        }
    }
}