Example usage for java.util Map entrySet

List of usage examples for java.util Map entrySet

Introduction

In this page you can find the example usage for java.util Map entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:org.fusesource.cloudmix.tests.consumer.Main.java

public static void main(String[] args) {
    if (args.length > 0 && args[0].equals("-debug")) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }//from   w w w  . jav a 2s  . com
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/context.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:org.fusesource.cloudmix.tests.broker.Main.java

public static void main(String[] args) {
    if (verbose || (args.length > 0 && args[0].equals("-debug"))) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }//from   w w  w.j a v a2 s. c o  m
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/activemq.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, Integer> map = new LinkedHashMap<>();

    map.put("Zero", 0);
    map.put("One", 1);
    map.put("Two", 2);
    map.put("Three", 3);
    map.put("Four", 4);

    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        System.out.println(entry.getKey() + " => " + entry.getValue());
    }//from ww w  . ja  v a2s .c  om
}

From source file:CheckFonts.java

public static void main(String[] a) throws Exception {
    Map<String, File> filesMUI = ResUtils.listFiles(OUT_DIR, "mui");

    for (Map.Entry<String, File> e : filesMUI.entrySet()) {
        System.out.println(e.getKey());
        ReaderWriterMUI mui = new ReaderWriterMUI(FileUtils.readFileToByteArray(e.getValue()));
        mui.read();//from w  w w  .  j  a  va  2 s.com
        Map<Object, Map<Object, byte[]>> res = mui.getCompiledResources();

        res = SkipResources.minus(e.getKey().replace("/be-BY/", "/en-US/"), res, SkipResources.SKIP_EXTRACT);

        Map<Object, byte[]> dialogs = res.get(ResUtils.TYPE_DIALOG);
        if (dialogs == null) {
            continue;
        }
        for (Map.Entry<Object, byte[]> en : dialogs.entrySet()) {
            ResourceDialog dialog = new ParserDialog(new MemoryFile(en.getValue())).parse();
            for (ResourceDialog.DlgItemTemplateEx it : dialog.items) {
                if (!(it.title instanceof String)) {
                    continue;
                }
                // int linesCount = 1;
                // try {
                // int h = it.cy;
                // if (h == dialog.pointsize - 1) {
                // h++;
                // }
                // linesCount = h / dialog.pointsize;
                // } catch (ArithmeticException ex) {
                // ex.printStackTrace();
                // System.out.println(en.getKey() + "/" + it.id + " - zero height");
                // }
                // if (linesCount == 0) {
                // System.out.println(en.getKey() + "/" + it.id + " - zero height");
                // continue;
                // }
                int w = getDimension(dialog, (String) it.title).width;
                if (w > it.cx) {
                    System.out.println(en.getKey() + "/" + it.id + " - \"" + it.title + "\" need width: " + w
                            + ", but width: " + it.cx + " [" + it.x + "," + it.y + "," + it.cx + "," + it.cy
                            + "]");
                }
            }
        }
    }
}

From source file:com.yahoo.flowetl.commons.runner.Main.java

/**
 * The main method entry point./*w w  w  .ja v  a2  s .  c  o m*/
 */
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println(
                Main.class.getSimpleName() + " [runner fully qualified java class name] arguments ...");
        return;
    }
    System.out.println("+Argument info:");
    StringBuilder argsStr = new StringBuilder();
    for (int i = 0; i < args.length; i++) {
        argsStr.append("(" + (i + 1) + ") " + args[i] + " [" + args[i].length() + " chars]");
        if (i + 1 != args.length) {
            argsStr.append(" ");
        }
    }
    System.out.println(argsStr);
    Map<String, Object> sysInfo = getRuntimeInfo();
    System.out.println("+Runtime info:");
    for (Entry<String, Object> e : sysInfo.entrySet()) {
        System.out.println("--- " + e.getKey() + " => " + (e.getValue() == null ? "" : e.getValue()));
    }
    String classToRun = args[0];
    Class<?> testToRun = KlassUtils.getClassForName(classToRun);
    if (KlassUtils.isAbstract(testToRun) || KlassUtils.isInterface(testToRun)) {
        System.out.println("+Runner class name that is not abstract or an interface is required!");
        return;
    }
    if (ClassUtils.isAssignable(testToRun, (Runner.class)) == false) {
        System.out.println("+Runner class name that is a instance/subclass of " + Runner.class.getSimpleName()
                + " is required!");
        return;
    }
    Class<Runner> rToRun = KlassUtils.getClassForName(classToRun);
    System.out.println("+Running program specified by runner class " + rToRun);
    Runner r = KlassUtils.getInstanceOf(rToRun, new Object[] {});
    String[] nargs = (String[]) ArrayUtils.subarray(args, 1, args.length);
    System.out.println("+Proxying to object " + r + " with arguments [" + StringUtils.join(nargs, ",") + "]");
    r.runProgram(nargs);
}

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> map = new HashMap<>();
    map.put("CSS", "style");
    map.put("HTML", "mark up");
    map.put("Oracle", "database");
    map.put("XML", "data");

    // Get the entry Set
    Set<Map.Entry<String, String>> entries = map.entrySet();

    entries.forEach((Map.Entry<String, String> entry) -> {
        String key = entry.getKey();
        String value = entry.getValue();
        System.out.println("key=" + key + ",  value=" + value);
    });/* w  w w  . j av a  2  s .c  om*/

}

From source file:com.rackspacecloud.blueflood.tools.ops.GetPoints.java

