List of usage examples for org.apache.commons.lang ArrayUtils toObject
public static Boolean[] toObject(boolean[] array)
Converts an array of primitive booleans to objects.
From source file:org.smartsnip.persistence.hibernate.SqlPersistenceImplTest.java
/** * Test method for/*w w w .jav a2s .co m*/ * {@link org.smartsnip.persistence.hibernate.SqlPersistenceImpl#getCodeFile(Long)} * and * {@link org.smartsnip.persistence.hibernate.SqlPersistenceImpl#writeCodeFile(Long, org.smartsnip.core.File, int)} * . * * * @throws Throwable */ @Test public void testWriteAndGetCodeFile() throws Throwable { String name = "hibernate.cfg.test_db.xml"; java.io.File file = new java.io.File("./test/" + name); FileInputStream in = new FileInputStream(file); long length = file.length(); assertTrue("File size > 0 expected. Size = " + length, length > 0); if (length > Integer.MAX_VALUE) { throw new IOException("file too large"); } byte[] buffer = new byte[(int) length]; Byte[] content; try { in.read(buffer); content = ArrayUtils.toObject(buffer); } finally { try { in.close(); } catch (IOException ignored) { } } File codeFile = helper.createCodeFile(name, content); Code code = helper.createCode(1L, "to test", "java", test_snip2.getHashId(), 1, null); Long codeId = instance.writeCode(code, IPersistence.DB_DEFAULT); instance.writeCodeFile(codeId, codeFile, IPersistence.DB_DEFAULT); File result = instance.getCodeFile(codeId); // Tests on the object assertEquals(name, result.getName()); assertEquals(content.length, result.getContent().length); assertArrayEquals(content, result.getContent()); }
From source file:org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTableRemoveCommand.java
@SuppressWarnings("unchecked") //$NON-NLS-1$ @Override// w ww . ja v a 2 s . c om public void execute() { List beansList = extendedTable.getBeansList(); if (indexItemToRemove != null) { removedBeans = new ArrayList(1); extendedTable.remove((int) indexItemToRemove); removedBeans.add(removedBeans); removedBeansIndices = new ArrayList(1); removedBeansIndices.add(indexItemToRemove); } if (indexItemsToRemove != null) { removedBeans = new ArrayList(extendedTable.remove(indexItemsToRemove)); removedBeansIndices = Arrays.asList(ArrayUtils.toObject(indexItemsToRemove)); } if (beansToRemove != null) { int lstSize = beansToRemove.size(); removedBeansIndices = new ArrayList(); List beansToRemove2 = new ArrayList(beansToRemove); for (int i = 0; i < lstSize; i++) { int index = beansList.indexOf(beansToRemove2.get(i)); if (index != -1) { removedBeansIndices.add(index); } else { beansToRemove.remove(i); } } if (extendedTable.removeAll((Collection) beansToRemove)) { removedBeans = new ArrayList(beansToRemove); } else { removedBeansIndices.clear(); } } if (beanToRemove != null) { int index = beansList.indexOf(beanToRemove); if (extendedTable.remove(beanToRemove)) { removedBeans = new ArrayList(1); removedBeans.add(beanToRemove); removedBeansIndices = new ArrayList(1); removedBeansIndices.add(index); } } }
From source file:org.tinygroup.jdbctemplatedslsession.SimpleDslSession.java
public int[] batchInsert(Insert insert, List<Map<String, Object>> params, int batchSize, boolean autoGeneratedKeys) { final List<Integer> records = new ArrayList<Integer>(); final InsertBatchOperate insertBatchOperate = newInsertBatch(insert, autoGeneratedKeys); if (params.size() > batchSize) { batchProcess(batchSize, params, new BatchOperateCallback() { public int[] callback(List<Map<String, Object>> params) { int[] affectNums = insertBatchOperate.batchProcess(params); Collections.addAll(records, ArrayUtils.toObject(affectNums)); return affectNums; }//from w w w . ja v a2 s .c o m public int[] callbackList(List<List<Object>> params) { return null; } public int[] callback(Map<String, Object>[] params) { return null; } }); return ArrayUtils.toPrimitive(records.toArray(new Integer[0])); } return insertBatchOperate.batchProcess(params); }
From source file:org.tinygroup.jdbctemplatedslsession.SimpleDslSession.java
private int[] executeBatch(final String sql, List<List<Object>> params, int batchSize) { final List<Integer> records = new ArrayList<Integer>(); if (params.size() > batchSize) { executeBatchProcess(batchSize, params, new BatchOperateCallback() { public int[] callbackList(List<List<Object>> params) { int[] affectedNums = jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetterImpl(params, null)); Collections.addAll(records, ArrayUtils.toObject(affectedNums)); return affectedNums; }/*from w w w . ja v a 2s . co m*/ public int[] callback(List<Map<String, Object>> params) { return null; } public int[] callback(Map<String, Object>[] params) { return null; } }); return ArrayUtils.toPrimitive(records.toArray(new Integer[0])); } return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetterImpl(params, null)); }
From source file:org.tinygroup.jdbctemplatedslsession.SimpleDslSession.java
private int[] executeBatchUpdate(final String sql, Map<String, Object>[] params, int batchSize) { final List<Integer> records = new ArrayList<Integer>(); if (params.length > batchSize) { batchProcess(batchSize, params, new BatchOperateCallback() { public int[] callback(List<Map<String, Object>> params) { return null; }/* ww w. ja va2 s.co m*/ public int[] callbackList(List<List<Object>> params) { return null; } public int[] callback(Map<String, Object>[] params) { int[] affectedNums = simpleJdbcTemplate.batchUpdate(sql, params); Collections.addAll(records, ArrayUtils.toObject(affectedNums)); return affectedNums; } }); return ArrayUtils.toPrimitive(records.toArray(new Integer[0])); } return simpleJdbcTemplate.batchUpdate(sql, params); }
From source file:org.uimafit.factory.ConfigurationParameterFactory.java
/** * Convert a value so it can be injected into a UIMA component. UIMA only supports several * parameter types. If the value is not of these types, this method can be used to coerce the * value into a supported type (typically String). It is also used to convert primitive * arrays to object arrays when necessary. * //from w w w . j a v a 2s. c om * @param param the configuration parameter. * @param aValue the parameter value. * @return the converted value. */ protected static Object convertParameterValue(ConfigurationParameter param, Object aValue) { Object value = aValue; if (value.getClass().isArray() && value.getClass().getComponentType().getName().equals("boolean")) { value = ArrayUtils.toObject((boolean[]) value); } else if (value.getClass().isArray() && value.getClass().getComponentType().getName().equals("int")) { value = ArrayUtils.toObject((int[]) value); } else if (value.getClass().isArray() && value.getClass().getComponentType().getName().equals("float")) { value = ArrayUtils.toObject((float[]) value); } else { try { if (param.getType().equals(ConfigurationParameter.TYPE_STRING)) { SimpleTypeConverter converter = new SimpleTypeConverter(); PropertyEditorUtil.registerUimaFITEditors(converter); if (value.getClass().isArray() || value instanceof Collection) { value = converter.convertIfNecessary(value, String[].class); } else { value = converter.convertIfNecessary(value, String.class); } } } catch (TypeMismatchException e) { throw new IllegalArgumentException(e.getMessage(), e); } } return value; }
From source file:org.uncertml.distribution.categorical.CategoricalUniformDistribution.java
/** * Constructor that takes an array of integers, each representing a unique * <code>CategoricalUniformDistribution</code>. This is in line with the UncertML * syntax whereby a collection of types can be represented by a single entity. * /*from ww w.java 2s .c o m*/ * @param numberOfClasses an array of integers representing the number of * classes for each unique categorical distribution. */ public CategoricalUniformDistribution(int[] numberOfClasses) { this(Arrays.asList(ArrayUtils.toObject(numberOfClasses))); }
From source file:org.uncertml.distribution.continuous.BetaDistribution.java
/** * Constructor that takes an array of doubles for alpha and beta parameters. * Each alpha and beta pair represents a unique beta distribution. This is * in line with the UncertML syntax whereby a collection of types can be * represented by a single entity. Both arrays must be of equal length and * contain no null elements.//from w ww .j a v a 2s.co m * * @param alpha an array of doubles representing the alpha parameter of n * beta distributions. * @param beta an array of doubles representing the beta parameter of n * beta distributions. */ public BetaDistribution(double[] alpha, double[] beta) { this(Arrays.asList(ArrayUtils.toObject(alpha)), Arrays.asList(ArrayUtils.toObject(beta))); }
From source file:org.uncertml.distribution.continuous.CauchyDistribution.java
/** * Constructor that takes an array of doubles for location and scale parameters. * Each location and scale pair represents a unique Cauchy distribution. This is * in line with the UncertML syntax whereby a collection of types can be * represented by a single entity. Both arrays must be of equal length and * contain no null elements./*w ww . jav a 2 s . co m*/ * * @param location an array of doubles representing the location parameter of n * Cauchy distributions. * @param scale an array of doubles representing the scale parameter of n * Cauchy distributions. */ public CauchyDistribution(double[] location, double[] scale) { this(Arrays.asList(ArrayUtils.toObject(location)), Arrays.asList(ArrayUtils.toObject(scale))); }
From source file:org.uncertml.distribution.continuous.ChiSquareDistribution.java
/** * Constructor that takes an array of integers for degrees of freedom parameters. * Each degrees of freedom represents a unique chi-square distribution. This * is in line with the UncertML syntax whereby a collection of types can be * represented by a single entity. The array must not contain any null elements. * //from ww w . j av a 2s .c om * @param degreesOfFreedom an array of integers representing the degrees of * freedom parameters of n chi-square distributions. */ public ChiSquareDistribution(int[] degreesOfFreedom) { this(Arrays.asList(ArrayUtils.toObject(degreesOfFreedom))); }