Example usage for org.apache.commons.lang ArrayUtils reverse

List of usage examples for org.apache.commons.lang ArrayUtils reverse

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils reverse.

Prototype

public static void reverse(boolean[] array) 

Source Link

Document

Reverses the order of the given array.

Usage

From source file:org.eurekastreams.server.service.actions.strategies.activity.IterpolationListColliderTest.java

/**
 * Test collision collding 100 sorted items with 100 unsorted items..
 * //from w  w w  . ja v  a  2  s.c om
 * @throws FileNotFoundException
 *             if the file is not found.
 */
@Test
public final void testCollision100x100() throws FileNotFoundException {
    final Long[] sorted = fileToList(ITEMS_100_SORTED_FILE, ONE_HUNDRED);

    // Method that generates array does it the ascending, switch to descending.
    ArrayUtils.reverse(sorted);

    final Long[] unsorted = fileToList(ITEMS_100_UNSORTED_FILE, ONE_HUNDRED);

    collideTest(sorted, unsorted, ONE_HUNDRED);
}

From source file:org.eurekastreams.server.service.actions.strategies.activity.IterpolationListColliderTest.java

/**
 * Test collision collding 1000 sorted items with 1000 unsorted items..
 * //from   w ww .jav a 2s.c  o  m
 * @throws FileNotFoundException
 *             if list file is not found.
 */
@Test
public final void testCollision1000x1000() throws FileNotFoundException {
    final Long[] sorted = fileToList(ITEMS_1000_SORTED_FILE, ONE_THOUSAND);

    // Method that generates array does it the ascending, switch to descending.
    ArrayUtils.reverse(sorted);

    final Long[] unsorted = fileToList(ITEMS_1000_UNSORTED_FILE, ONE_THOUSAND);

    collideTest(sorted, unsorted, ONE_THOUSAND);
}

From source file:org.eurekastreams.server.service.actions.strategies.activity.IterpolationListColliderTest.java

/**
 * Test collision collding 1000 sorted items with 1000 unsorted items, both are the same list.
 * //from   w w  w .j  a va 2  s  .co m
 * @throws FileNotFoundException
 *             if list file is not found.
 */
@Test
public final void testCollision1000x1000SameList() throws FileNotFoundException {
    final Long[] sorted = fileToList(ITEMS_1000_SORTED_FILE, ONE_THOUSAND);

    // Method that generates array does it the ascending, switch to descending.
    ArrayUtils.reverse(sorted);

    Long[] unsorted = sorted;

    collideTest(sorted, unsorted, ONE_THOUSAND);

}

From source file:org.jiemamy.eclipse.core.ui.composer.DbImporterWizardPage.java

private void createButtons(Composite cmpButtons) {
    btnAddJar = new Button(cmpButtons, SWT.PUSH);
    btnAddJar.setText("(&A)"); // RESOURCE
    btnAddJar.addSelectionListener(new SelectionAdapter() {

        @Override/*from w  ww.  ja  v a  2  s .com*/
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialog = new FileDialog(getShell(), SWT.MULTI | SWT.OPEN);
            fileDialog.setText("JDBC?jar??"); // RESOURCE
            fileDialog.setFilterExtensions(JAR_EXTENSIONS);
            if (fileDialog.open() == null) {
                return;
            }
            String[] fileNames = fileDialog.getFileNames();
            String filterPath = fileDialog.getFilterPath();
            for (String fileName : fileNames) {
                lstDriverJars.add(filterPath + SystemUtils.FILE_SEPARATOR + fileName);
            }
            if (ArrayUtils.isEmpty(fileNames) == false) {
                driverListChanged();
            }
        }
    });
    btnRemoveJar = new Button(cmpButtons, SWT.PUSH);
    btnRemoveJar.setText("(&R)"); // RESOURCE
    btnRemoveJar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int[] selectionIndices = lstDriverJars.getSelectionIndices();
            if (ArrayUtils.isEmpty(selectionIndices)) {
                return;
            }
            Arrays.sort(selectionIndices);
            ArrayUtils.reverse(selectionIndices);
            for (int selectionIndex : selectionIndices) {
                lstDriverJars.remove(selectionIndex);
            }
            if (ArrayUtils.isEmpty(selectionIndices) == false) {
                driverListChanged();
            }
        }
    });
}

From source file:org.jmangos.auth.wow.controller.AccountController.java

