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

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

Introduction

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

Prototype

private static Object remove(Object array, int index) 

Source Link

Document

Removes the element at the specified position from the specified array.

Usage

From source file:org.openhab.io.console.ConsoleInterpreter.java

/**
 * This method simply takes a list of arguments, where the first one is treated
 * as the console command (such as "update", "send" etc.). The following entries
 * are then the arguments for this command.
 * If the command is unknown, the complete usage is printed to the console.
 * /*from  w ww  .  j  a v  a 2 s . c  o  m*/
 * @param args array which contains the console command and all its arguments
 * @param console the console for printing messages for the user
 */
static public void handleRequest(String[] args, Console console) {
    String arg = args[0];
    args = (String[]) ArrayUtils.remove(args, 0);
    if (arg.equals("items")) {
        ConsoleInterpreter.handleItems(args, console);
    } else if (arg.equals("send")) {
        ConsoleInterpreter.handleSend(args, console);
    } else if (arg.equals("update")) {
        ConsoleInterpreter.handleUpdate(args, console);
    } else if (arg.equals("status")) {
        ConsoleInterpreter.handleStatus(args, console);
    } else if (arg.equals("say")) {
        ConsoleInterpreter.handleSay(args, console);
    } else if (arg.equals(">")) {
        ConsoleInterpreter.handleScript(args, console);
    } else {
        console.printUsage(getUsage());
    }
}

From source file:org.openlegacy.rpc.support.binders.RpcPartsBinder.java

private static void filterNullObjects(String namespace, String partName,
        SimpleRpcPojoFieldAccessor fieldAccesor, Object[] objects, List<Integer> emptyObjectsIndex) {

    Collections.sort(emptyObjectsIndex, new Comparator<Integer>() {

        @Override/*from   w w  w . j  av  a2s.com*/
        public int compare(Integer o1, Integer o2) {
            return o2.compareTo(o1);
        }
    });
    for (Integer index : emptyObjectsIndex) {
        objects = ArrayUtils.remove(objects, index);
    }
    fieldAccesor.setPartFieldValue(namespace, partName, objects);
}

From source file:org.opennms.web.alarm.AlarmUtil.java

/**
 * <p>getFilter</p>/*from www  .  j a  v  a 2  s  . co  m*/
 *
 * @param filterString a {@link java.lang.String} object.
 * @return a {@link org.opennms.web.filter.Filter} object.
 */
