Java Code Examples for org.apache.commons.lang3.ArrayUtils#toArray()

The following examples show how to use org.apache.commons.lang3.ArrayUtils#toArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuerydslUtilsBeanImpl.java    From gvnix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T> Class<?> getFieldType1(String fieldName, PathBuilder<T> entity) {
    Class<?> entityType = entity.getType();
    String fieldNameToFindType = fieldName;

    // Makes the array of classes to find fieldName agains them
    Class<?>[] classArray = ArrayUtils.<Class<?>> toArray(entityType);
    if (fieldName.contains(SEPARATOR_FIELDS)) {
        String[] fieldNameSplitted = StringUtils.split(fieldName,
                SEPARATOR_FIELDS);
        for (int i = 0; i < fieldNameSplitted.length - 1; i++) {
            Class<?> fieldType = BeanUtils.findPropertyType(
                    fieldNameSplitted[i],
                    ArrayUtils.<Class<?>> toArray(entityType));
            classArray = ArrayUtils.add(classArray, fieldType);
            entityType = fieldType;
        }
        fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1];
    }

    return BeanUtils.findPropertyType(fieldNameToFindType, classArray);
}
 
Example 2
Source File: QuerydslUtils.java    From gvnix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Obtains the class type of the property named as {@code fieldName} of the
 * entity.
 * 
 * @param fieldName the field name.
 * @param entity the entity with a property named as {@code fieldName}
 * @return the class type
 */
public static <T> Class<?> getFieldType1(String fieldName,
        PathBuilder<T> entity) {
    Class<?> entityType = entity.getType();
    String fieldNameToFindType = fieldName;

    // Makes the array of classes to find fieldName agains them
    Class<?>[] classArray = ArrayUtils.<Class<?>> toArray(entityType);
    if (fieldName.contains(SEPARATOR_FIELDS)) {
        String[] fieldNameSplitted = StringUtils.split(fieldName,
                SEPARATOR_FIELDS);
        for (int i = 0; i < fieldNameSplitted.length - 1; i++) {
            Class<?> fieldType = BeanUtils.findPropertyType(
                    fieldNameSplitted[i],
                    ArrayUtils.<Class<?>> toArray(entityType));
            classArray = ArrayUtils.add(classArray, fieldType);
            entityType = fieldType;
        }
        fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1];
    }

    return BeanUtils.findPropertyType(fieldNameToFindType, classArray);
}
 
Example 3
Source File: GetterExecutor.java    From OpenPeripheral with MIT License 5 votes vote down vote up
@Override
public Object[] call(IConverter converter, Object owner, Object... args) {
	Preconditions.checkArgument(args.length == 0, "Getter has no arguments");

	final Object target = PropertyUtils.getContents(owner, field);
	accessHandler.onGet(owner, target, field);
	final Object result = manipulator.getField(owner, target, field);
	final Object converted = converter.fromJava(result);
	return ArrayUtils.toArray(converted);
}
 
Example 4
Source File: TitanFileConverterUnitTest.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void basicTNConverterTest() {
    final File tempOutput = createTempFile("titanTN", ".tsv");
    TitanFileConverter.convertCRToTitanCovFile(COVERAGES_FILE, tempOutput);
    try {
        Assert.assertEquals(FileUtils.readLines(tempOutput).size(), FileUtils.readLines(COVERAGES_FILE).size());
        final String[] headers = ArrayUtils.toArray(FileUtils.readLines(tempOutput).get(0).split("\t"));
        Assert.assertEquals(headers, TitanCopyRatioEstimateColumns.FULL_COLUMN_NAME_ARRAY.toArray());
    } catch (final IOException ioe) {
        Assert.fail("Problem with unit test configuration.", ioe);
    }
}
 
