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

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

Introduction

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

Prototype

public static int indexOf(boolean[] array, boolean valueToFind) 

Source Link

Document

Finds the index of the given value in the array.

Usage

From source file:padl.creator.classfile.util.Utils.java

private static IFirstClassEntity searchForEnclosedEntity(final IAbstractLevelModel anAbstractModel,
        final IFirstClassEntity anEnclosingEntity, final char[] anEntityName) {

    final char[] nameFirstPart;
    if (Utils.isMemberEntity(anEntityName)) {
        nameFirstPart = ArrayUtils.subarray(anEntityName, 0, ArrayUtils.indexOf(anEntityName, '$'));
    } else {//from w  ww . j  a v a 2s  .c om
        nameFirstPart = ArrayUtils.subarray(anEntityName, 0, anEntityName.length);
    }

    // Yann 2016/09/18: Member IDs!
    // Member entities have their fully-qualified names (with $) as IDs...
    final char[] id = ArrayUtils.addAll(ArrayUtils.add(anEnclosingEntity.getID(), '$'), nameFirstPart);

    IFirstClassEntity firstClassEntity = (IFirstClassEntity) anEnclosingEntity.getConstituentFromID(id);
    if (firstClassEntity == null) {
        firstClassEntity = Utils.createMemberGhost(anAbstractModel, anEnclosingEntity, id);
    }

    if (Utils.isMemberEntity(anEntityName)) {
        return Utils.searchForEnclosedEntity(anAbstractModel, firstClassEntity, ArrayUtils
                .subarray(anEntityName, ArrayUtils.indexOf(anEntityName, '$') + 1, anEntityName.length));
    } else {
        return firstClassEntity;
    }
}

From source file:padl.creator.classfile.util.Utils.java

public static IFirstClassEntity searchForEntity(final IAbstractLevelModel anAbstractModel,
        final char[] anEntityName) {

    final char[] nameFirstPart;
    if (Utils.isMemberEntity(anEntityName)) {
        nameFirstPart = ArrayUtils.subarray(anEntityName, 0, ArrayUtils.indexOf(anEntityName, '$'));
    } else {/*from w ww. j av a 2  s  .c om*/
        nameFirstPart = ArrayUtils.subarray(anEntityName, 0, anEntityName.length);
    }

    IFirstClassEntity firstClassEntity = (IFirstClassEntity) anAbstractModel
            .getTopLevelEntityFromID(nameFirstPart);
    if (firstClassEntity == null) {
        firstClassEntity = Utils.createGhost(anAbstractModel, nameFirstPart);
    }

    if (Utils.isMemberEntity(anEntityName)) {
        return Utils.searchForEnclosedEntity(anAbstractModel, firstClassEntity, ArrayUtils
                .subarray(anEntityName, ArrayUtils.indexOf(anEntityName, '$') + 1, anEntityName.length));
    } else {
        return firstClassEntity;
    }
}

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

static String getExistingOperationOrCreateGhost(final ICodeLevelModel aCodeLevelModel,
        final Stack<IContainer> someContainers, final char[] aFunctionName) {

    final char[][] declaringEntityName = Utils.getQualifiedType(aFunctionName);
    final IContainer declaringEntity;
    final IOperation operation;

    if (declaringEntityName.length == 0) {
        declaringEntity = (IContainer) aCodeLevelModel.getConstituentFromID(Constants.DEFAULT_PACKAGE_ID);
    } else if (declaringEntityName.length == 1) {
        declaringEntity = (IContainer) SearchHelper.findContainerOrCreateGhostInModel(aCodeLevelModel,
                declaringEntityName[0], declaringEntityName[0], true, false);
    } else {// w ww .ja  v  a 2s. c  o m
        declaringEntity = (IContainer) SearchHelper.getExistingContainerOrCreateGhost(aCodeLevelModel,
                someContainers, declaringEntityName, false);
    }

    final char[] simpleName = Utils.getSimpleName(aFunctionName);
    final IConstituent constituent = declaringEntity.getConstituentFromID(simpleName);
    if (constituent instanceof IOperation) {
        operation = (IOperation) constituent;
    } else if (constituent instanceof IFirstClassEntity) {
        // Here, I must manage the case of a constructor:
        // it is possible that the constituent is not an 
        // operation but an entity... in this case, I must 
        // look into it for its constructor.
        final IOperation possibleOperation = (IOperation) ((IFirstClassEntity) constituent)
                .getConstituentFromID(aFunctionName);
        if (possibleOperation == null) {
            operation = CPPFactoryEclipse.getInstance().createConstructor(aFunctionName, simpleName);

            // Yann 2014/0417: Anti-patterns!
            // I need to set the lines of code of the methods
            // to allow the identification of some anti-patterns
            // like LongMethod and SpaghettiCode. This seems the
            // best place to do so :-)
            // In this case, I just add a null statement!
            Utils.addStatementsToFunction(operation);

            ((IFirstClassEntity) constituent).addConstituent(operation);
        } else {
            operation = possibleOperation;
        }
    } else {
        // Yann 2014/04/17: Parameter!
        // I don't forget that the ID contains the parameter list...
        // Important if I want to find the corresponding function
        // if it exists. BUT, it is not quite possible to build the
        // parameter because there is no bindings at this point.
        // So, it is rather the getExistingOperationOrCreateGhost()
        // method that must be smart: if it finds the method in the
        // declaring entity, then it should choose it; else if it
        // finds a method with the same name, but different parameters,
        // then it should choose it too, else it should look for
        // for (ghost) global functions.
        final Iterator<?> iterator = declaringEntity.getIteratorOnConstituents(IOperation.class);
        while (iterator.hasNext()) {
            final IOperation possibleOperation = (IOperation) iterator.next();
            final char[] operationName = possibleOperation.getID();
            final char[] operationNameWithoutParameters = ArrayUtils.subarray(operationName, 0,
                    ArrayUtils.indexOf(operationName, '('));
            final char[] simpleNameWithoutParameters = ArrayUtils.subarray(simpleName, 0,
                    ArrayUtils.indexOf(simpleName, '('));

            if (Arrays.equals(operationNameWithoutParameters, simpleNameWithoutParameters)) {

                return possibleOperation.getDisplayPath();
            }
        }

        if (Arrays.equals(((IConstituent) declaringEntity).getName(), simpleName)) {

            operation = CPPFactoryEclipse.getInstance().createConstructor(aFunctionName, simpleName);
        } else {
            if (declaringEntity instanceof IPackage) {
                // Yann 2015/07/16: Weird...
                // Why does the simple name include parentheses???
                final char[] simpleNameWithoutParameters = ArrayUtils.subarray(simpleName, 0,
                        ArrayUtils.indexOf(simpleName, '('));
                operation = ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance())
                        .createGlobalFunctionGhost(aFunctionName, simpleNameWithoutParameters);
            } else {
                operation = CPPFactoryEclipse.getInstance().createMethod(simpleName, simpleName);
            }
        }

        if (!declaringEntity.doesContainConstituentWithID(operation.getID())) {

            // Yann 2014/0417: Anti-patterns!
            // I need to set the lines of code of the methods
            // to allow the identification of some anti-patterns
            // like LongMethod and SpaghettiCode. This seems the
            // best place to do so :-)
            // In this case, I just add a null statement!
            Utils.addStatementsToFunction(operation);

            declaringEntity.addConstituent(operation);
        } else {
            // I must return the real constituent in the entity,
            // I cannot use the ones build above because they 
            // don't belong to any model yet.
            return declaringEntity.getConstituentFromID(operation.getID()).getDisplayPath();
        }
    }
    return operation.getDisplayPath();
}

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

