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

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

Introduction

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

Prototype

public static int getLength(Object array) 

Source Link

Document

Returns the length of the specified array.

Usage

From source file:com.scottwoodward.chestmail.commands.RemoveMailBoxCommand.java

@Override
public List<String> validate(CommandSender sender, String[] args) {
    List<String> errors = new ArrayList<String>();
    if (ArrayUtils.getLength(args) != 1 || StringUtils.isEmpty(args[0])) {
        errors.add(ChestMailConstants.ERROR_REMOVEMAILBOX_SYNTAX);
    } else if (ChestMailManager.getMailBoxByName(args[0]) == null) {
        errors.add(ChestMailConstants.ERROR_NO_MAILBOX_WITH_THAT_NAME);
    } else if (!ChestMailManager.isMailBoxOwner((Player) sender, args[0])
            && !sender.hasPermission("chestmail.flag.removeanymailbox")) {
        errors.add(ChestMailConstants.ERROR_CAN_ONLY_REMOVE_OWN_MAILBOX);
    }//ww w.j  a  v  a  2  s.  c  o m
    return errors;
}

From source file:com.carmanconsulting.cassidy.pojo.assembly.disassembler.ArrayDisassembler.java

@Override
public void disassemble(Object object, List<AssemblyStep> steps, CassidyContext context,
        DisassemblerService service) {//from w w  w  .  j  av a2s  .  c o  m
    steps.add(new MarkStep());
    final int length = ArrayUtils.getLength(object);
    for (int i = 0; i < length; ++i) {
        final Object element = Array.get(object, i);
        steps.addAll(service.disassemble(element));
    }
    steps.add(new ArrayStep(object.getClass().getComponentType()));
}

From source file:it.csi.iride2.iridefed.entity.Role.java

/**
 * Utility method to parse an <code>IRIDE</code> Role mnemonic string representation.<br />
 * It accepts a mnemonic string representation, expressed with the following format: <code>"role code{@link #SEPARATOR}domain code"</code>.
 *
 * @param mnemonic <code>IRIDE</code> Role mnemonic string representation
 * @return an <code>IRIDE</code> Role entity object
 * @throws IllegalArgumentException if the given mnemonic string representation is not in the expected format
 *///from  w w w  .j av  a 2s.co m
public static Role parseRole(String mnemonic) {
    final String[] tokens = StringUtils.splitByWholeSeparator(mnemonic, SEPARATOR);
    if (ArrayUtils.getLength(tokens) != 2) {
        throw new IllegalArgumentException(mnemonic);
    }

    return new Role(tokens[0], tokens[1]);
}

From source file:com.scottwoodward.chestmail.commands.SendMailCommand.java

@Override
public List<String> validate(CommandSender sender, String[] args) {
    List<String> errors = new ArrayList<String>();
    if (!(sender instanceof Player)) {
        errors.add(ChestMailConstants.ERROR_ONLY_PLAYER_CAN_SEND_MAIL);
    } else if (isHandEmpty((Player) sender)) {
        errors.add(ChestMailConstants.ERROR_MUST_HOLD_ITEM_TO_SEND);
    } else if (ArrayUtils.getLength(args) != 1 || StringUtils.isEmpty(args[0])) {
        errors.add(ChestMailConstants.ERROR_SENDMAIL_SYNTAX);
    } else if (ChestMailManager.getMailBoxByName(args[0]) == null) {
        errors.add(ChestMailConstants.ERROR_NO_MAILBOX_WITH_THAT_NAME);
    } else if (ChestMailManager.isMailBoxFull(args[0])) {
        errors.add(ChestMailConstants.ERROR_MAILBOX_FULL);
    } else if (ChestMailManager.getEconomy() != null
            && !ChestMailManager.hasEnoughToSendMail((Player) sender)) {
        errors.add(ChestMailConstants.ERROR_SENDMAIL_NOT_ENOUGH_MONEY);
    }//from  ww w .ja va 2s .  c  o  m
    return errors;
}

From source file:com.scottwoodward.chestmail.commands.SetMailboxCommand.java

public List<String> validate(CommandSender sender, String[] args) {
    List<String> errors = new ArrayList<String>();
    if (!(sender instanceof Player)) {
        errors.add(ChestMailConstants.ERROR_ONLY_PLAYER_CAN_SET_MAILBOX);
    } else if (ArrayUtils.getLength(args) != 1 || StringUtils.isEmpty(args[0])) {
        errors.add(ChestMailConstants.ERROR_MUST_PROVIDE_MAILBOX_NAME);
    } else if (ChestMailManager.doesMailBoxWithNameExist(args[0])) {
        errors.add(ChestMailConstants.ERROR_MAILBOX_ALREADY_EXISTS_WITH_NAME);
    } else if (ChestMailManager.getEconomy() != null
            && !ChestMailManager.hasEnoughToSetMailBox((Player) sender)) {
        errors.add(ChestMailConstants.ERROR_SETMAILBOX_NOT_ENOUGH_MONEY);
    }//from w w  w .  j  a  v  a2 s  .com
    return errors;
}

