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:padl.creator.cppfile.eclipse.plugin.internal.SearchHelper.java

static IEntity getExistingContainerOrCreateGhost0(final ICodeLevelModel aCodeLevelModel,
        final Stack<IContainer> someContainers, final char[][] qualifiedName, boolean isGlobalFunction) {

    char[] name = qualifiedName[0];
    if (Utils.isPrimitiveName(name)) {
        final IPrimitiveEntity entity;
        if (!aCodeLevelModel.doesContainConstituentWithName(name)) {
            aCodeLevelModel.addConstituent(
                    ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance()).createPrimitiveEntity(name));
        }/*  ww  w.  ja  v a  2s .com*/
        entity = (IPrimitiveEntity) aCodeLevelModel.getConstituentFromID(name);
        return entity;
    } else if (someContainers == null) {
        return (IFirstClassEntity) SearchHelper.findContainerOrCreateGhostInModelRecursively(aCodeLevelModel,
                qualifiedName, isGlobalFunction);
    } else {
        final IContainer container = someContainers.peek();
        char[] id = qualifiedName[0];
        IContainer entity = (IContainer) container.getConstituentFromName(id);
        if (entity == null) {
            return SearchHelper.getExistingContainerOrCreateGhost(aCodeLevelModel, null, qualifiedName,
                    isGlobalFunction);
        }
        if (entity instanceof IConstructor) {
            return (IFirstClassEntity) container;
        }
        for (int i = 1; i < qualifiedName.length; i++) {
            name = qualifiedName[i];
            id = ArrayUtils.addAll(ArrayUtils.add(id, Utils.SEPARATOR), qualifiedName[i]);
            entity = SearchHelper.findContainerOrCreateGhostInContainer((IContainer) entity, id, name,
                    isGlobalFunction, i == qualifiedName.length - 1);
        }
        return (IFirstClassEntity) entity;
    }
}

From source file:padl.creator.cppfile.eclipse.plugin.internal.Utils.java

static char[] buildID(final char[] fieldTypeName, final char[] fieldName) {
    char[] id = ArrayUtils.add(fieldTypeName, Utils.SEPARATOR);
    id = ArrayUtils.addAll(id, fieldName);
    id = Utils.purifyID(id);//from   ww  w  .j  a  va  2  s  .  co  m
    return id;
}

From source file:padl.creator.cppfile.eclipse.plugin.internal.Utils.java

static char[] getQualifiedName(final char[][] qualifiedNamedComponents) {
    char[] tmp = qualifiedNamedComponents[0];
    for (int i = 1; i < qualifiedNamedComponents.length; i++) {
        char[] cs = qualifiedNamedComponents[i];
        tmp = ArrayUtils.add(tmp, Utils.SEPARATOR);
        tmp = ArrayUtils.addAll(tmp, cs);
    }/*from w w w  .  ja v  a  2 s.c  o m*/
    return Utils.purifyID(tmp);
}

From source file:padl.path.Finder.java

private static IConstituent find0(final String aPath, final IConstituent aConstituent, final char aDelimiter)
        throws FormatException {

    final StringTokenizer tokenizer = new StringTokenizer(aPath, IConstants.ALL_SYMBOLS, true);
    Finder.Header.setLength(0);/*from www .  j  av  a 2s  .  c  o  m*/

    if (tokenizer.hasMoreTokens()) {
        if (aConstituent instanceof IContainer) {
            String token = tokenizer.nextToken();
            Finder.Header.append(token);

            // Yann 2014/04/21: Member parameter types!
            // It could be that the path contains:
            //   AssociateWithTest(ProfileSyncService$SyncTest *[])
            // In that case, I want to look for that constituent
            // (method) now, not split on the $ sign *inside* the
            // parentheses! Ah, C++...
            if (token.indexOf("(") > -1) {
                final char[] id = aPath.toCharArray();
                final IConstituent constituent = ((IContainer) aConstituent).getConstituentFromID(id);
                if (constituent == null) {
                    throw new FormatException(
                            "Cannot find ID: \"" + token + "\" in \"" + aConstituent.getDisplayID() + "\".");
                } else {
                    return constituent;
                }
            }

            final IConstituent constituent;
            if (aDelimiter == IConstants.MEMBER_ENTITY_SYMBOL) {
                // Yann 2010/06/29: Name vs. ID.
                // A member entity has for name its "simple name"
                // and for ID is fully qualified name, as any
                // other entity now...
                // Yann 2013/09/28: Name vs. ID, reloaded!
                // So, as per the previous comment, I need to
                // create the fully-qualified name of the member
                // entity OR look for it by name rather than by
                // ID BUT, if looking per name, I can retrieve
                // the wrong entity, in case a field of method
                // would have the same name as a member entity.
                // Yann 2014/04/21: Yet again...
                char[] id = aConstituent.getID();
                id = ArrayUtils.add(id, IConstants.MEMBER_ENTITY_SYMBOL);
                id = ArrayUtils.addAll(id, token.toCharArray());
                constituent = ((IContainer) aConstituent).getConstituentFromID(id);
            } else {
                // Yann 2013/09/12: A bit of mismatch!
                // The path of an operation includes parentheses
                // and parameter types while the ID of an operation
                // is just that, it is ID, without anything else.
                // Therefore, if the token includes parentheses,
                // I must remove them...
                // ... which is really NOT a good idea: ID must
                // include parenthesis and parameter types to
                // distinguish a field "a" from a method "a()"
                // from the overloaded method "a(int)!
                //   final int startOpeningParenthesisInclusive =
                //      ArrayUtils.indexOf(id, '(');
                //   if (startOpeningParenthesisInclusive > 0) {
                //      id =
                //         ArrayUtils.subarray(
                //            id,
                //            0,
                //            startOpeningParenthesisInclusive);
                //   }
                char[] id = token.toCharArray();
                constituent = ((IContainer) aConstituent).getConstituentFromID(id);
            }
            if (constituent != null) {
                if (tokenizer.hasMoreTokens()) {
                    token = tokenizer.nextToken();
                    Finder.Header.append(token);

                    return Finder.find0(aPath.substring(Finder.Header.length()), constituent, token.charAt(0));
                } else {
                    return constituent;
                }
            } else {
                throw new FormatException(
                        "Cannot find ID: \"" + token + "\" in \"" + aConstituent.getDisplayID() + "\".");
            }
        } else {
            throw new FormatException(
                    "Constituent with ID: \"" + aConstituent.getDisplayID() + "\" is not a container.");
        }
    } else {
        throw new FormatException("Empty path.");
    }
}

