Example usage for java.util Iterator hasNext

List of usage examples for java.util Iterator hasNext

Introduction

In this page you can find the example usage for java.util Iterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if the iteration has more elements.

Usage

From source file:Counter.java

public static void main(String[] args) throws FileNotFoundException {
    if (args.length == 0) {
        System.out.println(usage);
        System.exit(1);/*from  www .  ja v  a  2 s  .c  o m*/
    }
    WordCount1 wc = new WordCount1(args[0]);
    wc.countWords();
    Iterator keys = wc.keySet().iterator();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        System.out.println(key + ": " + wc.getCounter(key).read());
    }
    wc.dispose();
}

From source file:ImageTest.java

public static void main(String args[]) {
    args = new String[] { "image.json" };
    for (int a = 0; a < args.length; a++) {
        String version = "Unknown";
        try {//from  www .  j  av  a  2s . c  om
            JSONTokener tokener = new JSONTokener(new FileInputStream(args[a]));
            JSONObject jsonSubject = new JSONObject(tokener);
            JSONObject jsonSchema = new JSONObject(
                    new JSONTokener(ImageTest.class.getResourceAsStream("schema.json")));

            Schema schema = SchemaLoader.load(jsonSchema);
            schema.validate(jsonSubject);

            System.out.println("json-schema Valid " + args[a]);
        } catch (NullPointerException e) {
            System.out.println("json-config null point error " + args[a]);
        } catch (FileNotFoundException e) {
            System.out.println("json-file file missing " + e.getMessage() + " " + args[a]);
        } catch (JSONException je) {
            System.out.println("json-parse json " + je.getMessage() + " " + args[a]);
        } catch (ValidationException ve) {
            Iterator<ValidationException> i = ve.getCausingExceptions().iterator();
            while (i.hasNext()) {
                ValidationException veel = i.next();
                System.out.println("json-schema Validation error " + veel + " " + args[a]);
            }
        }
    }
}

From source file:com.camel.trainreserve.TicketReserver.java