From source file:com.scottwoodward.chestmail.commands.RemoveMailBoxCommand.java

@Override
public List<String> tabComplete(Command command, String[] args) {
    String arg = StringUtils.EMPTY;
    if (ArrayUtils.getLength(args) > 0) {
        arg = args[0];//from  w w  w  . ja va  2  s  .  c  o  m
    }
    return ChestMailManager.getSimilarMailBoxes(arg);
}

From source file:gda.analysis.numerical.straightline.StraightLineFit.java

public static Results fitInt(List<Object> data, long[] dims, double[] x) {

    Object object = data.get(0);//from  www  .  j a  v a2s.  c o  m
    if (!object.getClass().isArray()) {
        throw new IllegalArgumentException("fitInt can only accept arrays");
    }
    int numLines = ArrayUtils.getLength(object);
    int pointsPerLine = x.length;
    if (data.size() != pointsPerLine)
        throw new IllegalArgumentException("data.size() != pointsPerLine");

    for (int i = 0; i < pointsPerLine; i++) {
        if (ArrayUtils.getLength(data.get(i)) != numLines)
            throw new IllegalArgumentException("data.get(i).length != numLines");

    }

    double[] slopes = new double[numLines];
    double[] offsets = new double[numLines];
    short[] fitoks = new short[numLines];
    Arrays.fill(fitoks, (short) 0);
    if (pointsPerLine > 2) {
        double xAverage = getXAverage(x);
        double x1 = getX(x, xAverage);
        double[] y = new double[pointsPerLine];

        Arrays.fill(fitoks, (short) 1);
        for (int line = 0; line < numLines; line++) {
            for (int point = 0; point < pointsPerLine; point++) {
                y[point] = Array.getDouble(data.get(point), line);
            }
            Result fit2 = fit2(y, x, xAverage, x1);
            slopes[line] = fit2.getSlope();
            offsets[line] = fit2.getOffset();
        }
    } else if (pointsPerLine == 2) {

        double[] y = new double[pointsPerLine];
        Arrays.fill(fitoks, (short) 1);
        for (int line = 0; line < numLines; line++) {
            for (int point = 0; point < pointsPerLine; point++) {
                y[point] = Array.getDouble(data.get(point), line);
            }

            slopes[line] = (y[1] - y[0]) / (x[1] - x[0]);
            offsets[line] = y[1] - slopes[line] * x[1];
        }
    }
    return new Results(offsets, slopes, dims, fitoks);
}

From source file:gda.device.scannable.ScannableGetPositionWrapper.java

Object[] calcElements() {
    if (scannableGetPositionVal == null)
        return new Object[] {};

    Object[] elements = new Object[] { scannableGetPositionVal };
    if (scannableGetPositionVal instanceof Object[]) {
        elements = (Object[]) scannableGetPositionVal;
    } else if (scannableGetPositionVal instanceof PySequence) {
        PySequence seq = (PySequence) scannableGetPositionVal;
        int len = seq.__len__();
        elements = new Object[len];
        for (int i = 0; i < len; i++) {
            elements[i] = seq.__finditem__(i);
        }//from   ww w .  jav a  2  s  .c  o  m
    } else if (scannableGetPositionVal instanceof PyList) {
        PyList seq = (PyList) scannableGetPositionVal;
        int len = seq.__len__();
        elements = new Object[len];
        for (int i = 0; i < len; i++) {
            elements[i] = seq.__finditem__(i);
        }
    } else if (scannableGetPositionVal.getClass().isArray()) {
        int len = ArrayUtils.getLength(scannableGetPositionVal);
        elements = new Object[len];
        for (int i = 0; i < len; i++) {
            elements[i] = Array.get(scannableGetPositionVal, i);
        }
    } else if (scannableGetPositionVal instanceof PlottableDetectorData) {
        elements = ((PlottableDetectorData) scannableGetPositionVal).getDoubleVals();
    }
    return elements;
}

From source file:mitm.application.djigzo.james.EncryptedContainer.java

private void writeObject(ObjectOutputStream out) throws IOException, EncryptorException {
    out.writeLong(serialVersionUID);//from w  w w .  j a v a  2  s  .  c  o m

    byte[] encrypted = getEncryptor().encrypt(SerializationUtils.serialize(value));

    out.writeInt(ArrayUtils.getLength(encrypted));
    out.write(encrypted);
}

From source file:lodsve.springfox.config.SpringFoxDocket.java

private String getHost() {
    String serverUrl = serverProperties.getServerUrl();
    if (StringUtils.isBlank(serverUrl)) {
        return "localhost";
    }/*from   www .j  a v  a2  s. co m*/
    String[] schemaAndHostAndPath = serverUrl.split("://");
    if (ArrayUtils.isEmpty(schemaAndHostAndPath) || 2 != ArrayUtils.getLength(schemaAndHostAndPath)) {
        return "localhost";
    }

    String[] hostAndPath = schemaAndHostAndPath[1].split("/");
    if (ArrayUtils.isEmpty(hostAndPath)) {
        return "localhost";
    }

    return hostAndPath[0];
}