public static void main(String args[]) {
    Map<String, Object> options = parseOptions(args);

    Locator locator = Locator.createLocatorFromPathComponents((String) options.get(TENANT_ID),
            (String) options.get(METRIC));

    AstyanaxReader reader = AstyanaxReader.getInstance();

    Long from = (Long) options.get(FROM);
    Long to = (Long) options.get(TO);

    if (from == null || to == null) {
        System.out.println("Either start time or end time is null.");
        to = System.currentTimeMillis();
        from = to - DEFAULT_RANGE.toMillis();
        System.out.println("Using range: " + from + " - " + to);
    }//w  ww .  j  a  v  a  2s.  c o m

    if (from >= to) {
        System.err.println("End time " + to + " has to be greater than start time " + from);
        System.exit(2);
    }

    Granularity gran = Granularity.FULL;
    String res = (String) options.get("resolution");
    try {
        gran = Granularity.fromString(res.toLowerCase());
    } catch (Exception ex) {
        System.out.println("Exception mapping resolution to Granularity. Using FULL resolution instead.");
        gran = Granularity.FULL;
    } finally {
        if (gran == null) {
            gran = Granularity.FULL;
        }
    }

    System.out.println(
            "Locator: " + locator + ", from: " + from + ", to: " + to + ", resolution: " + gran.shortName());

    MetricData data = reader.getDatapointsForRange(locator, new Range(from, to), gran);
    Map<Long, Points.Point> points = data.getData().getPoints();
    for (Map.Entry<Long, Points.Point> item : points.entrySet()) {
        String output = String.format("Timestamp: %d, Data: %s, Unit: %s", item.getKey(),
                item.getValue().getData().toString(), data.getUnit());
        System.out.println(output);
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<Person> roster = createRoster();

    System.out.println("Members by gender:");
    Map<Person.Sex, List<Person>> byGender = roster.stream().collect(Collectors.groupingBy(Person::getGender));

    List<Map.Entry<Person.Sex, List<Person>>> byGenderList = new ArrayList<>(byGender.entrySet());

    byGenderList.stream().forEach(e -> {
        System.out.println("Gender: " + e.getKey());
        e.getValue().stream().map(Person::getName).forEach(f -> System.out.println(f));
    });/*from   ww  w  .jav  a  2  s. co m*/

}

From source file:URLConnectionTest.java

public static void main(String[] args) {
    try {/* ww  w . j ava  2 s.c o m*/
        String urlName;
        if (args.length > 0)
            urlName = args[0];
        else
            urlName = "http://java.sun.com";

        URL url = new URL(urlName);
        URLConnection connection = url.openConnection();

        // set username, password if specified on command line

        if (args.length > 2) {
            String username = args[1];
            String password = args[2];
            String input = username + ":" + password;
            String encoding = base64Encode(input);
            connection.setRequestProperty("Authorization", "Basic " + encoding);
        }

        connection.connect();

        // print header fields

        Map<String, List<String>> headers = connection.getHeaderFields();
        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
            String key = entry.getKey();
            for (String value : entry.getValue())
                System.out.println(key + ": " + value);
        }

        // print convenience functions

        System.out.println("----------");
        System.out.println("getContentType: " + connection.getContentType());
        System.out.println("getContentLength: " + connection.getContentLength());
        System.out.println("getContentEncoding: " + connection.getContentEncoding());
        System.out.println("getDate: " + connection.getDate());
        System.out.println("getExpiration: " + connection.getExpiration());
        System.out.println("getLastModifed: " + connection.getLastModified());
        System.out.println("----------");

        Scanner in = new Scanner(connection.getInputStream());

        // print first ten lines of contents

        for (int n = 1; in.hasNextLine() && n <= 10; n++)
            System.out.println(in.nextLine());
        if (in.hasNextLine())
            System.out.println(". . .");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.jgoetsch.eventtrader.EventTraderSpringLauncher.java

public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: " + EventTraderSpringLauncher.class.getSimpleName() + " <files>...");
        System.out.println("       files - List of paths to spring bean definition xml files.");
        System.out.println("               Each object defined that implements Runnable will be executed");
        System.out.println("               in its own thread.");
    } else {/*  w  w w. jav a  2  s  .  co m*/
        AbstractApplicationContext context = new ClassPathXmlApplicationContext(args);

        // auto register growl notifications after all GrowlNotification objects have been instantiated
        // if it is found on the classpath
        try {
            Class.forName("com.jgoetsch.eventtrader.processor.GrowlNotification").getMethod("autoRegister")
                    .invoke(null);
        } catch (Exception e) {
            log.warn("Growl not found, cannot autoRegister notifications: {}", e.getMessage());
        }

        Map<String, Runnable> runnables = BeanFactoryUtils.beansOfTypeIncludingAncestors(context,
                Runnable.class);
        List<Thread> threads = new ArrayList<Thread>(runnables.size());
        for (final Map.Entry<String, Runnable> runner : runnables.entrySet()) {
            final Thread th = new Thread(runner.getValue(), runner.getKey());
            threads.add(th);
            th.start();
        }

        // close spring context on JVM shutdown
        // this causes all @PreDestroy methods in the runnables to be called to allow for
        // them to shutdown gracefully
        context.registerShutdownHook();

        // wait for launched threads to finish before cleaning up beans
        for (Thread th : threads) {
            try {
                th.join();
            } catch (InterruptedException e) {
            }
        }
    }
}