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

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

Introduction

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

Prototype

private static Object remove(Object array, int index) 

Source Link

Document

Removes the element at the specified position from the specified array.

Usage

From source file:decision_tree_learning.Matrix.java

public ArrayList<Integer> reduce(Matrix reduced, double attr, double attr2, Range value) throws Exception {
    premodifyReducedMatrix(reduced);/*from w w w . j  a  v a  2 s .  c  o  m*/
    double max = (attr > attr2 ? attr : attr2);
    double min = (attr < attr2 ? attr : attr2);
    //Remove target attribute
    reduced.m_attr_name.remove((int) max);
    reduced.m_enum_to_str.remove((int) max);
    reduced.m_str_to_enum.remove((int) max);
    reduced.m_attr_name.remove((int) min);
    reduced.m_enum_to_str.remove((int) min);
    reduced.m_str_to_enum.remove((int) min);

    ArrayList<Integer> keepRows = getRowsWithAttrValues(attr, attr2, value);
    for (int i = 0; i < keepRows.size(); i++) {
        double[] row = this.row(keepRows.get(i));
        row = ArrayUtils.remove(row, (int) max);
        row = ArrayUtils.remove(row, (int) min);

        reduced.m_data.add(row);
    }
    return keepRows;
}

From source file:fr.inria.atlanmod.neoemf.datastore.estores.impl.DirectWriteHbaseResourceEStoreImpl.java

protected Object remove(NeoEMFEObject object, EAttribute eAttribute, int index) {
    Object oldValue = get(object, eAttribute, index);
    try {/*from w ww .  j av a  2s. com*/

        String[] array;
        boolean passed = false;
        int attemp = 0;

        do {
            array = (String[]) getFromTable(object, eAttribute);
            //array = (String[]) ArrayUtils.add(array, index, serializeValue(eAttribute, value));
            Put put = new Put(Bytes.toBytes(object.neoemfId())).add(PROPERTY_FAMILY,
                    Bytes.toBytes(eAttribute.getName()),
                    NeoEMFUtil.EncoderUtil.toBytes((String[]) ArrayUtils.remove(array, index)));
            passed = table.checkAndPut(Bytes.toBytes(object.neoemfId()), PROPERTY_FAMILY,
                    Bytes.toBytes(eAttribute.getName()),
                    array == null ? null : NeoEMFUtil.EncoderUtil.toBytes(array), put);
            if (!passed) {
                if (attemp > ATTEMP_TIMES_DEFAULT)
                    throw new TimeoutException();
                Thread.sleep((++attemp) * SLEEP_DEFAULT);
                oldValue = get(object, eAttribute, index);
            }

        } while (!passed);

    } catch (IOException e) {
        Logger.log(Logger.SEVERITY_ERROR,
                MessageFormat.format("Unable to delete ''{0}'' to ''{1}'' for element ''{2}''", oldValue,
                        eAttribute.getName(), object));
    } catch (TimeoutException e) {
        Logger.log(Logger.SEVERITY_ERROR,
                MessageFormat.format(
                        "Unable to delete ''{0}'' to ''{1}'' for element ''{2}'' after ''{3}'' times", oldValue,
                        eAttribute.getName(), object, ATTEMP_TIMES_DEFAULT));
        e.printStackTrace();
    } catch (InterruptedException e) {
        Logger.log(Logger.SEVERITY_ERROR, MessageFormat
                .format("InterruptedException while updating element ''{0}''.\n{1}", object, e.getMessage()));
        e.printStackTrace();
    }

    return oldValue;
}

From source file:fr.inria.atlanmod.neoemf.datastore.estores.impl.DirectWriteHbaseResourceEStoreImpl.java

