List of usage examples for java.util Map putIfAbsent
default V putIfAbsent(K key, V value)
From source file:org.apdplat.superword.tools.WordClassifier.java
public static void parse(String word, String html, Map<String, List<String>> data) { Document doc = Jsoup.parse(html); Elements es = doc.select(TYPE_CSS_PATH); for (Element e : es) { String type = e.text();/* ww w . jav a 2s .c om*/ LOGGER.debug("?" + type); if (StringUtils.isNotBlank(type)) { data.putIfAbsent(type, new ArrayList<>()); data.get(type).add(word); } } es = doc.select(UNFOUND_CSS_PATH); for (Element e : es) { String notFound = e.text(); LOGGER.debug("?" + notFound); if (StringUtils.isNotBlank(notFound) && (notFound.contains("?") || notFound.contains("??"))) { NOT_FOUND_WORDS.add(word); } } }
From source file:org.apdplat.superword.tools.JavaCodeAnalyzer.java
public static Map<String, AtomicInteger> parseDir(String dir) { LOGGER.info("?" + dir); Map<String, AtomicInteger> data = new HashMap<>(); try {// w w w . j a v a2 s .c om Files.walkFileTree(Paths.get(dir), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Map<String, AtomicInteger> r = parseFile(file.toFile().getAbsolutePath()); r.keySet().forEach(k -> { data.putIfAbsent(k, new AtomicInteger()); data.get(k).addAndGet(r.get(k).get()); }); r.clear(); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { LOGGER.error("?", e); } return data; }
From source file:org.apache.metron.parsers.topology.ParserTopologyBuilder.java
/** * Create a spout that consumes tuples from a Kafka topic. * * @param zkQuorum Zookeeper URL//from w w w . j av a2 s. co m * @param sensorType Type of sensor * @param kafkaConfigOptional Configuration options for the kafka spout * @param parserConfig Configuration for the parser * @return */ private static StormKafkaSpout<Object, Object> createKafkaSpout(String zkQuorum, String sensorType, Optional<String> securityProtocol, Optional<Map<String, Object>> kafkaConfigOptional, SensorParserConfig parserConfig) { Map<String, Object> kafkaSpoutConfigOptions = kafkaConfigOptional.orElse(new HashMap<>()); String inputTopic = parserConfig.getSensorTopic() != null ? parserConfig.getSensorTopic() : sensorType; kafkaSpoutConfigOptions.putIfAbsent(SpoutConfiguration.FIRST_POLL_OFFSET_STRATEGY.key, KafkaSpoutConfig.FirstPollOffsetStrategy.UNCOMMITTED_EARLIEST.name()); kafkaSpoutConfigOptions.putIfAbsent(ConsumerConfig.GROUP_ID_CONFIG, inputTopic + "_parser"); if (securityProtocol.isPresent()) { kafkaSpoutConfigOptions.putIfAbsent("security.protocol", KafkaUtils.INSTANCE.normalizeProtocol(securityProtocol.get())); } return SimpleStormKafkaBuilder.create(inputTopic, zkQuorum, Arrays.asList(SimpleStormKafkaBuilder.FieldsConfiguration.VALUE.getFieldName(), SimpleStormKafkaBuilder.FieldsConfiguration.KEY.getFieldName(), SimpleStormKafkaBuilder.FieldsConfiguration.TOPIC.getFieldName()), kafkaSpoutConfigOptions); }
From source file:org.apdplat.superword.tools.JavaCodeAnalyzer.java
public static Map<String, AtomicInteger> parseFile(String file) { Map<String, AtomicInteger> data = new HashMap<>(); LOGGER.info("?" + file); try (BufferedReader reader = new BufferedReader( new InputStreamReader(new BufferedInputStream(new FileInputStream(file))))) { String line = null;//from www . j a va 2 s .c o m while ((line = reader.readLine()) != null) { List<String> words = TextAnalyzer.seg(line); words.forEach(word -> { data.putIfAbsent(word, new AtomicInteger()); data.get(word).incrementAndGet(); }); words.clear(); } } catch (IOException e) { LOGGER.error("?", e); } return data; }
From source file:org.openecomp.sdc.vendorsoftwareproduct.services.CompositionDataExtractor.java
private static Map<String, List<String>> getNodeTemplatesGroupedByType( Map<String, NodeTemplate> nodeTemplates) { Map<String, List<String>> nodeTemplatesGrouped = new HashMap<>(); //key - node type, value - list of node ids with this type for (String nodeId : nodeTemplates.keySet()) { String nodeType = nodeTemplates.get(nodeId).getType(); nodeTemplatesGrouped.putIfAbsent(nodeType, new ArrayList<>()); nodeTemplatesGrouped.get(nodeType).add(nodeId); }/* ww w . j a va 2s .c o m*/ return nodeTemplatesGrouped; }
From source file:org.codice.ddf.commands.catalog.ExportCommand.java
/** * Generates stateful predicate to filter distinct elements by a certain key in the object. * * @param keyExtractor Function to pull the desired key out of the object * @return the stateful predicate/*from w ww . ja v a2 s . c om*/ */ private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { Map<Object, Boolean> seen = new ConcurrentHashMap<>(); return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; }
From source file:org.apdplat.superword.tools.WordClassifierForYouDao.java
public static void parse(String word, String html, Map<String, List<String>> data) { Document doc = Jsoup.parse(html); Elements es = doc.select(TYPE_CSS_PATH); for (Element e : es) { String types = e.text();/*from w w w. j av a 2 s . co m*/ LOGGER.debug("?" + types); for (String type : types.split("\\s+")) { if (StringUtils.isNotBlank(type)) { data.putIfAbsent(type, new ArrayList<>()); data.get(type).add(word); } } } es = doc.select(UNFOUND_CSS_PATH); for (Element e : es) { String notFound = e.text(); LOGGER.debug("?" + notFound); if (StringUtils.isNotBlank(notFound) && (notFound.contains("?") || notFound.contains("??"))) { NOT_FOUND_WORDS.add(word); } } }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesProviderUtils.java
static void upsertSecret(AccountDeploymentDetails<KubernetesAccount> details, Set<Pair<File, String>> files, String secretName, String namespace) { KubernetesClient client = getClient(details); if (client.secrets().inNamespace(namespace).withName(secretName).get() != null) { client.secrets().inNamespace(namespace).withName(secretName).delete(); }/*from w w w . ja v a 2 s . c o m*/ Map<String, String> secretContents = new HashMap<>(); files.forEach(pair -> { try { File file = pair.getLeft(); String name = pair.getRight(); String data = new String( Base64.getEncoder().encode(IOUtils.toByteArray(new FileInputStream(file)))); secretContents.putIfAbsent(name, data); } catch (IOException e) { throw new HalException(Severity.ERROR, "Unable to read contents of \"" + pair.getLeft() + "\": " + e); } }); SecretBuilder secretBuilder = new SecretBuilder(); secretBuilder = secretBuilder.withNewMetadata().withName(secretName).withNamespace(namespace).endMetadata() .withData(secretContents); client.secrets().inNamespace(namespace).create(secretBuilder.build()); }
From source file:org.apdplat.superword.tools.TextAnalyzer.java
/** * @param files ?//from ww w .ja v a2 s. com * @return ?? */ public static Map<String, AtomicInteger> frequency(Collection<String> files) { Map<String, AtomicInteger> map = new ConcurrentHashMap<>(); files.forEach(file -> { LOGGER.info("parse text file: " + file); //? Map<String, AtomicInteger> data = frequency(file); //? data.entrySet().forEach(entry -> { map.putIfAbsent(entry.getKey(), new AtomicInteger()); map.get(entry.getKey()).addAndGet(entry.getValue().get()); }); data.clear(); }); LOGGER.info("total unique words count: " + map.size()); return map; }
From source file:org.apdplat.superword.rule.TextAnalysis.java
/** * @param files ?/* w w w . j a v a 2s .co m*/ * @return ?? */ public static Map<String, AtomicInteger> frequency(Collection<String> files) { Map<String, AtomicInteger> map = new ConcurrentHashMap<>(); for (String file : files) { LOGGER.info("parse text file: " + file); //? Map<String, AtomicInteger> data = frequency(file); //? data.entrySet().forEach(entry -> { map.putIfAbsent(entry.getKey(), new AtomicInteger()); map.get(entry.getKey()).addAndGet(entry.getValue().get()); }); data.clear(); } LOGGER.info("total unique words count: " + map.size()); return map; }