Example usage for java.lang Integer Integer

List of usage examples for java.lang Integer Integer

Introduction

In this page you can find the example usage for java.lang Integer Integer.

Prototype

@Deprecated(since = "9")
public Integer(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Integer object that represents the int value indicated by the String parameter.

Usage

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(//  w ww  .j a v  a  2 s. co  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:FontSizeString.java

public static void main(String[] a) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Extents");

    final Canvas canvas = new Canvas(shell, SWT.NONE);

    shell.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent event) {
            canvas.setBounds(shell.getClientArea());
        }/*  w w w.ja  v  a2 s.  co m*/
    });
    canvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent event) {
            event.gc.setFont(font);
            Point pt = event.gc.stringExtent(STRING);

            System.out.println(pt);
        }
    });

    // Create an editor to house the dropdown
    ControlEditor editor = new ControlEditor(canvas);

    // Create the combo and fill it
    final Combo combo = new Combo(canvas, SWT.READ_ONLY);
    for (int i = 0, n = SIZES.length; i < n; i++) {
        combo.add(SIZES[i]);
    }

    // Set up the editor
    editor.horizontalAlignment = SWT.CENTER;
    editor.verticalAlignment = SWT.TOP;
    Point size = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    editor.minimumWidth = size.x;
    editor.minimumHeight = size.y;
    editor.setEditor(combo);

    combo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            if (font != null)
                font.dispose();
            font = new Font(shell.getDisplay(), "Helvetica", new Integer(combo.getText()).intValue(), SWT.BOLD);
            canvas.redraw();
        }
    });

    // Select the first item in the combo
    combo.select(0);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    if (font != null)
        font.dispose();
    display.dispose();
}

From source file:org.jfree.chart.demo.Second.java

/**
 * Starting point for the demo.//w ww .  j a v  a  2s  .  co m
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create some data...
    final XYSeries series1 = new XYSeries("Advisory Range");
    series1.add(new Integer(1200), new Integer(1));
    series1.add(new Integer(1500), new Integer(1));

    final XYSeries series2 = new XYSeries("Normal Range");
    series2.add(new Integer(2000), new Integer(4));
    series2.add(new Integer(2300), new Integer(4));

    final XYSeries series3 = new XYSeries("Recommended");
    series3.add(new Integer(2100), new Integer(2));

    final XYSeries series4 = new XYSeries("Current");
    series4.add(new Integer(2400), new Integer(3));

    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series1);
    data.addSeries(series2);
    data.addSeries(series3);
    data.addSeries(series4);

    // create a chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("My Chart", "Calories", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES, null);
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    final ValueAxis axis = plot.getRangeAxis();
    axis.setTickLabelsVisible(false);
    axis.setRange(0.0, 5.0);

    // create and display a frame...
    final ChartFrame frame = new ChartFrame("Test", chart);
    frame.pack();
    frame.setVisible(true);

}

From source file:com.sm.store.T1.java

public static void main(String[] args) {
    int i = -1, j = -(0xFF), k = 0xff;
    byte[] bs = new byte[4];
    putInt(bs, 0, i);//www . j av  a  2s  .c om
    putInt(bs, 0, j);
    putInt(bs, 0, k);

    T1.T2 t2 = new T1.T2("test-10", 20);
    T1 t1 = new T1("test-1", 1, new Integer(4), t2);
    HessianSerializer<T1> hs = new HessianSerializer<T1>();
    String str = new String(hs.toBytes(t1));
    System.out.println(str);
    t1 = new T1("test-1", 1, new Integer(4), null);
    str = new String(hs.toBytes(t1));
    System.out.println(str);
    //        Constructor[] cs = t1.getClass().getConstructors();
    //        for (Constructor each : cs) {
    //            Type[] ts= each.getParameterTypes();
    //            logger.info(ts.getClass().getName());
    //            for ( Type type : ts)
    //                logger.info(type.getClass().toString());
    //        }
}

From source file:SerializeJavaObjects_MySQL.java

public static void main(String args[]) throws Exception {
    Connection conn = null;// w  w  w.j a va 2s  .co m
    try {
        conn = getConnection();
        System.out.println("conn=" + conn);
        conn.setAutoCommit(false);
        List<Object> list = new ArrayList<Object>();
        list.add("This is a short string.");
        list.add(new Integer(1234));
        list.add(new Date());

        long objectID = writeJavaObject(conn, list);
        conn.commit();
        System.out.println("Serialized objectID => " + objectID);
        List listFromDatabase = (List) readJavaObject(conn, objectID);
        System.out.println("[After De-Serialization] list=" + listFromDatabase);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        conn.close();
    }
}

From source file:com.git.ifly6.components.Census.java

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    try {/*from  w w  w.j a  v a 2 s .co m*/
        region = new NSRegion(args[0]);
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.print("Please input the name of your region: \t");
        region = new NSRegion(scan.nextLine());
    }

    try {

        HashMap<String, Integer> endoMap = new HashMap<String, Integer>();
        String[] waMembers = region.getWAMembers();
        int[] valueCount = new int[waMembers.length];

        System.out.println(
                "[INFO] This census will take: " + time((int) Math.round(waitTime * waMembers.length)));

        for (int i = 0; i < waMembers.length; i++) {
            NSNation nation = new NSNation(waMembers[i]);
            valueCount[i] = nation.getEndoCount();
            endoMap.put(waMembers[i], new Integer(valueCount[i]));

            System.out.println("[LOG] Fetched information for: " + waMembers[i] + ", " + (i + 1) + " of "
                    + waMembers.length);
        }

        TreeMap<String, Integer> sortedMap = sortByValue(endoMap);

        int current = 0;
        int previous = sortedMap.firstEntry().getValue();

        System.out.printf("%-35s %12s %12s%n", "Nations", "Endorsements", "Difference");
        System.out.println("-------------------------------------------------------------");

        for (Map.Entry<String, Integer> entry : sortedMap.entrySet()) {

            String nationName = StringUtils.capitalize(entry.getKey().replace('_', ' '));
            current = entry.getValue();

            if ((previous - current) != 0) {
                System.out.printf("%-35s %12s %12s%n", nationName, entry.getValue(), (previous - current));
            } else {
                System.out.printf("%-35s %12s %12s%n", nationName, entry.getValue(), "-");
            }

            previous = entry.getValue();
        }

        System.out.println("-------------------------------------------------------------");
        System.out.printf("%-35s %12s %12s%n", "Delegate", "Endorsements", "Proportion");
        System.out.printf("%-35s %12s %12s%n",
                StringUtils.capitalize(sortedMap.firstEntry().getKey().replace('_', ' ')),
                sortedMap.firstEntry().getValue(),
                (double) (sortedMap.firstEntry().getValue() / waMembers.length));

    } catch (IOException e) {
        printError("Failed to fetch WA members or get endorsements in this region. "
                + "Check your internet connection or the state of the API.");
    }

    scan.close();
}

