List of usage examples for java.lang Integer intValue
@HotSpotIntrinsicCandidate public int intValue()
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); MyPdfPageEventHelper tracker = new MyPdfPageEventHelper(); writer.setPageEvent(tracker);//from w ww .j a v a 2 s .co m document.open(); document.add(createParagraph("Fox", "Hello lazy dog.")); document.newPage(); HashMap lines = tracker.getLines(); for (Iterator i = lines.keySet().iterator(); i.hasNext();) { String speaker = (String) i.next(); Integer count = (Integer) lines.get(speaker); document.add(new Paragraph(speaker + ": " + count.intValue() + " lines.")); } document.close(); }
From source file:Main.java
public static void main(String[] args) { Integer intObj = new Integer("10"); byte b = intObj.byteValue(); System.out.println(b);/* w w w.j a v a2 s.com*/ short s = intObj.shortValue(); System.out.println(s); int i = intObj.intValue(); System.out.println(i); float f = intObj.floatValue(); System.out.println(f); double d = intObj.doubleValue(); System.out.println(d); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map map = new HashMap(); // Create int wrapper object Integer refInt = new Integer(123); // Store int in map map.put("key", refInt); // Get int value from map refInt = (Integer) map.get("key"); // Get the integer value from wrapper object int i = refInt.intValue(); }
From source file:com.pureinfo.srm.reports.table.data.sci.SCIBySchoolStatistic.java
public static void main(String[] args) throws PureException { IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); IStatement stat = mgr.createQuery(//from ww w.j a va 2 s . c o m "select count({this.id}) _NUM, {this.englishScience} AS _SUB from {this} group by _SUB", 0); IObjects nums = stat.executeQuery(false); DolphinObject num = null; Map map = new HashedMap(); while ((num = nums.next()) != null) { String subest = num.getStrProperty("_SUB"); if (subest == null || subest.trim().length() == 0) continue; String[] subs = subest.split(";"); int nNum = num.getIntProperty("_NUM", 0); for (int i = 0; i < subs.length; i++) { String sSub = subs[i].trim(); Integer odValue = (Integer) map.get(sSub); int sum = odValue == null ? nNum : (nNum + odValue.intValue()); map.put(sSub, new Integer(sum)); } } List l = new ArrayList(map.size()); for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { Map.Entry en = (Map.Entry) iter.next(); l.add(new Object[] { en.getKey(), en.getValue() }); } Collections.sort(l, new Comparator() { public int compare(Object _sO1, Object _sO2) { Object[] arr1 = (Object[]) _sO1; Object[] arr2 = (Object[]) _sO2; Comparable s1 = (Comparable) arr1[1]; Comparable s2 = (Comparable) arr2[01]; return s1.compareTo(s2); } }); for (Iterator iter = l.iterator(); iter.hasNext();) { Object[] arr = (Object[]) iter.next(); System.out.println(arr[0] + " = " + arr[1]); } }
From source file:WordCount.java
public static void main(String args[]) throws Exception { String filename = "WordCount.java"; // Map File from filename to byte buffer FileInputStream input = new FileInputStream(filename); FileChannel channel = input.getChannel(); int fileLength = (int) channel.size(); MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength); // Convert to character buffer Charset charset = Charset.forName("ISO-8859-1"); CharsetDecoder decoder = charset.newDecoder(); CharBuffer charBuffer = decoder.decode(buffer); // Create line pattern Pattern linePattern = Pattern.compile(".*$", Pattern.MULTILINE); // Create word pattern Pattern wordBreakPattern = Pattern.compile("[\\p{Punct}\\s}]"); // Match line pattern to buffer Matcher lineMatcher = linePattern.matcher(charBuffer); Map map = new TreeMap(); Integer ONE = new Integer(1); // For each line while (lineMatcher.find()) { // Get line CharSequence line = lineMatcher.group(); // Get array of words on line String words[] = wordBreakPattern.split(line); // For each word for (int i = 0, n = words.length; i < n; i++) { if (words[i].length() > 0) { Integer frequency = (Integer) map.get(words[i]); if (frequency == null) { frequency = ONE;/* ww w . j a va 2 s. c o m*/ } else { int value = frequency.intValue(); frequency = new Integer(value + 1); } map.put(words[i], frequency); } } } System.out.println(map); }
From source file:com.discursive.jccook.xml.bardsearch.TermFreq.java
public static void main(String[] pArgs) throws Exception { logger.info("Threshold is 200"); Integer threshold = new Integer(200); IndexReader reader = IndexReader.open("index"); TermEnum enumVar = reader.terms();/* w w w. jav a2 s .co m*/ List termList = new ArrayList(); while (enumVar.next()) { if (enumVar.docFreq() >= threshold.intValue() && enumVar.term().field().equals("speech")) { Freq freq = new Freq(enumVar.term().text(), enumVar.docFreq()); termList.add(freq); } } Collections.sort(termList); Collections.reverse(termList); System.out.println("Frequency | Term"); Iterator iterator = termList.iterator(); while (iterator.hasNext()) { Freq freq = (Freq) iterator.next(); System.out.print(freq.frequency); System.out.println(" | " + freq.term); } }
From source file:fdtutilscli.Main.java
/** * //w ww.ja v a2s . c o m * @param args the command line arguments */ public static void main(String[] args) { CommandLineParser parser = new PosixParser(); CommandLine line = null; Options options = new Options(); OptionGroup optCommand = new OptionGroup(); OptionGroup optOutput = new OptionGroup(); HelpFormatter formatter = new HelpFormatter(); TRACE trace = TRACE.DEFAULT; optCommand.addOption(OptionBuilder.withArgName("ndf odf nif key seperator").hasArgs(5) .withValueSeparator(' ').withDescription("Description").create("delta")); optCommand.addOption(OptionBuilder.withArgName("dupsfile key seperator").hasArgs(3) .withDescription("Description").create("duplicates")); optCommand.addOption(OptionBuilder.withLongOpt("help").withDescription("print this message.").create("h")); optCommand.addOption( OptionBuilder.withLongOpt("version").withDescription("print version information.").create("V")); optOutput.addOption(new Option("verbose", "be extra verbose")); optOutput.addOption(new Option("quiet", "be extra quiet")); optOutput.addOption(new Option("silent", "same as --quiet")); options.addOptionGroup(optCommand); options.addOptionGroup(optOutput); try { line = parser.parse(options, args); if (line.hasOption("verbose")) { trace = TRACE.VERBOSE; } else if (line.hasOption("quiet") || line.hasOption("silent")) { trace = TRACE.QUIET; } if (line.hasOption("h")) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, null, true); return; } else if (line.hasOption("V")) { System.out.println(APP_NAME + " version " + VERSION); System.out.println("fDTDeltaBuilder version " + DTDeltaBuilder.version()); System.out.println("DTDuplicateKeyFinder version " + DTDuplicateKeyFinder.version()); return; } else if (line.hasOption("delta")) { String ndf = line.getOptionValues("delta")[0]; String odf = line.getOptionValues("delta")[1]; String nif = line.getOptionValues("delta")[2]; Integer key = (line.getOptionValues("delta").length <= 3) ? DEFAULT_KEY : new Integer(line.getOptionValues("delta")[3]); String seperator = (line.getOptionValues("delta").length <= 4) ? DEFAULT_SEPERATOR : line.getOptionValues("delta")[4]; doDelta(ndf, odf, nif, key.intValue(), seperator, trace); return; } else if (line.hasOption("duplicates")) { String dupsFile = line.getOptionValues("duplicates")[0]; Integer key = (line.getOptionValues("duplicates").length <= 1) ? DEFAULT_KEY : new Integer(line.getOptionValues("duplicates")[1]); String seperator = (line.getOptionValues("duplicates").length <= 2) ? DEFAULT_SEPERATOR : line.getOptionValues("duplicates")[2]; doDuplicates(dupsFile, key.intValue(), seperator, trace); return; } else if (args.length == 0) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, null, true); } else { throw new UnrecognizedOptionException(E_MSG_UNREC_OPT); } } catch (UnrecognizedOptionException e) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, HELP_FOOTER + e.getMessage(), true); } catch (ParseException e) { formatter.printHelp(HELP_SYNTAX, HELP_HEADER, options, HELP_FOOTER + e.getMessage(), true); } }
From source file:com.bitsofproof.example.Simple.java
public static void main(String[] args) { Security.addProvider(new BouncyCastleProvider()); final CommandLineParser parser = new GnuParser(); final Options gnuOptions = new Options(); gnuOptions.addOption("h", "help", false, "I can't help you yet"); gnuOptions.addOption("s", "server", true, "Server URL"); gnuOptions.addOption("u", "user", true, "User"); gnuOptions.addOption("p", "password", true, "Password"); System.out.println("BOP Bitcoin Server Simple Client 3.5.0 (c) 2013-2014 bits of proof zrt."); CommandLine cl = null;/*from ww w . j a va2s . c o m*/ String url = null; String user = null; String password = null; try { cl = parser.parse(gnuOptions, args); url = cl.getOptionValue('s'); user = cl.getOptionValue('u'); password = cl.getOptionValue('p'); } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); System.exit(1); } if (url == null || user == null || password == null) { System.err.println("Need -s server -u user -p password"); System.exit(1); } BCSAPI api = getServer(url, user, password); try { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); long start = System.currentTimeMillis(); api.ping(start); System.out.println("Server round trip " + (System.currentTimeMillis() - start) + "ms"); api.addAlertListener(new AlertListener() { @Override public void alert(String s, int severity) { System.err.println("ALERT: " + s); } }); System.out.println("Talking to " + (api.isProduction() ? "PRODUCTION" : "test") + " server"); ConfirmationManager confirmationManager = new ConfirmationManager(); confirmationManager.init(api, 144); System.out.printf("Please enter wallet name: "); String wallet = input.readLine(); SimpleFileWallet w = new SimpleFileWallet(wallet + ".wallet"); TransactionFactory am = null; if (!w.exists()) { System.out.printf("Enter passphrase: "); String passphrase = input.readLine(); System.out.printf("Enter master (empty for new): "); String master = input.readLine(); if (master.equals("")) { w.init(passphrase); w.unlock(passphrase); System.out.printf("First account: "); String account = input.readLine(); am = w.createAccountManager(account); w.lock(); w.persist(); } else { StringTokenizer tokenizer = new StringTokenizer(master, "@"); String key = tokenizer.nextToken(); long since = 0; if (tokenizer.hasMoreElements()) { since = Long.parseLong(tokenizer.nextToken()) * 1000; } w.init(passphrase, ExtendedKey.parse(key), true, since); w.unlock(passphrase); System.out.printf("First account: "); String account = input.readLine(); am = w.createAccountManager(account); w.lock(); w.persist(); w.sync(api); } } else { w = SimpleFileWallet.read(wallet + ".wallet"); w.sync(api); List<String> names = w.getAccountNames(); System.out.println("Accounts:"); System.out.println("---------"); String first = null; for (String name : names) { System.out.println(name); if (first == null) { first = name; } } System.out.println("---------"); am = w.getAccountManager(first); System.out.println("Using account " + first); } confirmationManager.addAccount(am); api.registerTransactionListener(am); while (true) { printMenu(); String answer = input.readLine(); System.out.printf("\n"); if (answer.equals("1")) { System.out.printf("The balance is: " + printBit(am.getBalance()) + "\n"); System.out.printf(" confirmed: " + printBit(am.getConfirmed()) + "\n"); System.out.printf(" receiveing: " + printBit(am.getReceiving()) + "\n"); System.out.printf(" change: " + printBit(am.getChange()) + "\n"); System.out.printf("( sending: " + printBit(am.getSending()) + ")\n"); } else if (answer.equals("2")) { for (Address a : am.getAddresses()) { System.out.printf(a + "\n"); } } else if (answer.equals("3")) { ExtendedKeyAccountManager im = (ExtendedKeyAccountManager) am; System.out.printf( im.getMaster().serialize(api.isProduction()) + "@" + im.getCreated() / 1000 + "\n"); } else if (answer.equals("4")) { System.out.printf("Enter passphrase: "); String passphrase = input.readLine(); w.unlock(passphrase); ExtendedKeyAccountManager im = (ExtendedKeyAccountManager) am; System.out.printf( im.getMaster().serialize(api.isProduction()) + "@" + im.getCreated() / 1000 + "\n"); w.lock(); } else if (answer.equals("5")) { System.out.printf("Enter passphrase: "); String passphrase = input.readLine(); w.unlock(passphrase); System.out.printf("Number of recipients"); Integer nr = Integer.valueOf(input.readLine()); Transaction spend; if (nr.intValue() == 1) { System.out.printf("Receiver address: "); String address = input.readLine(); System.out.printf("amount (Bit): "); long amount = parseBit(input.readLine()); spend = am.pay(Address.fromSatoshiStyle(address), amount); System.out.println("About to send " + printBit(amount) + " to " + address); } else { List<Address> addresses = new ArrayList<>(); List<Long> amounts = new ArrayList<>(); long total = 0; for (int i = 0; i < nr; ++i) { System.out.printf("Receiver address: "); String address = input.readLine(); addresses.add(Address.fromSatoshiStyle(address)); System.out.printf("amount (Bit): "); long amount = parseBit(input.readLine()); amounts.add(amount); total += amount; } spend = am.pay(addresses, amounts); System.out.println("About to send " + printBit(total)); } System.out.println("inputs"); for (TransactionInput in : spend.getInputs()) { System.out.println(in.getSourceHash() + " " + in.getIx()); } System.out.println("outputs"); for (TransactionOutput out : spend.getOutputs()) { System.out.println(out.getOutputAddress() + " " + printBit(out.getValue())); } w.lock(); System.out.printf("Type yes to go: "); if (input.readLine().equals("yes")) { api.sendTransaction(spend); System.out.printf("Sent transaction: " + spend.getHash()); } else { System.out.printf("Nothing happened."); } } else if (answer.equals("6")) { System.out.printf("Address: "); Set<Address> match = new HashSet<Address>(); match.add(Address.fromSatoshiStyle(input.readLine())); api.scanTransactionsForAddresses(match, 0, new TransactionListener() { @Override public boolean process(Transaction t) { System.out.printf("Found transaction: " + t.getHash() + "\n"); return true; } }); } else if (answer.equals("7")) { System.out.printf("Public key: "); ExtendedKey ek = ExtendedKey.parse(input.readLine()); api.scanTransactions(ek, 0, 10, 0, new TransactionListener() { @Override public boolean process(Transaction t) { System.out.printf("Found transaction: " + t.getHash() + "\n"); return true; } }); } else if (answer.equals("a")) { System.out.printf("Enter account name: "); String account = input.readLine(); am = w.getAccountManager(account); api.registerTransactionListener(am); confirmationManager.addAccount(am); } else if (answer.equals("c")) { System.out.printf("Enter account name: "); String account = input.readLine(); System.out.printf("Enter passphrase: "); String passphrase = input.readLine(); w.unlock(passphrase); am = w.createAccountManager(account); System.out.println("using account: " + account); w.lock(); w.persist(); api.registerTransactionListener(am); confirmationManager.addAccount(am); } else if (answer.equals("m")) { System.out.printf("Enter passphrase: "); String passphrase = input.readLine(); w.unlock(passphrase); System.out.println(w.getMaster().serialize(api.isProduction())); System.out.println(w.getMaster().getReadOnly().serialize(true)); w.lock(); } else if (answer.equals("s")) { System.out.printf("Enter private key: "); String key = input.readLine(); ECKeyPair k = ECKeyPair.parseWIF(key); KeyListAccountManager alm = new KeyListAccountManager(); alm.addKey(k); alm.syncHistory(api); Address a = am.getNextReceiverAddress(); Transaction t = alm.pay(a, alm.getBalance(), PaymentOptions.receiverPaysFee); System.out.println("About to sweep " + printBit(alm.getBalance()) + " to " + a); System.out.println("inputs"); for (TransactionInput in : t.getInputs()) { System.out.println(in.getSourceHash() + " " + in.getIx()); } System.out.println("outputs"); for (TransactionOutput out : t.getOutputs()) { System.out.println(out.getOutputAddress() + " " + printBit(out.getValue())); } System.out.printf("Type yes to go: "); if (input.readLine().equals("yes")) { api.sendTransaction(t); System.out.printf("Sent transaction: " + t.getHash()); } else { System.out.printf("Nothing happened."); } } else { System.exit(0); } } } catch (Exception e) { System.err.println("Something went wrong"); e.printStackTrace(); System.exit(1); } }
From source file:ClassFileUtilities.java
/** * Program that computes the dependencies between the Batik jars. * <p>/* w w w. j av a 2 s . com*/ * Run this from the main Batik distribution directory, after building * the jars. For every jar file in the batik-xxx/ build directory, * it will determine which other jar files it directly depends on. * The output is lines of the form: * </p> * <pre> <i>number</i>,<i>from</i>,<i>to</i></pre> * <p> * where mean that the <i>from</i> jar has <i>number</i> class files * that depend on class files in the <i>to</i> jar. * </p> */ public static void main(String[] args) { boolean showFiles = false; if (args.length == 1 && args[0].equals("-f")) { showFiles = true; } else if (args.length != 0) { System.err.println("usage: ClassFileUtilities [-f]"); System.err.println(); System.err.println(" -f list files that cause each jar file dependency"); System.exit(1); } File cwd = new File("."); File buildDir = null; String[] cwdFiles = cwd.list(); for (int i = 0; i < cwdFiles.length; i++) { if (cwdFiles[i].startsWith("batik-")) { buildDir = new File(cwdFiles[i]); if (!buildDir.isDirectory()) { buildDir = null; } else { break; } } } if (buildDir == null || !buildDir.isDirectory()) { System.out.println("Directory 'batik-xxx' not found in current directory!"); return; } try { Map cs = new HashMap(); Map js = new HashMap(); collectJars(buildDir, js, cs); Set classpath = new HashSet(); Iterator i = js.values().iterator(); while (i.hasNext()) { classpath.add(((Jar) i.next()).jarFile); } i = cs.values().iterator(); while (i.hasNext()) { ClassFile fromFile = (ClassFile) i.next(); // System.out.println(fromFile.name); Set result = getClassDependencies(fromFile.getInputStream(), classpath, false); Iterator j = result.iterator(); while (j.hasNext()) { ClassFile toFile = (ClassFile) cs.get(j.next()); if (fromFile != toFile && toFile != null) { fromFile.deps.add(toFile); } } } i = cs.values().iterator(); while (i.hasNext()) { ClassFile fromFile = (ClassFile) i.next(); Iterator j = fromFile.deps.iterator(); while (j.hasNext()) { ClassFile toFile = (ClassFile) j.next(); Jar fromJar = fromFile.jar; Jar toJar = toFile.jar; if (fromFile.name.equals(toFile.name) || toJar == fromJar || fromJar.files.contains(toFile.name)) { continue; } Integer n = (Integer) fromJar.deps.get(toJar); if (n == null) { fromJar.deps.put(toJar, new Integer(1)); } else { fromJar.deps.put(toJar, new Integer(n.intValue() + 1)); } } } List triples = new ArrayList(10); i = js.values().iterator(); while (i.hasNext()) { Jar fromJar = (Jar) i.next(); Iterator j = fromJar.deps.keySet().iterator(); while (j.hasNext()) { Jar toJar = (Jar) j.next(); Triple t = new Triple(); t.from = fromJar; t.to = toJar; t.count = ((Integer) fromJar.deps.get(toJar)).intValue(); triples.add(t); } } Collections.sort(triples); i = triples.iterator(); while (i.hasNext()) { Triple t = (Triple) i.next(); System.out.println(t.count + "," + t.from.name + "," + t.to.name); if (showFiles) { Iterator j = t.from.files.iterator(); while (j.hasNext()) { ClassFile fromFile = (ClassFile) j.next(); Iterator k = fromFile.deps.iterator(); while (k.hasNext()) { ClassFile toFile = (ClassFile) k.next(); if (toFile.jar == t.to && !t.from.files.contains(toFile.name)) { System.out.println("\t" + fromFile.name + " --> " + toFile.name); } } } } } } catch (IOException e) { e.printStackTrace(); } }
From source file:ArrayUtils.java
/** * A testing method//from w ww .ja v a 2 s . c o m * * @param args * The command-line arguments. The first argument is used to * determine what test to run. */ public static void main(String[] args) { String test; if (args.length == 0) test = "intSort"; else test = args[0]; if (test.equals("intSort")) { int[] random = new int[10000]; int[] random2 = new int[random.length]; for (int i = 0; i < random.length; i++) random[i] = (int) (Math.random() * Integer.MAX_VALUE); ArrayAdjuster.mergeSort(random2, random, 0, random.length); boolean sorted = true; for (int i = 0; i < random.length - 1; i++) if (random[i] < random[i + 1]) { sorted = false; break; } System.out.println("Sort " + (sorted ? "succeeded" : "failed")); } else if (test.equals("adjust")) { final Integer[] start = new Integer[25]; for (int i = 0; i < start.length; i++) start[i] = new Integer(i); Integer[] modifier = new Integer[start.length]; for (int i = 0; i < modifier.length; i++) { if (i % 5 != 0) modifier[i] = new Integer(i); else modifier[i] = new Integer(i / 5 * start.length); } Integer[] result = adjust(start, modifier, new DifferenceListener<Integer, Integer>() { public boolean identity(Integer o1, Integer o2) { return o1.equals(o2); } public Integer added(Integer o, int mIdx, int retIdx) { return o; } public Integer removed(Integer o, int oIdx, int oIdxAdj, int retIdx) { return o; } public Integer set(Integer o1, int idx1, int oIdxAdj, Integer o2, int idx2, int retIdx) { if (o1.intValue() % 5 == 2) return null; return o1; } }); System.out.println("Original array=" + toString(start)); System.out.println("Modifier array=" + toString(modifier)); System.out.println("Adjusted array=" + toString(result)); } else throw new IllegalArgumentException("Unrecognized test: " + test); }