List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:org.apache.hadoop.hive.ql.optimizer.ConstantPropagateProcFactory.java
/** * Cast type from expression type to expected type ti. * * @param desc constant expression//from w w w . ja v a 2 s . co m * @param ti expected type info * @param performSafeTypeCast when true then don't perform typecast because it could be unsafe (loosing leading zeroes etc.) * @return cast constant, or null if the type cast failed. */ private static ExprNodeConstantDesc typeCast(ExprNodeDesc desc, TypeInfo ti, boolean performSafeTypeCast) { if (desc instanceof ExprNodeConstantDesc && null == ((ExprNodeConstantDesc) desc).getValue()) { return null; } if (!(ti instanceof PrimitiveTypeInfo) || !(desc.getTypeInfo() instanceof PrimitiveTypeInfo)) { return null; } PrimitiveTypeInfo priti = (PrimitiveTypeInfo) ti; PrimitiveTypeInfo descti = (PrimitiveTypeInfo) desc.getTypeInfo(); if (unSupportedTypes.contains(priti.getPrimitiveCategory()) || unSupportedTypes.contains(descti.getPrimitiveCategory())) { // FIXME: support template types. It currently has conflict with ExprNodeConstantDesc if (LOG.isDebugEnabled()) { LOG.debug("Unsupported types " + priti + "; " + descti); } return null; } // We shouldn't cast strings to other types because that can break original data in cases of // leading zeros or zeros trailing after decimal point. // Example: "000126" => 126 => "126" boolean brokenDataTypesCombination = unsafeConversionTypes.contains(priti.getPrimitiveCategory()) && !unsafeConversionTypes.contains(descti.getPrimitiveCategory()); if (performSafeTypeCast && brokenDataTypesCombination) { if (LOG.isDebugEnabled()) { LOG.debug("Unsupported cast " + priti + "; " + descti); } return null; } if (LOG.isDebugEnabled()) { LOG.debug("Casting " + desc + " to type " + ti); } ExprNodeConstantDesc c = (ExprNodeConstantDesc) desc; if (null != c.getFoldedFromVal() && priti.getTypeName().equals(serdeConstants.STRING_TYPE_NAME)) { // avoid double casting to preserve original string representation of constant. return new ExprNodeConstantDesc(c.getFoldedFromVal()); } ObjectInspector origOI = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(desc.getTypeInfo()); ObjectInspector oi = TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(ti); Converter converter = ObjectInspectorConverters.getConverter(origOI, oi); Object convObj = converter.convert(c.getValue()); // Convert integer related types because converters are not sufficient if (convObj instanceof Integer) { switch (priti.getPrimitiveCategory()) { case BYTE: convObj = new Byte((byte) (((Integer) convObj).intValue())); break; case SHORT: convObj = new Short((short) ((Integer) convObj).intValue()); break; case LONG: convObj = new Long(((Integer) convObj).intValue()); default: } } return new ExprNodeConstantDesc(ti, convObj); }
From source file:com.jaspersoft.jasperserver.test.ReportSchedulingTestTestNG.java
/** * doPersistenceTest// w ww . j ava 2 s.c o m */ @Test() public void doPersistenceTest() { m_logger.info("ReportSchedulingTestTestNG => doPersistenceTest() called"); // REPORT JOB 1 ReportJobSource source = new ReportJobSource(); source.setReportUnitURI("/test/reportURI"); Map params = new HashMap(); params.put("param1", new Integer(5)); params.put("param2", "value2"); source.setParametersMap(params); Date startDate = new Date(); ReportJobSimpleTrigger trigger = new ReportJobSimpleTrigger(); trigger.setStartDate(startDate); trigger.setOccurrenceCount(20); trigger.setRecurrenceInterval(10); trigger.setRecurrenceIntervalUnit(ReportJobSimpleTrigger.INTERVAL_DAY); ReportJobRepositoryDestination repositoryDestination = new ReportJobRepositoryDestination(); repositoryDestination.setFolderURI("/test/scheduled"); repositoryDestination.setOutputDescription("report output"); repositoryDestination.setSequentialFilenames(true); repositoryDestination.setTimestampPattern("yyyyMMdd"); repositoryDestination.setDefaultReportOutputFolderURI("/default/report_output/folder"); repositoryDestination.setUsingDefaultReportOutputFolderURI(true); ReportJobMailNotification mailNotification = new ReportJobMailNotification(); mailNotification.addTo("john@smith.com"); mailNotification.setSubject("Scheduled report"); mailNotification.setMessageText("Executed report"); ReportJob job_01 = new ReportJob(); job_01.setLabel("foo"); job_01.setDescription("bar"); job_01.setSource(source); job_01.setTrigger(trigger); job_01.setBaseOutputFilename("foo"); job_01.addOutputFormat(ReportJob.OUTPUT_FORMAT_PDF); job_01.addOutputFormat(ReportJob.OUTPUT_FORMAT_RTF); job_01.setContentRepositoryDestination(repositoryDestination); job_01.setMailNotification(mailNotification); job_01 = m_reportJobsPersistenceService.saveJob(m_executionContext, job_01); m_logger.info("saved job_01 " + job_01.getId() + " has version=" + job_01.getVersion()); assertNotNull(job_01); long jobId_01 = job_01.getId(); String userName = job_01.getUsername(); // Report Job 02 source = new ReportJobSource(); source.setReportUnitURI("/test/A_ReportURI"); params = new HashMap(); params.put("param1", new Integer(5)); params.put("param2", "value2"); source.setParametersMap(params); startDate = new Date(); ReportJobCalendarTrigger trigger2 = new ReportJobCalendarTrigger(); trigger2.setMinutes("0"); trigger2.setHours("0"); trigger2.setDaysTypeCode(trigger2.DAYS_TYPE_ALL); TreeSet months = new TreeSet(); months.add(new Byte((byte) 1)); months.add(new Byte((byte) 2)); months.add(new Byte((byte) 3)); trigger2.setMonthDays(""); trigger2.setMonths(months); trigger2.setTimezone("America/Los_Angeles"); trigger2.setStartType(trigger2.START_TYPE_NOW); repositoryDestination = new ReportJobRepositoryDestination(); repositoryDestination.setFolderURI("/test/scheduled"); repositoryDestination.setOutputDescription("report output"); repositoryDestination.setSequentialFilenames(false); repositoryDestination.setTimestampPattern("yyyyMMdd"); repositoryDestination.setSaveToRepository(false); repositoryDestination.setOutputLocalFolder("c:/tmp"); FTPInfo ftpInfo = new FTPInfo(); ftpInfo.setUserName("JohnSmith"); HashMap<String, String> map = new HashMap<String, String>(); map.put("PORT", "27"); ftpInfo.setPropertiesMap(map); repositoryDestination.setOutputFTPInfo(ftpInfo); mailNotification = new ReportJobMailNotification(); mailNotification.addTo("john@smith.com"); mailNotification.addTo("peter@pan.com"); mailNotification.setSubject("Scheduled report"); mailNotification.setMessageText("Executed report"); mailNotification.setSkipNotificationWhenJobFails(true); ReportJobAlert alert = new ReportJobAlert(); alert.setRecipient(ReportJobAlert.Recipient.ADMIN); alert.setMessageText("CUSTOMIZE MESSAGE"); alert.setJobState(ReportJobAlert.JobState.FAIL_ONLY); ArrayList<String> to_Addresses = new ArrayList<String>(); to_Addresses.add("peterpan@jaspersoft.com"); to_Addresses.add("peter.pan@gmail.com"); alert.setToAddresses(to_Addresses); ReportJob job_02 = new ReportJob(); job_02.setLabel("A_ReportJob_2"); job_02.setDescription("bar"); job_02.setSource(source); job_02.setTrigger(trigger2); job_02.setBaseOutputFilename("aReportJob_2_OUTPUT"); job_02.addOutputFormat(ReportJob.OUTPUT_FORMAT_PDF); job_02.addOutputFormat(ReportJob.OUTPUT_FORMAT_RTF); job_02.setContentRepositoryDestination(repositoryDestination); job_02.setAlert(alert); boolean exceptionCaught = false; try { job_02.setMailNotification(mailNotification); } catch (Exception ex) { exceptionCaught = true; } assertTrue(exceptionCaught); mailNotification.setResultSendTypeCode(mailNotification.RESULT_SEND_ATTACHMENT); job_02.setMailNotification(mailNotification); job_02 = m_reportJobsPersistenceService.saveJob(m_executionContext, job_02); assertEquals(false, job_02.getContentRepositoryDestination().isSaveToRepository()); assertNotNull(job_02); long jobId_02 = job_02.getId(); // test creation date assertTrue((System.currentTimeMillis() - job_01.getCreationDate().getTime()) < 60000); assertTrue((System.currentTimeMillis() - job_02.getCreationDate().getTime()) < 60000); // test default report output of user assertEquals("/default/report_output/folder", job_02.getContentRepositoryDestination().getDefaultReportOutputFolderURI()); assertEquals("/default/report_output/folder", job_01.getContentRepositoryDestination().getDefaultReportOutputFolderURI()); assertEquals(true, job_01.getContentRepositoryDestination().isUsingDefaultReportOutputFolderURI()); assertEquals(false, job_02.getContentRepositoryDestination().isUsingDefaultReportOutputFolderURI()); // test alert testAlert(job_02.getAlert()); // test output destination assertNull(job_01.getContentRepositoryDestination().getOutputLocalFolder()); assertTrue((job_01.getContentRepositoryDestination().getOutputFTPInfo() == null) || (job_01.getContentRepositoryDestination().getOutputFTPInfo().getFolderPath() == null)); assertEquals("c:/tmp", job_02.getContentRepositoryDestination().getOutputLocalFolder()); assertEquals("JohnSmith", job_02.getContentRepositoryDestination().getOutputFTPInfo().getUserName()); Map<String, String> ftpProperties = job_02.getContentRepositoryDestination().getOutputFTPInfo() .getPropertiesMap(); assertEquals("27", ftpProperties.get("PORT")); assertNotNull(job_02.getContentRepositoryDestination().getOutputFTPInfo().getPassword()); //password was encrypted. Unencrypted pwd is never stored. // test mail notification assertTrue(!job_01.getMailNotification().isSkipNotificationWhenJobFails()); assertTrue(job_02.getMailNotification().isSkipNotificationWhenJobFails()); boolean deleted = true; try { job_01 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_01)); m_logger.info("retrieved job_01 " + job_01.getId() + " has version=" + job_01.getVersion()); assertNotNull(job_01); assertEquals("foo", job_01.getLabel()); Set outputFormats = job_01.getOutputFormatsSet(); assertNotNull(outputFormats); assertEquals(2, outputFormats.size()); assertTrue(outputFormats.contains(new Byte(ReportJob.OUTPUT_FORMAT_PDF))); assertTrue(outputFormats.contains(new Byte(ReportJob.OUTPUT_FORMAT_RTF))); source = job_01.getSource(); assertNotNull(source); assertEquals("/test/reportURI", source.getReportUnitURI()); params = source.getParametersMap(); assertNotNull(params); assertEquals(2, params.size()); assertTrue(params.containsKey("param1")); assertEquals(new Integer(5), params.get("param1")); assertTrue(params.containsKey("param2")); assertEquals("value2", params.get("param2")); assertNotNull(job_01.getTrigger()); assertTrue(job_01.getTrigger() instanceof ReportJobSimpleTrigger); trigger = (ReportJobSimpleTrigger) job_01.getTrigger(); assertEquals(20, trigger.getOccurrenceCount()); assertNotNull(trigger.getRecurrenceIntervalUnit()); assertEquals(ReportJobSimpleTrigger.INTERVAL_DAY, trigger.getRecurrenceIntervalUnit().byteValue()); repositoryDestination = job_01.getContentRepositoryDestination(); assertNotNull(repositoryDestination); assertEquals("/test/scheduled", repositoryDestination.getFolderURI()); assertEquals("report output", repositoryDestination.getOutputDescription()); assertTrue(repositoryDestination.isSequentialFilenames()); assertEquals("yyyyMMdd", repositoryDestination.getTimestampPattern()); assertFalse(repositoryDestination.isOverwriteFiles()); mailNotification = job_01.getMailNotification(); assertNotNull(mailNotification); assertEquals("Scheduled report", mailNotification.getSubject()); List toAddresses = mailNotification.getToAddresses(); assertNotNull(toAddresses); assertEquals(1, toAddresses.size()); assertEquals("john@smith.com", toAddresses.get(0)); long origJobId = job_01.getId(); int origJobVersion = job_01.getVersion(); long origTriggerId = trigger.getId(); int origTriggerVersion = trigger.getVersion(); long origMailId = mailNotification.getId(); int origMailVersion = mailNotification.getVersion(); job_01.setDescription("updated"); mailNotification.setSubject("updated subject"); mailNotification.addTo("joan@smith.com"); mailNotification.addCc("mary@smith.com"); m_reportJobsPersistenceService.updateJob(m_executionContext, job_01); job_01 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_01)); assertNotNull(job_01); assertEquals("foo", job_01.getLabel()); assertEquals("updated", job_01.getDescription()); assertEquals(origJobId, job_01.getId()); assertEquals(origJobVersion + 1, job_01.getVersion()); assertNotNull(job_01.getTrigger()); assertTrue(job_01.getTrigger() instanceof ReportJobSimpleTrigger); trigger = (ReportJobSimpleTrigger) job_01.getTrigger(); assertEquals(origTriggerId, trigger.getId()); assertEquals(origTriggerVersion, trigger.getVersion()); mailNotification = job_01.getMailNotification(); assertNotNull(mailNotification); assertEquals(origMailId, mailNotification.getId()); assertEquals(origMailVersion + 1, mailNotification.getVersion()); assertEquals("updated subject", mailNotification.getSubject()); toAddresses = mailNotification.getToAddresses(); assertEquals(2, toAddresses.size()); assertEquals("john@smith.com", toAddresses.get(0)); assertEquals("joan@smith.com", toAddresses.get(1)); List ccAddresses = mailNotification.getCcAddresses(); assertNotNull(ccAddresses); assertEquals(1, ccAddresses.size()); assertEquals("mary@smith.com", ccAddresses.get(0)); List jobs = m_reportJobsPersistenceService.listJobs(m_executionContext, "/test/reportURI"); assertNotNull(jobs); assertTrue(1 <= jobs.size()); boolean found = false; for (Iterator it = jobs.iterator(); it.hasNext();) { Object element = it.next(); assertTrue(element instanceof ReportJobSummary); ReportJobSummary summary = (ReportJobSummary) element; if (summary.getId() == jobId_01) { found = true; assertEquals("foo", summary.getLabel()); break; } } assertTrue(found); // test listJobs function by filtering Report Job Criteria model testListJobs(jobId_01, jobId_02, userName); // test sorting feature testSorting(jobId_01, jobId_02); testSortingDES(jobId_01, jobId_02); testSortingNONEDES(jobId_01, jobId_02); // test pagination feature testPagination(jobId_01, jobId_02); // test bulk update feature by using report job model testUpdateJobsByIDFAIL(jobId_01, jobId_02); // test bulk update feature by using report job model testUpdateJobsByIDFAILInvalidID(jobId_01, jobId_02); // test bulk update feature by using report job model testUpdateJobsByIDFAILInvalidPath(jobId_01, jobId_02); // testUpdateJobsByID(jobId_01, jobId_02); // testUpdateJobsByReference(job_01, job_02); m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_01)); m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_02)); deleted = true; job_01 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_01)); assertNull(job_01); job_02 = m_reportJobsPersistenceService.loadJob(m_executionContext, new ReportJobIdHolder(jobId_02)); assertNull(job_02); } finally { if (!deleted) { m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_01)); m_reportJobsPersistenceService.deleteJob(m_executionContext, new ReportJobIdHolder(jobId_02)); } } }
From source file:org.openvpms.component.system.common.jxpath.OpenVPMSTypeConverter.java
/** * Convert a {@link BigInteger} to another type * /* www . j a va 2 s . c o m*/ * @param type * the class to convert too * @param value * the value to convert * @return Number * the converted number of null. * */ protected Number allocateNumber(Class type, BigInteger value) { if (type == Byte.class || type == byte.class) { return new Byte(value.byteValue()); } if (type == Short.class || type == short.class) { return new Short(value.shortValue()); } if (type == Integer.class || type == int.class) { return new Integer(value.intValue()); } if (type == Long.class || type == long.class) { return new Long(value.longValue()); } if (type == Float.class || type == float.class) { return new Float(value.floatValue()); } if (type == Double.class || type == double.class) { return new Double(value.doubleValue()); } if (type == BigDecimal.class) { return new BigDecimal(value); } if (type == BigInteger.class) { return value; } return null; }
From source file:com.uraroji.garage.android.arrraycopybench.MainActivity.java
private void startBench() { mResultTextView.setText(""); final String arrayTypeStr = mArrayTypeSpinner.getSelectedItem().toString(); final int arrayLength = Integer.parseInt(mArrayLengthSpinner.getSelectedItem().toString()); final int benchTimes = Integer.parseInt(mBenchTimesSpinner.getSelectedItem().toString()); final ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage(getString(R.string.benchmarking)); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setCancelable(false);//from ww w . j av a 2 s .com dialog.show(); final Handler handler = new Handler(); if (arrayTypeStr.equals("byte")) { final byte[] src = new byte[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (byte) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("short")) { final short[] src = new short[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (short) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("int")) { final int[] src = new int[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (int) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("long")) { final long[] src = new long[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (long) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("double")) { final double[] src = new double[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = (double) i; } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); benchResult = copyNative(src, benchTimes); showResult("native", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Object")) { final Object[] src = new Object[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Object(); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Byte")) { final Byte[] src = new Byte[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Byte((byte) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Integer")) { final Integer[] src = new Integer[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Integer((int) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Long")) { final Long[] src = new Long[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Long((long) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else if (arrayTypeStr.equals("Double")) { final Double[] src = new Double[arrayLength]; for (int i = 0; i < src.length; ++i) { src[i] = new Double((double) i); } new Thread(new Runnable() { @Override public void run() { BenchResult benchResult = null; benchResult = copyClone(src, benchTimes); showResult("clone", benchResult, handler); benchResult = copyArraycopy(src, benchTimes); showResult("System.arraycopy", benchResult, handler); benchResult = copyArraysCopyOf(src, benchTimes); showResult("Arrays.copyOf", benchResult, handler); benchResult = copyForLoop(src, benchTimes); showResult("for loop", benchResult, handler); dialog.dismiss(); } }).start(); } else { dialog.dismiss(); } }
From source file:com.willwinder.universalgcodesender.GrblControllerTest.java
/** * Test of issueSoftReset method, of class GrblController. *//*from w w w.j a va2 s .c o m*/ @Test public void testIssueSoftReset() throws IOException, Exception { System.out.println("issueSoftReset"); GrblController instance = new GrblController(mgc); // Noop if called while comm is closed. instance.issueSoftReset(); // Did not send reset command to communicator or issue reset. assertEquals(0, mgc.sentBytes.size()); assertEquals(0, mgc.numSoftResetCalls); try { instance.openCommPort(getSettings().getConnectionDriver(), "blah", 1234); } catch (Exception e) { fail("Unexpected exception from GrblController: " + e.getMessage()); } // Automatic soft reset assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); assertEquals(0, mgc.numSoftResetCalls); // Enable real time mode by sending correct GRBL version: instance.rawResponseHandler("Grbl 0.8c"); instance.issueSoftReset(); // Sent reset command to communicator and issued reset. assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); assertEquals(1, mgc.numSoftResetCalls); // GRBL version that might not have the command but I send it to anyway: mgc.resetInputsAndFunctionCalls(); instance.openCommPort(getSettings().getConnectionDriver(), "blah", 1234); assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); instance.rawResponseHandler("Grbl 0.8a"); instance.issueSoftReset(); // This version doesn't support soft reset. assertEquals(0, mgc.numSoftResetCalls); // GRBL version that should not be sent the command: mgc.resetInputsAndFunctionCalls(); instance.openCommPort(getSettings().getConnectionDriver(), "blah", 1234); assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); mgc.sentBytes.clear(); instance.rawResponseHandler("Grbl 0.7"); instance.issueSoftReset(); // Sent reset command to communicator and issued reset. assertEquals(0, mgc.sentBytes.size()); assertEquals(0, mgc.numSoftResetCalls); }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java
protected Object[] convertPrimitiveArrayToObjectArray(Object array) { Class<?> componentType = array.getClass().getComponentType(); Object[] result = null;/* w w w. j av a2 s. c o m*/ if (componentType == null) { throw new NullPointerException("componentType is null"); } else if (componentType == Character.TYPE) { char[] carray = (char[]) array; result = new Object[carray.length]; for (int i = 0; i < carray.length; i++) { result[i] = new Character(carray[i]); } } else if (componentType == Byte.TYPE) { byte[] barray = (byte[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Byte(barray[i]); } } else if (componentType == Short.TYPE) { short[] sarray = (short[]) array; result = new Object[sarray.length]; for (int i = 0; i < sarray.length; i++) { result[i] = new Short(sarray[i]); } } else if (componentType == Integer.TYPE) { int[] iarray = (int[]) array; result = new Object[iarray.length]; for (int i = 0; i < iarray.length; i++) { result[i] = Integer.valueOf(iarray[i]); } } else if (componentType == Long.TYPE) { long[] larray = (long[]) array; result = new Object[larray.length]; for (int i = 0; i < larray.length; i++) { result[i] = new Long(larray[i]); } } else if (componentType == Double.TYPE) { double[] darray = (double[]) array; result = new Object[darray.length]; for (int i = 0; i < darray.length; i++) { result[i] = new Double(darray[i]); } } else if (componentType == Float.TYPE) { float[] farray = (float[]) array; result = new Object[farray.length]; for (int i = 0; i < farray.length; i++) { result[i] = new Float(farray[i]); } } else if (componentType == Boolean.TYPE) { boolean[] barray = (boolean[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Boolean(barray[i]); } } else { throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName()); } return result; }
From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java
/** * Convert null to a primitive type.//w w w .jav a 2 s . com * @param toType destination class * @return a wrapper */ protected Object convertNullToPrimitive(Class toType) { if (toType == boolean.class) { return Boolean.FALSE; } if (toType == char.class) { return new Character('\0'); } if (toType == byte.class) { return new Byte((byte) 0); } if (toType == short.class) { return new Short((short) 0); } if (toType == int.class) { return new Integer(0); } if (toType == long.class) { return new Long(0L); } if (toType == float.class) { return new Float(0.0f); } if (toType == double.class) { return new Double(0.0); } return null; }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Convert any Number object to the specified type for this * <i>Converter</i>./*from w w w .j a v a 2 s . com*/ * <p> * This method handles conversion to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The Number to convert. * * @return The converted value. */ private Number toNumber(Class sourceType, Class targetType, Number value) { // Correct Number type already if (targetType.equals(value.getClass())) { return value; } // Byte if (targetType.equals(Byte.class)) { long longValue = value.longValue(); if (longValue > Byte.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Byte.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Byte(value.byteValue()); } // Short if (targetType.equals(Short.class)) { long longValue = value.longValue(); if (longValue > Short.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Short.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Short(value.shortValue()); } // Integer if (targetType.equals(Integer.class)) { long longValue = value.longValue(); if (longValue > Integer.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } if (longValue < Integer.MIN_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too small " + toString(targetType)); } return new Integer(value.intValue()); } // Long if (targetType.equals(Long.class)) { return new Long(value.longValue()); } // Float if (targetType.equals(Float.class)) { if (value.doubleValue() > Float.MAX_VALUE) { throw new ConversionException( toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType)); } return new Float(value.floatValue()); } // Double if (targetType.equals(Double.class)) { return new Double(value.doubleValue()); } // BigDecimal if (targetType.equals(BigDecimal.class)) { if (value instanceof Float || value instanceof Double) { return new BigDecimal(value.toString()); } else if (value instanceof BigInteger) { return new BigDecimal((BigInteger) value); } else { return BigDecimal.valueOf(value.longValue()); } } // BigInteger if (targetType.equals(BigInteger.class)) { if (value instanceof BigDecimal) { return ((BigDecimal) value).toBigInteger(); } else { return BigInteger.valueOf(value.longValue()); } } String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'"; throw new ConversionException(msg); }
From source file:org.apache.cocoon.taglib.core.ForEachSupport.java
protected ForEachIterator toForEachIterator(byte[] a) { Byte[] wrapped = new Byte[a.length]; for (int i = 0; i < a.length; i++) wrapped[i] = new Byte(a[i]); return new SimpleForEachIterator(Arrays.asList(wrapped).iterator()); }
From source file:org.opencms.util.CmsDataTypeUtil.java
/** * Parses the given data as a byte.<p> * //from w ww. j av a 2 s . c o m * @param data the data to parse * * @return the converted data value */ public static Byte parseByte(String data) { return new Byte(data); }