public WoWAuthResponse checkPassword(final AccountInfo account, final byte[] a, final byte[] m1) {

    logger.debug("a length " + a.length);
    logger.debug("a value " + new BigInteger(1, a).toString(16).toUpperCase());
    logger.debug("m1 length " + m1.length);
    logger.debug("m1 value " + new BigInteger(1, m1).toString(16).toUpperCase());
    MessageDigest sha = null;// ww  w .  j ava 2s .c om
    try {
        sha = MessageDigest.getInstance("SHA-1");
    } catch (final NoSuchAlgorithmException e) {
        e.printStackTrace();
        return WoWAuthResponse.WOW_FAIL_INCORRECT_PASSWORD;
    }
    final BigNumber B = account.getcryptoB();
    logger.debug("B value " + B.asHexStr());
    sha.update(a);
    sha.update(B.asByteArray(32));
    final BigNumber u = new BigNumber();
    u.setBinary(sha.digest());
    logger.debug("u value" + u.asHexStr());
    final BigNumber A = new BigNumber();
    A.setBinary(a);
    logger.debug("A:" + A.asHexStr());
    final BigNumber S = A.multiply((account.getV_crypto().modPow(u, AccountUtils.N))).modPow(account.getB(),
            AccountUtils.N);

    final byte[] t1 = new byte[16];
    final byte[] vK = new byte[40];

    final byte[] t = S.asByteArray(32);
    for (int i = 0; i < 16; ++i) {
        t1[i] = t[i * 2];
    }
    sha.update(t1);
    byte[] t2 = sha.digest();
    for (int i = 0; i < 20; ++i) {
        vK[i * 2] = t2[i];
    }
    for (int i = 0; i < 16; ++i) {
        t1[i] = t[(i * 2) + 1];
    }
    sha.update(t1);
    t2 = sha.digest();
    for (int i = 0; i < 20; ++i) {
        vK[(i * 2) + 1] = t2[i];
    }

    byte[] hash = new byte[20];
    logger.debug("N:" + AccountUtils.N.asHexStr());
    sha.update(AccountUtils.N.asByteArray(32));
    hash = sha.digest();
    logger.debug("hash:" + new BigInteger(1, hash).toString(16).toUpperCase());
    sha.update(AccountUtils.g.asByteArray(1));
    final byte[] gH = sha.digest();
    for (int i = 0; i < 20; ++i) {
        hash[i] ^= gH[i];
    }

    byte[] t4 = new byte[20];
    sha.update(account.getName().toUpperCase().getBytes(Charset.forName("UTF-8")));
    t4 = sha.digest();

    sha.update(hash);
    sha.update(t4);
    sha.update(account.getS_crypto().asByteArray(32));
    sha.update(A.asByteArray(32));
    sha.update(B.asByteArray(32));
    sha.update(vK);

    final byte[] sh = sha.digest();

    if (Arrays.equals(sh, m1)) {
        sha.update(A.asByteArray(32));
        sha.update(sh);
        sha.update(vK);

        account.setM2(sha.digest());
        account.setvK(vK);
        ArrayUtils.reverse(vK);

        final AccountEntity accountEntity = this.accountService.readAccountByUserName(account.getName());
        if (accountEntity != null) {
            final String sessionKey = new BigInteger(1, vK).toString(16).toUpperCase();
            accountEntity.setSessionKey(sessionKey);
            account.setSessionKey(new BigNumber(vK));
            this.accountService.createOrUpdateAccount(accountEntity);
        } else {
            return WoWAuthResponse.WOW_FAIL_INCORRECT_PASSWORD;
        }
        return WoWAuthResponse.WOW_SUCCESS;
    } else {
        return WoWAuthResponse.WOW_FAIL_INCORRECT_PASSWORD;
    }
}

From source file:org.jmangos.realm.network.packet.auth.client.CMD_AUTH_LOGON_CHALLENGE.java