public static Filter getFilter(String filterString, ServletContext servletContext) {
    if (filterString == null) {
        throw new IllegalArgumentException("Cannot take null parameters.");
    }

    Filter filter = null;

    String[] tempTokens = filterString.split("=");
    String type;
    String value;
    try {
        type = tempTokens[0];
        String[] values = (String[]) ArrayUtils.remove(tempTokens, 0);
        value = org.apache.commons.lang.StringUtils.join(values, "=");
    } catch (NoSuchElementException e) {
        throw new IllegalArgumentException("Could not tokenize filter string: " + filterString);
    }

    if (type.equals(SeverityFilter.TYPE)) {
        filter = new SeverityFilter(OnmsSeverity.get(WebSecurityUtils.safeParseInt(value)));
    } else if (type.equals(NodeFilter.TYPE)) {
        filter = new NodeFilter(WebSecurityUtils.safeParseInt(value), servletContext);
    } else if (type.equals(NodeNameLikeFilter.TYPE)) {
        filter = new NodeNameLikeFilter(value);
    } else if (type.equals(InterfaceFilter.TYPE)) {
        filter = new InterfaceFilter(InetAddressUtils.addr(value));
    } else if (type.equals(ServiceFilter.TYPE)) {
        filter = new ServiceFilter(WebSecurityUtils.safeParseInt(value), servletContext);
    } else if (type.equals(PartialUEIFilter.TYPE)) {
        filter = new PartialUEIFilter(value);
    } else if (type.equals(ExactUEIFilter.TYPE)) {
        filter = new ExactUEIFilter(value);
    } else if (type.equals(AcknowledgedByFilter.TYPE)) {
        filter = new AcknowledgedByFilter(value);
    } else if (type.equals(NegativeSeverityFilter.TYPE)) {
        filter = new NegativeSeverityFilter(OnmsSeverity.get(WebSecurityUtils.safeParseInt(value)));
    } else if (type.equals(NegativeNodeFilter.TYPE)) {
        filter = new NegativeNodeFilter(WebSecurityUtils.safeParseInt(value), servletContext);
    } else if (type.equals(NegativeInterfaceFilter.TYPE)) {
        filter = new NegativeInterfaceFilter(InetAddressUtils.addr(value));
    } else if (type.equals(NegativeServiceFilter.TYPE)) {
        filter = new NegativeServiceFilter(WebSecurityUtils.safeParseInt(value), servletContext);
    } else if (type.equals(NegativePartialUEIFilter.TYPE)) {
        filter = new NegativePartialUEIFilter(value);
    } else if (type.equals(NegativeExactUEIFilter.TYPE)) {
        filter = new NegativeExactUEIFilter(value);
    } else if (type.equals(NegativeAcknowledgedByFilter.TYPE)) {
        filter = new NegativeAcknowledgedByFilter(value);
    } else if (type.equals(IPAddrLikeFilter.TYPE)) {
        filter = new IPAddrLikeFilter(value);
    } else if (type.equals(LogMessageSubstringFilter.TYPE)) {
        filter = new LogMessageSubstringFilter(value);
    } else if (type.equals(LogMessageMatchesAnyFilter.TYPE)) {
        filter = new LogMessageMatchesAnyFilter(value);
    } else if (type.equals(BeforeLastEventTimeFilter.TYPE)) {
        filter = new BeforeLastEventTimeFilter(WebSecurityUtils.safeParseLong(value));
    } else if (type.equals(BeforeFirstEventTimeFilter.TYPE)) {
        filter = new BeforeFirstEventTimeFilter(WebSecurityUtils.safeParseLong(value));
    } else if (type.equals(AfterLastEventTimeFilter.TYPE)) {
        filter = new AfterLastEventTimeFilter(WebSecurityUtils.safeParseLong(value));
    } else if (type.equals(AfterFirstEventTimeFilter.TYPE)) {
        filter = new AfterFirstEventTimeFilter(WebSecurityUtils.safeParseLong(value));
    } else if (type.equals(EventParmLikeFilter.TYPE)) {
        filter = new EventParmLikeFilter(value);
    } else if (type.equals(NegativeEventParmLikeFilter.TYPE)) {
        filter = new NegativeEventParmLikeFilter(value);
    }

    return filter;
}

From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorIT.java

private void removeColumnFromModel(ModelInfo info) {
    ColumnInfo[] columns = info.getColumns();
    ColumnInfo[] newColumns = (ColumnInfo[]) ArrayUtils.remove(columns, columns.length - 1);
    info.setColumns(newColumns);/*www .  j a va2s  .c o  m*/
}

From source file:org.quackbot.hooks.core.CoreQuackbotListener.java