From source file:paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity.java

private void setHoldable(int n64Index, boolean holdable) {
    String index = String.valueOf(n64Index);

    // Get the serialized list from the profile
    String serialized = mProfile.get(TOUCHSCREEN_AUTOHOLDABLES, "");
    String[] holdables = serialized.split(AUTOHOLDABLES_DELIMITER);

    // Modify the list as necessary
    if (!holdable) {
        holdables = (String[]) ArrayUtils.removeElement(holdables, index);
    } else if (!ArrayUtils.contains(holdables, index)) {
        holdables = (String[]) ArrayUtils.add(holdables, index);
    }//from   w w  w  .ja v a  2s  . c om

    // Put the serialized list back into the profile
    serialized = TextUtils.join(AUTOHOLDABLES_DELIMITER, holdables);
    mProfile.put(TOUCHSCREEN_AUTOHOLDABLES, serialized);
}

From source file:pcgen.core.facade.util.SortedListFacade.java

@Override
public void elementAdded(ListEvent<E> e) {
    transform = (Integer[]) ArrayUtils.add(transform, transform.length);
    sanityCheck();//  w w  w  .ja v a2s  .c  o m
    Arrays.sort(transform, indexComparator);
    int index = Arrays.binarySearch(transform, e.getIndex(), indexComparator);
    fireElementAdded(this, e.getElement(), index);
}

From source file:pcgen.gui2.util.SortedListModel.java

public void elementAdded(ListEvent<E> e) {
    transform = (Integer[]) ArrayUtils.add(transform, transform.length);
    Arrays.sort(transform, indexComparator);
    int index = Arrays.binarySearch(transform, e.getIndex(), indexComparator);
    fireIntervalAdded(this, index, index);
}

From source file:rascal.object.name.AbstractMessageDigestObjectNameResolverIntegrationTest.java

@Test
public void testGetBlobName() throws Exception {
    String objectName = getObjectNameResolver().getObjectName(new FileBlobSource(tempFile));
    String headerString = String.format("%s %d", GitObjectType.BLOB, testData.length);
    byte[] header = ArrayUtils.add(headerString.getBytes(), (byte) 0);
    Assert.assertEquals(getHash(ArrayUtils.addAll(header, testData)), objectName);
}

From source file:rascal.object.source.BlobSource.java

public final void copyTo(WritableByteChannel destination) throws IOException {
    String headerString = String.format("%s %d", GitObjectType.BLOB, getBlobSize());
    byte[] header = ArrayUtils.add(headerString.getBytes(), (byte) 0);
    destination.write(ByteBuffer.wrap(header));
    copyBlobDataTo(destination);/*from  w  w  w. ja  va  2 s  .co  m*/
}

From source file:rascal.object.source.FilelBlobSourceIntegrationTest.java

@Test
public void testCopyTo() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    fileBlobSource.copyTo(Channels.newChannel(output));
    byte[] buffer = output.toByteArray();
    String expectedHeaderString = String.format("%s %d", GitObjectType.BLOB, testData.length);
    byte[] expectedHeader = ArrayUtils.add(expectedHeaderString.getBytes(), (byte) 0);
    byte[] header = ArrayUtils.subarray(buffer, 0, expectedHeader.length);
    Assert.assertTrue("Header should be of format \"type(space)size(null byte)\"",
            ArrayUtils.isEquals(expectedHeader, header));
    byte[] content = ArrayUtils.subarray(buffer, expectedHeader.length, buffer.length);
    Assert.assertTrue(ArrayUtils.isEquals(testData, content));
}