List of usage examples for org.apache.commons.lang ArrayUtils remove
private static Object remove(Object array, int index)
Removes the element at the specified position from the specified array.
From source file:org.eclipse.smarthome.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 a2 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, Set<ConsoleCommandExtension> consoleCommandExtensions) { String arg = args[0]; boolean handledByExtension = false; Iterator<ConsoleCommandExtension> extensionIterator = consoleCommandExtensions.iterator(); while (!handledByExtension && extensionIterator.hasNext()) { ConsoleCommandExtension consoleCommandExtension = extensionIterator.next(); // The clients should not break the whole processing, so we need to catch exceptions in canHandle boolean canHandle = false; try { canHandle = consoleCommandExtension.canHandle(args); } catch (Exception e) { logger.error("An error occured while invoking the command extension's can handle method.", e); } if (canHandle) { handledByExtension = true; try { consoleCommandExtension.execute(args, console); } catch (Exception e) { logger.error("An error occured while executing the console command.", e); console.println("An unexpected error occured during execution."); } } } if (!handledByExtension) { 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 { console.printUsage(getUsage(consoleCommandExtensions)); } } }
From source file:org.eclipse.smarthome.model.core.internal.folder.FolderObserver.java
@SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { // make sure to clear the caches first lastFileNames.clear();/*from ww w. j av a 2 s . co m*/ lastCheckedMap.clear(); folderFileExtMap.clear(); folderRefreshMap.clear(); Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String foldername = (String) keys.nextElement(); if (foldername.equals("service.pid")) continue; String[] values = ((String) config.get(foldername)).split(","); try { Integer refreshValue = Integer.valueOf(values[0]); String[] fileExts = (String[]) ArrayUtils.remove(values, 0); File folder = getFolder(foldername); if (folder.exists() && folder.isDirectory()) { folderFileExtMap.put(foldername, fileExts); if (refreshValue > 0) { folderRefreshMap.put(foldername, refreshValue); if (!this.isAlive()) { // seems we have the first folder to observe, so let's start the thread this.start(); } else { // make sure that we notify the sleeping thread and directly refresh the folders synchronized (FolderObserver.this) { notify(); checkFolder(foldername); } } } else { // deactivate the refresh for this folder folderRefreshMap.remove(foldername); checkFolder(foldername); } } else { logger.warn( "Directory '{}' does not exist in '{}'. Please check your configuration settings!", foldername, ConfigDispatcher.getConfigFolder()); } // now update the refresh information for the thread Integer[] refreshValues = folderRefreshMap.values().toArray(new Integer[0]); if (refreshValues.length > 0) { gcdRefresh = MathUtils.gcd(refreshValues); lcmRefresh = MathUtils.lcm(refreshValues); } refreshCount = 0; } catch (NumberFormatException e) { logger.warn("Invalid value '{}' for configuration '{}'. Integer value expected!", values[0], ModelCoreConstants.SERVICE_PID + ":" + foldername); } } } }
From source file:org.eclipse.wb.android.internal.model.layouts.table.TableLayoutSupport.java
/** * Removes single column./*from www. ja v a 2 s.c om*/ * * @param column * a column number to remove. */ private void removeColumn(int column) throws Exception { for (int row = 0; row < m_rows; ++row) { CellInfo cell = m_cells[row][column]; // remove a cell from row cells m_cells[row] = (CellInfo[]) ArrayUtils.remove(m_cells[row], column); // shrink span, as TableLayout cannot keep span thru empty column if (cell.isSpanSpace()) { cell.spannedViewCell.span--; 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 c = column; c < m_columns - 1; ++c) { CellInfo rightCell = m_cells[row][c]; if (!rightCell.isEmpty()) { if (prevEmpty) { // set explicit column TableLayoutUtils.setExplicitColumn(rightCell.view, c); } prevEmpty = false; } else { prevEmpty = true; } } } } m_columns--; }
From source file:org.eclipse.wb.android.internal.model.layouts.table.TableLayoutSupport.java
/** * Removes single row./*from www.j a v a2 s .c o m*/ * * @param row * a row number to remove. */ private void removeRow(int row) throws Exception { m_cells = (CellInfo[][]) ArrayUtils.remove(m_cells, row); m_layout.deleteRow0(row); m_rows--; }
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 w ww.j a va 2s. c o m 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.core.utils.ast.binding.DesignerMethodBinding.java
/** * Removes parameter type with given index. *///ww w . ja v a2s .com public void removeParameterType(int index) { m_parameterTypes = (ITypeBinding[]) ArrayUtils.remove(m_parameterTypes, index); if (m_methodDeclaration != this) { m_methodDeclaration.removeParameterType(index); } }
From source file:org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo.java
@Override protected Interval[] checkColumnIntervals(Interval[] columnIntervals) { GridBagLayout layout = (GridBagLayout) getObject(); final int lastIndex = columnIntervals.length - 1; if (columnIntervals.length > 0 && layout.columnWeights != null && layout.columnWeights.length >= columnIntervals.length && layout.columnWeights[lastIndex] > 0.0 && layout.columnWeights[lastIndex] < 0.001 && getColumnOperations().isEmpty(lastIndex)) { return (Interval[]) ArrayUtils.remove(columnIntervals, lastIndex); }/* w ww . j ava 2 s . c o m*/ return columnIntervals; }
From source file:org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo.java
@Override protected Interval[] checkRowIntervals(Interval[] rowIntervals) { GridBagLayout layout = (GridBagLayout) getObject(); int lastIndex = rowIntervals.length - 1; if (rowIntervals.length > 0 && layout.rowWeights != null && layout.rowWeights.length >= rowIntervals.length && layout.rowWeights[lastIndex] > 0.0 && layout.rowWeights[lastIndex] < 0.001 && getRowOperations().isEmpty(lastIndex)) { return (Interval[]) ArrayUtils.remove(rowIntervals, lastIndex); }/* w w w . java 2 s . c o m*/ return rowIntervals; }
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 . j a v a2 s.c o m*/ 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.internal.xwt.model.widgets.SashFormInfo.java
/** * Removes weight for {@link ControlInfo} that is still in children. *//* w w w.j a v a2s . com*/ private void removeWeight(ControlInfo control) throws Exception { String weightsString = getCreationSupport().getElement().getAttribute("weights"); if (weightsString != null) { int index = getChildrenControls().indexOf(control); int[] weights = getWeights(weightsString); weights = ArrayUtils.remove(weights, index); setWeights(weights); } }