From source file:mx.unam.fesa.isoo.msp.MSPMain.java

/**
 * @param args//from  w  ww . ja v a2  s. com
 * @throws Exception
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    //
    // creating options
    //

    Options options = new Options();

    // help option
    //
    options.addOption(
            OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP));

    // server option
    //
    options.addOption(OptionBuilder.withDescription("The server this MineSweeperPlayer will connect to.")
            .hasArg().withArgName("SERVER").withLongOpt("server").create(OPT_SERVER));

    // port option
    //
    options.addOption(OptionBuilder.withDescription("The port this MineSweeperPlayer will connect to.").hasArg()
            .withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT));

    // parsing options
    //
    String hostname = DEFAULT_SERVER;
    int port = DEFAULT_PORT;
    try {
        // using GNU standard
        //
        CommandLine line = new GnuParser().parse(options, args);

        if (line.hasOption(OPT_HELP)) {
            new HelpFormatter().printHelp("msc [options]", options);
            return;
        }

        if (line.hasOption(OPT_PORT)) {
            try {
                port = (Integer) line.getOptionObject(OPT_PORT);
            } catch (Exception e) {
            }
        }

        if (line.hasOption(OPT_SERVER)) {
            hostname = line.getOptionValue(OPT_PORT);
        }
    } catch (ParseException e) {
        System.err.println("Could not parse command line options correctly: " + e.getMessage());
        return;
    }

    //
    // configuring logging services
    //

    try {
        LogManager.getLogManager()
                .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE));
    } catch (Exception e) {
        throw new Error("Could not load logging properties file.", e);
    }

    //
    // setting up Mine Sweeper client
    //

    try {
        new MSClient(hostname, port);
    } catch (Exception e) {
        System.err.println("Could not execute MineSweeper client: " + e.getMessage());
    }
}

From source file:examples.TelnetClientExample.java

/***
 * Main for the TelnetClientExample./*from w  w  w .  j a v a  2  s. c  om*/
 ***/
