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.wb.tests.designer.core.model.parser.AbstractJavaInfoRelatedTest.java
/** * Removes liens which start with "// filler". *//* ww w . ja v a 2 s . com*/ protected static String[] removeFillerLines(String... lines) { while (lines.length != 0 && lines[0].startsWith("// filler")) { lines = (String[]) ArrayUtils.remove(lines, 0); } return lines; }
From source file:org.eclipse.wb.tests.designer.core.TestProject.java
/** * Removes source folder./*from w w w . ja v a2 s .c o m*/ */ public void removeSourceFolder(String pathLocation) throws JavaModelException { IClasspathEntry[] oldEntries = m_javaProject.getRawClasspath(); for (int i = 0; i < oldEntries.length; i++) { IClasspathEntry entry = oldEntries[i]; if (entry.getPath().toPortableString().equals(pathLocation)) { IClasspathEntry[] newEntries = (IClasspathEntry[]) ArrayUtils.remove(oldEntries, i); m_javaProject.setRawClasspath(newEntries, null); } } }
From source file:org.eclipse.wb.tests.designer.core.util.jdt.core.CodeUtilsTest.java
/** * Single project without "src" folder, so project itself is source container. *///from w ww . j av a 2s. c o m @DisposeProjectAfter public void test_getSourceContainers_2() throws Exception { // remove "src" { IClasspathEntry[] rawClasspath = m_javaProject.getRawClasspath(); rawClasspath = (IClasspathEntry[]) ArrayUtils.remove(rawClasspath, rawClasspath.length - 1); m_javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor()); } // add "" m_testProject.addSourceFolder("/TestProject"); // assert that source container is project itself List<IContainer> sourceContainers = CodeUtils.getSourceContainers(m_javaProject, true); assertThat(sourceContainers).hasSize(1); assertEquals("/TestProject", sourceContainers.get(0).getFullPath().toString()); }
From source file:org.eclipse.wb.tests.designer.core.util.jdt.core.CodeUtilsTest.java
/** * {@link IJavaProject} as element, but no separate source folders, so {@link IJavaProject} itself * is source folder.// w w w.j av a 2 s. co m */ public void test_getPackageFragmentRoot_3() throws Exception { try { IJavaProject javaProject = m_testProject.getJavaProject(); // remove "src" { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); rawClasspath = (IClasspathEntry[]) ArrayUtils.remove(rawClasspath, rawClasspath.length - 1); javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor()); } // add "" { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); rawClasspath = (IClasspathEntry[]) ArrayUtils.add(rawClasspath, JavaCore.newSourceEntry(new Path("/TestProject"))); javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor()); } // IJavaProject as element { IJavaElement element = javaProject; IPackageFragmentRoot packageFragmentRoot = CodeUtils.getPackageFragmentRoot(element); assertPackageFragmentRootPath("/TestProject", packageFragmentRoot); } } finally { do_projectDispose(); do_projectCreate(); } }
From source file:org.ejbca.core.protocol.ocsp.ProtocolOcspTestBase.java
protected void test12CorruptRequests() throws Exception { // NOPMD, this is not a test class itself log.trace(">test12CorruptRequests()"); loadUserCert(this.caid); // An OCSP request, ocspTestCert is already created in earlier tests OCSPReqBuilder gen = new OCSPReqBuilder(); gen.addRequest(new JcaCertificateID(SHA1DigestCalculator.buildSha1Instance(), cacert, ocspTestCert.getSerialNumber())); Extension[] extensions = new Extension[1]; extensions[0] = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false, new DEROctetString("123456789".getBytes())); gen.setRequestExtensions(new Extensions(extensions)); OCSPReq req = gen.build();/*w ww . ja va 2 s.c om*/ // Request 1 // // Send the request and receive a singleResponse byte[] orgbytes = req.getEncoded(); // Save original bytes, so we can // make different strange values byte[] bytes = req.getEncoded(); // Switch the first byte, now it's a really corrupted request bytes[0] = 0x44; SingleResp[] singleResps = helper.sendOCSPPost(bytes, "123456789", OCSPRespBuilder.MALFORMED_REQUEST, 200); // error // code // 1 // means // malformed // request assertNull("SingleResps should be null.", singleResps); // Request 2 // // Remove the last byte, should still be quite corrupted // bytes = Arrays.copyOf(orgbytes, orgbytes.length-1); only works in // Java 6 bytes = ArrayUtils.remove(orgbytes, orgbytes.length - 1); singleResps = helper.sendOCSPPost(bytes, "123456789", OCSPRespBuilder.MALFORMED_REQUEST, 200); // error // code // 1 // means // malformed // request assertNull("SingleResps should be null.", singleResps); // Request 3 // // more than 1 million bytes // bytes = Arrays.copyOf(orgbytes, 1000010); only works in Java 6 bytes = ArrayUtils.addAll(orgbytes, new byte[1000010]); singleResps = helper.sendOCSPPost(bytes, "123456789", OCSPRespBuilder.MALFORMED_REQUEST, 200); // // // error // code // 1 // means // malformed // request assertNull("SingleResps should be null.", singleResps); // Request 4 // // // A completely empty request with no question in it gen = new OCSPReqBuilder(); req = gen.build(); bytes = req.getEncoded(); singleResps = helper.sendOCSPPost(bytes, "123456789", 1, 200); // assertNull("SingleResps should be null.", singleResps); log.trace("<test12CorruptRequests()"); }
From source file:org.exoplatform.social.webui.Utils.java
private static Cookie[] removeCookie(String key) { PortalRequestContext request = Util.getPortalRequestContext(); Cookie[] cookies = request.getRequest().getCookies(); if (cookies != null) { int found = -1; for (int i = 0; i < cookies.length; i++) { if (key.equals(cookies[i].getName())) { found = i;//from w ww. ja v a 2s. co m break; } } if (found > -1) { ArrayUtils.remove(cookies, found); } } return cookies; }
From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java
/** * Checks whether -t test mode switch has been passed. Will return an args * array with -t removed if found.//from w w w . j av a 2s . co m */ static String[] checkTestModeArgument(String[] args) { if (ArrayUtils.contains(args, "-t")) { setTestMode(true); return (String[]) ArrayUtils.remove(args, ArrayUtils.indexOf(args, "-t")); } return args; }
From source file:org.hippoecm.frontend.plugins.console.editor.PropertyValueEditor.java
@Override protected void populateItem(Item item) { try {/*from w w w. j a v a 2s . c om*/ final JcrPropertyValueModel valueModel = (JcrPropertyValueModel) item.getModel(); Component valueEditor = createValueEditor(valueModel); item.add(valueEditor); final AjaxLink removeLink = new AjaxLink("remove") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { try { Property prop = propertyModel.getProperty(); Value[] values = prop.getValues(); values = (Value[]) ArrayUtils.remove(values, valueModel.getIndex()); prop.getParent().setProperty(prop.getName(), values, prop.getType()); } catch (RepositoryException e) { log.error(e.getMessage()); } NodeEditor editor = findParent(NodeEditor.class); if (editor != null) { target.add(editor); } } }; removeLink.add(TitleAttribute.set(getString("property.value.remove"))); PropertyDefinition definition = propertyModel.getProperty().getDefinition(); removeLink.setVisible(definition.isMultiple() && !definition.isProtected()); item.add(removeLink); if (focusOnLastItem && item.getIndex() == getItemCount() - 1) { focusOnLastItem = false; AjaxRequestTarget ajax = RequestCycle.get().find(AjaxRequestTarget.class); if (ajax != null && valueEditor instanceof AjaxUpdatingWidget) { ajax.focusComponent(((AjaxUpdatingWidget) valueEditor).getFocusComponent()); } } } catch (RepositoryException e) { log.error(e.getMessage()); item.add(new Label("value", e.getClass().getName() + ":" + e.getMessage())); item.add(new Label("remove", "")); } }
From source file:org.isatools.tablib.parser.RowSectionParser.java
/** * Parses a CSV header line and creates the corresponding resulting schema in the section * (i.e.: a set of fields with positions) *//* w w w . j a v a2 s . co m*/ protected List<Field> parseHeaders(List<String[]> csvLines, int fromRow, int toRow, int fromCol, int toCol) { Section section = sectionInstance.getSection(); String sectionId = section.getId(); String headers[] = csvLines.get(0); log.trace("Headers for section " + sectionId + ": " + Arrays.toString(headers)); int nlines = csvLines.size(); for (int j = 0; j < headers.length; j++) { String header = StringUtils.trimToNull(headers[j]); if (header == null) { // Empty header, let's remove all! // log.warn(i18n.msg("empty_column", j)); for (int i = 0; i < nlines; i++) { String[] line = csvLines.get(i); if (j == line.length) // This happens sometime: the header has one extra-tab and the lines are OK // we need to recraft the header only in that case { continue; } csvLines.set(i, (String[]) ArrayUtils.remove(line, j)); } headers = csvLines.get(0); j--; // Restart from this point, which is now the next column continue; } log.trace("Working on header " + j + ":" + header); Field field = section.getFieldByHeader(header, false); if (field == null) { throw new TabValidationException(i18n.msg("unexpected_field_in_section_error", header, sectionId)); } // Let's add a new real field on the basis of the header. The new field created gets its id from the // original one in the schema, so it will have the "canonical" form, independently on what we found // on the input (e.g.: upper case). // field = field.parseHeader(header, j, false); sectionInstance.addField(field); } return sectionInstance.getFields(); }
From source file:org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.java
/** * Remove the first referenced library those absolute path contains the given name. * //from w ww . j ava2 s .co m * @param javaProject * @param name * @param progressMonitor * @throws CoreException * @throws InterruptedException * @throws OperationCanceledException */ public static List<IPackageFragmentRoot> removeClasspathEntry(IJavaProject javaProject, String name, IProgressMonitor progressMonitor) throws CoreException, OperationCanceledException, InterruptedException { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); int index = 0; List<IPackageFragmentRoot> fragments = null; for (IClasspathEntry entry : classpathEntries) { if (entry.getPath().toFile().getAbsolutePath().contains(name)) { fragments = new ArrayList<IPackageFragmentRoot>(); for (IPackageFragmentRoot fragment : javaProject.getAllPackageFragmentRoots()) { if (fragment.getRawClasspathEntry().equals(entry)) { fragments.add(fragment); } } break; } index++; } if (index < classpathEntries.length) { classpathEntries = (IClasspathEntry[]) ArrayUtils.remove(classpathEntries, index); javaProject.setRawClasspath(classpathEntries, progressMonitor); } WorkbenchTasks.buildProject(javaProject.getProject(), progressMonitor); return fragments; }