Example 5
Source File: IndexedGetterExecutor.java    From OpenPeripheral with MIT License 5 votes vote down vote up
@Override
public Object[] call(IConverter converter, Object owner, Object... args) {
	Preconditions.checkArgument(args.length == 1, "Getter should have exactly one argument (index)");
	final Object index = converter.toJava(args[0], typeInfo.keyType);
	Preconditions.checkArgument(index != null, "Invalid index");

	final Object target = PropertyUtils.getContents(owner, field);
	accessHandler.onGet(owner, target, field, index);
	final Object result = manipulator.getField(owner, target, field, index);
	final Object converted = converter.fromJava(result);
	return ArrayUtils.toArray(converted);
}
 
Example 6
Source File: FilterConfigurationDialog.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
private SeverityEditingSupport(TableViewer viewer) {
    super(viewer);
    this.viewer = viewer;
    displayValues = ArrayUtils.toArray("Any", "Style", "Low", "Medium", "High", "Critical");
    severityValues = ArrayUtils.toArray(Severity.ANY, Severity.STYLE, Severity.LOW,
            Severity.MEDIUM, Severity.HIGH, Severity.CRITICAL);
    this.editor = new ComboBoxCellEditor(viewer.getTable(), displayValues, SWT.DROP_DOWN
            | SWT.READ_ONLY);
}
 
Example 7
Source File: CheckerGroupContentProvider.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {

    if (parentElement instanceof SearchList) {
        return this.reportListView.getReportList().get().getCheckers().toArray();
    }

    if (parentElement instanceof String) {
        return this.reportListView.getReportList().get().getReportsFor((String)
                parentElement).toArray();
    }

    if (parentElement instanceof ReportInfo) {
    	ReportInfo ri = (ReportInfo) parentElement;
    	Optional<ProblemInfo> bp = ri.getChildren();
    	if (bp != null && bp.isPresent()) {
            ArrayList<BugPathItem> result = new ArrayList<>(bp.get().getItems());
            Iterables.removeIf(result, new Predicate<BugPathItem>() {
                @Override
                public boolean apply(BugPathItem pi) {
                    return "".equals(pi.getMessage());
                }
            });
            return result.toArray();
        }
    }

    return ArrayUtils.toArray();
}
 
Example 8
Source File: RouterFunctionData.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
/**
 * Get method request method [ ].
 *
 * @param methods the methods
 * @return the request method [ ]
 */
private RequestMethod[] getMethod(Set<HttpMethod> methods) {
	if (!CollectionUtils.isEmpty(methods)) {
		return methods.stream().map(this::getRequestMethod).toArray(RequestMethod[]::new);
	}
	return ArrayUtils.toArray();
}
 
Example 9
Source File: TestBroadcastMessageStorage.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
private void verifyExecution(Function<FakeMessageStorage, Boolean> isExecutedFunction) {
    for (FakeMessageStorage messageStorage :
            ArrayUtils.toArray(primaryMessageStorage, secondaryMessageStorage)) {
        assertTrue(isExecutedFunction.apply(messageStorage));
    }
}
 
Example 10
Source File: FilterConfigurationDialog.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 4 votes vote down vote up
private SuppressedEditingSupport(TableViewer viewer) {
    super(viewer);
    this.viewer = viewer;
    this.editor = new ComboBoxCellEditor(viewer.getTable(), ArrayUtils.toArray("yes",
            "no"), SWT.DROP_DOWN | SWT.READ_ONLY);
}
 
Example 11
Source File: CtableSPInstruction.java    From systemds with Apache License 2.0 4 votes vote down vote up
@Override
public MatrixBlock[] call(Tuple2<Tuple2<MatrixBlock, MatrixBlock>, MatrixBlock> v1) throws Exception {
	return ArrayUtils.toArray(v1._1()._1(), v1._1()._2(), v1._2());
}
 
Example 12
Source File: CtableSPInstruction.java    From systemds with Apache License 2.0 4 votes vote down vote up
@Override
public MatrixBlock[] call(Tuple2<MatrixBlock, MatrixBlock> v1) throws Exception {
	return ArrayUtils.toArray(v1._1(), v1._2());
}
 
