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

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

Introduction

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

Prototype

public static double[] addAll(double[] array1, double[] array2) 

Source Link

Document

Adds all the elements of the given arrays into a new array.

Usage

From source file:com.novartis.opensource.yada.test.ServiceTest.java

/**
 * Combines the queries from multiple resources into a single array to
 * facilitate execution of tests from multiple files
 * //from   w  w  w . j  a  v  a  2s  . c om
 * @param paths the paths to the test scripts
 * @return an array of query or JSON strings
 * @throws URISyntaxException when a handle can't be attached to the test file
 *         path
 * @throws IOException if the {@link InputStream} used for reading test files
 *         can't be closed
 */
public String[] mergeArrays(String[] paths) throws URISyntaxException, IOException {
    String engine = ConnectionFactoryTest.getProps().getProperty("jdbc.engine");
    String[] params = null;
    for (int i = 0; i < paths.length; i++) {
        params = (String[]) ArrayUtils.addAll(params, loadResource(paths[i]));

        if (engine != null) {
            String enginePath = paths[i].replace(".txt", "_" + engine + ".txt");
            String[] engineResources = loadResource(enginePath);
            if (engineResources != null)
                params = (String[]) ArrayUtils.addAll(params, engineResources);
        }
    }
    List<String> list = new ArrayList<>(Arrays.asList(params));
    List<String> comments = new ArrayList<>();
    for (String entry : list) {
        if (isComment(entry) || entry.length() == 0) {
            comments.add(entry);
        }
    }
    list.removeAll(comments);
    params = list.toArray(new String[list.size()]);

    return params;
}

From source file:LicenseGenerator.java

