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 double[] add(double[] array, int index, double element) 

Source Link

Document

Inserts the specified element at the specified position in the array.

Usage

From source file:org.eclipse.wb.android.internal.model.layouts.table.TableLayoutSupport.java

/**
 * Adds information about new column. Note: it doesn't update visual information.
 *//*from www . jav  a  2s. c om*/
public void insertColumn(int columnIndex) throws Exception {
    for (int row = 0; row < m_rows; ++row) {
        CellInfo newCell = new CellInfo(row, columnIndex);
        CellInfo cell = null;
        if (columnIndex < m_columns) {
            cell = m_cells[row][columnIndex];
        }
        // insert a cell into row cells
        m_cells[row] = (CellInfo[]) ArrayUtils.add(m_cells[row], columnIndex, newCell);
        // null cell means appending to the end
        if (cell != null) {
            // extend span
            if (cell.isSpanSpace()) {
                cell.spannedViewCell.span++;
                newCell.spannedViewCell = cell.spannedViewCell;
                TableLayoutUtils.setSpanValue(cell.spannedViewCell.view, cell.spannedViewCell.span);
            } else {
                // find a next cell with view to right to adjust the column number
                boolean prevEmpty = true;
                for (int column = columnIndex + 1; column < m_columns + 1; ++column) {
                    CellInfo rightCell = m_cells[row][column];
                    if (!rightCell.isEmpty()) {
                        if (prevEmpty) {
                            // set explicit column
                            TableLayoutUtils.setExplicitColumn(rightCell.view, column);
                        }
                        prevEmpty = false;
                    } else {
                        prevEmpty = true;
                    }
                }
            }
        }
    }
    m_columns++;
    // fix column number in cell
    for (int row = 0; row < m_rows; ++row) {
        for (int column = columnIndex + 1; column < m_columns; ++column) {
            m_cells[row][column].column++;
        }
    }
}

From source file:org.eclipse.wb.internal.core.model.util.factory.FactoryActionsSupport.java

/**
 * Adds new factory type into history, but limit history to some size.
 *//*from  ww  w.  jav a  2s . com*/
static void addPreviousTypeName(JavaInfo component, String typeName) throws CoreException {
    String[] typeNames = getPreviousTypeNames(component);
    // move element into head
    typeNames = (String[]) ArrayUtils.removeElement(typeNames, typeName);
    typeNames = (String[]) ArrayUtils.add(typeNames, 0, typeName);
    // limit history size
    if (typeNames.length > MAX_PREVIOUS_FACTORIES) {
        typeNames = (String[]) ArrayUtils.remove(typeNames, typeNames.length - 1);
    }
    // set new type names
    IProject project = component.getEditor().getJavaProject().getProject();
    project.setPersistentProperty(KEY_PREVIOUS_FACTORIES, StringUtils.join(typeNames, ','));
}

From source file:org.eclipse.wb.internal.xwt.model.widgets.SashFormInfo.java

/**
 * Adds weight for {@link ControlInfo} that is already in children.
 *///from w  w  w.  ja v a2  s . c om
private void addWeight(ControlInfo newControl) throws Exception {
    int[] weights = getEnsureWeights();
    // prepare weight for "newControl"
    int newWeight;
    if (weights.length == 0) {
        newWeight = 1;
    } else {
        newWeight = 0;
        for (int i = 0; i < weights.length; i++) {
            newWeight += weights[i];
        }
        newWeight /= weights.length;
    }
    // add weight
    int newControlIndex = getChildrenControls().indexOf(newControl);
    weights = ArrayUtils.add(weights, newControlIndex, newWeight);
    setWeights(weights);
}

From source file:org.eclipse.wb.internal.xwt.model.widgets.SashFormInfo.java

/**
 * Moves weight for {@link ControlInfo} that is already moved in children.
 *//*from   ww  w  . ja  va 2s .  com*/
private void moveWeight(ControlInfo newControl, int oldIndex) throws Exception {
    int[] weights = getEnsureWeights();
    int weight = weights[oldIndex];
    int newIndex = getChildrenControls().indexOf(newControl);
    weights = ArrayUtils.remove(weights, oldIndex);
    weights = ArrayUtils.add(weights, newIndex, weight);
    setWeights(weights);
}

From source file:org.eclipse.wb.tests.designer.swt.model.layouts.AbsoluteLayoutTest.java

/**
 * generic check for bounds changing.//from ww  w  .j  a v a 2  s . c  o m
 */