protected Object remove(NeoEMFEObject object, EReference eReference, int index) {

    Object oldValue = get(object, eReference, index);

    try {// w  ww.  jav a2  s . c o  m

        String[] array;
        boolean passed = false;
        int attemp = 0;

        do {
            array = (String[]) getFromTable(object, eReference);
            //array = (String[]) ArrayUtils.add(array, index, referencedObject.neoemfId());
            Put put = new Put(Bytes.toBytes(object.neoemfId())).add(PROPERTY_FAMILY,
                    Bytes.toBytes(eReference.getName()),
                    NeoEMFUtil.EncoderUtil.toBytesReferences((String[]) ArrayUtils.remove(array, index)));

            passed = table.checkAndPut(Bytes.toBytes(object.neoemfId()), PROPERTY_FAMILY,
                    Bytes.toBytes(eReference.getName()),
                    array == null ? null : NeoEMFUtil.EncoderUtil.toBytesReferences(array), put);

            if (!passed) {
                if (attemp > ATTEMP_TIMES_DEFAULT)
                    throw new TimeoutException();

                Thread.sleep((++attemp) * SLEEP_DEFAULT);
            }

        } while (!passed);

    } catch (IOException e) {
        Logger.log(Logger.SEVERITY_ERROR, MessageFormat.format(
                "Unable to delete ''{0}[{1}''] for element ''{2}''", eReference.getName(), index, object));
    } catch (TimeoutException e) {
        Logger.log(Logger.SEVERITY_ERROR, MessageFormat.format(
                "Unable to delete ''{0}[{1}''] for element ''{2}''", eReference.getName(), index, object));
        e.printStackTrace();
    } catch (InterruptedException e) {
        Logger.log(Logger.SEVERITY_ERROR, MessageFormat
                .format("InterruptedException while updating element ''{0}''.\n{1}", object, e.getMessage()));
        e.printStackTrace();
    }

    return oldValue;
}

From source file:com.ibm.jaggr.service.impl.modulebuilder.css.CSSModuleBuilder.java

/**
 * Processes the input CSS to replace &#064;import statements with the
 * contents of the imported CSS.  The imported CSS is minified, image
 * URLs in-lined, and this method recursively called to in-line nested
 * &#064;imports./*w w  w  .j a va 2 s .  c  o  m*/
 * 
 * @param css
 *            The current CSS containing &#064;import statements to be
 *            processed
 * @param uri
 *            The URI for the current CSS
 * @param path
 *            The path, as specified in the &#064;import statement used to
 *            import the current CSS, or null if this is the top level CSS.
 * 
 * @return The input CSS with &#064;import statements replaced with the
 *         contents of the imported files.
 * 
 * @throws IOException
 */