@Override
protected void readImpl() throws BufferUnderflowException, RuntimeException {

    readC();//from  ww w. j a v  a 2s  .  c o m
    if (readC() == WoWAuthResponse.WOW_SUCCESS.getMessageId()) {
        final SecureRandom random = new SecureRandom();
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA-1");
        } catch (final NoSuchAlgorithmException e) {
            e.printStackTrace();
            return;
        }
        final BigInteger k = new BigInteger("3");
        final byte[] Bb = readB(32);
        final BigInteger g = new BigInteger(readB(readC()));
        final byte[] Nb = readB(readC());
        final byte[] saltb = readB(32);
        /* byte[] unk3 = */readB(16);
        readC();
        ArrayUtils.reverse(Bb);
        final BigInteger B = new BigInteger(1, Bb);
        ArrayUtils.reverse(Bb);
        ArrayUtils.reverse(Nb);
        final BigInteger N = new BigInteger(1, Nb);
        ArrayUtils.reverse(Nb);
        final BigInteger a = new BigInteger(1, random.generateSeed(19));

        final byte[] passhash = sha.digest(this.config.AUTH_LOGIN.toUpperCase().concat(":")
                .concat(this.config.AUTH_PASSWORD.toUpperCase()).getBytes(Charset.forName("UTF-8")));
        sha.update(saltb);
        sha.update(passhash);

        final byte[] xhash = sha.digest();
        ArrayUtils.reverse(xhash);
        final BigInteger x = new BigInteger(1, xhash);
        logger.debug("x:" + x.toString(16).toUpperCase());
        final BigInteger v = g.modPow(x, N);
        logger.debug("v:" + v.toString(16).toUpperCase());
        final BigInteger A = g.modPow(a, N);
        logger.debug("A:" + A.toString(16).toUpperCase());
        logger.debug("B:" + B.toString(16).toUpperCase());
        this.ahash = A.toByteArray();
        ArrayUtils.reverse(this.ahash);
        sha.update(this.ahash);
        sha.update(Bb);
        final byte[] hashu = sha.digest();
        ArrayUtils.reverse(hashu);
        final BigInteger u = new BigInteger(1, hashu);
        logger.debug("u:" + u.toString(16).toUpperCase());
        final BigInteger S = (B.subtract(k.multiply(g.modPow(x, N)))).modPow(a.add(u.multiply(x)), N);

        final byte[] full_S = S.toByteArray();
        ArrayUtils.reverse(full_S);
        logger.debug("t:" + StringUtils.toHexString(full_S));
        final byte[] s1_hash = new byte[16];
        final byte[] s2_hash = new byte[16];
        for (int i = 0; i < 16; i++) {
            s1_hash[i] = full_S[i * 2];
            s2_hash[i] = full_S[(i * 2) + 1];
        }
        final byte[] t1 = sha.digest(s1_hash);
        final byte[] t2 = sha.digest(s2_hash);
        final byte[] vK = new byte[40];
        for (int i = 0; i < 20; i++) {
            vK[i * 2] = t1[i];
            vK[(i * 2) + 1] = t2[i];
        }

        byte[] hash = new byte[20];
        logger.debug("N:" + N.toString(16).toUpperCase());
        hash = sha.digest(Nb);

        logger.debug("hash:" + new BigInteger(1, hash).toString(16).toUpperCase());

        byte[] gH = new byte[20];
        sha.update(g.toByteArray());
        gH = sha.digest();
        for (int i = 0; i < 20; ++i) {
            hash[i] ^= gH[i];
        }

        byte[] t4 = new byte[20];
        t4 = sha.digest(this.config.AUTH_LOGIN.toUpperCase().getBytes(Charset.forName("UTF-8")));

        sha.update(hash);
        logger.debug("hash:" + StringUtils.toHexString(hash));
        sha.update(t4);
        logger.debug("t4:" + StringUtils.toHexString(t4));
        sha.update(saltb);
        logger.debug("saltb:" + StringUtils.toHexString(saltb));
        sha.update(this.ahash);
        logger.debug("ahash:" + StringUtils.toHexString(this.ahash));
        sha.update(Bb);
        logger.debug("Bb:" + StringUtils.toHexString(Bb));
        sha.update(vK);
        logger.debug("vK:" + StringUtils.toHexString(vK));
        this.m1 = sha.digest();

        sha.update(this.ahash);
        sha.update(this.m1);
        sha.update(vK);
        logger.debug("m1 value" + StringUtils.toHexString(this.m1));
        @SuppressWarnings("unused")
        final byte[] m2 = sha.digest();

        final ChannelPipeline pipeline = getClient().getChannel().getPipeline();
        ((RealmToAuthChannelHandler) pipeline.getLast()).setSeed(vK);

    } else {
        getChannel().getPipeline().remove("handler");
        getChannel().getPipeline().remove("eventlog");
        getChannel().getPipeline().remove("executor");
        getChannel().close();
        getChannel().getFactory().releaseExternalResources();
    }
}

From source file:org.kuali.kfs.module.cam.util.KualiDecimalUtils.java

/**
 * Allocate a sum of money amongst many targets by quantity.
 *
 * @param divisor//from  w  w  w . j ava 2 s.co  m
 * @return KualiDecimal[]
 */
public KualiDecimal[] allocateByQuantity(int divisor) {
    // calculate lowest and highest amount
    KualiDecimalUtils lowAmount = setNewAmount(totalAmount / divisor);
    KualiDecimalUtils highAmount = setNewAmount(lowAmount.totalAmount + 1);

    int remainder = (int) Math.abs(totalAmount % divisor);

    // allocate amounts into array
    KualiDecimal[] amountsArray = new KualiDecimal[divisor];

    // set the lowest amount into array
    KualiDecimal low = new KualiDecimal(lowAmount.totalAmount);
    for (int i = remainder; i < divisor; i++) {
        amountsArray[i] = low.divide(new KualiDecimal(centFactor()));
    }

    // set the highest amount into array
    KualiDecimal high = new KualiDecimal(highAmount.totalAmount);
    for (int i = 0; i < remainder; i++) {
        amountsArray[i] = high.divide(new KualiDecimal(centFactor()));
    }

    ArrayUtils.reverse(amountsArray);

    return amountsArray;
}