Example 13
Source File: CtableSPInstruction.java    From systemds with Apache License 2.0 4 votes vote down vote up
@Override
public MatrixBlock[] call(MatrixBlock v1) throws Exception {
	return ArrayUtils.toArray(v1);
}
 
Example 14
Source File: CtableSPInstruction.java    From systemds with Apache License 2.0 4 votes vote down vote up
@Override
public MatrixBlock[] call(Tuple2<MatrixBlock, MatrixBlock> v1) throws Exception {
	return ArrayUtils.toArray(v1._1(), v1._2());
}
 
Example 15
Source File: CtableSPInstruction.java    From systemds with Apache License 2.0 4 votes vote down vote up
@Override
public MatrixBlock[] call(Tuple2<Tuple2<MatrixBlock, MatrixBlock>, MatrixBlock> v1) throws Exception {
	return ArrayUtils.toArray(v1._1()._1(), v1._1()._2(), v1._2());
}
 
Example 16
Source File: LibDaiFgIoTest.java    From pacaya with Apache License 2.0 4 votes vote down vote up
@Test
    public void testConfigIdToLibdaIx() {
        Var v1 = new Var(VarType.PREDICTED, 3, "v1", Arrays.asList("a", "b", "c"));
        Var v2 = new Var(VarType.PREDICTED, 2, "v2", Arrays.asList("e", "f"));
        VarSet vs = new VarSet(v1, v2);
        org.junit.Assert.assertArrayEquals(array(v1.getNumStates(), v2.getNumStates()), vs.getDims());

        Var[] vars = ArrayUtils.toArray(v2, v1);
        VarSet vs2 = new VarSet(vars);
        org.junit.Assert.assertArrayEquals(array(v1.getNumStates(), v2.getNumStates()), vs2.getDims());

        assertEquals(LibDaiFgIo.configIdToLibDaiIx(0, vs), 0);
        int[] dims = {  v2.getNumStates(), v1.getNumStates() };
        // because the order in vs2 is sorted and is the reverse of the order in vars, they should all match
        for (int i = 0; i < vs2.calcNumConfigs(); i++) {
            assertEquals(LibDaiFgIo.libDaiIxToConfigId(i, dims, vars, vs2), i);
        }
        // pacaya order:
        // v1 v2
        // 0 0 (becomes 0)
        // 0 1 (becomes 3)
        // 1 0 (becomes 1)
        // 1 1 (becomes 4)
        // 2 0 (becomes 2)
        // 2 1 (becomes 5)
        
        // reversed:
        // 0 0
        // 1 0
        // 2 0
        // 0 1
        // 1 1
        // 2 1
        
        // the conversion the other direction doesn't allow you to specify the order
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(0, vs2), 0);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(1, vs2), 3);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(2, vs2), 1);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(3, vs2), 4);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(4, vs2), 2);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(5, vs2), 5);
        // since the pacaya var set is sorted, it doesn't matter which vs we use
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(0, vs), 0);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(1, vs), 3);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(2, vs), 1);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(3, vs), 4);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(4, vs), 2);
        assertEquals(LibDaiFgIo.configIdToLibDaiIx(5, vs), 5);
}
 
Example 17
Source File: CtableSPInstruction.java    From systemds with Apache License 2.0 4 votes vote down vote up
@Override
public MatrixBlock[] call(MatrixBlock v1) throws Exception {
	return ArrayUtils.toArray(v1);
}
 
Example 18
Source File: SafePeripheralFactory.java    From OpenPeripheral with MIT License 4 votes vote down vote up
@Override
public String[] getMethodNames() {
	return ArrayUtils.toArray(BOGUS_METODS[RANDOM.nextInt(BOGUS_METODS.length)]);
}
 
