Java Code Examples for org.apache.commons.lang.ArrayUtils.reverse()

The following are Jave code examples for showing how to use reverse() of the org.apache.commons.lang.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: teasy   File: MethodsInvoker.java   View Source Code Vote up 4 votes
/**
 * Called when using all project-specific annotations (OurBeforeGroups, OurAfterMethod, etc.)
 * We decided to catch all kind of exceptions here because
 * based on (https://groups.google.com/forum/#!topic/testng-users/0JhqmewMezM) we think that tests get skipped
 * in case of failure in any before/after method
 *
 * @param context
 * @param isBeforeAfterGroup
 */
protected void invokeMethodsByAnnotation(final TestClassContext context, boolean isBeforeAfterGroup) {
    try {

        //for invoke all public methods with @OurBefore... and @OurAfter... from super or this class
        Method[] publicMethods = context.getTestClass().getMethods();

        //for invoke private methods with @OurBefore... and @OurAfter... from this class
        Method[] privateMethods = context.getTestClass().getDeclaredMethods();

        //remove public methods of test class
        List<Method> filteredMethods = Arrays.asList(publicMethods).stream()
                .filter(name -> !name.getDeclaringClass().getName().contains(context.getTestClass().getName()))
                .collect(Collectors.toList());

        //paste all methods from test class to top of the list
        for (int i = 0; i < privateMethods.length; i++) {
            filteredMethods.add(i, privateMethods[i]);
        }

        Method[] allMethods = new Method[filteredMethods.size()];
        filteredMethods.toArray(allMethods);

        //reverse methods array for correct invoke order if TestClass extends SuperClass with @Before methods
        if (context.getAnnotationToInvokeMethod().getName().contains("OurBefore")) {
            ArrayUtils.reverse(allMethods);
        }
        for (Method method : allMethods) {
            if (isMethodShouldBeInvoked(method, context)) {
                AbstractTest testInstance = context.getTestInstance();
                if (testInstance != null || (testInstance = createTestClassInstance(context.getTestClass())) != null) {
                    //hack for E4 project only (@LoginAs and @LoginTo) by default the method will do nothing until you override it
                    //and add some specific logic. For example handle your special annotations
                    testInstance.handleBeforeAfterAnnotations(method);

                    invokeMethod(testInstance, method, context, isBeforeAfterGroup);
                }
            }
        }
    } catch (StopTestExecutionException e) {
        if (e.getCause() instanceof InvocationTargetException) {
            Throwable targetException = ((InvocationTargetException) e.getCause()).getTargetException();
            new Report("*****StopTestExecutionException*****" + context.getTestClass() + " " + targetException.getCause(), e).jenkins();
        } else {
            new Report("*****StopTestExecutionException*****" + context.getTestClass() + " " + e.getCause(), e).jenkins();
        }
        try {
            context.getTestInstance().setStopTextExecutionThrowable(e);
        } catch (NullPointerException ignored) {
        }
    } catch (Throwable t) {
        new Report("*****Throwable*****" + context.getTestClass(), t).jenkins();
    }
}
 
Example 2
Project: neo-java   File: ECPoint.java   View Source Code Vote up 4 votes
private static byte[] reverse(final byte[] ba) {
	ArrayUtils.reverse(ba);
	return ba;
}
 
Example 3
Project: neo-java   File: BlockDbH2Impl.java   View Source Code Vote up 4 votes
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {

	final JdbcTemplate t = new JdbcTemplate(ds);

	for (final Block block : blocks) {
		final byte[] prevHashBa = block.prevHash.toByteArray();
		ArrayUtils.reverse(prevHashBa);

		final String putBlockSql = getSql("putBlock");
		final byte[] blockIndexBa = block.index.toByteArray();
		t.update(putBlockSql, block.hash.toByteArray(), prevHashBa, blockIndexBa, block.toHeaderByteArray());

		final String putTransactionSql = getSql("putTransaction");
		final String putTransactionInputSql = getSql("putTransactionInput");
		final String putTransactionOutputSql = getSql("putTransactionOutput");
		final String putTransactionScriptSql = getSql("putTransactionScript");
		int transactionIndex = 0;

		final List<Object[]> putTransactionList = new ArrayList<>();
		final List<Object[]> putTransactionInputList = new ArrayList<>();
		final List<Object[]> putTransactionOutputList = new ArrayList<>();
		final List<Object[]> putTransactionScriptList = new ArrayList<>();

		for (final Transaction transaction : block.getTransactionList()) {
			final byte[] txIxByte = new UInt16(transactionIndex).toByteArray();
			final byte[] transactionBaseBa = transaction.toBaseByteArray();
			add(putTransactionList, blockIndexBa, txIxByte, transaction.hash.toByteArray(), transactionBaseBa);

			for (int inputIx = 0; inputIx < transaction.inputs.size(); inputIx++) {
				final byte[] txInputIxByte = new UInt32(inputIx).toByteArray();
				final CoinReference input = transaction.inputs.get(inputIx);
				add(putTransactionInputList, blockIndexBa, txIxByte, txInputIxByte,
						input.prevHash.toByteArray(), input.prevIndex.toByteArray());
			}

			for (int outputIx = 0; outputIx < transaction.outputs.size(); outputIx++) {
				final byte[] txOutputIxByte = new UInt16(outputIx).toByteArray();
				final TransactionOutput output = transaction.outputs.get(outputIx);
				add(putTransactionOutputList, blockIndexBa, txIxByte, txOutputIxByte,
						output.assetId.toByteArray(), output.value.toByteArray(),
						output.scriptHash.toByteArray());
			}

			for (int scriptIx = 0; scriptIx < transaction.scripts.size(); scriptIx++) {
				final byte[] txScriptIxByte = new UInt32(scriptIx).toByteArray();
				final Witness script = transaction.scripts.get(scriptIx);
				add(putTransactionScriptList, blockIndexBa, txIxByte, txScriptIxByte,
						script.getCopyOfInvocationScript(), script.getCopyOfVerificationScript());
			}

			transactionIndex++;
		}

		t.batchUpdate(putTransactionSql, putTransactionList);
		t.batchUpdate(putTransactionInputSql, putTransactionInputList);
		t.batchUpdate(putTransactionOutputSql, putTransactionOutputList);
		t.batchUpdate(putTransactionScriptSql, putTransactionScriptList);
	}
}
 
