List of usage examples for java.util Map forEach
default void forEach(BiConsumer<? super K, ? super V> action)
From source file:DeliverWork.java
public static void main(String[] args) throws UnsupportedEncodingException, MessagingException { JdbcFactory jdbcFactoryChanye = new JdbcFactory( "jdbc:mysql://127.0.0.1:3306/fp_guimin?useUnicode=true&characterEncoding=UTF-8", "guimin_db", "guimin@98fhi3p2hUFHfdfoi", "com.mysql.jdbc.Driver"); connection = jdbcFactoryChanye.getConnection(); Map<String, String> map = new HashMap(); try {/*from w w w. j ava2 s .co m*/ PreparedStatement ps = connection.prepareStatement(selectAccount); ResultSet resultSet = ps.executeQuery(); while (resultSet.next()) { map.put(resultSet.getString(1), resultSet.getString(2)); } ps.close(); map.forEach((k, v) -> { syncTheFile(k, v); }); connection.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:es.uam.eps.ir.ranksys.examples.RerankerExample.java
public static void main(String[] args) throws Exception { String trainDataPath = args[0]; String featurePath = args[1]; String recIn = args[2];//w ww . j a va 2 s. co m int cutoff = 100; PreferenceData<Long, Long> trainData = SimplePreferenceData .load(SimpleRatingPreferencesReader.get().read(trainDataPath, lp, lp)); FeatureData<Long, String, Double> featureData = SimpleFeatureData .load(SimpleFeaturesReader.get().read(featurePath, lp, sp)); Map<String, Supplier<Reranker<Long, Long>>> rerankersMap = new HashMap<>(); rerankersMap.put("MMR", () -> { double lambda = 0.5; ItemDistanceModel<Long> dist = new JaccardFeatureItemDistanceModel<>(featureData); return new MMR<>(lambda, cutoff, dist); }); rerankersMap.put("xQuAD", () -> { double lambda = 0.5; IntentModel<Long, Long, String> intentModel = new FeatureIntentModel<>(trainData, featureData); AspectModel<Long, Long, String> aspectModel = new ScoresAspectModel<>(intentModel); return new XQuAD<>(aspectModel, lambda, cutoff, true); }); rerankersMap.put("RxQuAD", () -> { double alpha = 0.5; double lambda = 0.5; IntentModel<Long, Long, String> intentModel = new FeatureIntentModel<>(trainData, featureData); AspectModel<Long, Long, String> aspectModel = new ScoresRelevanceAspectModel<>(intentModel); return new AlphaXQuAD<>(aspectModel, alpha, lambda, cutoff, true); }); rerankersMap.put("PM", () -> { double alpha = 0.5; double lambda = 0.9; BinomialModel<Long, Long, String> binomialModel = new BinomialModel<>(false, Stream.empty(), trainData, featureData, alpha); return new PM<>(featureData, binomialModel, lambda, cutoff); }); RecommendationFormat<Long, Long> format = new SimpleRecommendationFormat<>(lp, lp); rerankersMap.forEach(Unchecked.biConsumer((name, rerankerSupplier) -> { String recOut = Paths.get(Paths.get(recIn).getParent().toString(), String.format("%s-%s", name, FilenameUtils.getName(recIn))).toString(); System.out.printf("running %s, output to %s\n", name, recOut); Reranker<Long, Long> reranker = rerankerSupplier.get(); try (RecommendationFormat.Writer<Long, Long> writer = format.getWriter(recOut)) { format.getReader(recIn).readAll().map(rec -> reranker.rerankRecommendation(rec, cutoff)) .forEach(Unchecked.consumer(writer::write)); } })); }
From source file:com.khartec.waltz.jobs.AppHarness.java
private static void prettyPrint(Map<AssetCodeRelationshipKind, List<Application>> grouped) { grouped.forEach((key, apps) -> System.out .println(key.name() + map(apps, relatedApp -> "\n\t" + toString(relatedApp)))); }
From source file:com.diffplug.gradle.ConfigMisc.java
/** Creates an XML string from a groovy.util.Node. */ public static byte[] props(Map<String, String> map) { Properties properties = new Properties(); map.forEach((key, value) -> properties.put(key, value)); try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { Errors.rethrow().run(() -> properties.store(output, "")); return output.toByteArray(); } catch (IOException e) { throw Errors.asRuntime(e); }//from w w w . j a v a 2 s. c o m }
From source file:Main.java
/** * Copy each map entry to a new map but check that each key and value isn't null. Throw * a {@code NullPointerException} if it's the case. * * @param entries entries to copy//from w w w. j a v a2 s .com * @param <K> type of key * @param <V> type of value * @return cloned map * @throws NullPointerException if a key or value is null */ public static <K, V> Map<K, V> copyMapButFailOnNull(Map<? extends K, ? extends V> entries) { Map<K, V> entriesToRemap = new HashMap<>(entries.size()); entries.forEach((k, v) -> { // If a key/value is null, throw NPE, nothing gets mutated if (k == null || v == null) { throw new NullPointerException(); } entriesToRemap.put(k, v); }); return entriesToRemap; }
From source file:org.wso2.carbon.identity.oauth2.client.authentication.ClientAuthUtil.java
public static Map<String, List<String>> getBodyContent(Map<String, String> contentStrings) { Map<String, List<String>> bodyContent = new HashMap<>(); contentStrings.forEach((key, value) -> { List<String> valueList = new ArrayList<String>(); valueList.add(value);//from w ww.j av a 2 s .c o m bodyContent.put(key, valueList); }); return bodyContent; }
From source file:net.GoTicketing.GetNecessaryCookie.java
/** * CookieMap ? http request //from ww w . j a v a2 s .c o m * @param CookieMap Map ? cookie * @return http request */ public static String CookieMapToString(Map<String, String> CookieMap) { StringBuilder CookieBuilder = new StringBuilder(); CookieMap.forEach((key, value) -> { CookieBuilder.append("; ").append(key).append("=").append(value); }); if (CookieBuilder.length() > 2) return CookieBuilder.substring(2); else return CookieBuilder.toString(); }
From source file:com.blackducksoftware.integration.hub.detect.workflow.report.util.ObjectPrinter.java
public static void printObject(final ReportWriter writer, final String prefix, final Object guy) { Map<String, String> fieldMap = new HashMap<>(); populateObject(prefix, guy, fieldMap); fieldMap.forEach((key, value) -> { writer.writeLine(key + ": " + value); });/*from w w w . ja va2 s. c o m*/ }
From source file:com.blackducksoftware.integration.hub.detect.workflow.report.util.ObjectPrinter.java
public static void printObjectPrivate(final ReportWriter writer, final Object guy) { Map<String, String> fieldMap = new HashMap<>(); populateObjectPrivate(null, guy, fieldMap); fieldMap.forEach((key, value) -> { writer.writeLine(key + ": " + value); });/*from w w w.j a va2s .co m*/ }
From source file:org.openlmis.fulfillment.service.request.RequestParameters.java
/** * Constructs new RequestParameters based on Map with request parameters. *//* w ww . ja v a2 s. c o m*/ public static RequestParameters of(Map<String, Object> params) { RequestParameters requestParameters = new RequestParameters(); params.forEach(requestParameters::set); return requestParameters; }