From source file:org.matsim.contrib.common.stats.StatsWriter.java

/**
 * Writes a plain text file with two columns where the first column contains the map keys and second the map
 * values.// ww  w .j  a va2s  .c o  m
 *
 * @param map        a map (histogram)
 * @param keyCol     the header for the first column
 * @param valCol     the header for the second column
 * @param file       a filename
 * @param descending if <tt>true</tt> rows are sorted descending according to the map keys, otherwise ascending.
 * @throws IOException
 */
public static void writeHistogram(TDoubleDoubleHashMap map, String keyCol, String valCol, String file,
        boolean descending) throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));

    writer.write(keyCol);
    writer.write(TAB);
    writer.write(valCol);
    writer.newLine();

    double[] keys = map.keys();
    Arrays.sort(keys);
    if (descending)
        ArrayUtils.reverse(keys);

    for (double key : keys) {
        writer.write(String.valueOf(key));
        writer.write(TAB);
        writer.write(String.valueOf(map.get(key)));
        writer.newLine();
    }

    writer.close();
}

From source file:org.nema.medical.mint.server.util.StorageUtil.java

/**
 * Will return true always unless something catastrophically unexpected
 * occurs.// www. ja v a  2  s.  co m
 *
 * @param directory
 * @param shiftAmount
 * @throws Exception
 */
private static void shiftBinaryFiles(final File directory, final int shiftAmount) throws Exception {
    final String[] fileNames = directory.list();
    //Sort file names so that we start renaming the highest index to be sure that the new name does not yet exist
    Arrays.sort(fileNames, numberFileNameComparator);
    ArrayUtils.reverse(fileNames);
    for (final String name : fileNames) {
        if (name.endsWith(BINARY_FILE_EXTENSION) || name.endsWith(EXCLUDED_BINARY_FILE_EXTENSION)) {
            if (!name.startsWith("metadata")) {
                try {
                    final int oldBid;
                    final int extStart = name.indexOf('.');
                    if (extStart > 0) {
                        oldBid = Integer.parseInt(name.substring(0, extStart));
                    } else {
                        oldBid = Integer.parseInt(name);
                    }
                    final int newBid = oldBid + shiftAmount;

                    final String newName = newBid + "." + BINARY_FILE_EXTENSION;

                    //It is a binary file, shift it!
                    final File oldFile = new File(directory, name);
                    final File newFile = new File(directory, newName);
                    if (!oldFile.renameTo(newFile)) {
                        final String errorText = "Error moving/renaming file '" + oldFile.getPath() + " to "
                                + newFile.getPath();
                        LOG.error(errorText);
                        throw new Exception(errorText);
                    }
                } catch (final NumberFormatException e) {
                    LOG.warn("Detected binary item file whose name was not an integer as was expected.", e);
                }
            }
        }
    }
}

From source file:org.opentestsystem.shared.search.SearchTest.java

@Test
public void testSorting() {
    String[] stringvals = new String[] { "Alpha", "Beta", "Delta", "Elephant" };
    Integer[] intValues = new Integer[] { 3, 11, 12, 14 };
    initializeSortObjects(stringvals, intValues);

    List<TestDomain> allValues = mongoTemplate.findAll(TestDomain.class);
    for (int i = 0; i < stringvals.length; i++) {
        assertFalse("id order, for: " + i, stringvals[i].equals(allValues.get(i).getStringValue()));
    }//from  w w  w.  ja va2s.  c  o m

    Map<String, String[]> requestMap = new HashMap<String, String[]>();
    requestMap.put(PAGE_SIZE, new String[] { ONE_HUNDRED });
    requestMap.put(CURRENT_PAGE, new String[] { "0" });
    requestMap.put(SORT_DIR, new String[] { ASC });
    requestMap.put(SORT_KEY, new String[] { "stringValue" });

    TestDomainSearchRequest searchRequest = new TestDomainSearchRequest(requestMap);
    List<TestDomain> results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class);
    assertEquals("wrong number of results finding true", 4, results.size());

    checkStringOrder(stringvals, results);

    requestMap.put(SORT_DIR, new String[] { DESC });
    searchRequest = new TestDomainSearchRequest(requestMap);
    results = mongoTemplate.find(searchRequest.buildQuery(), TestDomain.class);
    ArrayUtils.reverse(stringvals);
    checkStringOrder(stringvals, results);
}