protected String executeOnCommandLong(CommandEvent commandEvent) throws Exception {
    try {//from www  .  j a  v  a 2s .com
        Command command = commandEvent.getCommandClass();
        Class clazz = command.getClass();
        for (Method curMethod : clazz.getMethods())
            if (curMethod.getName().equalsIgnoreCase("onCommand")
                    && curMethod.getParameterTypes().length != 1) {
                //Get parameters leaving off the first one
                Class[] parameters = (Class[]) ArrayUtils.remove(curMethod.getParameterTypes(), 0);

                Object[] args = new Object[0];
                String[] userArgs = commandEvent.getArgs();
                log.debug("UserArgs: " + StringUtils.join(userArgs, ", "));
                //Try and fill argument list, handling arrays
                for (int i = 0; i < userArgs.length; i++) {
                    log.trace("Current parameter: " + i);
                    if (i < parameters.length && parameters[i].isArray()) {
                        log.trace("Parameter " + i + " is an array");
                        //Look ahead to see how big of an array we need
                        int arrayLength = parameters.length - (i - 1);
                        for (int s = i; s < parameters.length; s++)
                            if (!parameters[s].isArray())
                                arrayLength--;

                        //Add our array of specified length
                        log.trace("Parameter " + i + " is an array. Assigning it the next " + arrayLength
                                + " args");
                        Object[] curArray = ArrayUtils.subarray(userArgs, i, i + arrayLength);
                        args = ArrayUtils.add(args, curArray);
                        log.trace("Parameter " + i + " set to " + StringUtils.join(curArray, ", "));

                        //Move the index forward to account for the args folded into the array
                        i += arrayLength - 1;
                    } else {
                        log.trace("User arg " + i + " isn't an array, assigning " + userArgs[i]);
                        args = ArrayUtils.add(args, userArgs[i]);
                    }
                }

                //Pad the args with null values
                args = Arrays.copyOf(args, parameters.length);

                //Prefix with command event
                args = ArrayUtils.addAll(new Object[] { commandEvent }, args);
                log.trace("Args minus CommandEvent: " + StringUtils.join(ArrayUtils.remove(args, 0), ", "));

                //Execute method
                return (String) curMethod.invoke(command, args);
            }
    } catch (InvocationTargetException e) {
        //Unrwap if nessesary
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof Exception)
            throw (Exception) e.getCause();
        throw e;
    }
    return null;
}

From source file:org.quackbot.hooks.core.CoreQuackbotListener.java

public String[] getArgs(String message) {
    message = message.trim();/*from ww  w.j a  v  a 2 s.  c  o  m*/
    String[] args;
    if (message.contains(" "))
        args = (String[]) ArrayUtils.remove(message.split(" "), 0);
    else
        args = new String[0];
    return args;
}

From source file:org.talend.core.hadoop.version.custom.HadoopCustomVersionDefineDialog.java

public ECustomVersionType[] getTypes() {
    ECustomVersionType[] types = getDisplayTypes();
    if (types == null) {
        return null;
    }//  www  .j a  v  a 2 s  .  co  m

    if (ArrayUtils.contains(types, ECustomVersionType.ALL)) {
        types = ECustomVersionType.values();
        types = (ECustomVersionType[]) ArrayUtils.remove(types,
                ArrayUtils.indexOf(types, ECustomVersionType.ALL));
    }
    return types;
}

From source file:org.talend.core.runtime.conf.DefaultConfsManager.java

private static Object getValue(Object object, String... args) {
    if (args.length > 0) {
        String arg = args[0];//from   w  w  w  .jav a  2  s.c om
        Object obj = ((JSONObject) object).get(arg);
        String[] newArgs = (String[]) ArrayUtils.remove(args, 0);
        return getValue(obj, newArgs);
    } else {
        return object;
    }
}

From source file:org.talend.designer.runprocess.java.JavaProcessorUtilities.java