Example 4
Project: roc-completion   File: SettingLookupElement.java   View Source Code Vote up 4 votes
@Override
public void handleInsert(InsertionContext context)
{
    // Remove the text the user typed.
    context
        .getDocument()
        .deleteString(context.getStartOffset(), context.getTailOffset());

    context.commitDocument();

    // Grab the deepest property available for insertion... hø hø hø!
    JSProperty targetProperty = getTargetProperty(context.getFile());
    // Generate the remaining jsNotation.
    String quote = JSCodeStyleSettings.getQuote(targetProperty);
    String jsNotation = setting.toRelativeJsNotation(targetProperty, quote);

    // Create a new file to initiate all lexers, parsers grumpkins and snarks...
    PsiFile psiContainer = PsiFileFactory
        .getInstance(context.getProject())
        .createFileFromText(targetProperty.getLanguage(), jsNotation);

    JSExpression value = targetProperty.getValue();

    if (value == null)
    {
        return;
    }

    PsiElement[] childrenForInsertion = psiContainer.getChildren();
    // Insert in reverse order. Probably an easier way, but this works just fine...
    ArrayUtils.reverse(childrenForInsertion);

    // Grab all created elements in the temporary file and insert them into the document.
    for (PsiElement completion : childrenForInsertion)
    {
        value.addAfter(completion, value.getFirstChild());
    }

    PsiElement formattedValue = CodeStyleManager
        .getInstance(context.getProject())
        .reformat(value);

    value.replace(formattedValue);

    List<LookupElement> subCompletions = setting.getSubCompletionVariants();
    // User does not need to edit bools or enums with single value.
    if (setting.getType().equals("Boolean") || subCompletions.size() == 1)
    {
        return;
    }

    context.commitDocument();
    moveCursor(context);

    if (subCompletions.size() > 1)
    {
        AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor());
    }
}
 
Example 5
Project: neo-java   File: NetworkUtil.java   View Source Code Vote up 3 votes
/**
 * writes a ByteArraySerializable to an output stream.
 *
 * @param out
 *            the output stream to use.
 * @param t
 *            the object to write.
 * @param reversed
 *            if true, reverse the byte array before writing.
 * @param <T>
 *            the ByteArraySerializable type.
 */
public static <T extends ByteArraySerializable> void write(final OutputStream out, final T t,
		final boolean reversed) {
	final byte[] ba = t.toByteArray();
	if (reversed) {
		ArrayUtils.reverse(ba);
	}
	write(out, ba);
}
 
Example 6
Project: ProjectAres   File: HologramFrame.java   View Source Code Vote up 2 votes
/**
 * Creates a new {@link HologramFrame} with the specified content.
 *
 * @param content The content to be displayed
 */
public HologramFrame(String... content) {
    ArrayUtils.reverse(content);
    this.content = Arrays.asList(content);
}
 
Example 7
Project: neo-java   File: AbstractByteArray.java   View Source Code Vote up 2 votes
/**
 * returns a positive BigInteger, in reverse byte order.
 *
 * @return this array as a BigInteger, assuming the bytes represent a signed int
 *         in reverse byte order.
 */
public final BigInteger toReverseBytesPositiveBigInteger() {
	final byte[] reverseBytes = getBytesCopy();
	ArrayUtils.reverse(reverseBytes);
	return new BigInteger(1, reverseBytes);
}
 
Example 8
Project: neo-java   File: NetworkUtil.java   View Source Code Vote up 2 votes
/**
 * writes a short as a byte array to the output stream.
 *
 * @param out
 *            the output stream to use.
 * @param x
 *            the short to write. (the short can be any integer even a long,
 *            only the lower bytes will be written).
 */
public static void writeShort(final OutputStream out, final long x) {
	final byte[] ba = getShortByteArray(x);
	ArrayUtils.reverse(ba);
	write(out, ba);
}