List of usage examples for org.apache.commons.lang ArrayUtils subarray
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java
/** * Given the Request path, find the first Real Parent of the Request (even if the resource doesnt exist) * * @param resource//www. j a va 2 s . com * @return */ private Resource findFirstRealParentOrSelf(Resource resource) { if (resource != null && !ResourceUtil.isNonExistingResource(resource)) { return resource; } try { final Resource parent = resource.getParent(); if (parent != null) { return parent; } } catch (NullPointerException ex) { // continue } final ResourceResolver resourceResolver = resource.getResourceResolver(); final String path = resource.getPath(); final PathInfo pathInfo = new PathInfo(path); String[] parts = StringUtils.split(pathInfo.getResourcePath(), '/'); for (int i = parts.length - 1; i >= 0; i--) { String[] tmpArray = (String[]) ArrayUtils.subarray(parts, 0, i); String tmpStr = "/".concat(StringUtils.join(tmpArray, '/')); final Resource tmpResource = resourceResolver.getResource(tmpStr); if (tmpResource != null) { return tmpResource; } } return null; }
From source file:com.adobe.acs.commons.errorpagehandler.impl.ErrorPageHandlerImpl.java
/** * Given the Request path, find the first Real Parent of the Request (even if the resource doesnt exist). * * @param request the request object//from w ww . j av a2 s .com * @param errorResource the error resource * @return */ private Resource findFirstRealParentOrSelf(SlingHttpServletRequest request, Resource errorResource) { if (errorResource == null) { log.debug("Error resource is null"); return null; } log.trace("Finding first real parent for [ {} ]", errorResource.getPath()); final ResourceResolver resourceResolver = errorResource.getResourceResolver(); // Get the lowest aggregate node ancestor for the errorResource String path = StringUtils.substringBefore(errorResource.getPath(), JcrConstants.JCR_CONTENT); Resource resource = errorResource; if (!StringUtils.equals(path, errorResource.getPath())) { // Only resolve the resource if the path of the errorResource is different from the cleaned up path; else // we know the errorResource and what the path resolves to is the same // #1415 - First try to get get the resource at the direct path; this look-up is very fast (compared to rr.resolve and often what's required) resource = resourceResolver.getResource(path); if (resource == null) { // #1415 - If the resource is not available at the direct path, then try to resolve (handle sling:alias). // First map the path, as the resolve could duplicate pathing. resource = resourceResolver.resolve(request, resourceResolver.map(request, path)); } } // If the resource exists, then use it! if (!ResourceUtil.isNonExistingResource(resource)) { log.debug("Found real aggregate resource at [ {} }", resource.getPath()); return resource; } // Quick check for the Parent; Handles common case of deactivated pages final Resource parent = resource.getParent(); if (parent != null && !ResourceUtil.isNonExistingResource(resource)) { log.debug("Found real aggregate resource via getParent() at [ {} ]", parent.getPath()); return parent; } // Start checking the path until the first real ancestor is found final PathInfo pathInfo = new PathInfo(resource.getPath()); String[] parts = StringUtils.split(pathInfo.getResourcePath(), '/'); for (int i = parts.length - 1; i >= 0; i--) { String[] tmpArray = (String[]) ArrayUtils.subarray(parts, 0, i); String candidatePath = "/".concat(StringUtils.join(tmpArray, '/')); final Resource candidateResource = resourceResolver.resolve(request, candidatePath); if (candidateResource != null && !ResourceUtil.isNonExistingResource(candidateResource)) { log.debug("Found first real aggregate parent via path look-up at [ {} ]", candidateResource.getPath()); return candidateResource; } } log.debug("Could not find real parent for [ {} ]", errorResource.getPath()); return null; }
From source file:com.atlassian.jira.util.IOUtil.java
/** * Reads at most the given number of bytes from the input stream and returns them in an array. Does not * close the {@link java.io.InputStream}. * * @param is the {@link java.io.InputStream} to read bytes from. * @param numBytes the maximum number of bytes to return. * @return the first numBytes bytes (or all if there are less in the stream). * @throws IOException if the stream cannot be read. *//* ww w . ja v a 2 s . c o m*/ public static byte[] getLeadingBytes(final InputStream is, final int numBytes) throws IOException { final byte[] bytes = new byte[numBytes]; int i = 0; while (true) { final int n = is.read(bytes, i, numBytes - i); if (n == -1) { return ArrayUtils.subarray(bytes, 0, i); } else { i += n; if (i >= numBytes) { return bytes; } } } }
From source file:com.opengamma.integration.copier.portfolio.writer.MasterPortfolioWriter.java
private ManageablePortfolioNode findNode(String[] path, ManageablePortfolioNode startNode) { // Degenerate case if (path.length == 0) { return startNode; }/*from w ww.jav a 2s. c o m*/ for (ManageablePortfolioNode childNode : startNode.getChildNodes()) { if (path[0].equals(childNode.getName())) { ManageablePortfolioNode result = findNode((String[]) ArrayUtils.subarray(path, 1, path.length), childNode); if (result != null) { return result; } } } return null; }
From source file:gda.hrpd.pmac.EpicsCVScanController.java
private double[] get2Theta() { double[] x1 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try {/*from w w w . ja va 2 s .c om*/ // logger.info("gets MAC1X"); x1 = getMAC1X(); // logger.info("gets MAC1X DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC1X", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC1X", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC1X", e); } double[] x2 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC2X"); x2 = getMAC2X(); // logger.info("gets MAC2X DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC2X", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC2X", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC2X", e); } double[] x3 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC3X"); x3 = getMAC3X(); // logger.info("gets MAC3X DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC3X", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC3X", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC3X", e); } double[] x4 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC4X"); x4 = getMAC4X(); // logger.info("gets MAC4X DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC4X", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC4X", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC4X", e); } double[] x5 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC5X"); x5 = getMAC5X(); // logger.info("gets MAC5X DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC5X", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC5X", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC5X", e); } return ArrayUtils.subarray( ArrayUtils.addAll(ArrayUtils.addAll(ArrayUtils.addAll(ArrayUtils.addAll(x1, x2), x3), x4), x5), 16500, 305000); }
From source file:gda.hrpd.pmac.EpicsCVScanController.java
private double[] getCount() { double[] y1 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try {// w w w . j av a2s. c o m // logger.info("gets MAC1Y"); y1 = getMAC1Y(); // logger.info("gets MAC1Y DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC1Y", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC1Y", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC1Y", e); } double[] y2 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC2Y"); y2 = getMAC2Y(); // logger.info("gets MAC2Y DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC2Y", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC2Y", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC2Y", e); } double[] y3 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC3Y"); y3 = getMAC3Y(); // logger.info("gets MAC3Y DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC3Y", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC3Y", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC3Y", e); } double[] y4 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC4Y"); y4 = getMAC4Y(); // logger.info("gets MAC4Y DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC4Y", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC4Y", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC4Y", e); } double[] y5 = ArrayUtils.EMPTY_DOUBLE_ARRAY; try { // logger.info("gets MAC5Y"); y5 = getMAC5Y(); // logger.info("gets MAC5Y DONE"); } catch (TimeoutException e) { logger.error("Timeout while gets MAC5Y", e); e.printStackTrace(); } catch (CAException e) { logger.error("CAException while gets MAC5Y", e); e.printStackTrace(); } catch (InterruptedException e) { logger.error("InterruptedException while gets MAC5Y", e); } return ArrayUtils.subarray( ArrayUtils.addAll(ArrayUtils.addAll(ArrayUtils.addAll(ArrayUtils.addAll(y1, y2), y3), y4), y5), 16500, 305000); }
From source file:com.haulmont.cuba.gui.components.filter.FilterDelegateImpl.java
protected FilterEntity getDefaultFilter(List<FilterEntity> filters) { Window window = ComponentsHelper.getWindow(filter); // First check if there is parameter with name equal to this filter component id, containing a filter code to apply Map<String, Object> params = filter.getFrame().getContext().getParams(); String code = (String) params.get(filter.getId()); if (!StringUtils.isBlank(code)) { for (FilterEntity filter : filters) { if (code.equals(filter.getCode())) return filter; }/*from ww w. ja v a 2s. c o m*/ } // No 'filter' parameter found, load default filter SettingsImpl settings = new SettingsImpl(window.getId()); String componentPath = ComponentsHelper.getFilterComponentPath(filter); String[] strings = ValuePathHelper.parse(componentPath); String name = ValuePathHelper.format((String[]) ArrayUtils.subarray(strings, 1, strings.length)); Element e = settings.get(name).element("defaultFilter"); if (e != null) { String defIdStr = e.attributeValue("id"); Boolean applyDefault = Boolean.valueOf(e.attributeValue("applyDefault")); if (!StringUtils.isBlank(defIdStr)) { UUID defaultId = null; try { defaultId = UUID.fromString(defIdStr); } catch (IllegalArgumentException ex) { // } if (defaultId != null) { for (FilterEntity filter : filters) { if (defaultId.equals(filter.getId())) { filter.setIsDefault(true); filter.setApplyDefault(applyDefault); return filter; } } } } } FilterEntity globalDefaultFilter = filters.stream() .filter(filterEntity -> Boolean.TRUE.equals(filterEntity.getGlobalDefault())).findAny() .orElse(null); return globalDefaultFilter; }
From source file:adalid.core.AbstractEntity.java
private BooleanExpression defaultInstanceParameterSearchQueryFilter() { Operation operation = getDeclaringOperation(); List<State> list = operation.getInitialStatesList(); int size = list.size(); if (size == 0) { return null; }//w w w.j av a 2 s . c o m Expression exp; Map<String, Expression> map = getExpressionsMap(); State[] array = new State[size]; int i = 0; for (State state : list) { exp = map.get(state.getName()); array[i++] = (State) exp; } switch (array.length) { case 1: return array[0]; case 2: return or(array[0], array[1]); default: return or(array[0], array[1], (State[]) ArrayUtils.subarray(array, 2, array.length)); } }
From source file:net.stuxcrystal.simpledev.commands.arguments.ArgumentList.java
/** * Parses the args./*w w w . j a v a 2s .c o m*/ * * @param args The array of arguments to be parsed. */ private void parseArgs(String[] args) { String rawArgs = StringUtils.join(args, " "); String[] parsed = this.handler.getArgumentHandler().getArgumentSplitter().split(rawArgs); if (parsed.length >= 1) { flags = parsed[0]; } if (parsed.length >= 2) { arguments = (String[]) ArrayUtils.subarray(parsed, 1, parsed.length); } }
From source file:net.stuxcrystal.simpledev.commands.arguments.ArgumentList.java
/** * Joins the arguments using the given indexes. * @param beginIndex First Index (Inclusive) * @param endIndex Last Index (Exclusive) * @return The joined string./*from www . j ava 2 s . c om*/ */ public String getJoinedString(int beginIndex, int endIndex) { int pBegin = beginIndex, pEnd = endIndex; beginIndex = this.getRealIndex(beginIndex, false); // Inclusive endIndex = this.getRealIndex(endIndex, true); // Exclusive if (beginIndex < 0) throw new IndexOutOfBoundsException(this.outOfBoundsMsg(pBegin)); if (endIndex < 0) throw new IndexOutOfBoundsException(this.outOfBoundsMsg(pEnd)); String[] arguments = (String[]) ArrayUtils.subarray(this.arguments, beginIndex, endIndex); return StringUtils.join(arguments, " "); }