List of usage examples for java.lang Long Long
@Deprecated(since = "9") public Long(String s) throws NumberFormatException
From source file:de.msg.repository.driver.TestRouteRepositoryDriver.java
@PostConstruct public void initRoutesList() { for (short i = 0; i < routeCount; i++) { String flightNumber = flightNumberList.get(i); String departure = departureList.get(i); String destination = destinationList.get(i); Route route = new Route(flightNumber, departure, destination); route.setId(new Long(i + 1)); route.addScheduledDaily();//from w w w . j ava 2s . c om route.setDepartureTime(LocalTime.of(9 - i, 30)); route.setArrivalTime(LocalTime.of(14 - i, 0)); routeList.add(route); } }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/*from w w w . j av a 2 s . c o m*/ * * <p>If the input array is <code>null</code>, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1L], 0, 2L) = [2L, 1L] * ArrayUtils.add([2L, 6L], 2, 10L) = [2L, 6L, 10L] * ArrayUtils.add([2L, 6L], 0, -4L) = [-4L, 2L, 6L] * ArrayUtils.add([2L, 6L, 3L], 2, 1L) = [2L, 6L, 1L, 3L] * </pre> * * @param array the array to add the element to, may be <code>null</code> * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static long[] add(long[] array, int index, long element) { return (long[]) add(array, index, new Long(element), Long.TYPE); }
From source file:org.cloudfoundry.caldecott.server.converter.ByteBufferHttpMessageConverter.java
@Override protected Long getContentLength(ByteBuffer buffer, MediaType contentType) { return new Long(buffer.limit()); }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert// www . j a va 2s .c o m * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class targetClass) throws IllegalArgumentException { if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:com.estampate.corteI.servlet.servlets.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w. j a v a 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); dirUploadFiles = getServletContext().getRealPath(getServletContext().getInitParameter("dirUploadFiles")); HttpSession sesion = request.getSession(true); if (ServletFileUpload.isMultipartContent(request)) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(new Long(getServletContext().getInitParameter("maxFileSize")).longValue()); List listUploadFiles = null; FileItem item = null; try { listUploadFiles = upload.parseRequest(request); Iterator it = listUploadFiles.iterator(); while (it.hasNext()) { item = (FileItem) it.next(); if (!item.isFormField()) { if (item.getSize() > 0) { String nombre = item.getName(); String tipo = item.getContentType(); long tamanio = item.getSize(); String extension = nombre.substring(nombre.lastIndexOf(".")); sesion.setAttribute("sArNombre", String.valueOf(nombre)); sesion.setAttribute("sArTipo", String.valueOf(tipo)); sesion.setAttribute("sArExtension", String.valueOf(extension)); File archivo = new File(dirUploadFiles, "nombreRequest" + extension); item.write(archivo); if (archivo.exists()) { response.sendRedirect("uploadsave.jsp"); } else { sesion.setAttribute("sArError", "Ocurrio un error al subir el archiv o"); response.sendRedirect("uploaderror.jsp"); } } } } } catch (FileUploadException e) { sesion.setAttribute("sArError", String.valueOf(e.getMessage())); response.sendRedirect("uploaderror.jsp"); } catch (Exception e) { sesion.setAttribute("sArError", String.valueOf(e.getMessage())); response.sendRedirect("uploaderror.jsp"); } } out.close(); }
From source file:nl.edia.sakai.tool.skinmanager.download.SkinDowloadController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // First check permission if (SakaiUtils.hasPermission(Permissions.PERMISSION_EDIA_SAKAI_SKININSTALL_EDIT)) { // Get the required id parameter String myId = request.getParameter("id"); if (myId != null) { // Create the data map Map<String, Object> myData = new HashMap<String, Object>(); myData.put("id", myId); // Try to get the version String myVersion = request.getParameter("version"); if (myVersion != null) { try { myData.put("version", new Long(myVersion)); } catch (Exception e) { // ignore }/* ww w. ja v a2s.c o m*/ } // go to skin download view. return new ModelAndView(new SkinDownloadView(skinArchiveService), myData); } } return new ModelAndView(errorView); }
From source file:com.baculsoft.beanutils.test.TestBeanUtil2.java
@Test public void testCopy() throws Throwable { PojoExample pojoSource = new PojoExample(); pojoSource.setStringProp("String Property"); pojoSource.setBooleanProp(true);// w w w . ja v a2 s .c o m pojoSource.setBooleanProp1(Boolean.TRUE); pojoSource.setDateProp(new Date()); pojoSource.setByteProp1(new Byte((byte) 11)); pojoSource.setIntProp1(new Integer(15125)); pojoSource.setLongProp1(new Long(20053215235l)); pojoSource.setFloatProp1(new Float(20053215235f)); PojoExample pojoTarget = new PojoExample(); pojoDescriptor.copy(pojoSource, pojoTarget); pojoDescriptor.reset(pojoTarget); PojoExample pojoTarget2 = new PojoExample(); PojoExample pojoTarget3 = new PojoExample(); BeanUtils.copyProperties(pojoSource, pojoTarget2); org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3); long t1 = System.currentTimeMillis(); for (int i = 0; i < 50; i++) { pojoDescriptor.copy(pojoSource, pojoTarget); } t1 = System.currentTimeMillis() - t1; long t2 = System.currentTimeMillis(); for (int i = 0; i < 50; i++) { BeanUtils.copyProperties(pojoSource, pojoTarget2); } t2 = System.currentTimeMillis() - t2; long t3 = System.currentTimeMillis(); for (int i = 0; i < 50; i++) { org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3); } t3 = System.currentTimeMillis() - t3; System.out.println("Time to copy properties "); System.out.println("this class: t1 ---> " + t1); System.out.println("spring-beans: t2 --->" + t2); System.out.println("apache commons: t3 --->" + t3); System.out.println(pojoDescriptor.describe(pojoTarget).equals(pojoDescriptor.describe(pojoTarget2))); assertEquals(pojoDescriptor.describe(pojoTarget), pojoDescriptor.describe(pojoTarget2)); }
From source file:org.tec.webapp.jdbc.entity.TestUserRole.java
/** * test insert/* w w w . j av a 2 s . co m*/ */ @Test() public void insert() { UserRoleBean userRole = testUserRole(); mUserRoleDba.delete(userRole); List<UserRoleBean> l = mUserRoleDba.getRoles(new Long(userRole.getUser().getUserId())); Assert.assertNull("should be no roles for " + userRole.getUser(), l); }
From source file:org.araneaframework.tests.FormElementTest.java
/** * Tests that {@link TextControl} return <code>null</code> on empty request. * @throws Exception/*www . j a v a2 s. com*/ */ public void testDataCycling() throws Exception { MockHttpServletRequest emptyRequest = new MockHttpServletRequest(); emptyRequest.addParameter("myTextBox", ""); FormElement sfe = new FormElement(); sfe._getComponent().init(new MockEnviroment()); TextControl tb = new TextControl(); tb.setMandatory(true); sfe.setControl(tb); sfe.setData(new LongData()); sfe.setConverter(new StringToLongConverter()); sfe._getWidget().update(new StandardServletInputData(emptyRequest)); sfe.convertAndValidate(); sfe.getData().setValue(new Long(110)); sfe._getWidget().process(); assertEquals("The textbox must have the data item value!", ((StringArrayRequestControl.ViewModel) sfe.getControl()._getViewable().getViewModel()) .getSimpleValue(), "110"); sfe._getComponent().destroy(); }
From source file:net.jradius.packet.attribute.AttributeFactory.java
private static RadiusAttribute vsa(long vendor, long type) throws InstantiationException, IllegalAccessException { RadiusAttribute attr = null;/*w w w .j a va 2s . c o m*/ VendorValue v = vendorValueMap.get(new Long(vendor)); Class<?> c = null; if (v != null) { c = v.typeMap.get(new Long(type)); } if (c != null) { attr = (RadiusAttribute) c.newInstance(); } else { RadiusLog.warn("Unknown Vendor Specific Attribute: " + vendor + ":" + type); attr = new Attr_UnknownVSAttribute(vendor, type); } return attr; }