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

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

Introduction

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

Prototype

public static short[] add(short[] array, short element) 

Source Link

Document

Copies the given array and adds the given element at the end of the new array.

Usage

From source file:gda.gui.scriptcontroller.logging.ScriptControllerLogContentProvider.java

public ScriptControllerLogContentProvider(ScriptControllerLogView view, String scriptControllerNames) {
    super();/*from  ww  w  .ja v a  2s  .  c o m*/
    this.view = view;

    String[] controllerNames = scriptControllerNames.split(",");

    for (String name : controllerNames) {
        Findable objRef = Finder.getInstance().find(name.trim());
        if (objRef instanceof ILoggingScriptController) {
            ILoggingScriptController newcontroller = (ILoggingScriptController) objRef;
            controllers = (ILoggingScriptController[]) ArrayUtils.add(controllers, newcontroller);
            try {
                newcontroller.addIObserver(new ScriptControllerLogHelper(this));
            } catch (Exception e) {
                logger.error("Error adding observer to logging script controller", e);
            }
        } else {
            logger.warn("ScriptControllerLogContentProvider could not find a LoggingScriptController called "
                    + name + ". The ScriptControllerLogView view will not work");
        }

    }

}

From source file:gda.device.detector.countertimer.TFGScalerWithRatio.java

@Override
public double[] readout() throws DeviceException {
    double[] output = super.readout();

    if (getDarkCurrent() != null) {
        output = adjustForDarkCurrent(output, getCollectionTime());
    }/*  ww w . j  a  v  a 2 s.c  o  m*/

    if (outputRatio) {
        Double ratio = new Double(0);
        // find which col is which I0, It and Iref
        Double[] values = getI0It(output);

        ratio = values[1] / values[0];

        // always return a numerical value
        if (ratio.isInfinite() || ratio.isNaN()) {
            ratio = 0.0;
        }

        // append to output array
        output = correctCounts(output, values);
        output = ArrayUtils.add(output, ratio);
    }
    return output;
}

From source file:de.tudarmstadt.lt.n2n.utilities.PatternGenerator.java

public static int[][] comb(int k, int n, int[] fixed, boolean sort) {
    int[][] s = new int[0][];
    for (int u = 0; u < 1 << n; u++)
        if (bitcount(u) == k) {
            int[] c = bitadd(u, k);
            boolean add = true;
            for (int f : fixed)
                add &= !ArrayUtils.contains(c, f);
            if (add)
                s = (int[][]) ArrayUtils.add(s, c);
        }/*from ww w.  j  ava  2  s  .  co  m*/
    if (sort)
        Arrays.sort(s, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                for (int i = 0; i < o1.length; i++) {
                    int r = o2[i] - o1[i];
                    if (r != 0)
                        return r;
                }
                return 0;
            }
        });
    return s;
}

From source file:mitm.common.net.NetUtils.java

/**
 * Parses the provided URL query and returns a map with all names to values. The values are URL decoded. If 
 * toLowercase is true the keys of the map will be converted to lowecase.
 * /* w w w  .ja  v  a  2s.  c o  m*/
 * Example:
 * test=123&value=%27test%27&value=abc maps to test -> [123] and value -> ["test", abc]
 * @throws IOException 
 */
public static Map<String, String[]> parseQuery(String query, boolean toLowercase) throws IOException {
    Map<String, String[]> map = new HashMap<String, String[]>();

    if (query == null) {
        return map;
    }

    String[] elements = StringUtils.split(query, '&');

    for (String element : elements) {
        element = element.trim();

        if (StringUtils.isEmpty(element)) {
            continue;
        }

        String name;
        String value;

        int i = element.indexOf('=');

        if (i > -1) {
            name = StringUtils.substring(element, 0, i);
            value = StringUtils.substring(element, i + 1);
        } else {
            name = element;
            value = "";
        }

        name = StringUtils.trimToEmpty(name);
        value = StringUtils.trimToEmpty(value);

        if (toLowercase) {
            name = name.toLowerCase();
        }

        value = URLDecoder.decode(value, CharacterEncoding.UTF_8);

        String[] updated = (String[]) ArrayUtils.add(map.get(name), value);

        map.put(name, updated);
    }

    return map;
}

From source file:net.navasoft.madcoin.backend.services.vo.response.impl.BusinessFailedResponseVO.java

/**
 * Gets the causes.//from  ww  w .j a  va 2 s  .c om
 * 
 * @return the causes
 * @since 24/08/2014, 08:10:23 PM
 */
@Override
@JsonIgnore
public Object[] getCauses() {
    Object[] causes = (Object[]) Array.newInstance(Object.class, 0);
    causes = ArrayUtils.add(causes, lob);
    return causes;
}

From source file:gda.jython.authoriser.FileAuthoriser.java

/**
 * @return Vector of strings of the entries in this file
 *///w  ww.ja  v  a2s  .  co  m
