List of usage examples for java.lang Integer Integer
@Deprecated(since = "9") public Integer(String s) throws NumberFormatException
From source file:net.sf.morph2.integration.commons.lang.LanguageStrLookupTestCase.java
public void testMe() { HashMap map = new HashMap(); map.put("string", "\"string\""); map.put("one", new Integer(1)); map.put("array", new String[] { "foo", "bar", "baz" }); StrSubstitutor ss = new StrSubstitutor(new LanguageStrLookup(map)); assertEquals("\"string\"", ss.replace("${string}")); assertEquals("1", ss.replace("${one}")); assertEquals("foo", ss.replace("${array[0]}")); assertEquals("bar", ss.replace("${array[1]}")); assertEquals("baz", ss.replace("${array[2]}")); }
From source file:Main.java
public static void saveDocument(Document doc, File transform, File file) throws IOException { try {/* w ww .j a v a 2s. c o m*/ TransformerFactory tFactory = TransformerFactory.newInstance(); tFactory.setAttribute("indent-number", new Integer(2)); Transformer transformer = tFactory.newTransformer(new StreamSource(transform)); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); FileOutputStream fos = new FileOutputStream(file.getPath()); DOMSource source = new DOMSource(doc); CharsetEncoder utf8Encoder = Charset.forName("UTF-8").newEncoder(); StreamResult result = new StreamResult(new OutputStreamWriter(fos, utf8Encoder)); transformer.transform(source, result); fos.close(); } catch (TransformerException e) { throw new IOException(e); } }
From source file:Producer.java
synchronized void add(int i) { while (count == SIZE) { try {//from w ww. jav a2s .c o m wait(); } catch (InterruptedException ie) { ie.printStackTrace(); System.exit(0); } } queue.addElement(new Integer(i)); ++count; notifyAll(); }
From source file:CookieServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { Cookie cookie = null;//from w ww. j av a 2s . c o m Cookie[] cookies = request.getCookies(); boolean newCookie = false; if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals("mycookie")) { cookie = cookies[i]; } } } if (cookie == null) { newCookie = true; int maxAge; try { maxAge = new Integer(getServletContext().getInitParameter("cookie-age")).intValue(); } catch (Exception e) { maxAge = -1; } cookie = new Cookie("mycookie", "" + getNextCookieValue()); cookie.setPath(request.getContextPath()); cookie.setMaxAge(maxAge); response.addCookie(cookie); } response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Cookie info</title>"); out.println("</head>"); out.println("<body>"); out.println("<h2> Information about the cookie named \"mycookie\"</h2>"); out.println("Cookie value: " + cookie.getValue() + "<br>"); if (newCookie) { out.println("Cookie Max-Age: " + cookie.getMaxAge() + "<br>"); out.println("Cookie Path: " + cookie.getPath() + "<br>"); } out.println("</body>"); out.println("</html>"); out.close(); }
From source file:com.diffeo.dossier.fc.StringCounterTest.java
@Test public void billClintonDocstring() { StringCounter name = new StringCounter(); name.getStrings().put("Bill Clinton", 1); name.add("William Jefferson Clinton", 1); assertThat(name.getStrings(), hasEntry("Bill Clinton", new Integer(1))); assertThat(name.getStrings(), hasEntry("William Jefferson Clinton", new Integer(1))); assertThat(name.getStrings().size(), is(2)); }
From source file:moviedatas.View.BarChartView.java
public JPanel initView() { observer = this; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(0, "Budget", new Integer(1)); dataset.addValue(0, "Gross", new Integer(1)); JFreeChart barChart = ChartFactory.createBarChart("", "Movie", "Value (in $)", dataset, VERTICAL, true, true, false);//from ww w. j a v a2s . c o m cPanel = new ChartPanel(barChart); cPanel.setPreferredSize(new Dimension(400, 300)); return cPanel; }
From source file:DynaBeansExampleV1.java
private static Object createMovieBean() throws Exception { // first create the properties DynaProperty properties[] = new DynaProperty[] { new DynaProperty("title", String.class), new DynaProperty("dateOfRelease", Date.class), new DynaProperty("keywords", String[].class), new DynaProperty("genre", Map.class), new DynaProperty("actors", List.class), new DynaProperty("director", DynaBean.class) }; // next using the properties define the class DynaClass movieClass = new BasicDynaClass("movie", null, properties); // now, with the class, create a new instance DynaBean movieBean = movieClass.newInstance(); // set its properties movieBean.set("title", "The Italian Job"); movieBean.set("dateOfRelease", new GregorianCalendar(1969, 0, 1).getTime()); movieBean.set("keywords", new String[] { "Italy", "Bank Robbery" }); Map genre = new HashMap(); genre.put("THR", "Thriller"); movieBean.set("genre", genre); movieBean.set("genre", "ACT", "Action"); DynaBean director = createPersonBean(); director.set("name", "Peter Collinson"); director.set("gender", new Integer(1)); movieBean.set("director", director); return movieBean; }
From source file:FibonacciTest.java
public int calculateWithCache(int x) { Integer key = new Integer(x); Integer result = values.get(key); if (result == null) { result = new Integer(calculate(x)); values.putIfAbsent(key, result); }//from w w w . ja va2 s. c o m return result.intValue(); }
From source file:com.pontorural.pedidovenda.converter.PedidoConverter.java
@Override public Object getAsObject(FacesContext context, UIComponent component, String value) { Pedido retorno = null;/*from w ww .j ava2 s . c om*/ if (StringUtils.isNotEmpty(value)) { Integer codigo = new Integer(value); retorno = pedidos.porId(codigo); } return retorno; }
From source file:it.unipr.ce.dsg.s2p.example.peer.FullPeer.java
public static void main(String[] args) { boolean active = true; if (args.length != 0) { FullPeer peer = null;// w ww . j a v a 2s . c om if (args.length == 3) { //args[0]=file peer configuration args[1]=key peer = new FullPeer(args[0], args[1]); } else if (args.length == 5) { //args[0]=file peer configuration args[1]=key args[2]=peer name args[3]=peer port peer = new FullPeer(args[0], args[1], args[2], new Integer(args[3])); } for (int i = 0; i < args.length; i++) { /* * join to bootstrapPeer */ if (args[i].equals("-j")) { peer.joinToBootstrapPeer(); } /* * request public address from SBC */ else if (args[i].equals("-s")) { peer.contactSBC(); } /* * join to bootstrapPeer, wait and send ping message to random peer */ else if (args[i].equals("-jp")) { peer.joinToBootstrapPeer(); //wait for 3 seconds try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } peer.pingToPeerRandomFromList(); } /* * join to bootstrapPeer, wait and send ping message to random peer recursively */ else if (args[i].equals("-jr")) { peer.joinToBootstrapPeer(); while (active) { //wait for 15 seconds try { Thread.sleep(15000); } catch (InterruptedException e) { e.printStackTrace(); } //ping to random peer peer.pingToPeerRandomFromList(); } } else if (args[i].equals("-p")) { peer.pingToPeer(args[5]); } else if (args[i].equals("-sd")) { peer.contactSBC(); try { Thread.sleep(7000); } catch (InterruptedException e) { e.printStackTrace(); } peer.disconnectGWP(); } /* * contact SBC, wait, join to bootstrapPeer, wait and send ping message to random peer recursively */ else if (args[i].equals("-a")) { peer.contactSBC(); try { Thread.sleep(4000); } catch (InterruptedException e) { e.printStackTrace(); } peer.joinToBootstrapPeer(); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } peer.pingToPeerRandomFromList(); } } } }