static boolean isQualifiedName(final char[] aName) {
    return ArrayUtils.indexOf(aName, Utils.SEPARATOR) > -1;
}

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

static char[] removeQualifiers(char[] aName) {
    char cleanedName[] = ArrayUtils.subarray(aName, ArrayUtils.lastIndexOf(aName, ' ') + 1, aName.length);
    int indexOfLessThan = ArrayUtils.indexOf(cleanedName, '<');
    if (indexOfLessThan > -1) {
        cleanedName = ArrayUtils.subarray(cleanedName, 0, indexOfLessThan);
    }/*from   w w w .java  2 s .  c  o  m*/
    return cleanedName;
}

From source file:padl.creator.javafile.eclipse.util.PadlParserUtil.java

/**
 * extract the name of a package via the name of an entity
 * //  w w w . j  a v  a2  s  .c  o m
 * @param aJVMClassName
 * @return
 */
public static char[] extractPackageName(final char[] aJVMClassName) {
    if (ArrayUtils.indexOf(aJVMClassName, '.') == -1) {
        return PadlParserUtil.DEFAULT_PACKAGE_NAME;
    } else {
        return ArrayUtils.subarray(aJVMClassName, 0, ArrayUtils.lastIndexOf(aJVMClassName, '.'));
    }
}

From source file:paulscode.android.mupen64plusae.persistent.GlobalPrefs.java

public void changeLocale(final Activity activity) {
    // Get the index of the current locale
    final int currentIndex = ArrayUtils.indexOf(mLocaleCodes, mLocaleCode);

    // Populate and show the language menu
    final Builder builder = new Builder(activity);
    builder.setTitle(R.string.menuItem_localeOverride);
    builder.setSingleChoiceItems(mLocaleNames, currentIndex, new DialogInterface.OnClickListener() {
        @Override/*from  w  w w  . ja v  a  2  s.c o m*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (which >= 0 && which != currentIndex) {
                mPreferences.edit().putString(KEY_LOCALE_OVERRIDE, mLocaleCodes[which]).apply();
                ActivityHelper.restartActivity(activity);
            }
        }
    });
    builder.create().show();
}

From source file:paulscode.android.mupen64plusae.persistent.UserPrefs.java

public void changeLocale(final Activity activity) {
    // Get the index of the current locale
    final int currentIndex = ArrayUtils.indexOf(mLocaleCodes, mLocaleCode);

    // Populate and show the language menu
    Builder builder = new Builder(activity);
    builder.setTitle(R.string.menuItem_localeOverride);
    builder.setSingleChoiceItems(mLocaleNames, currentIndex, new DialogInterface.OnClickListener() {
        @Override/*ww  w . j  a v a 2s  . co m*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (which >= 0 && which != currentIndex) {
                mPreferences.edit().putString(KEY_LOCALE_OVERRIDE, mLocaleCodes[which]).commit();
                activity.finish();
                activity.startActivity(activity.getIntent());
            }
        }
    });
    builder.create().show();
}

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

@Override
public void elementRemoved(ListEvent<E> e) {
    int index = ArrayUtils.indexOf(transform, e.getIndex());
    transform = (Integer[]) ArrayUtils.removeElement(transform, transform.length - 1);
    sanityCheck();/*from   w w  w.  j  a v  a  2 s .  c o  m*/
    Arrays.sort(transform, indexComparator);
    fireElementRemoved(this, e.getElement(), index);
}

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

public void elementRemoved(ListEvent<E> e) {
    int index = ArrayUtils.indexOf(transform, e.getIndex());
    transform = (Integer[]) ArrayUtils.removeElement(transform, transform.length - 1);
    Arrays.sort(transform, indexComparator);
    fireIntervalRemoved(this, index, index);
}