private void check_changeBounds(String[] initial, String[] expected, Point location, Dimension size)
        throws Exception {
    String[] initialCode = new String[] { "class Test extends Shell {", "  public Test() {",
            "    setLayout(null);", "    Button button = new Button(this, SWT.NONE);",
            "    button.setText(\"test\");", "  }", "}" };
    // prepare initial code
    String[] initialLines = (String[]) ArrayUtils.clone(initialCode);
    for (int i = 0; i < initial.length; i++) {
        if (!StringUtils.isEmpty(initial[i])) {
            initialLines = (String[]) ArrayUtils.add(initialLines, 4 + i, initial[i]);
        }
    }
    // prepare expected code
    String[] expectedLines = (String[]) ArrayUtils.clone(initialCode);
    for (int i = 0; i < expected.length; i++) {
        if (!StringUtils.isEmpty(expected[i])) {
            expectedLines = (String[]) ArrayUtils.add(expectedLines, 4 + i, expected[i]);
        }
    }
    // prepare model
    CompositeInfo shellInfo = parseComposite(initialLines);
    shellInfo.refresh();
    ControlInfo buttonInfo = shellInfo.getChildrenControls().get(0);
    AbsoluteLayoutInfo layoutInfo = (AbsoluteLayoutInfo) shellInfo.getLayout();
    // perform code modifications
    layoutInfo.commandChangeBounds(buttonInfo, location, size);
    // check the results
    assertEditor(expectedLines);
}

From source file:org.gitools.ui.app.actions.BookmarksDropdown.java

private void setBookmarks(final Bookmarks bookmarks) {
    this.bookmarks = bookmarks;
    Bookmark[] bookmarkArray = bookmarks.getAll().toArray(new Bookmark[bookmarks.getAll().size()]);
    bookmarksSelectPanel.setVisible(bookmarks.getAll().size() > 0);
    if (bookmarks.getAll().size() == 0)
        return;/*from w  w w.ja  va  2  s .co m*/

    NO_OPTION.setName(
            String.valueOf(bookmarkArray.length) + (bookmarkArray.length > 1 ? " Bookmarks:" : " Bookmark:"));
    bookmarkArray = (Bookmark[]) ArrayUtils.add(bookmarkArray, 0, NO_OPTION);
    bookmarkComboBox.setModel(new DefaultComboBoxModel<>(bookmarkArray));
    bookmarkComboBox.getModel().setSelectedItem(NO_OPTION);

}

From source file:org.jahia.pipelines.impl.GenericPipeline.java

/**
 * @since Jahia 6.6.0.0/*from  www. ja  v  a 2  s.c  o  m*/
 */
public void addValve(int position, Valve valve) {
    // Add this Valve to the set associated with this Pipeline
    synchronized (valvesLock) {
        Valve[] results = new Valve[valves.length + 1];
        if (position == -1 || position >= valves.length) {
            System.arraycopy(valves, 0, results, 0, valves.length);
            results[valves.length] = valve;
        } else {
            results = (Valve[]) ArrayUtils.add(valves, position, valve);
        }
        valves = results;
    }
}

From source file:org.jumpmind.symmetric.io.data.writer.MsSqlBulkDatabaseWriterTest.java

@Test
public void testInsertReorderColumns() throws Exception {
    if (shouldTestRun(platform)) {
        String id = getNextId();//from   w  w w. ja  va2 s  . c  om
        String[] values = { "string with space in it", "string-with-no-space", "string with space in it",
                "string-with-no-space", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "47",
                "67.89", "-0.0747663", encode("string with space in it"), id };
        List<CsvData> data = new ArrayList<CsvData>();
        data.add(new CsvData(DataEventType.INSERT, (String[]) ArrayUtils.clone(values)));
        Table table = (Table) platform.getTableFromCache(getTestTable(), false).clone();
        Column firstColumn = table.getColumn(0);
        table.removeColumn(firstColumn);
        table.addColumn(firstColumn);
        writeData(new MsSqlBulkDatabaseWriter(platform, stagingManager, new CommonsDbcpNativeJdbcExtractor(),
                1000, false, uncPath, null, null), new TableCsvData(table, data));
        values = (String[]) ArrayUtils.remove(values, values.length - 1);
        values = (String[]) ArrayUtils.add(values, 0, id);
        assertTestTableEquals(id, values);
    }
}

From source file:org.jumpmind.symmetric.io.MySqlBulkDatabaseWriter.java

protected byte[] escape(byte[] byteData) {
    ArrayList<Integer> indexes = new ArrayList<Integer>();
    for (int i = 0; i < byteData.length; i++) {
        if (byteData[i] == '"' || byteData[i] == '\\') {
            indexes.add(i + indexes.size());
        }/*from  w w w  . j a v  a2  s.c  o  m*/
    }
    for (Integer index : indexes) {
        byteData = ArrayUtils.add(byteData, index, (byte) '\\');
    }
    return byteData;
}

From source file:org.openvpms.web.workspace.admin.style.StyleBrowser.java

/**
 * Returns the available resolutions./*from   ww  w  . java  2s  . c om*/
 * <p/>
 * This always returns a model with at least one resolution.
 *
 * @return the resolutions
 */
private DefaultListModel getResolutions() {
    Dimension[] sizes = (Dimension[]) ArrayUtils.add(styles.getResolutions(), 0, StyleHelper.ANY_RESOLUTION);
    return new DefaultListModel(sizes);
}