public static void main(String[] args) throws IOException {
    FileOutputStream fout = null;

    if (args.length < 1) {
        System.err.println("Usage: TelnetClientExample1 <remote-ip> [<remote-port>]");
        System.exit(1);
    }

    String remoteip = args[0];

    int remoteport;

    if (args.length > 1) {
        remoteport = (new Integer(args[1])).intValue();
    } else {
        remoteport = 23;
    }

    try {
        fout = new FileOutputStream("spy.log", true);
    } catch (Exception e) {
        System.err.println("Exception while opening the spy file: " + e.getMessage());
    }

    tc = new TelnetClient();

    TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false);
    EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
    SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);

    try {
        tc.addOptionHandler(ttopt);
        tc.addOptionHandler(echoopt);
        tc.addOptionHandler(gaopt);
    } catch (InvalidTelnetOptionException e) {
        System.err.println("Error registering option handlers: " + e.getMessage());
    }

    while (true) {
        boolean end_loop = false;
        try {
            tc.connect(remoteip, remoteport);

            Thread reader = new Thread(new TelnetClientExample());
            tc.registerNotifHandler(new TelnetClientExample());
            System.out.println("TelnetClientExample");
            System.out.println("Type AYT to send an AYT telnet command");
            System.out.println("Type OPT to print a report of status of options (0-24)");
            System.out.println("Type REGISTER to register a new SimpleOptionHandler");
            System.out.println("Type UNREGISTER to unregister an OptionHandler");
            System.out.println("Type SPY to register the spy (connect to port 3333 to spy)");
            System.out.println("Type UNSPY to stop spying the connection");

            reader.start();
            OutputStream outstr = tc.getOutputStream();

            byte[] buff = new byte[1024];
            int ret_read = 0;

            do {
                try {
                    ret_read = System.in.read(buff);
                    if (ret_read > 0) {
                        if ((new String(buff, 0, ret_read)).startsWith("AYT")) {
                            try {
                                System.out.println("Sending AYT");

                                System.out.println("AYT response:" + tc.sendAYT(5000));
                            } catch (Exception e) {
                                System.err.println("Exception waiting AYT response: " + e.getMessage());
                            }
                        } else if ((new String(buff, 0, ret_read)).startsWith("OPT")) {
                            System.out.println("Status of options:");
                            for (int ii = 0; ii < 25; ii++)
                                System.out.println("Local Option " + ii + ":" + tc.getLocalOptionState(ii)
                                        + " Remote Option " + ii + ":" + tc.getRemoteOptionState(ii));
                        } else if ((new String(buff, 0, ret_read)).startsWith("REGISTER")) {
                            StringTokenizer st = new StringTokenizer(new String(buff));
                            try {
                                st.nextToken();
                                int opcode = (new Integer(st.nextToken())).intValue();
                                boolean initlocal = (new Boolean(st.nextToken())).booleanValue();
                                boolean initremote = (new Boolean(st.nextToken())).booleanValue();
                                boolean acceptlocal = (new Boolean(st.nextToken())).booleanValue();
                                boolean acceptremote = (new Boolean(st.nextToken())).booleanValue();
                                SimpleOptionHandler opthand = new SimpleOptionHandler(opcode, initlocal,
                                        initremote, acceptlocal, acceptremote);
                                tc.addOptionHandler(opthand);
                            } catch (Exception e) {
                                if (e instanceof InvalidTelnetOptionException) {
                                    System.err.println("Error registering option: " + e.getMessage());
                                } else {
                                    System.err.println("Invalid REGISTER command.");
                                    System.err.println(
                                            "Use REGISTER optcode initlocal initremote acceptlocal acceptremote");
                                    System.err.println("(optcode is an integer.)");
                                    System.err.println(
                                            "(initlocal, initremote, acceptlocal, acceptremote are boolean)");
                                }
                            }
                        } else if ((new String(buff, 0, ret_read)).startsWith("UNREGISTER")) {
                            StringTokenizer st = new StringTokenizer(new String(buff));
                            try {
                                st.nextToken();
                                int opcode = (new Integer(st.nextToken())).intValue();
                                tc.deleteOptionHandler(opcode);
                            } catch (Exception e) {
                                if (e instanceof InvalidTelnetOptionException) {
                                    System.err.println("Error unregistering option: " + e.getMessage());
                                } else {
                                    System.err.println("Invalid UNREGISTER command.");
                                    System.err.println("Use UNREGISTER optcode");
                                    System.err.println("(optcode is an integer)");
                                }
                            }
                        } else if ((new String(buff, 0, ret_read)).startsWith("SPY")) {
                            try {
                                tc.registerSpyStream(fout);
                            } catch (Exception e) {
                                System.err.println("Error registering the spy");
                            }
                        } else if ((new String(buff, 0, ret_read)).startsWith("UNSPY")) {
                            tc.stopSpyStream();
                        } else {
                            try {
                                outstr.write(buff, 0, ret_read);
                                outstr.flush();
                            } catch (Exception e) {
                                end_loop = true;
                            }
                        }
                    }
                } catch (Exception e) {
                    System.err.println("Exception while reading keyboard:" + e.getMessage());
                    end_loop = true;
                }
            } while ((ret_read > 0) && (end_loop == false));

            try {
                tc.disconnect();
            } catch (Exception e) {
                System.err.println("Exception while connecting:" + e.getMessage());
            }
        } catch (Exception e) {
            System.err.println("Exception while connecting:" + e.getMessage());
            System.exit(1);
        }
    }
}