private static void sortClasspath(Set<String> jobModuleList, IProcess process)
        throws CoreException, BusinessException {
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IClasspathEntry jreClasspathEntry = JavaCore
            .newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); //$NON-NLS-1$
    IClasspathEntry classpathEntry = JavaCore
            .newSourceEntry(javaProject.getPath().append(JavaUtils.JAVA_SRC_DIRECTORY));

    boolean changesDone = false;
    if (!ArrayUtils.contains(entries, jreClasspathEntry)) {
        entries = (IClasspathEntry[]) ArrayUtils.add(entries, jreClasspathEntry);
        changesDone = true;//ww w  .  j av  a2s  . c o  m
    }
    if (!ArrayUtils.contains(entries, classpathEntry)) {
        IClasspathEntry source = null;
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                source = entry;
                break;
            }
        }
        if (source != null) {
            entries = (IClasspathEntry[]) ArrayUtils.remove(entries, ArrayUtils.indexOf(entries, source));
        }
        entries = (IClasspathEntry[]) ArrayUtils.add(entries, classpathEntry);
        changesDone = true;
    }

    // Added by Marvin Wang on Nov. 8, 2012. Maybe some modules are in the list with a directory, so cut the
    // directory only file name remaining.
    Set<String> listModulesReallyNeeded = ModuleNameExtractor.extractFileName(jobModuleList);
    Set<String> listModulesNeededByProcess = new HashSet<String>();
    if (listModulesReallyNeeded != null && listModulesReallyNeeded.size() > 0) {
        for (String jobModule : listModulesReallyNeeded) {
            listModulesNeededByProcess.add(jobModule);
        }
    }

    Set<String> optionalJarsOnlyForRoutines = new HashSet<String>();

    if (listModulesReallyNeeded == null) {
        listModulesReallyNeeded = new HashSet<String>();
    }

    // only for wizards or additional jars only to make the java project compile without any error.
    for (ModuleNeeded moduleNeeded : ModulesNeededProvider
            .getModulesNeededForRoutines(ERepositoryObjectType.ROUTINES)) {
        optionalJarsOnlyForRoutines.add(moduleNeeded.getModuleName());
    }

    if (ERepositoryObjectType.getType("BEANS") != null) {
        for (ModuleNeeded moduleNeeded : ModulesNeededProvider
                .getModulesNeededForRoutines(ERepositoryObjectType.getType("BEANS"))) {
            optionalJarsOnlyForRoutines.add(moduleNeeded.getModuleName());
        }
    }

    for (ModuleNeeded moduleNeeded : ModulesNeededProvider
            .getModulesNeededForRoutines(ERepositoryObjectType.PIG_UDF)) {
        optionalJarsOnlyForRoutines.add(moduleNeeded.getModuleName());
    }
    // list contains all routines linked to job as well as routines not used in the job
    // rebuild the list to have only the libs linked to routines "not used".
    optionalJarsOnlyForRoutines.removeAll(listModulesReallyNeeded);

    // at this point, the Set for optional jars really only contains optional jars for routines
    // only to be able to compile java project without error.
    for (String jar : optionalJarsOnlyForRoutines) {
        listModulesReallyNeeded.add(jar);
    }

    addLog4jToJarList(listModulesReallyNeeded);

    File libDir = getJavaProjectLibFolder();
    if ((libDir != null) && (libDir.isDirectory())) {
        Set<String> jarsNeedRetrieve = new HashSet<String>(listModulesReallyNeeded);
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            jarsNeedRetrieve.remove(externalLib.getName());
        }
        List<IClasspathEntry> entriesToRemove = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                boolean found = false;
                for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
                    if (entry.getPath().toPortableString().endsWith(externalLib.getName())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    // jar not anymore in the lib path, need to update the classpath
                    entriesToRemove.add(entry);
                }
            }
        }
        for (IClasspathEntry entry : entriesToRemove) {
            entries = (IClasspathEntry[]) ArrayUtils.remove(entries, ArrayUtils.indexOf(entries, entry));
            changesDone = true;
        }

        if (!jarsNeedRetrieve.isEmpty()) {
            // get original context value
            Set<String> originalConexts = new HashSet<String>();
            Iterator<String> iterator = jarsNeedRetrieve.iterator();
            while (iterator.hasNext()) {
                String jarNeedRetrieve = iterator.next();
                if (ContextParameterUtils.isContainContextParam(jarNeedRetrieve)
                        && process instanceof IProcess2) {
                    iterator.remove(); // remove the context one.
                    IContext lastRunContext = ((IProcess2) process).getLastRunContext();
                    if (lastRunContext != null) {
                        String contextValue = ContextParameterUtils.parseScriptContextCode(jarNeedRetrieve,
                                lastRunContext);
                        if (contextValue != null) {
                            originalConexts.add(new File(contextValue).getName());
                        }
                    } else {
                        IContextManager contextManager = process.getContextManager();
                        if (contextManager != null) {
                            String contextValue = ContextParameterUtils.parseScriptContextCode(jarNeedRetrieve,
                                    contextManager.getDefaultContext());
                            if (contextValue != null) {
                                originalConexts.add(new File(contextValue).getName());
                            }
                        }
                    }
                }
            }
            jarsNeedRetrieve.addAll(originalConexts);
            ILibraryManagerService repositoryBundleService = CorePlugin.getDefault()
                    .getRepositoryBundleService();
            repositoryBundleService.retrieve(jarsNeedRetrieve, libDir.getAbsolutePath());
            if (process instanceof IProcess2) {
                ((IProcess2) process).checkProcess();
            }
        }
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            if (externalLib.isFile() && listModulesReallyNeeded.contains(externalLib.getName())) {
                IClasspathEntry newEntry = JavaCore.newLibraryEntry(new Path(externalLib.getAbsolutePath()),
                        null, null);
                if (!ArrayUtils.contains(entries, newEntry)) {
                    entries = (IClasspathEntry[]) ArrayUtils.add(entries, newEntry);
                    changesDone = true;
                }
            }
        }
    }

    String missingJars = null;
    // String missingJarsForRoutinesOnly = null;
    Set<String> missingJarsForRoutinesOnly = new HashSet<String>();
    Set<String> missingJarsForProcessOnly = new HashSet<String>();
    // sort
    int exchange = 2; // The first,second library is JVM and SRC.
    for (String jar : listModulesReallyNeeded) {
        int index = indexOfEntry(entries, jar);
        if (index < 0) {
            if (ContextParameterUtils.isContainContextParam(jar)) {
                continue;
            }
            if (listModulesNeededByProcess.contains(jar)) {
                missingJarsForProcessOnly.add(jar);
            } else {
                missingJarsForRoutinesOnly.add(jar);
            }
            if (missingJars == null) {
                missingJars = Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess") + jar; //$NON-NLS-1$
            } else {
                missingJars = missingJars + ", " + jar; //$NON-NLS-1$
            }
        } else {
            if (index != exchange) {
                // exchange
                IClasspathEntry entry = entries[index];
                IClasspathEntry first = entries[exchange];
                entries[index] = first;
                entries[exchange] = entry;
                changesDone = true;
            }
            exchange++;
        }
    }
    if (changesDone) {
        javaProject.setRawClasspath(entries, null);
        javaProject.setOutputLocation(javaProject.getPath().append(JavaUtils.JAVA_CLASSES_DIRECTORY), null);
    }
    if (missingJars != null) {
        handleMissingJarsForProcess(missingJarsForRoutinesOnly, missingJarsForProcessOnly, missingJars);
    }
}

