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.apache.streams.pig.StreamsProcessDatumExec.java
public StreamsProcessDatumExec(String... execArgs) throws ClassNotFoundException { Preconditions.checkNotNull(execArgs); Preconditions.checkArgument(execArgs.length > 0); String classFullName = execArgs[0]; Preconditions.checkNotNull(classFullName); String[] prepareArgs = (String[]) ArrayUtils.remove(execArgs, 0); streamsProcessor = StreamsComponentFactory.getProcessorInstance(Class.forName(classFullName)); if (execArgs.length == 1) { LOGGER.debug("prepare (null)"); streamsProcessor.prepare(null);/*from w w w . j a va 2 s. co m*/ } else if (execArgs.length > 1) { LOGGER.debug("prepare " + Arrays.toString(prepareArgs)); streamsProcessor.prepare(prepareArgs); } }
From source file:org.apache.streams.pig.StreamsProcessDocumentExec.java
public StreamsProcessDocumentExec(String... execArgs) throws ClassNotFoundException { Preconditions.checkNotNull(execArgs); Preconditions.checkArgument(execArgs.length > 0); String classFullName = execArgs[0]; Preconditions.checkNotNull(classFullName); String[] prepareArgs = (String[]) ArrayUtils.remove(execArgs, 0); streamsProcessor = StreamsComponentFactory.getProcessorInstance(Class.forName(classFullName)); if (execArgs.length == 1) { LOGGER.debug("prepare (null)"); streamsProcessor.prepare(null);/*from w ww . j av a 2 s. c o m*/ } else if (execArgs.length > 1) { LOGGER.debug("prepare " + Arrays.toString(prepareArgs)); streamsProcessor.prepare(prepareArgs); } }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.JcrValueUtils.java
public static void replaceValue(Node node, ItemQName property, Value newValue, Value oldValue, Boolean isPropertyMultivalued) throws RepositoryException { //Node does not have property if (!node.hasProperty(property.getJcrName())) { //New Value is null. Do nothing if (newValue == null) return; //Determine if property is multiple, if this info is not provided if (isPropertyMultivalued == null) { isPropertyMultivalued = propertyIsMultiValued(node, property); }/*w ww . j a v a 2 s . c om*/ if (isPropertyMultivalued) node.setProperty(property.getJcrName(), new Value[] { newValue }); else node.setProperty(property.getJcrName(), newValue); } else { //Node has property Property jcrProperty = node.getProperty(property.getJcrName()); if (isPropertyMultivalued == null) //Determine by property isPropertyMultivalued = jcrProperty.getDefinition().isMultiple(); if (!isPropertyMultivalued) { if (oldValue == null || (oldValue != null && oldValue.equals(jcrProperty.getValue()))) { //Set newValue only if no old value is provided OR //oldValue is provided and it really exists there jcrProperty.setValue(newValue); } } else { Value[] values = jcrProperty.getValues(); //Remove oldValue if (oldValue != null) { int index = ArrayUtils.indexOf(values, oldValue); if (index == ArrayUtils.INDEX_NOT_FOUND) throw new ItemNotFoundException( "Value " + oldValue.getString() + " in property " + jcrProperty.getPath()); values = (Value[]) ArrayUtils.remove(values, index); } //Add new value if (newValue != null && !ArrayUtils.contains(values, newValue)) values = (Value[]) ArrayUtils.add(values, newValue); //If at the end values array is empty //remove property if (ArrayUtils.isEmpty(values)) { node.setProperty(property.getJcrName(), JcrValueUtils.getJcrNullForMultiValue()); } else { node.setProperty(property.getJcrName(), values); } } } }
From source file:org.carewebframework.vista.ui.notification.AbstractNotification.java
/** * Sets the value for a parameter in extra info. * // w w w . jav a 2s.c o m * @param param Parameter name. * @param value Parameter value (null to remove). * @return Index of parameter in extra info. */ protected int setParam(String param, Object value) { int i = findParam(param); if (value == null && i < 0) { return i; } if (i < 0) { i = extraInfo.length; extraInfo = Arrays.copyOf(extraInfo, i + 1); } if (value == null) { extraInfo = (String[]) ArrayUtils.remove(extraInfo, i); } else { extraInfo[i] = param + "=" + value; } return i; }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
public static void removeGroovyNature(final IProject project) throws CoreException { GroovyCore.trace("GroovyRuntime.removeGroovyNature()"); final IProjectDescription description = project.getDescription(); final String[] ids = description.getNatureIds(); for (int i = 0; i < ids.length; ++i) { if (ids[i].equals(GroovyNature.GROOVY_NATURE)) { final String[] newIds = (String[]) ArrayUtils.remove(ids, i); description.setNatureIds(newIds); project.setDescription(description, null); return; }/*from ww w .j av a 2 s. co m*/ } }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
public static void removeLibraryFromClasspath(final IJavaProject javaProject, final IPath libraryPath) throws JavaModelException { final IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); for (int i = 0; i < oldEntries.length; i++) { final IClasspathEntry entry = oldEntries[i]; if (entry.getPath().equals(libraryPath)) { final IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.remove(oldEntries, i); javaProject.setRawClasspath(newEntries, null); return; }//from w w w .j av a 2 s . c om } }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
public static void removeClasspathContainer(IPath containerPath, IJavaProject javaProject) { try {/*from w w w . j a v a 2 s .co m*/ if (!hasGroovyClasspathContainer(javaProject)) { return; } IClasspathEntry[] entries = javaProject.getRawClasspath(); int removeIndex = -1; for (int i = 0; i < entries.length; i++) { if (entries[i].getPath().equals(containerPath)) { removeIndex = i; break; } } IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.remove(entries, removeIndex); javaProject.setRawClasspath(newEntries, null); } catch (final CoreException ce) { GroovyCore.logException("Failed to add groovy classpath container:" + ce.getMessage(), ce); throw new RuntimeException(ce); } }
From source file:org.cytoscape.biopax.internal.BioPaxReaderTask.java
private void createBiopaxSifAttributes(Model model, CyNetwork cyNetwork, File sifNodes, TaskMonitor taskMonitor) throws IOException { taskMonitor.setStatusMessage("Updating SIF network " + "node/edge attributes from the BioPAX model..."); //parse the extended sif nodes file into map: "URI" -> other attributes (as a single TSV string) Map<String, String> uriToDescriptionMap = new HashMap<String, String>(); BufferedReader reader = new BufferedReader(new FileReader(sifNodes)); while (reader.ready()) { String line = reader.readLine(); if (line.trim().isEmpty()) continue; //skip blank lines if any accidentally present there //columns are: URI\tTYPE\tNAME\tUnifXrefs(semicolon-separated) String[] cols = line.split("\t"); assert cols.length == 4 : "BUG: unexpected number of columns (" + cols.length + "; must be 4) in the SIF file: " + sifNodes.getAbsolutePath(); // put into the map uriToDescriptionMap.put(cols[0], StringUtils.join(ArrayUtils.remove(cols, 0), '\t')); }/*w w w . j ava 2 s . c o m*/ reader.close(); // Set the Quick Find Default Index AttributeUtil.set(cyNetwork, cyNetwork, "quickfind.default_index", CyNetwork.NAME, String.class); if (cancelled) return; // Set node/edge attributes from the Biopax Model for (CyNode node : cyNetwork.getNodeList()) { String uri = cyNetwork.getRow(node).get(CyNetwork.NAME, String.class); BioPAXElement e = model.getByID(uri);// can be null (for generic/group nodes) if (e instanceof EntityReference || e instanceof Entity) { //note: in fact, SIF formatted data contains only ERs, PEs (no sub-classes), and Complexes / Generics. BioPaxMapper.createAttributesFromProperties(e, model, node, cyNetwork); } else if (e != null) { log.warn("SIF network has an unexpected node: " + uri + " of type " + e.getModelInterface()); BioPaxMapper.createAttributesFromProperties(e, model, node, cyNetwork); } else { //e == null; the URI/ID was auto-generated by the sif-converter and not present in the model AttributeUtil.set(cyNetwork, node, BioPaxMapper.BIOPAX_URI, uri, String.class); //set other attributes from the tmp_biopax2sif_nodes*.sif file String sifNodeAttrs = uriToDescriptionMap.get(uri); assert (sifNodeAttrs != null && !sifNodeAttrs.isEmpty()) : "Bug: no SIF attributes found for " + uri; String[] cols = sifNodeAttrs.split("\t"); AttributeUtil.set(cyNetwork, node, BioPaxMapper.BIOPAX_ENTITY_TYPE, cols[0], String.class); AttributeUtil.set(cyNetwork, node, CyRootNetwork.SHARED_NAME, cols[1], String.class); AttributeUtil.set(cyNetwork, node, CyNetwork.NAME, cols[1], String.class); if (cols.length > 2) { //no xrefs is possible for some generic nodes List<String> xrefs = Arrays.asList(cols[2].split(";")); AttributeUtil.set(cyNetwork, node, BioPaxMapper.BIOPAX_RELATIONSHIP, xrefs, String.class); AttributeUtil.set(cyNetwork, node, CyNetwork.HIDDEN_ATTRS, BioPaxMapper.BIOPAX_RELATIONSHIP_REFERENCES, xrefs, String.class); } } } }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.parser.DisplayOptionsParser.java
/** * Returns all possible options from the given datapoint. *///from w w w .j a v a 2 s . co m private String[] getAvailableOptions(HmChannel channel, String datapointName) { HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, datapointName); HmDatapoint dp = channel.getDatapoint(dpInfo); if (dp != null) { String[] options = (String[]) ArrayUtils.remove(dp.getOptions(), 0); for (String onOffString : onOff) { int onIdx = ArrayUtils.indexOf(options, onOffString); if (onIdx != -1) { options[onIdx] = datapointName + "_" + onOffString; } } return options; } return new String[0]; }
From source file:org.eclipse.smarthome.core.scriptengine.internal.extensions.ScriptEngineConsoleCommandExtension.java
@Override public void execute(String[] args, Console console) { // remove first argument args = (String[]) ArrayUtils.remove(args, 0); if (scriptEngine != null) { String scriptString = Joiner.on(" ").join(args); Script script;/*from ww w . j a va 2 s . co m*/ try { script = scriptEngine.newScriptFromString(scriptString); Object result = script.execute(); if (result != null) { console.println(result.toString()); } else { console.println("OK"); } } catch (ScriptParsingException e) { console.println(e.getMessage()); } catch (ScriptExecutionException e) { console.println(e.getMessage()); } } else { console.println("Script engine is not available."); } }