From source file:at.ac.tuwien.dsg.comot.m.adapter.Main.java

public static void main(String[] args) {

    Options options = createOptions();//from ww  w.  j a  va 2  s .  c om

    try {
        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("mh") && cmd.hasOption("ih") && cmd.hasOption("ip")) {

            Integer infoPort = null;

            try {
                infoPort = new Integer(cmd.getOptionValue("ip"));
            } catch (NumberFormatException e) {
                LOG.warn("infoPort must be a number");
                showHelp(options);
            }

            AppContextAdapter.setBrokerHost(cmd.getOptionValue("mh"));
            AppContextAdapter.setInfoHost(cmd.getOptionValue("ih"));
            AppContextAdapter.setInfoPort(infoPort);

            context = new AnnotationConfigApplicationContext(AppContextAdapter.class);

            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    if (context != null) {
                        context.close();
                    }
                }
            });

            if (cmd.hasOption("m") || cmd.hasOption("r") || cmd.hasOption("s")) {

                Manager manager = context.getBean(EpsAdapterManager.class);
                String serviceId = getServiceInstanceId();
                String participantId = context.getBean(InfoClient.class).getOsuInstanceByServiceId(serviceId)
                        .getId();

                if (cmd.hasOption("m")) {

                    Monitoring processor = context.getBean(Monitoring.class);
                    manager.start(participantId, processor);

                } else if (cmd.hasOption("r")) {

                    Control processor = context.getBean(Control.class);
                    manager.start(participantId, processor);

                } else if (cmd.hasOption("s")) {

                    Deployment processor = context.getBean(Deployment.class);
                    manager.start(participantId, processor);
                }

            } else {
                LOG.warn("No adapter type specified");
                showHelp(options);
            }
        } else {
            LOG.warn("Required parameters were not specified.");
            showHelp(options);
        }
    } catch (Exception e) {
        LOG.error("{}", e);
        showHelp(options);
    }
}

From source file:edu.lternet.pasta.portal.user.SavedData.java

/**
 * @param args/*from   ww w . ja  va  2s  .  c  o  m*/
 */
public static void main(String[] args) {
    String uid = "ucarroll";
    String scope1 = "knb-lter-nin";
    Integer identifier1 = new Integer(1);
    String scope2 = "knb-lter-sbc";
    Integer identifier2 = new Integer(28);
    Integer revision = new Integer(1);
    String savedDataXML = null;

    ConfigurationListener.configure();
    SavedData savedData = new SavedData(uid);

    savedData.addDocid(scope1, identifier1, revision);
    savedData.addDocid(scope2, identifier2, revision);
    List<String> dataStore = savedData.fetchDataStore();
    String savedDataList = savedData.getSavedDataList();
    System.out.println(String.format("Saved data list: %s", savedDataList));
    try {
        savedDataXML = savedData.getSavedDataXML("0", "10", null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    //savedData.removeDocid(scope2, identifier2);
    dataStore = savedData.fetchDataStore();
    //savedData.removeAllDataPackages();
}