public static void main(String[] args) {
    getCaptchaImg();/*from w ww.  j  a v a 2s. co m*/

    String filePath = FileUtils.getFileAbsolutePath();
    Properties props = FileUtils.readProperties(filePath + "/trainreserve/checkorderInfo.properties");
    Iterator it = props.keySet().iterator();
    while (it.hasNext()) {
        String key = (String) it.next();
        NameValuePair nvp = new BasicNameValuePair(key, (String) props.get(key));
        datas.add(nvp);
    }
    String formDate = URLEncodedUtils.format(datas, "UTF-8");
    String res = null;
    try {
        res = JDKHttpsClient.doPost(checkOrderUrl, cookieStr, formDate, "UTF-8", 3000, 2000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("response =" + res);
}

From source file:ObjectTest.java

public static void main(String args[]) {
    for (int a = 0; a < args.length; a++) {
        String version = "Unknown";
        try {//ww w .j  av a 2s  . c o m
            JSONTokener tokener = new JSONTokener(new FileInputStream(args[a]));
            JSONObject jsonSubject = new JSONObject(tokener);
            version = jsonSubject.getJSONObject("X3D").getString("@version");
            JSONObject jsonSchema = new JSONObject(new JSONTokener(
                    ObjectTest.class.getResourceAsStream("x3d-" + version + "-JSONSchema.json")));

            Schema schema = SchemaLoader.load(jsonSchema);
            schema.validate(jsonSubject);

            // System.out.println("json-schema "+version+" Valid "+args[a]);
        } catch (NullPointerException npe) {
            System.out.println("json-config " + version + " null point error " + args[a]);
        } catch (FileNotFoundException e) {
            System.out.println("json-file file missing " + e.getMessage() + " " + args[a]);
        } catch (NumberFormatException nfe) {
            System.out.println("json-parse json " + nfe.getMessage() + " " + args[a]);
        } catch (JSONException je) {
            System.out.println("json-parse json " + je.getMessage() + " " + args[a]);
        } catch (ValidationException ve) {
            Iterator<ValidationException> i = ve.getCausingExceptions().iterator();
            while (i.hasNext()) {
                ValidationException veel = i.next();
                System.out.println("json-schema " + version + " Validation error " + veel + " " + args[a]);
            }
        }
    }
}

From source file:NavigableSetDemo.java

public static void main(String[] args) {
    List<Integer> list = Arrays.asList(3, 2, 4, 1, 5);
    NavigableSet<Integer> ns = new TreeSet<Integer>(list);
    System.out.println("Ascending order (default): " + ns);

    Iterator<Integer> descendingIterator = ns.descendingIterator();
    StringBuilder sb = new StringBuilder("Descending order: ");
    while (descendingIterator.hasNext()) {
        int m = descendingIterator.next();
        sb.append(m + " ");
    }//from   ww w .ja v a2  s  . co m
    System.out.println(sb);

    int greatest = ns.lower(3);
    System.out.println("Lower of 3 = " + greatest);

    int smallest = ns.higher(3);
    System.out.println("Higher of 3 = " + smallest);
}

From source file:LegacyTest.java

public static void main(String[] args) {
    try {/*from   w  w  w .ja  va  2  s  .c o  m*/
        PdfAs pdfAS = PdfAsFactory.createPdfAs();

        SignParameters signParameters = new SignParameters();
        signParameters.setSignatureDevice("bku");
        signParameters.setSignatureProfileId("SIGNATURBLOCK_DE");

        InputStream is = LegacyTest.class.getResourceAsStream("simple.pdf");

        byte[] inputData = IOUtils.toByteArray(is);
        ByteArrayDataSink bads = new ByteArrayDataSink();
        signParameters.setDocument(new ByteArrayDataSource(inputData));
        signParameters.setOutput(bads);
        SignResult result = pdfAS.sign(signParameters);
        IOUtils.write(bads.getBytes(), new FileOutputStream("/tmp/test.pdf"));

        System.out.println("Signed @ " + result.getSignaturePosition().toString());
        System.out.println("Signed by " + result.getSignerCertificate().getSubjectDN().getName());

        VerifyParameters verifyParameters = new VerifyParameters();
        verifyParameters.setDocument(new ByteArrayDataSource(bads.getBytes()));
        verifyParameters.setSignatureToVerify(0);

        VerifyResults results = pdfAS.verify(verifyParameters);

        Iterator iter = results.getResults().iterator();

        while (iter.hasNext()) {
            Object obj = iter.next();
            if (obj instanceof VerifyResult) {
                VerifyResult vresult = (VerifyResult) obj;
                System.out.println("Verified: " + vresult.getValueCheckCode().getCode() + " "
                        + vresult.getValueCheckCode().getMessage());
            }
        }

    } catch (Throwable e) {
        System.out.println("ERROR");
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    HashMap<String, String> hashmap = new HashMap<String, String>();

    hashmap.put("one", "1");
    hashmap.put("two", "2");
    hashmap.put("three", "3");
    hashmap.put("four", "4");
    hashmap.put("five", "5");
    hashmap.put("six", "6");

    Iterator<String> keyIterator = hashmap.keySet().iterator();
    Iterator<String> valueIterator = hashmap.values().iterator();

    while (keyIterator.hasNext()) {
        System.out.println("key: " + keyIterator.next());
    }//w w w .j av a 2 s .co  m

    while (valueIterator.hasNext()) {
        System.out.println("value: " + valueIterator.next());
    }
}

From source file:NumberTest.java

public static void main(String args[]) {
    args = new String[] { "number.json" };
    for (int a = 0; a < args.length; a++) {
        System.out.println(args[a]);
        String version = "Unknown";
        try {//from   ww  w .java2  s.  c  o  m
            System.out.println("Starting");
            JSONTokener tokener = new JSONTokener(new FileInputStream(args[a]));
            JSONObject jsonSubject = new JSONObject(tokener);
            System.out.println(
                    jsonSubject.getJSONObject("MovieTexture").get("@startTime").getClass().getSimpleName());
            JSONObject jsonSchema = new JSONObject(
                    new JSONTokener(NumberTest.class.getResourceAsStream("numberschema.json")));

            Schema schema = SchemaLoader.load(jsonSchema);
            schema.validate(jsonSubject);
            System.out.println("Finishing");

            System.out.println("json-schema Valid " + args[a]);
        } catch (NullPointerException e) {
            System.out.println("json-config null point error " + args[a]);
        } catch (FileNotFoundException e) {
            System.out.println("json-file file missing " + e.getMessage() + " " + args[a]);
        } catch (JSONException je) {
            System.out.println("json-parse json " + je.getMessage() + " " + args[a]);
        } catch (ValidationException ve) {
            ve.printStackTrace();
            System.out.println("json-schema Validation error " + ve + " " + args[a]);
            Iterator<ValidationException> i = ve.getCausingExceptions().iterator();
            while (i.hasNext()) {
                ValidationException veel = i.next();
                System.out.println("json-schema Validation error " + veel + " " + args[a]);
            }
        }
    }
}

From source file:is.java

  public static void main(String[] args) {
  List<Integer> list = Arrays.asList(3, 2, 4, 1, 5);
  NavigableSet<Integer> ns = new TreeSet<Integer>(list);
  System.out.println("Ascending order (default): " + ns);

  Iterator<Integer> descendingIterator = ns.descendingIterator();
  StringBuilder sb = new StringBuilder("Descending order: ");
  while (descendingIterator.hasNext()) {
    int m = descendingIterator.next();
    sb.append(m + " ");
  }/*from   w w w  .j a va  2s.  c  o  m*/
  System.out.println(sb);

  int greatest = ns.lower(3);
  System.out.println("Lower of 3 = " + greatest);

  int smallest = ns.higher(3);
  System.out.println("Higher of 3 = " + smallest);
}

From source file:com.apipulse.bastion.Main.java

public static void main(String[] args) throws IOException, ClassNotFoundException {
    log.info("Bastion starting. Loading chains");
    final File dir = new File("etc/chains");

    final LinkedList<ActorRef> chains = new LinkedList<ActorRef>();
    for (File file : dir.listFiles()) {
        if (!file.getName().startsWith(".") && file.getName().endsWith(".yaml")) {
            log.info("Loading chain: " + file.getName());
            ChainConfig config = new ChainConfig(IOUtils.toString(new FileReader(file)));
            ActorRef ref = BastionActors.getInstance().initChain(config.getName(),
                    Class.forName(config.getQualifiedClass()));
            Iterator<StageConfig> iterator = config.getStages().iterator();
            while (iterator.hasNext())
                ref.tell(iterator.next(), null);
            chains.add(ref);//from   ww  w . jav a2 s . com
        }
    }
    SpringApplication app = new SpringApplication();
    HashSet<Object> objects = new HashSet<Object>();
    objects.add(ApiController.class);
    final ConfigurableApplicationContext context = app.run(ApiController.class, args);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                log.info("Bastion shutting down");
                Iterator<ActorRef> iterator = chains.iterator();
                while (iterator.hasNext())
                    iterator.next().tell(new StopMessage(), null);
                Thread.sleep(2000);
                context.stop();
                log.info("Bastion shutdown complete");
            } catch (Exception e) {
            }
        }
    });
}