From source file:org.talend.designer.runprocess.ui.views.ProcessView.java

private EComponentCategory[] getCategories() {
    EComponentCategory[] categories = EElementType.RUN_PROCESS.getCategories();
    if (processContext != null && processContext.getProcess() != null) {
        if (processContext.getProcess().getComponentsType()
                .equals(ComponentCategory.CATEGORY_4_MAPREDUCE.getName())) {
            categories = (EComponentCategory[]) ArrayUtils.remove(categories,
                    ArrayUtils.indexOf(categories, EComponentCategory.DEBUGRUN));
            categories = (EComponentCategory[]) ArrayUtils.add(categories, 1,
                    EComponentCategory.MAPREDUCE_JOB_CONFIG_FOR_HADOOP);
        }//w ww  .ja va 2s . c  o  m
        if (processContext.getProcess().getComponentsType()
                .equals(ComponentCategory.CATEGORY_4_STORM.getName())) {
            categories = (EComponentCategory[]) ArrayUtils.add(categories, 1,
                    EComponentCategory.STORM_JOB_CONFIG);
        }

        if (processContext.getProcess().getComponentsType().equals(ComponentCategory.CATEGORY_4_SPARK.getName())
                || processContext.getProcess().getComponentsType()
                        .equals(ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName())) {
            categories = (EComponentCategory[]) ArrayUtils.add(categories, 1,
                    EComponentCategory.SPARK_JOB_CONFIG);
        }
    }
    return categories;
}