protected String inlineImports(HttpServletRequest req, String css, IResource res, String path)
        throws IOException {

    // In-lining of imports can be disabled by request parameter for debugging
    if (!TypeUtil.asBoolean(req.getParameter(INLINEIMPORTS_REQPARAM_NAME), true)) {
        return css;
    }

    StringBuffer buf = new StringBuffer();
    IAggregator aggregator = (IAggregator) req.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME);
    IOptions options = aggregator.getOptions();
    /*
     * True if we should include the name of imported CSS files in a comment at
     * the beginning of the file.
     */
    boolean includePreamble = TypeUtil.asBoolean(req.getAttribute(IHttpTransport.SHOWFILENAMES_REQATTRNAME))
            && (options.isDebugMode() || options.isDevelopmentMode());
    if (includePreamble && path != null && path.length() > 0) {
        buf.append("/* @import " + path + " */\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    Matcher m = importPattern.matcher(css);
    while (m.find()) {
        String fullMatch = m.group(0);
        String importNameMatch = m.group(2);
        String mediaTypes = m.group(4);

        /*
         * CSS rules require that all @import statements appear before any
         * style definitions within a document. Most browsers simply ignore
         * @import statements which appear following any styles definitions.
         * This means that once we've inlined an @import, then we can't not
         * inline any subsequent @imports. The implication is that all
         * @imports which cannot be inlined (i.e. non-relative url or device
         * specific media types) MUST appear before any @import that is
         * inlined. For this reason, we throw an error if we encounter an
         * @import which we cannot inline if we have already inlined a
         * previous @import.
         */

        //Only process media type "all" or empty media type rules.
        if (mediaTypes.length() > 0 && !"all".equals(StringUtils.trim(mediaTypes))) { //$NON-NLS-1$
            m.appendReplacement(buf, ""); //$NON-NLS-1$
            buf.append(fullMatch);
            continue;
        }
        // remove quotes.
        importNameMatch = quotedStringTrimPattern.matcher(importNameMatch).replaceAll(""); //$NON-NLS-1$
        importNameMatch = forwardSlashPattern.matcher(importNameMatch).replaceAll("/"); //$NON-NLS-1$

        // if name is not relative, then bail
        if (importNameMatch.startsWith("/") || protocolPattern.matcher(importNameMatch).find()) { //$NON-NLS-1$
            m.appendReplacement(buf, ""); //$NON-NLS-1$
            buf.append(fullMatch);
            continue;
        }

        IResource importRes = res.resolve(importNameMatch);
        String importCss = null;
        importCss = readToString(new CommentStrippingReader(
                new InputStreamReader(importRes.getURI().toURL().openStream(), "UTF-8" //$NON-NLS-1$
                )));
        importCss = minify(importCss, importRes);
        // Inline images
        importCss = inlineImageUrls(req, importCss, importRes);

        if (inlineImports) {
            importCss = inlineImports(req, importCss, importRes, importNameMatch);
        }
        m.appendReplacement(buf, ""); //$NON-NLS-1$
        buf.append(importCss);
    }
    m.appendTail(buf);

    css = buf.toString();
    /*
     * Now re-write all relative URLs in url(...) statements to make them relative
     * to the importing CSS
     */
    if (path != null && path.length() > 0) {
        int idx = path.lastIndexOf("/"); //$NON-NLS-1$
        //Make a file path based on the last slash.
        //If no slash, so must be just a file name. Use empty string then.
        path = (idx != -1) ? path.substring(0, idx + 1) : ""; //$NON-NLS-1$
        buf = new StringBuffer();
        m = urlPattern.matcher(css);
        while (m.find()) {
            String fullMatch = m.group(0);
            String urlMatch = m.group(1);

            urlMatch = StringUtils.trim(urlMatch.replace("\\", "/")); //$NON-NLS-1$ //$NON-NLS-2$
            String quoted = ""; //$NON-NLS-1$
            if (urlMatch.charAt(0) == '"' && urlMatch.charAt(urlMatch.length() - 1) == '"') {
                quoted = "\""; //$NON-NLS-1$
                urlMatch = urlMatch.substring(1, urlMatch.length() - 1);
            } else if (urlMatch.charAt(0) == '\'' && urlMatch.charAt(urlMatch.length() - 1) == '\'') {
                quoted = "'"; //$NON-NLS-1$
                urlMatch = urlMatch.substring(1, urlMatch.length() - 1);
            }

            // Don't modify non-relative URLs
            if (urlMatch.startsWith("/") || urlMatch.startsWith("#") //$NON-NLS-1$//$NON-NLS-2$
                    || protocolPattern.matcher(urlMatch).find()) {
                m.appendReplacement(buf, ""); //$NON-NLS-1$
                buf.append(fullMatch);
                continue;
            }

            String fixedUrl = path + ((path.endsWith("/") || path.length() == 0) ? "" : "/") + urlMatch; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            //Collapse '..' and '.'
            String[] parts = fixedUrl.split("/"); //$NON-NLS-1$
            for (int i = parts.length - 1; i > 0; i--) {
                if (".".equals(parts[i])) { //$NON-NLS-1$
                    parts = (String[]) ArrayUtils.remove(parts, i);
                } else if ("..".equals(parts[i])) { //$NON-NLS-1$
                    if (i != 0 && !"..".equals(parts[i - 1])) { //$NON-NLS-1$
                        parts = (String[]) ArrayUtils.remove(parts, i - 1);
                        parts = (String[]) ArrayUtils.remove(parts, i - 1);
                    }
                }
            }
            m.appendReplacement(buf, ""); //$NON-NLS-1$
            buf.append("url(") //$NON-NLS-1$
                    .append(quoted).append(StringUtils.join(parts, "/")) //$NON-NLS-1$
                    .append(quoted).append(")"); //$NON-NLS-1$
        }
        m.appendTail(buf);
        css = buf.toString();
    }
    return css;
}

From source file:com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder.java

/**
 * Processes the input CSS to replace &#064;import statements with the
 * contents of the imported CSS.  The imported CSS is minified, image
 * URLs in-lined, and this method recursively called to in-line nested
 * &#064;imports./*  www  .j a v  a  2  s .  c o  m*/
 *
 * @param req
 *            The request associated with the call.
 * @param css
 *            The current CSS containing &#064;import statements to be
 *            processed
 * @param res
 *            The resource for the CSS file.
 * @param path
 *            The path, as specified in the &#064;import statement used to
 *            import the current CSS, or null if this is the top level CSS.
 *
 * @return The input CSS with &#064;import statements replaced with the
 *         contents of the imported files.
 *
 * @throws IOException
 */
protected String inlineImports(HttpServletRequest req, String css, IResource res, String path)
        throws IOException {

    // In-lining of imports can be disabled by request parameter for debugging
    if (!TypeUtil.asBoolean(req.getParameter(INLINEIMPORTS_REQPARAM_NAME), true)) {
        return css;
    }

    StringBuffer buf = new StringBuffer();
    IAggregator aggregator = (IAggregator) req.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME);
    IOptions options = aggregator.getOptions();
    /*
     * True if we should include the name of imported CSS files in a comment at
     * the beginning of the file.
     */
    boolean includePreamble = TypeUtil.asBoolean(req.getAttribute(IHttpTransport.SHOWFILENAMES_REQATTRNAME))
            && (options.isDebugMode() || options.isDevelopmentMode());
    if (includePreamble && path != null && path.length() > 0) {
        buf.append("/* @import " + path + " */\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    Matcher m = importPattern.matcher(css);
    while (m.find()) {
        String fullMatch = m.group(0);
        String importNameMatch = m.group(2);
        String mediaTypes = m.group(4);
        /*
         * CSS rules require that all @import statements appear before any
         * style definitions within a document. Most browsers simply ignore
         * @import statements which appear following any styles definitions.
         * This means that once we've inlined an @import, then we can't not
         * inline any subsequent @imports. The implication is that all
         * @imports which cannot be inlined (i.e. non-relative url or device
         * specific media types) MUST appear before any @import that is
         * inlined. For this reason, we throw an error if we encounter an
         * @import which we cannot inline if we have already inlined a
         * previous @import.
         */

        //Only process media type "all" or empty media type rules.
        if (mediaTypes.length() > 0 && !"all".equals(StringUtils.trim(mediaTypes))) { //$NON-NLS-1$
            m.appendReplacement(buf, ""); //$NON-NLS-1$
            buf.append(fullMatch);
            continue;
        }
        // remove quotes.
        importNameMatch = dequote(importNameMatch);
        importNameMatch = forwardSlashPattern.matcher(importNameMatch).replaceAll("/"); //$NON-NLS-1$

        if (importNameMatch.startsWith("/") || protocolPattern.matcher(importNameMatch).find()) { //$NON-NLS-1$
            m.appendReplacement(buf, ""); //$NON-NLS-1$
            buf.append(fullMatch);
            continue;
        }

        IResource importRes = res.resolve(importNameMatch);
        URI uri = null;
        if (importRes.exists()) {
            uri = importRes.getURI();
        } else if (includeAMDPaths && importNameMatch.contains("/") && !importNameMatch.startsWith(".")) { //$NON-NLS-1$ //$NON-NLS-2$
            // Resource not found using relative path to res.  If path is not relative (starts with .)
            // then try to find the resource using config paths and packages.
            uri = aggregator.getConfig().locateModuleResource(importNameMatch);
            if (uri != null) {
                uri = aggregator.newResource(uri).getURI();
            }
        }
        if (uri == null) {
            throw new NotFoundException(importNameMatch);
        }

        String importCss = null;
        importCss = readToString(
                new CommentStrippingReader(new InputStreamReader(uri.toURL().openStream(), "UTF-8" //$NON-NLS-1$
                )));
        importCss = minify(importCss, importRes);
        // Inline images
        importCss = inlineImageUrls(req, importCss, importRes);

        if (inlineImports) {
            importCss = inlineImports(req, importCss, importRes, importNameMatch);
        }
        m.appendReplacement(buf, ""); //$NON-NLS-1$
        buf.append(importCss);
    }
    m.appendTail(buf);

    css = buf.toString();
    /*
     * Now re-write all relative URLs in url(...) statements to make them relative
     * to the importing CSS
     */
    if (path != null && path.length() > 0) {
        int idx = path.lastIndexOf("/"); //$NON-NLS-1$
        //Make a file path based on the last slash.
        //If no slash, so must be just a file name. Use empty string then.
        path = (idx != -1) ? path.substring(0, idx + 1) : ""; //$NON-NLS-1$
        buf = new StringBuffer();
        m = urlPattern.matcher(css);
        while (m.find()) {
            String fullMatch = m.group(0);
            String urlMatch = m.group(1);

            urlMatch = StringUtils.trim(urlMatch.replace("\\", "/")); //$NON-NLS-1$ //$NON-NLS-2$
            String quoted = ""; //$NON-NLS-1$
            if (urlMatch.charAt(0) == '"' && urlMatch.charAt(urlMatch.length() - 1) == '"') {
                quoted = "\""; //$NON-NLS-1$
                urlMatch = urlMatch.substring(1, urlMatch.length() - 1);
            } else if (urlMatch.charAt(0) == '\'' && urlMatch.charAt(urlMatch.length() - 1) == '\'') {
                quoted = "'"; //$NON-NLS-1$
                urlMatch = urlMatch.substring(1, urlMatch.length() - 1);
            }

            // Don't modify non-relative URLs
            if (urlMatch.startsWith("/") || urlMatch.startsWith("#") //$NON-NLS-1$//$NON-NLS-2$
                    || protocolPattern.matcher(urlMatch).find()) {
                m.appendReplacement(buf, ""); //$NON-NLS-1$
                buf.append(fullMatch);
                continue;
            }

            String fixedUrl = path + ((path.endsWith("/") || path.length() == 0) ? "" : "/") + urlMatch; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            //Collapse '..' and '.'
            String[] parts = fixedUrl.split("/"); //$NON-NLS-1$
            for (int i = parts.length - 1; i > 0; i--) {
                if (".".equals(parts[i])) { //$NON-NLS-1$
                    parts = (String[]) ArrayUtils.remove(parts, i);
                } else if ("..".equals(parts[i])) { //$NON-NLS-1$
                    if (i != 0 && !"..".equals(parts[i - 1])) { //$NON-NLS-1$
                        parts = (String[]) ArrayUtils.remove(parts, i - 1);
                        parts = (String[]) ArrayUtils.remove(parts, i - 1);
                    }
                }
            }
            m.appendReplacement(buf, ""); //$NON-NLS-1$
            buf.append("url(") //$NON-NLS-1$
                    .append(quoted).append(StringUtils.join(parts, "/")) //$NON-NLS-1$
                    .append(quoted).append(")"); //$NON-NLS-1$
        }
        m.appendTail(buf);
        css = buf.toString();
    }
    return css;
}

From source file:com.prowidesoftware.swift.model.SwiftTagListBlock.java

/**
 * Returns a new block that includes (<code>true</code>) or excludes (<code>false</code>), depending on <code>includeOrExclude</code> flag
 * all tags with names matching any of the parameter names.<br />
 * Once a tagname is matched, it is removed from the list of tags to be matched, causing to be only included/excluded the first instance of every tagname.<br />
 * For example: 1, 2, 3, 4, 5, 6 filter by names 2, 4, 5 will return 1, 3, 6.
 *
 * @param include if <code>true</code> include all tags with given names, if <code>false</code> include all tags with a name <em>not</em> in names
 * @param names list of tagnames to match
 * @return a new list, an empty list if empty message, preconditions not met or nothing found
 * @since 7.2/*w  w w  .  ja v  a2 s  .  com*/
 */
public SwiftTagListBlock filterByName(final boolean include, final String... names) {
    final SwiftTagListBlock result = new SwiftTagListBlock();
    if (names.length == 0) {
        if (include) {
            // do nothing, will return empty list later
        } else {
            // return all current tags since none is to be excluded
            result.setTags(getTags());
        }
    } else {
        String[] tagnames = names;
        for (int i = 0; i < this.tags.size(); i++) {
            final Tag t = this.tags.get(i);
            // see if tag names is matched first
            boolean matched = false;
            for (int j = 0; !matched && j < tagnames.length; j++) {
                if (StringUtils.equals(t.getName(), tagnames[j])) {
                    matched = true;
                    tagnames = (String[]) ArrayUtils.remove(tagnames, j);
                }
            }
            if (matched && include) {
                result.append(t);
            }
            if ((!matched) && !include) {
                result.append(t);
            }
        }
    }
    return result;
}

From source file:com.prowidesoftware.swift.model.SwiftTagListBlock.java

/**
 * Returns a new block that includes all tags with names matching any of the parameter names until a non matching tag is found.<br />
 * Once a tagname is matched, it is removed from the list of tags to be matched, causing to be only included/excluded the first instance of every tagname.<br />
 * For example: 1, 2, 3, 9, 4, 5, 6 filter by names 1, 2, 3, 4 will return 1, 2, 3.
 *
 * @param names list of tagnames to match
 * @return a new list, an empty list if empty message, preconditions not met or nothing found
 * @since 7.2/*from   w  w w.j  a v  a2s .c  o m*/
 */
public SwiftTagListBlock filterByNameOrdered(final String... names) {
    String[] tagnames = names;
    final SwiftTagListBlock result = new SwiftTagListBlock();
    for (final Tag t : getTags()) {
        boolean matched = false;
        for (int j = 0; !matched && j < tagnames.length; j++) {
            if (StringUtils.equals(t.getName(), tagnames[j])) {
                matched = true;
                tagnames = (String[]) ArrayUtils.remove(tagnames, j);
                result.append(t);
            }
        }
        if (!matched) {
            break;
        }
    }
    return result;
}

From source file:com.novartis.opensource.yada.YADARequest.java

/**
* Deconstructs the {@link YADARequest#PS_PLUGIN} string into a {@link Preprocess}, {@link Postprocess},
* or {@link Bypass} plugin, and {@link List} of plugin argument {@link List}s.  The original version
* of this method was a simple mutator for the {@link #plugin} variable.
* @param configs the {@link String}[] array passed in the url 
* @since 7.1.0//  w  ww  .  j  a  v  a  2s  .  co  m
*/
public void setPlugin(String[] configs) {
    int length = configs.length;
    this.plugin = new String[length];
    for (int i = 0; i < configs.length; i++) //each plugin parameter
    {
        String config = configs[i];
        String[] pluginConfig = config.split(","); //separate the pl and args
        this.plugin[i] = pluginConfig[0];
        if (pluginConfig.length > 1) // there's args
        {
            String[] args = (String[]) ArrayUtils.remove(pluginConfig, 0);
            this.addPluginArgs(new LinkedList<>(Arrays.asList(args)));
        } else {
            this.addPluginArgs(null); // placeholder
        }
    }
}

From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java

public void payingVendorBillDiscount1(Integer MoAccountID, Integer checkNumber, Integer yearID,
        Integer periodID, String username, Date transactionDate, Integer userID)
        throws BankingException, VendorException {

    Integer[] rxMasterID = null;// w  w w  . j a  v  a  2  s .co m
    Session aSession1 = null;
    StringBuffer totalAmountQuery = null;
    String vendorPayBeanQuery = null;
    String rxMasterList = null;
    try {
        aSession1 = itsSessionFactory.openSession();

        rxMasterList = "SELECT BillPayUniqueIDs.rxMasterID FROM (SELECT rxMasterID FROM (SELECT veBill.rxMasterID FROM veBill LEFT JOIN veBillPay ON veBill.veBillID = veBillPay.veBillID WHERE veBillPay.moAccountId = "
                + MoAccountID + " And veBillPay.userID = " + userID
                + " And veBillPay.ApplyingAmount<>0) AS BillPayIDs GROUP BY rxMasterID) AS BillPayUniqueIDs "
                + "INNER JOIN rxMaster ON BillPayUniqueIDs.rxMasterID = rxMaster.rxMasterID ORDER BY Name";
        Query aQuery1 = aSession1.createSQLQuery(rxMasterList);
        itsLogger.info(aQuery1.toString());
        List<?> rxMasterLists = aQuery1.list();
        rxMasterID = new Integer[aQuery1.list().size()];

        for (int i = 0; i < rxMasterLists.size(); i++) {
            rxMasterID[i] = (Integer) rxMasterLists.get(i);

        }

        itsLogger.info("Checking======>>>" + rxMasterID.length);

        for (int i = 0; i < rxMasterID.length; i++) {
            totalAmountQuery = new StringBuffer(
                    "SELECT SUM(P.ApplyingAmount) AS CheckAmount FROM veBillPay AS P INNER JOIN veBill AS B ON P.veBillID = B.veBillID Where P.moAccountId="
                            + MoAccountID + " And P.userID = " + userID + " And (B.rxMasterID =")
                                    .append(rxMasterID[i]).append(")");
            Query aQuery2 = aSession1.createSQLQuery(totalAmountQuery.toString());
            List<?> totalList = aQuery2.list();
            for (int j = 0; j < totalList.size(); j++) {
                if ((BigDecimal) totalList.get(j) != null) {
                    BigDecimal amt = (BigDecimal) totalList.get(j);

                    if (amt.signum() < 0) {
                        rxMasterID = (Integer[]) ArrayUtils.remove(rxMasterID, i);
                    }
                }

            }
        }

        itsLogger.info("Checking======>>>" + rxMasterID.length);

        int chkno = 0;
        chkno = checkNumber;
        for (int i = 0; i < rxMasterID.length; i++) {

            BigDecimal TotalAmt = new BigDecimal(0);
            BigDecimal ApplyingAmt = new BigDecimal(0);
            BigDecimal DiscountAmt = new BigDecimal(0);

            Motransaction aMotransaction = new Motransaction();

            aMotransaction.setMoAccountId(MoAccountID);

            SysAccountLinkage aSysAccountLinkage = gltransactionService.getsysAccountLinkageDetail();

            //Get Discount ID

            Coaccount CoAccountIdDiscountdetails = gltransactionService
                    .getCoaccountDetailsBasedoncoAccountid(aSysAccountLinkage.getCoAccountIddiscountsTaken());

            //Get coAccount Details

            Coaccount coaccount = gltransactionService.getcoAccountDetails(aMotransaction);

            Coaccount CoAccountIdapdetails = null;

            CoAccountIdapdetails = gltransactionService
                    .getCoaccountDetailsBasedoncoAccountid(aSysAccountLinkage.getCoAccountIdap());
            Rxmaster liRxmasters = gltransactionService.getTransactionDescriptionfromrxMasterID(rxMasterID[i]);

            Cofiscalperiod aCofiscalperiod = accountingCyclesService.getCurrentPeriod(periodID);
            Cofiscalyear aCofiscalyear = accountingCyclesService.getCurrentYear(yearID);

            Coledgersource aColedgersource = gltransactionService.getColedgersourceDetail("WC");

            GlTransaction glTransaction = new GlTransaction();

            // period
            glTransaction.setCoFiscalPeriodId(aCofiscalperiod.getCoFiscalPeriodId());
            glTransaction.setPeriod(aCofiscalperiod.getPeriod());
            glTransaction.setpStartDate(aCofiscalperiod.getStartDate());
            glTransaction.setpEndDate(aCofiscalperiod.getEndDate());

            // year
            glTransaction.setCoFiscalYearId(aCofiscalyear.getCoFiscalYearId());

            if (aCofiscalyear.getFiscalYear() != null)
                glTransaction.setFyear(aCofiscalyear.getFiscalYear());

            glTransaction.setyStartDate(aCofiscalyear.getStartDate());
            glTransaction.setyEndDate(aCofiscalyear.getEndDate());

            // journal
            glTransaction.setJournalId(aColedgersource.getJournalID());
            glTransaction.setJournalDesc(aColedgersource.getDescription());
            glTransaction.setEntrydate(new Date());
            glTransaction.setEnteredBy(username);
            glTransaction.setTransactionDate(transactionDate);

            // Ponumber and trDesc

            glTransaction.setPoNumber("" + chkno);

            if (liRxmasters.getName() != null)
                glTransaction.setTransactionDesc(liRxmasters.getName());

            ArrayList<VendorPayBean> payBean = new ArrayList<VendorPayBean>();
            List<VendorPayBean> payBeanList = new ArrayList<VendorPayBean>();

            vendorPayBeanQuery = "SELECT veBillPay.veBillPayID, veBillPay.veBillID, veBillPay.ApplyingAmount, veBillPay.DiscountAmount "
                    + "FROM veBill LEFT JOIN veBillPay ON veBill.veBillID = veBillPay.veBillID "
                    + "WHERE veBillPay.ApplyingAmount<>0 AND veBillPay.moAccountId=" + MoAccountID
                    + " And veBillPay.userID = " + userID + " AND veBill.rxMasterID= " + rxMasterID[i]
                    + " ORDER BY veBill.InvoiceNumber, veBill.BillDate;";

            Query aQuery4 = aSession1.createSQLQuery(vendorPayBeanQuery);
            payBeanList = aQuery4.list();
            Iterator<?> aIterator = payBeanList.iterator();
            while (aIterator.hasNext()) {
                Object[] aObj = (Object[]) aIterator.next();
                VendorPayBean aPayBean = new VendorPayBean();
                aPayBean.setVebillpayId((Integer) aObj[0]);
                aPayBean.setVebillID((Integer) aObj[1]);
                aPayBean.setApplyingAmount((BigDecimal) aObj[2]);
                aPayBean.setDiscountAmount((BigDecimal) aObj[3]);
                payBean.add(aPayBean);
            }

            for (int j = 0; j < payBean.size(); j++) {

                /*Get Account Payable and Discount IDs*/

                TotalAmt = payBean.get(j).getApplyingAmount().add(payBean.get(j).getDiscountAmount())
                        .add(TotalAmt);
                ApplyingAmt = payBean.get(j).getApplyingAmount().add(ApplyingAmt);
                DiscountAmt = payBean.get(j).getDiscountAmount().add(DiscountAmt);

            }

            int gltranID = 0;
            int gltranID1 = 0;
            int gltranID2 = 0;
            //insert GlTransacion Table using Banking Details

            gltranID = insertBankDettoglTranfromwritechecks(glTransaction, coaccount, aColedgersource,
                    ApplyingAmt);

            /*for(int j=0;j<payBean.size();j++){*/
            if (gltranID != 0)
                //glLinkageInsert(aColedgersource,gltranID,payBean.get(j).getVebillID   ());
                glLinkageInsert(aColedgersource, gltranID, chkno, MoAccountID);

            /*   }*/

            //insert GlTransacion Table using Account Payable Details

            gltranID1 = insertaccApDettoglTranfromwritechecks(glTransaction, CoAccountIdapdetails,
                    aColedgersource, TotalAmt);

            /*   for(int j=0;j<payBean.size();j++){*/
            if (gltranID1 != 0)
                glLinkageInsert(aColedgersource, gltranID1, chkno, MoAccountID);
            /*   }*/

            //insert GlTransacion Table using Discount Details

            gltranID2 = insertDiscDettoglTranfromwritechecks(glTransaction, CoAccountIdDiscountdetails,
                    aColedgersource, DiscountAmt);

            /*for(int j=0;j<payBean.size();j++){*/

            if (gltranID2 != 0)
                glLinkageInsert(aColedgersource, gltranID2, chkno, MoAccountID);
            /*}*/

            if (payBeanList.size() > 25) // checkno increment
            {
                int incCheckno = payBeanList.size() / 25;
                if (payBeanList.size() % 25 > 0)
                    incCheckno += 1;

                chkno = chkno + incCheckno;
            } else {
                chkno++;
            }
        }
    } catch (Exception e) {
        itsLogger.error(e.getMessage(), e);
        BankingException aBankingException = new BankingException(e.getMessage(), e);
        throw aBankingException;
    } finally {

        aSession1.flush();
        aSession1.close();
        totalAmountQuery = null;
        vendorPayBeanQuery = null;
        rxMasterList = null;
    }
}

From source file:net.stuxcrystal.simpledev.commands.CommandHandler.java

/**
 * Implementation of the execute method that uses the first argument as its command name.
 *
 * @param executor The executor that executes the command.
 * @param rawArgs  The raw arguments.//from  ww w .  java  2s .  c  om
 */
public void execute(CommandExecutor executor, String[] rawArgs) {
    String name;
    if (rawArgs.length == 0) {
        name = CommandHandler.FALLBACK_COMMAND_NAME;
        rawArgs = new String[0];
    } else {
        name = rawArgs[0];
        rawArgs = (String[]) ArrayUtils.remove(rawArgs, 0);
    }

    if (!this.execute(executor, name, rawArgs))
        executor.sendMessage(T(executor, "cmd.notfound"));
}