Example 19
Source File: SafePeripheralFactory.java    From OpenPeripheral with MIT License 4 votes vote down vote up
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
	return ArrayUtils.toArray("This peripheral is broken. You can show your log in #OpenMods");
}
 
Example 20
Source File: ConvertUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 将动态数组转成数组.
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * String[] array = ConvertUtil.toArray("1", "2");                  =   ["1", "2"];
 * 
 * String[] emptyArray = ConvertUtil.{@code <String>}toArray();     =   [] ; //= new String[] {};
 * Integer[] emptyArray = ConvertUtil.{@code <Integer>}toArray();   =   [] ; //= new Integer[] {};
 * 
 * <span style="color:red">//注意</span>
 * String[] nullArray = ConvertUtil.toArray(null)                   =   null;
 * ConvertUtil.toArray((String) null)                               =   new String[] { null }
 * </pre>
 * 
 * </blockquote>
 * 
 * <h3>注意:</h3>
 * 
 * <blockquote>
 * <p>
 * 数组是具体化的(reified),而泛型在运行时是被擦除的(erasure)。<br>
 * 数组是在运行时才去判断数组元素的类型约束,而泛型正好相反,在运行时,泛型的类型信息是会被擦除的,只有编译的时候才会对类型进行强化。
 * </p>
 * 
 * <b>泛型擦除的规则:</b>
 * 
 * <ol>
 * <li>所有参数化容器类都被擦除成非参数化的(raw type); 如 List{@code <E>}、List{@code <List<E>>}都被擦除成 List</li>
 * <li>所有参数化数组都被擦除成非参数化的数组;如 List{@code <E>}[],被擦除成 List[]</li>
 * <li>Raw type 的容器类,被擦除成其自身,如 List{@code <E>}被擦 除成 List</li>
 * <li>原生类型(int,String 还有 wrapper 类)都擦除成他们的自身</li>
 * <li>参数类型 E,如果没有上限,则被擦除成 Object</li>
 * <li>所有约束参数如{@code <? Extends E>}、{@code <X extends E>}都被擦 除成 E</li>
 * <li>如果有多个约束,擦除成第一个,如{@code <T extends Object & E>},则擦除成 Object</li>
 * </ol>
 * 
 * <p>
 * 这将会导致下面的代码:
 * </p>
 * 
 * <pre class="code">
 * 
 * public static {@code <K, V>} Map{@code <K, V[]>} toArrayValueMap(Map{@code <K, V>} singleValueMap){
 *     Map{@code <K, V[]>} arrayValueMap = newLinkedHashMap(singleValueMap.size());//保证顺序和参数singleValueMap顺序相同
 *     for (Map.Entry{@code <K, V>} entry : singleValueMap.entrySet()){
 *         arrayValueMap.put(entry.getKey(), toArray(entry.getValue()));//注意此处的Value不要声明成V,否则会变成Object数组
 *     }
 *     return arrayValueMap;
 * }
 * </pre>
 * 
 * 调用的时候,
 * 
 * <pre class="code">
 * Map{@code <String, String>} singleValueMap = MapUtil.newLinkedHashMap(2);
 * singleValueMap.put("province", "江苏省");
 * singleValueMap.put("city", "南通市");
 * 
 * Map{@code <String, String[]>} arrayValueMap = MapUtil.toArrayValueMap(singleValueMap);
 * String[] strings = arrayValueMap.get("province");//此时返回的是 Object[]
 * </pre>
 * 
 * 会出现异常
 * 
 * <pre class="code">
 * java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
 * </pre>
 * 
 * </blockquote>
 *
 * @param <T>
 *            the generic type
 * @param arrays
 *            the arrays
 * @return 如果 <code>arrays</code> 是null,返回null<br>
 * @see org.apache.commons.lang3.ArrayUtils#toArray(Object...)
 * @since commons-lang 3
 * @since 1.6.0
 */
@SafeVarargs
public static <T> T[] toArray(T...arrays){
    return ArrayUtils.toArray(arrays);
}