public UserEntry[] getEntries() {
    try {
        FileConfiguration configFile = openConfigFile();
        UserEntry[] entries = new UserEntry[0];

        @SuppressWarnings("rawtypes")
        Iterator i = configFile.getKeys();
        while (i.hasNext()) {
            String username = (String) i.next();
            if (!username.equals("")) {
                int level = configFile.getInt(username);
                entries = (UserEntry[]) ArrayUtils.add(entries,
                        new UserEntry(username, level, isLocalStaff(username)));
            }
        }

        return entries;

    } catch (Exception e) {
        logger.error(
                "Exception while trying to read file of list of user authorisation levels:" + e.getMessage());
        return null;
    }

}

From source file:com.codeabovelab.dm.cluman.cluster.docker.model.Ports.java

/**
 * Adds a new {@link PortBinding} for the specified {@link ExposedPort} and {@link Binding} to the current bindings.
 *//* www. j  av a  2  s.  c  o  m*/
public void bind(ExposedPort exposedPort, Binding binding) {
    if (ports.containsKey(exposedPort)) {
        Binding[] bindings = ports.get(exposedPort);
        ports.put(exposedPort, (Binding[]) ArrayUtils.add(bindings, binding));
    } else {
        if (binding == null) {
            ports.put(exposedPort, null);
        } else {
            ports.put(exposedPort, new Binding[] { binding });
        }
    }
}

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

/**
 * This must be called after all Scannables and Functions added {@inheritDoc}
 * //from  w  w  w .j  av  a2 s.  c  om
 * @see gda.device.DeviceBase#configure()
 */
@Override
public void configure() throws FactoryException {

    // fill the array of Scannables
    Finder finder = Finder.getInstance();
    if (scannableNames != null && scannableNames.length > 0) {
        for (String name : scannableNames) {
            Findable scannable = finder.find(name);

            if (scannable == null || !(scannable instanceof Scannable)) {
                logger.warn(
                        "Error during configure of " + name + ": scannable " + name + " could not be found!");
            }
            theScannables = (Scannable[]) ArrayUtils.add(theScannables, finder.find(name));
        }
    }

    // check that the arrays are the same length
    if (theFunctions.length != 0 && theScannables.length != theFunctions.length) {
        throw new FactoryException(getName()
                + " cannot complete configure() as arrays of Scannables and Functions are of different lengths");
    }
    for (Scannable scannable : theScannables) {
        scannable.addIObserver(this);
    }

    // set up the arrays of input and extra names properly
    this.inputNames = new String[] { getName() };
    this.extraNames = new String[0];
    this.outputFormat = new String[] { "%5.5g" };
    scannablesMoving = new boolean[theScannables.length];
    if (!unitsComponent.unitHasBeenSet()) {
        try {
            Scannable first = theScannables[0];
            if (first instanceof ScannableMotionUnits) {
                this.setUserUnits(((ScannableMotionUnits) first).getUserUnits());
            }
        } catch (DeviceException e) {
            logger.error("Error setting the hardware units", e);
        }
    }
}

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

@Override
public void configure() {
    theMotor = (ScannableMotor) Finder.getInstance().find(motorName);

    if (this.inputNames.length == 1 && this.inputNames[0].equals("value")) {
        this.inputNames = new String[] { getName() };
    }//from  w w  w  . j  av  a 2 s  . c o m

    try {
        motorUnit = QuantityFactory.createUnitFromString(this.motorUnitString);
        if (initialUserUnits == null) {
            userUnits = motorUnit;
        } else {
            userUnits = QuantityFactory.createUnitFromString(initialUserUnits);
        }

        acceptableUnits = (Unit[]) ArrayUtils.add(acceptableUnits, NonSIext.mDEG_ANGLE);
        acceptableUnits = (Unit[]) ArrayUtils.add(acceptableUnits, NonSIext.DEG_ANGLE);
        acceptableUnits = (Unit[]) ArrayUtils.add(acceptableUnits, NonSI.ANGSTROM);
        acceptableUnits = (Unit[]) ArrayUtils.add(acceptableUnits, SI.NANO(SI.METER));
        acceptableUnits = (Unit[]) ArrayUtils.add(acceptableUnits, NonSI.ELECTRON_VOLT);
        acceptableUnits = (Unit[]) ArrayUtils.add(acceptableUnits, SI.KILO(NonSI.ELECTRON_VOLT));

        this.configured = true;
    } catch (Exception e) {
        // do not throw an error as this would stop ObjectFactory from
        // completing its initialisation
        logger.error(
                "Exception during configure of " + getName() + " (motor=" + StringUtils.quote(motorName) + ")",
                e);
    }
}

From source file:net.navasoft.madcoin.backend.services.controller.exception.impl.BusinessControllerException.java

/**
 * Formulate tips./*from  w w w . j a  va2  s  .  c  om*/
 * 
 * @return the string[]
 * @since 24/08/2014, 07:46:29 PM
 */
@Override
public String[] formulateTips() {
    String[] finalTips = (String[]) Array.newInstance(String.class, 0);
    if (allowedTipsQuantity != -1) {
        for (int availableTip = 1; availableTip < allowedTipsQuantity + 1; availableTip++) {
            finalTips = (String[]) ArrayUtils.add(finalTips,
                    tips.getMessage(MessageFormat.format(locatedMessage + tipSuffix, availableTip),
                            new Object[] { availableTip }, "", language));
        }
    } // Add the filter chain or REGEXP case handling, if applies.
    return finalTips;
}