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

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

Introduction

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

Prototype

public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive) 

Source Link

Document

Produces a new boolean array containing the elements between the start and end indices.

Usage

From source file:org.restcomm.sbc.media.MediaZone.java

public byte[] decodeRTP(byte[] data, int offset, int length) {
    /*//from  w  w  w  .  j  ava2  s. co  m
    if(LOG.isTraceEnabled()) {
       LOG.trace("VOID Encoding "+length+" bytes");
    }
    */
    return ArrayUtils.subarray(data, offset, length);
}

From source file:org.royaldev.royalcommands.rcommands.ParentCommand.java

@Override
protected List<String> customList(final CommandSender cs, final Command cmd, final String label, String[] args,
        final String arg) {
    // It's not pretty, but it works
    final List<String> completions = new ArrayList<>();
    if (args.length > 1) {
        final SubCommand sc = this.getSubCommand(args[0]);
        if (sc == null)
            return completions;
        args = (String[]) ArrayUtils.subarray(args, 1, args.length);
        final int ctIndex = args.length - 1;
        if (ctIndex < 0 || ctIndex >= sc.getCompletionTypes().length)
            return completions;
        for (final CompletionType ct : CompletionType
                .getCompletionTypes(sc.getCompletionTypes()[args.length - 1])) {
            final List<String> scCompletions = sc.getCompletionsFor(cs, cmd, label, args, ct);
            if (scCompletions == null)
                continue;
            completions.addAll(scCompletions);
        }/*from  www. java2  s  . c om*/
    } else {
        for (final SubCommand sc : this.subcommands) {
            if (sc == null)
                continue;
            final String name = sc.getShortName();
            if (!this.isAuthorized(cs, sc))
                continue;
            if (completions.contains(name))
                continue;
            completions.add(name);
        }
    }
    return completions;
}

From source file:org.royaldev.royalcommands.rcommands.ParentCommand.java

@Override
protected boolean runCommand(final CommandSender cs, final Command cmd, final String label,
        final String[] eargs, final CommandArguments ca) {
    if (eargs.length < 1) {
        this.showHelp(cs, label);
        return true;
    }//from  w w  w . j  a v  a 2  s . c o m
    final SubCommand sc = this.getSubCommand(eargs[0]);
    if (sc == null) {
        cs.sendMessage(MessageColor.NEGATIVE + "No such subcommand.");
        return true;
    }
    if (sc.checkPermissions() && !this.isAuthorized(cs, sc)) {
        RUtils.dispNoPerms(cs, new String[] { "rcmds." + sc.getName() });
        return true;
    }
    // Exceptions already caught, since we're in a runCommand
    return sc.runCommand(cs, cmd, label, (String[]) ArrayUtils.subarray(eargs, 1, eargs.length), ca);
}

From source file:org.sleuthkit.autopsy.casemodule.RecentCases.java

/**
 * Gets the recent case names./*from w w w .ja  v a  2 s .com*/
 *
 * @return caseNames An array String[LENGTH - 1], newest case first, with any
 * extra spots filled with ""
 */
public String[] getRecentCaseNames() {
    String[] caseNames = new String[LENGTH];

    Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator();
    int i = 0;
    String currentCaseName = null;
    try {
        currentCaseName = Case.getCurrentCase().getName();
    } catch (IllegalStateException ex) {
        // in case there is no current case.
    }

    while (mostRecentFirst.hasNext()) {
        String name = mostRecentFirst.next().name;
        if ((currentCaseName != null && !name.equals(currentCaseName)) || currentCaseName == null) {
            // exclude currentCaseName from the caseNames[]
            caseNames[i] = name;
            i++;
        }
    }

    while (i < caseNames.length) {
        caseNames[i] = "";
        i++;
    }

    // return last 5 case names
    return (String[]) ArrayUtils.subarray(caseNames, 0, LENGTH - 1);
}

From source file:org.sleuthkit.autopsy.casemodule.RecentCases.java

/**
 * Gets the recent case paths.//from   w ww . jav a 2s.c  o  m
 *
 * @return casePaths An array String[LENGTH - 1], newest case first, with any
 * extra spots filled with ""
 */
