List of usage examples for org.apache.commons.beanutils ConvertUtils convert
public static Object convert(String values[], Class clazz)
Convert an array of specified values to an array of objects of the specified class (if possible).
For more details see ConvertUtilsBean
.
From source file:ro.nextreports.server.api.client.jdbc.ResultSet.java
@Override public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { // return (BigDecimal) getObject(columnIndex); return (BigDecimal) ConvertUtils.convert(getObject(columnIndex), BigDecimal.class); }
From source file:ro.nextreports.server.api.client.jdbc.ResultSet.java
@Override public Date getDate(int columnIndex) throws SQLException { // return (Date) getObject(columnIndex); return (Date) ConvertUtils.convert(getObject(columnIndex), Date.class); }
From source file:ro.nextreports.server.api.client.jdbc.ResultSet.java
@Override public Time getTime(int columnIndex) throws SQLException { // return (Time) getObject(columnIndex); return (Time) ConvertUtils.convert(getObject(columnIndex), Time.class); }
From source file:ro.nextreports.server.api.client.jdbc.ResultSet.java
@Override public Timestamp getTimestamp(int columnIndex) throws SQLException { // return (Timestamp) getObject(columnIndex); return (Timestamp) ConvertUtils.convert(getObject(columnIndex), Timestamp.class); }
From source file:test.openmobster.device.agent.frameworks.mobileObject.TestBeanUtils.java
public void testPropertySetting() throws Exception { Object pojo = Thread.currentThread().getContextClassLoader() .loadClass("test.openmobster.device.agent.frameworks.mobileObject.MockPOJO").newInstance(); //Set Simple Property String simpleProperty = "value"; PropertyUtils.setProperty(pojo, simpleProperty, "parent"); //Set Nested Property String nestedProperty = "child.value"; StringTokenizer st = new StringTokenizer(nestedProperty, "."); Object courObj = pojo;//from ww w . j av a2s.c o m while (st.hasMoreTokens()) { String token = st.nextToken(); if (!st.hasMoreTokens()) { PropertyDescriptor metaData = PropertyUtils.getPropertyDescriptor(courObj, token); PropertyUtils.setNestedProperty(pojo, nestedProperty, ConvertUtils.convert("child", metaData.getPropertyType())); } else { PropertyDescriptor metaData = PropertyUtils.getPropertyDescriptor(courObj, token); if (PropertyUtils.getProperty(courObj, token) == null) { Object nestedObj = metaData.getPropertyType().newInstance(); PropertyUtils.setProperty(courObj, token, nestedObj); courObj = nestedObj; } else { courObj = PropertyUtils.getProperty(courObj, token); } } } //Set Nested Property non-string nestedProperty = "child.id"; st = new StringTokenizer(nestedProperty, "."); courObj = pojo; while (st.hasMoreTokens()) { String token = st.nextToken(); if (!st.hasMoreTokens()) { PropertyDescriptor metaData = PropertyUtils.getPropertyDescriptor(courObj, token); PropertyUtils.setNestedProperty(pojo, nestedProperty, ConvertUtils.convert("123", metaData.getPropertyType())); } else { PropertyDescriptor metaData = PropertyUtils.getPropertyDescriptor(courObj, token); if (PropertyUtils.getProperty(courObj, token) == null) { Object nestedObj = metaData.getPropertyType().newInstance(); PropertyUtils.setProperty(courObj, token, nestedObj); courObj = nestedObj; } else { courObj = PropertyUtils.getProperty(courObj, token); } } } //Set Indexed Property //String indexedProperty = "childArray[0]"; //st = new StringTokenizer(indexedProperty, "."); //courObj = pojo; //while(st.hasMoreTokens()) //{ // String token = st.nextToken(); // if(!st.hasMoreTokens()) // { // PropertyDescriptor metaData = PropertyUtils.getPropertyDescriptor(courObj, token); // PropertyUtils.setIndexedProperty(pojo, indexedProperty, ConvertUtils.convert("child://0", metaData.getPropertyType())); // } // else // { /*if(token.indexOf('[') != -1) { token = token.substring(0, token.indexOf('[')); }*/ // PropertyDescriptor metaData = PropertyUtils.getPropertyDescriptor(courObj, token); // if(PropertyUtils.getProperty(courObj, token) == null) // { // Object nestedObj = metaData.getPropertyType().newInstance(); // PropertyUtils.setProperty(courObj, token, nestedObj); // courObj = nestedObj; // } // else // { // courObj = PropertyUtils.getProperty(courObj, token); // } // } //} //Assert String[] childArray = ((MockPOJO) pojo).getChildArray(); assertEquals("Value does not match", ((MockPOJO) pojo).getValue(), "parent"); assertEquals("Value does not match", ((MockPOJO) pojo).getChild().getValue(), "child"); assertEquals("Value does not match", ((MockPOJO) pojo).getChild().getId(), 123); //assertEquals("Value does not match", childArray[0], "child://0"); }
From source file:uk.ac.diamond.scisoft.analysis.processing.operations.ncd.NcdSectorIntegrationOperation.java
@Override public OperationData process(IDataset slice, IMonitor monitor) throws OperationException { IROI roi = model.getRegion();//from w w w .ja v a 2s.c om if (model.getRegion() == null) { try { NexusNcdMetadataReader reader = new NexusNcdMetadataReader(model.getFilePath()); roi = reader.getROIDataFromFile(); if (roi == null) { throw new Exception("ROI must be defined for this operation"); } } catch (Exception e) { throw new OperationException(this, e); } } if (!(roi instanceof SectorROI)) { throw new OperationException(this, new IllegalArgumentException("The ROI must be a sector ROI")); } SectorROI sectorRoi = (SectorROI) roi; if (!sectorRoi.checkSymmetry(sectorRoi.getSymmetry())) { throw new OperationException(this, new IllegalArgumentException("The symmetry is not compatible with the ROI")); } sectorRoi.setAverageArea(false); sectorRoi.setClippingCompensation(true); model.setRegion(sectorRoi); SectorIntegration sec = new SectorIntegration(); int[] frames = NcdOperationUtils.addDimension(slice.getShape()); int dimension = 2; //should match input rank int[] areaShape = (int[]) ConvertUtils .convert(Arrays.copyOfRange(frames, frames.length - dimension, frames.length), int[].class); List<MaskMetadata> mask; try { mask = slice.getMetadata(MaskMetadata.class); } catch (Exception e) { throw new OperationException(this, e); } Dataset maskDataset = null; if (mask != null) { maskDataset = (Dataset) mask.get(0).getMask().getSlice(); } Dataset sliceDataset = (Dataset) slice.getSliceView(); sliceDataset.resize(NcdOperationUtils.addDimension(sliceDataset.getShape())); Dataset sliceErrors = sliceDataset.getError(); sliceDataset.clearMetadata(null); sliceDataset.setError(sliceErrors); if (!sliceDataset.hasErrors()) { // Use counting statistics if no input error estimates are available DoubleDataset inputErrorsBuffer = new DoubleDataset(sliceDataset); sliceDataset.setErrorBuffer(inputErrorsBuffer); } boolean calculateAzimuthal; if (model.getAzimuthalOrRadialIntegration() .equals(NcdSectorIntegrationModel.IntegrationOperationName.azimuthal)) { calculateAzimuthal = false; //azimuthal integration, so calculate radial profile } else { calculateAzimuthal = true; } Dataset[] areaData = ROIProfile.area(areaShape, Dataset.FLOAT32, maskDataset, sectorRoi, !calculateAzimuthal, calculateAzimuthal, false); sec.setAreaData(areaData); sec.setCalculateRadial(!calculateAzimuthal); sec.setCalculateAzimuthal(calculateAzimuthal); sec.setROI(sectorRoi); Dataset[] mydata = sec.process(sliceDataset, 1, maskDataset); int resLength = slice.getShape().length - dimension + 1; int dataIndex; // mydata[0] is azimuthal profile, radial integration. mydata[1] is radial profile, azimuthal integration if (model.getAzimuthalOrRadialIntegration() .equals(NcdSectorIntegrationModel.IntegrationOperationName.radial)) { dataIndex = 0; } else { dataIndex = 1; } Dataset myraddata = DatasetUtils.cast(mydata[dataIndex], Dataset.FLOAT32); Dataset myraderrors = null; if (myraddata != null) { if (myraddata.hasErrors()) { myraderrors = NcdOperationUtils.getErrorBuffer(mydata[dataIndex]); } int[] resRadShape = Arrays.copyOf(slice.getShape(), resLength); resRadShape[resLength - 1] = myraddata.getShape()[myraddata.getRank() - 1]; myraddata = myraddata.reshape(resRadShape); if (myraderrors != null) { myraderrors = myraderrors.reshape(resRadShape); myraddata.setErrorBuffer(myraderrors); } } Dataset qaxis = null; try { if (slice.getMetadata(IDiffractionMetadata.class) == null) { throw new Exception( "Diffraction metadata is required for this operation - add an Import Detector Calibration operation before this sector integration"); } NexusNcdMetadataReader reader = new NexusNcdMetadataReader(model.getFilePath()); qaxis = calculateQaxisDataset(reader.getQAxisCalibrationFromFile(), getFirstDiffractionMetadata(slice), myraddata.getShape(), (SectorROI) model.getRegion()); } catch (Exception e) { throw new OperationException(this, e); } OperationData toReturn = new OperationData(); Dataset myres = new FloatDataset(myraddata); if (myraderrors != null) { myres.setErrorBuffer(new DoubleDataset(myraderrors)); } if (qaxis != null) { AxesMetadataImpl axes = new AxesMetadataImpl(1); axes.setAxis(0, qaxis); myres.setMetadata(axes); } toReturn.setData(myres); return toReturn; }
From source file:uk.ac.diamond.scisoft.ncd.core.Average.java
public float[] process(Serializable buffer, final int[] dimensions) { float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class); // first dim is timeframe int firstdim = dimensions[0]; int[] imagedim = Arrays.copyOfRange(dimensions, 1, dimensions.length); int imagesize = 1; for (int n : imagedim) imagesize *= n;//from www. j a v a2s . c om float[] mydata = new float[imagesize]; for (int i = 0; i < parentdata.length; i++) { mydata[i % imagesize] += parentdata[i] / firstdim; } return mydata; }
From source file:uk.ac.diamond.scisoft.ncd.core.BackgroundSubtraction.java
public Object[] process(Serializable buffer, Serializable error, final int[] dimensions) { float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class); double[] parenterror = (double[]) ConvertUtils.convert(error, double[].class); float[] mydata = new float[parentdata.length]; double[] myerror = new double[parenterror.length]; // first dim is timeframe int[] imagedim = Arrays.copyOfRange(dimensions, 1, dimensions.length); int bgsize = 1; for (int n : background.getShape()) { bgsize *= n;// w ww . j a va 2s . co m } int parentsize = 1; for (int n : dimensions) { parentsize *= n; } // match if (bgsize == parentsize) { for (int i = 0; i < parentdata.length; i++) { mydata[i] = parentdata[i] - background.getData()[i]; myerror[i] = parenterror[i] + backgroundErrors.getData()[i]; } } else { float[] mybg = background.getData().clone(); double[] myerr = backgroundErrors.getData().clone(); if (background.getShape().length >= dimensions.length) { // averaging logger.warn("averaging background to fit data"); bgsize = 1; for (int n : imagedim) { bgsize *= n; } mybg = new float[bgsize]; myerr = new double[bgsize]; double multiplicity = parentdata.length / bgsize; for (int i = 0; i < background.getData().length; i++) { mybg[i % bgsize] += background.getData()[i] / multiplicity; myerr[i % bgsize] += backgroundErrors.getData()[i] / multiplicity; } } if (parentsize % bgsize == 0) { for (int i = 0; i < parentdata.length; i++) { mydata[i] = parentdata[i] - mybg[i % bgsize]; myerror[i] = parenterror[i] + myerr[i % bgsize]; } } else { logger.error("background and data sizes incompatible"); } } return new Object[] { mydata, myerror }; }
From source file:uk.ac.diamond.scisoft.ncd.core.data.DataSliceIdentifiers.java
public void setSlice(SliceSettings slice) { long[] frames = slice.getFrames(); long[] start_pos = (long[]) ConvertUtils.convert(slice.getStart(), long[].class); int sliceDim = slice.getSliceDim(); int sliceSize = slice.getSliceSize(); long[] start_data = Arrays.copyOf(start_pos, frames.length); long[] block_data = Arrays.copyOf(frames, frames.length); Arrays.fill(block_data, 0, slice.getSliceDim(), 1); block_data[sliceDim] = Math.min(frames[sliceDim] - start_pos[sliceDim], sliceSize); long[] count_data = new long[frames.length]; Arrays.fill(count_data, 1);//from w w w .j a v a2 s . c o m setSlice(start_data, block_data, count_data, block_data); }
From source file:uk.ac.diamond.scisoft.ncd.core.DegreeOfOrientation.java
public Object[] process(Serializable buffer, Serializable axis, final int[] dimensions) { double[] parentaxis = (double[]) ConvertUtils.convert(axis, double[].class); float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class); int size = dimensions[dimensions.length - 1]; double[] myaxis = new double[size]; double[] mydata = new double[size]; double[] cos2data = new double[size]; double[] sin2data = new double[size]; double[] sincosdata = new double[size]; for (int i = 0; i < parentaxis.length; i++) { myaxis[i] = Math.toRadians(parentaxis[i]); mydata[i] = parentdata[i];/*from w w w . ja v a2 s. com*/ float cos2alpha = (float) Math.cos(2.0 * myaxis[i]); float sin2alpha = (float) Math.sin(2.0 * myaxis[i]); cos2data[i] = (1.0f + cos2alpha) * parentdata[i] / 2.0; sin2data[i] = (1.0f - cos2alpha) * parentdata[i] / 2.0; sincosdata[i] = sin2alpha * parentdata[i] / 2.0; } UnivariateInterpolator interpolator = new SplineInterpolator(); UnivariateFunction function = interpolator.interpolate(myaxis, mydata); UnivariateFunction cos2Function = interpolator.interpolate(myaxis, cos2data); UnivariateFunction sin2Function = interpolator.interpolate(myaxis, sin2data); UnivariateFunction sincosFunction = interpolator.interpolate(myaxis, sincosdata); UnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(15, BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY, BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY); try { float cos2mean = (float) integrator.integrate(INTEGRATION_POINTS, cos2Function, myaxis[0], myaxis[myaxis.length - 1]); float sin2mean = (float) integrator.integrate(INTEGRATION_POINTS, sin2Function, myaxis[0], myaxis[myaxis.length - 1]); float sincosmean = (float) integrator.integrate(INTEGRATION_POINTS, sincosFunction, myaxis[0], myaxis[myaxis.length - 1]); float norm = (float) integrator.integrate(INTEGRATION_POINTS, function, myaxis[0], myaxis[myaxis.length - 1]); cos2mean /= norm; sin2mean /= norm; sincosmean /= norm; float result = (float) Math.sqrt(Math.pow(cos2mean - sin2mean, 2) - 4.0 * sincosmean * sincosmean); double angle = MathUtils.normalizeAngle(Math.atan2(2.0 * sincosmean, cos2mean - sin2mean) / 2.0, Math.PI); Object[] output = new Object[] { new float[] { result }, new float[] { (float) Math.toDegrees(angle) }, new float[] { (float) (result * Math.cos(angle)), (float) (result * Math.sin(angle)) }, }; return output; } catch (TooManyEvaluationsException e) { return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } }; } catch (MaxCountExceededException e) { return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } }; } }