private void cmdLicense_click(ActionEvent e) {
    // ?license/*w w w  . j  a v  a2 s .  co m*/
    StringBuffer buffer = new StringBuffer();

    int[] adapterFlag = new int[128];
    String[] adapterDate = new String[128];
    Arrays.fill(adapterDate, "00000000");

    if (chkAdapter.isSelected()) {
        checkAdapter(chkHTTP_C, txtHTTP_C, adapterFlag, adapterDate);
        checkAdapter(chkHTTP_S, txtHTTP_S, adapterFlag, adapterDate);
        checkAdapter(chkSOAP_C, txtSOAP_C, adapterFlag, adapterDate);
        checkAdapter(chkSOAP_S, txtSOAP_S, adapterFlag, adapterDate);
        checkAdapter(chkTCP_C, txtTCP_C, adapterFlag, adapterDate);
        checkAdapter(chkTCP_S, txtTCP_S, adapterFlag, adapterDate);
        checkAdapter(chkUDP_C, txtUDP_C, adapterFlag, adapterDate);
        checkAdapter(chkUDP_S, txtUDP_S, adapterFlag, adapterDate);
        checkAdapter(chkTUXEDO_C, txtTUXEDO_C, adapterFlag, adapterDate);
        checkAdapter(chkTUXEDO_S, txtTUXEDO_S, adapterFlag, adapterDate);
        checkAdapter(chkMQ_C, txtMQ_C, adapterFlag, adapterDate);
        checkAdapter(chkMQ_S, txtMQ_S, adapterFlag, adapterDate);
    } else {
        Arrays.fill(adapterFlag, 1);
    }

    buffer.append(StringUtils.join(ArrayUtils.toObject(adapterFlag))).append("\r");
    buffer.append("|" + StringUtils.join(adapterDate, "|")).append("\r");
    buffer.append(chkDate.isSelected() ? txtDate.getText() : "00000000").append("\r");
    buffer.append(chkAdapterNum.isSelected() ? txtAdapterNum.getText() : "0");

    System.out.print(buffer);

    // license
    try {
        byte[] data = buffer.toString().getBytes(RuntimeUtils.utf8);
        byte[] key = "nuclearg".getBytes();

        // des
        byte[] enData = encrypt(data, key);
        enData = ArrayUtils.addAll(enData, key);

        // ?license
        String license = new BASE64Encoder().encode(enData);

        // license?

        // base64decode
        byte[] _enData = new BASE64Decoder().decodeBuffer(license);
        System.out.println("_enData == enData " + Arrays.equals(_enData, enData));

        // 
        byte[] _buffer = new byte[_enData.length - 8];
        System.arraycopy(_enData, 0, _buffer, 0, _enData.length - 8);
        byte[] _data = decrypt(_buffer, "nuclearg".getBytes());
        System.out.println("_data == data " + Arrays.equals(_data, data));

        System.out.println(new String(_data, RuntimeUtils.utf8));

        txtLicense.setText(license);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:at.gv.egiz.bku.slcommands.impl.cms.Signature.java

private byte[] getContent(CMSDataObjectOptionalMetaType dataObject, URLDereferencer urlDereferencer)
        throws InvalidParameterException, SLCommandException, IOException {
    byte[] data = dataObject.getContent().getBase64Content();
    if (data == null) {
        String reference = dataObject.getContent().getReference();
        if (reference == null)
            throw new SLCommandException(4003);
        InputStream is = urlDereferencer.dereference(reference).getStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        for (int i = is.read(buffer); i > -1; i = is.read(buffer)) {
            baos.write(buffer, 0, i);//from  w  ww .  ja  v a 2  s  .  c  om
        }
        data = baos.toByteArray();
        is.close();
    }
    this.signedDocument = data.clone();

    this.excludedByteRange = dataObject.getExcludedByteRange();
    if (this.excludedByteRange == null)
        return data;

    int from = this.excludedByteRange.getFrom().intValue();
    int to = this.excludedByteRange.getTo().intValue();
    if (from > data.length || to > data.length || from > to)
        throw new InvalidParameterException("ExcludedByteRange contains invalid data: [" + from + "-" + to
                + "], Content length: " + data.length);

    // Fill ExcludedByteRange with 0s for document to display in viewer
    Arrays.fill(this.signedDocument, from, to + 1, (byte) 0);

    // Remove ExcludedByteRange from data to be signed
    byte[] first = null;
    byte[] second = null;
    if (from > 0)
        first = Arrays.copyOfRange(data, 0, from);
    if ((to + 1) < data.length)
        second = Arrays.copyOfRange(data, to + 1, data.length);
    data = ArrayUtils.addAll(first, second);
    log.debug("ExcludedByteRange [" + from + "-" + to + "], Content length: " + data.length);
    return data;
}

From source file:com.ikanow.infinit.e.data_model.store.document.DocumentPojo.java

public void addToMetadata(String fieldName, Object[] fieldVals) {
    if (null == metadata) {
        metadata = new LinkedHashMap<String, Object[]>();
    }/*from  w  w w  . j  a  v a 2s  .  co m*/
    Object[] current = metadata.get(fieldName);
    if (null != current) {
        metadata.put(fieldName, ArrayUtils.addAll(current, fieldVals));
    } else {
        metadata.put(fieldName, fieldVals);
    }
}

From source file:bdv.bigcat.label.FragmentSegmentAssignment.java

/**
 * Assign all fragments of segmentId1 to segmentId2.
 *
 * @param segmentId1// w  w w  .  j ava  2 s . c om
 * @param segmentId2
 */
public void assignFragments(final long segmentId1, final long segmentId2) {
    if (segmentId1 == segmentId2)
        return;

    synchronized (this) {
        final long[] fragments1 = ilut.get(segmentId1);
        final long[] fragments2 = ilut.get(segmentId2);
        for (final long fragmentId : fragments1)
            lut.put(fragmentId, segmentId2);
        ilut.put(segmentId2, ArrayUtils.addAll(fragments1, fragments2));
        ilut.remove(segmentId1);
    }
}

From source file:gda.scan.ScanDataPoint.java

/**
 * Add a detector to the list of detectors this object holds data from. This stores the name in the detectorHeader
 * array and detectorNames array. If its a countertimer is stored in the boolean array. The contents of the
 * detectorHeader and detectorNames arrays will be different if the detector is a countertimer.
 * <p>//  w w  w . j av a  2s.c om
 * Note this does not readout the detector! Data must be added by using the addData method.
 * 
 * @param det
 */
@Override
public void addDetector(Detector det) {
    //      detectorNames = (String[]) ArrayUtils.add(detectorNames, det.getName());
    scanInfo.setDetectorNames((String[]) ArrayUtils.add(scanInfo.getDetectorNames(), det.getName()));
    String[] extraNames = det.getExtraNames();
    if (extraNames != null && extraNames.length > 0) {
        detectorHeader = (String[]) ArrayUtils.addAll(detectorHeader, extraNames);
    } else {
        detectorHeader = (String[]) ArrayUtils.add(detectorHeader, det.getName());
    }
    detectors.add(det);
}

From source file:gda.jython.commands.ScannableCommands.java

/**
 * prints to console all the scannables and their current position in the system
 * @throws DeviceException // ww  w.j a  va  2 s . co  m
 */
public static void pos() throws DeviceException {
    posCommandIsInTheProcessOfListingAllScannables = true;
    try {
        Map<String, Object> map = InterfaceProvider.getJythonNamespace().getAllFromJythonNamespace();

        // create a list of all the members of scannable groups
        String[] scannableGroupMembers = new String[0];
        for (String objName : map.keySet()) {
            Object obj = map.get(objName);
            if (obj instanceof IScannableGroup) {
                scannableGroupMembers = (String[]) ArrayUtils.addAll(scannableGroupMembers,
                        ((IScannableGroup) obj).getGroupMemberNames());
            }
        }

        // remove those members from the global list, if they are there
        for (String groupMember : scannableGroupMembers) {
            if (map.keySet().contains(groupMember)) {
                map.remove(groupMember);
            }
        }

        // find the longest name, to help with formatting the output
        int longestName = 0;
        for (String objName : map.keySet()) {
            Object obj = map.get(objName);
            if (obj instanceof Scannable && objName.length() > longestName) {
                longestName = objName.length();
            }
        }

        // then loop over the reduced list and print each item separately, logging any errors if they occur
        for (String objName : map.keySet()) {
            Object obj = map.get(objName);
            try {
                if (obj instanceof IScannableGroup) {
                    InterfaceProvider.getTerminalPrinter().print(((IScannableGroup) obj).toFormattedString());
                } else if (obj instanceof Scannable) {
                    InterfaceProvider.getTerminalPrinter()
                            .print(ScannableUtils.prettyPrintScannable((Scannable) obj, longestName + 1));
                }
            } catch (PyException e) {
                InterfaceProvider.getTerminalPrinter().print(objName);
                logger.warn("Exception while getting position of " + objName + " : " + e.toString());
            } catch (Exception e) {
                InterfaceProvider.getTerminalPrinter().print(objName);
                logger.warn("Exception while getting position of " + objName + " : " + e.getMessage());
            }
        }
    } finally {
        posCommandIsInTheProcessOfListingAllScannables = false;
    }
}

From source file:gda.device.scannable.scannablegroup.ScannableGroup.java

@Override
public String toFormattedString() {
    //TODO this method does not provide correct indentation level for a scannable group inside another scannable group
    //TODO the regex parser is unreliable as described by FIXME below
    // IT would be better to create format message by delegate to individual members directly, rather than re-parsing output again.

    //TODO this works if the toFormattedString method of the members conforms to a standard. But I don't think there is one!
    //Rather use getPosition and format here.
    String membersOutput = getName() + " ::\n";
    for (Scannable member : groupMembers) {
        membersOutput += member.toFormattedString() + "\n";
    }/*from w w w .  j  a va  2  s . c  o m*/

    String[] originalInputNames = getInputNames();
    String[] namesToSplitOn = getInputNames();
    String[] names = getGroupMemberNames();
    String[] extras = getExtraNames();

    // FIXME regex-based splitting of membersOutput is broken if one group member name is a substring of another - e.g. "col_y" and "col_yaw"

    if (originalInputNames.length + extras.length == 0) {
        return membersOutput;
    }

    if (extras.length > 0) {
        namesToSplitOn = (String[]) ArrayUtils.addAll(namesToSplitOn, extras);
    }

    // find the longest name, to help with formatting the output
    int longestName = 0;
    for (String objName : namesToSplitOn) {
        if (objName.length() > longestName) {
            longestName = objName.length();
        }
    }
    namesToSplitOn = (String[]) ArrayUtils.add(namesToSplitOn, getName());
    namesToSplitOn = (String[]) ArrayUtils.addAll(namesToSplitOn, names);

    String regex = "";
    for (String name : namesToSplitOn) {
        regex += name + " +|";
    }
    regex = regex.substring(0, regex.length() - 1);

    String[] values = membersOutput.split(regex);

    String returnString = getName() + "::\n";
    int nextNameIndex = 0;
    for (int i = 0; i < values.length; i++) {
        String value = values[i].trim();
        if (value.startsWith(":")) {
            value = value.substring(1).trim();
        }
        if (StringUtils.containsOnly(value, ":()") || value.isEmpty()) {
            continue;
        }
        returnString += " " + StringUtils.rightPad(namesToSplitOn[nextNameIndex], longestName) + ": " + value
                + "\n";
        nextNameIndex++;
    }
    returnString.trim();
    returnString = returnString.substring(0, returnString.length() - 1);

    return returnString;
}

From source file:com.linkedin.cubert.analyzer.physical.AggregateRewriter.java

private void createMVBlockgen(String[] dimensions, String[] measures) throws AggregateRewriteException {
    String[] mvDimensions = (dimensions);
    String[] mvMeasures = (measures);
    String[] mvColumns = (String[]) ArrayUtils.addAll(mvDimensions, mvMeasures);

    // Step1: At the very beginnning of the program, create a blockgen by index for
    // the/*from ww w .ja  va 2  s.  c om*/
    // historical MV
    if (this.mvExists) {
        ObjectNode mvBlockgenJobNode = (ObjectNode) createBlockgenForMV(programNode, cubeOperatorNode, bgInfo,
                mvName, mvPath, mvColumns);

        ArrayNode jobsListNode = JsonUtils.insertNodeListBefore((ArrayNode) (programNode.get("jobs")),
                cubeJobNode, Arrays.asList(new ObjectNode[] { mvBlockgenJobNode }));
        programNode.put("jobs", jobsListNode);
    }
}

From source file:com.cloudera.sqoop.TestSqoopOptions.java

private void validateImportOptions(String[] extraArgs) throws Exception {
    String[] args = { "--connect", HsqldbTestServer.getUrl(), "--table", "test", "-m", "1", };
    ImportTool importTool = new ImportTool();
    SqoopOptions opts = importTool.parseArguments((String[]) ArrayUtils.addAll(args, extraArgs), null, null,
            false);/*from ww w.j  a  v  a 2 s.c o m*/
    importTool.validateOptions(opts);
}