public String[] getRecentCasePaths() {
    String[] casePaths = new String[LENGTH];
    String currentCasePath = null;
    try {
        currentCasePath = Case.getCurrentCase().getCaseMetadata().getFilePath().toString();
    } catch (IllegalStateException ex) {
        // in case there is no current case.
    }

    Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator();
    int i = 0;
    while (mostRecentFirst.hasNext()) {
        String path = mostRecentFirst.next().path;
        if ((currentCasePath != null && !path.equals(currentCasePath)) || currentCasePath == null) {
            // exclude currentCasePath from the casePaths[]
            casePaths[i] = path;
            i++;
        }
    }

    while (i < casePaths.length) {
        casePaths[i] = "";
        i++;
    }

    // return last 5 case paths
    return (String[]) ArrayUtils.subarray(casePaths, 0, LENGTH - 1);
}

From source file:org.sonar.java.ast.parser.JavaGrammar.java

private static void keywords(LexerlessGrammarBuilder b) {
    b.rule(LETTER_OR_DIGIT).is(javaIdentifierPart(b));
    for (JavaKeyword tokenType : JavaKeyword.values()) {
        b.rule(tokenType).is(tokenType.getValue(), b.nextNot(LETTER_OR_DIGIT), SPACING);
    }/*  w  w w  . j av  a2s  .c  om*/
    String[] keywords = JavaKeyword.keywordValues();
    Arrays.sort(keywords);
    ArrayUtils.reverse(keywords);
    b.rule(KEYWORD).is(b.firstOf(keywords[0], keywords[1], ArrayUtils.subarray(keywords, 2, keywords.length)),
            b.nextNot(LETTER_OR_DIGIT));
}

From source file:org.sonar.plugins.plsqltoad.PlSqlToadPageBuilder.java

private static File[] getPageFiles(Collection<File> files, PlSqlToadPluginConfiguration pluginConf, int page) {
    int offset = page * pluginConf.getToadLimit();
    return (File[]) ArrayUtils.subarray(files.toArray(new File[files.size()]), offset,
            offset + pluginConf.getToadLimit());
}

From source file:org.springframework.ldap.support.LdapUtils.java

/**
 * Converts the given number to a binary representation of the specified
 * length and "endian-ness".// w ww . j av a2  s .c o m
 * 
 * @param number String with number to convert
 * @param length How long the resulting binary array should be
 * @param bigEndian <code>true</code> if big endian (5=0005), or
 * <code>false</code> if little endian (5=5000)
 * @return byte array containing the binary result in the given order
 */
static byte[] numberToBytes(String number, int length, boolean bigEndian) {
    BigInteger bi = new BigInteger(number);
    byte[] bytes = bi.toByteArray();
    int remaining = length - bytes.length;
    if (remaining < 0) {
        bytes = ArrayUtils.subarray(bytes, -remaining, bytes.length);
    } else {
        byte[] fill = new byte[remaining];
        bytes = ArrayUtils.addAll(fill, bytes);
    }
    if (!bigEndian) {
        ArrayUtils.reverse(bytes);
    }
    return bytes;
}

From source file:org.stormcat.jvbeans.jvlink.analyze.binder.JvStandardDataBinder.java

private byte[] subarray(byte[] data, int position, int byteLength) {
    return ArrayUtils.subarray(data, position - 1, position + byteLength - 1);
}

From source file:org.stormcat.jvbeans.jvlink.converter.JvIncludeSeparatorDataConvertor.java

private void appendString(StringBuilder builder, String data, List<JvRecordMeta> metaItems) {
    int position = 0;
    byte[] bytes = StringUtil.getBytes(data, Charset.WINDOWS31J);
    for (JvRecordMeta meta : metaItems) {
        int byteLength = meta.getByteLength();
        int repeatCount = meta.getRepeatCount();
        for (int i = 1; i <= repeatCount; i++) {
            byte[] parts = ArrayUtils.subarray(bytes, position, position + byteLength);
            String rawData = StringUtil.getString(parts, Charset.WINDOWS31J);
            List<JvRecordMeta> joinItems = meta.getJoinMetaItems();
            if (joinItems != null && !joinItems.isEmpty()) {
                appendString(builder, rawData, joinItems);
            } else {
                builder.append("\"");
                builder.append(JvStringUtil.trim(rawData));
                builder.append("\"");
                builder.append(getSeparator());
            }//from  w ww.  j  a  va 2s  . c  om
            position += byteLength;
        }
    }
}