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:org.talend.commons.ui.runtime.geometry.Curve2DBezier.java
void computeSegments() { Point2DList pl = (Point2DList) plist; n = pl.size() - 1;//from ww w. j a va 2 s. co m size = (int) (subdiv * n * time); if (size > getMaximumSegements()) { size = getMaximumSegements(); } if (size < getMinimumSegements()) { size = getMinimumSegements(); } tmp = new double[size + 1]; for (int i = 0; i <= size; i++) tmp[i] = (double) time * i / size; double bt; int[] pointsTmp = new int[2 * (size + 1)]; double x, y; int indexTStart = -1; int indexTEnd = -1; boolean firstInvisiblePoint = true; for (int t = 0; t <= size; t++) { x = 0; y = 0; for (int i = 0; i <= n; i++) { bt = (double) (Math.comb(n, i) * Math.pow(1 - tmp[t], n - i) * Math.pow(tmp[t], i)); x += ((Point2D) pl.get(i)).getX() * bt; y += ((Point2D) pl.get(i)).getY() * bt; } if (y >= yMinVisiblePoints && y <= yMaxVisiblePoints || firstInvisiblePoint || pointsTmp.length > 4) { if (indexTStart == -1) { indexTStart = t; } pointsTmp[2 * t] = (int) java.lang.Math.round(x); pointsTmp[2 * t + 1] = (int) java.lang.Math.round(y); if (firstInvisiblePoint && y < yMinVisiblePoints && y < yMaxVisiblePoints) { firstInvisiblePoint = false; } } else if (indexTStart != -1) { indexTEnd = t; break; } } if (indexTEnd == -1 && indexTStart != -1) { indexTEnd = size + 1; } // System.out.println("size="+size + " indexTStart=" + indexTStart + " indexTEnd="+indexTEnd); if (indexTEnd == -1) { this.points = new int[0]; } else { this.points = ArrayUtils.subarray(pointsTmp, 2 * indexTStart, 2 * indexTEnd); // System.out.println("pointsTmp="); // for (int i = pointsTmp.length - 4; i < pointsTmp.length; i++) { // System.out.println(pointsTmp[i]); // } // // // System.out.println("this.points="); // for (int i = points.length - 4; i < points.length; i++) { // System.out.println(points[i]); // } } }
From source file:org.talend.dataprep.transformation.service.ExportStrategy.java
/** * Returns the actions for the preparation with <code>preparationId</code> between <code>startStepId</code> and * <code>endStepId</code>.//from www . j a v a 2s. c o m * * @param preparationId The preparation id, if <code>null</code> or blank, returns <code>{actions: []}</code> * @param startStepId A step id that must exist in given preparation id. * @param endStepId A step id that must exist in given preparation id. * @return The actions that can be parsed by ActionParser. * @see org.talend.dataprep.transformation.api.action.ActionParser */ protected String getActions(String preparationId, String startStepId, String endStepId) { if (rootStep.id().equals(startStepId)) { return getActions(preparationId, endStepId); } String actions; if (StringUtils.isBlank(preparationId)) { actions = "{\"actions\": []}"; } else { try { final PreparationGetActions startStepActions = applicationContext .getBean(PreparationGetActions.class, preparationId, startStepId); final PreparationGetActions endStepActions = applicationContext.getBean(PreparationGetActions.class, preparationId, endStepId); final StringWriter actionsAsString = new StringWriter(); final Action[] startActions = mapper.readValue(startStepActions.execute(), Action[].class); final Action[] endActions = mapper.readValue(endStepActions.execute(), Action[].class); if (endActions.length > startActions.length) { final Action[] filteredActions = (Action[]) ArrayUtils.subarray(endActions, startActions.length, endActions.length); LOGGER.debug("Reduced actions list from {} to {} action(s)", endActions.length, filteredActions.length); mapper.writeValue(actionsAsString, filteredActions); } else { LOGGER.debug("Unable to reduce list of actions (has {})", endActions.length); mapper.writeValue(actionsAsString, endActions); } return "{\"actions\": " + actionsAsString + '}'; } catch (IOException e) { final ExceptionContext context = ExceptionContext.build().put("id", preparationId).put("version", endStepId); throw new TDPException(UNABLE_TO_READ_PREPARATION, e, context); } } return actions; }
From source file:org.tinygroup.jdbctemplatedslsession.SimpleDslSession.java
private void batchProcess(int batchSize, Map<String, Object>[] params, BatchOperateCallback callback) { int totalSize = params.length; int times = totalSize % batchSize == 0 ? totalSize / batchSize : totalSize / batchSize + 1; int numOfEach = totalSize % times == 0 ? totalSize / times : totalSize / times + 1; int fromIndex = 0; for (int i = 0; i < times; i++) { int endIndex = fromIndex + numOfEach; if (endIndex > totalSize) { endIndex = totalSize;/*from w ww .j a v a 2 s . co m*/ } Map<String, Object>[] processParams = (Map<String, Object>[]) ArrayUtils.subarray(params, fromIndex, endIndex); fromIndex += numOfEach; callback.callback(processParams); } }
From source file:org.twinkql.result.PropertySetter.java
/** * Adjust for collection./* www.ja v a2 s .c o m*/ * * @param target the target * @param property the property * @return the string */ private String adjustForCollection(Object target, String property) { if (StringUtils.countMatches(property, "[]") > 1) { throw new MappingException( "Cannot have more than one Collection Indicator ('[]') in a 'property' attribute."); } String[] parts = StringUtils.split(property, '.'); for (int i = 0; i < parts.length; i++) { String part = parts[i]; if (StringUtils.endsWith(part, "[]")) { String propertySoFar = StringUtils .removeEnd(StringUtils.join(ArrayUtils.subarray(parts, 0, i + 1), '.'), "[]"); Collection<?> collection = (Collection<?>) BeanUtil.getSimplePropertyForced(target, propertySoFar, true); int index = collection.size(); parts[i] = StringUtils.replace(part, "[]", "[" + index + "]"); } } return StringUtils.join(parts, '.'); }
From source file:org.web4thejob.web.util.MediaUtil.java
public static String getMediaFormat(byte[] media) { int index = 0; for (byte b : ArrayUtils.subarray(media, 0, MEDIA_TYPE_SIGNATURE)) { if (b == 0) break; index += 1;// ww w .j av a 2 s. c om } if (index > 0) { return new String(ArrayUtils.subarray(media, 0, index)).toLowerCase(); } return ""; }
From source file:org.web4thejob.web.util.MediaUtil.java
public static byte[] getMediaBytes(byte[] media) { return ArrayUtils.subarray(media, MEDIA_TYPE_SIGNATURE, media.length); }
From source file:org.xenmaster.pool.XMPacket.java
public void setContents(byte[] data, int length) { if (length < 2) { return;//from w w w . ja v a2s.c o m } // 101101011101 ~ 29/09 = birthday of initial commit if (!(data[0] == (byte) 0b10110101 && data[1] == (byte) 0b1101_0000)) { Logger.getLogger(getClass()).debug("Illegal prefix for packet"); return; } byte flags = data[2]; alive = (flags & 0b1) != 0; master = (flags & 0b10) != 0; contents = new String(ArrayUtils.subarray(data, 3, length)); }
From source file:org.xwiki.contrib.mail.internal.AbstractMailStore.java
/** * {@inheritDoc}/*from w w w.ja va 2 s . c o m*/ * * @see org.xwiki.contrib.mail.IMailReader#readFromStore(java.lang.String) */ @Override public List<Message> read(String folder, boolean onlyUnred, int max) throws MessagingException { Store store = getJavamailStore(); store.connect(); Folder mailFolder = store.getDefaultFolder(); if (StringUtils.isNotEmpty(folder)) { mailFolder = mailFolder.getFolder(folder); } mailFolder.open(Folder.READ_WRITE); Message[] msgsArray = mailFolder.getMessages(); if (max > 0 && msgsArray.length > max) { msgsArray = (Message[]) ArrayUtils.subarray(msgsArray, 0, max); } List<Message> messages = new ArrayList<Message>(Arrays.asList(msgsArray)); mailFolder.close(false); store.close(); return messages; }
From source file:org.xwiki.contrib.mail.internal.DefaultMailReader.java
/** * {@inheritDoc}//from w w w .j a v a 2s . c o m * * @throws MessagingException * @throws * @throws Exception * @see org.xwiki.contrib.mail.IMailReader#read(java.lang.String, int, java.lang.String, java.lang.String, * java.lang.String, java.lang.String, boolean, int) */ @Override public List<Message> read(final String folder, final boolean onlyUnread, final int max) throws MessagingException { assert (getMailSource() != null); assert (getMailSource().getHostname() != null); store = null; List<Message> messages = new ArrayList<Message>(); boolean isGmail = getMailSource().getHostname() != null && getMailSource().getHostname().endsWith(".gmail.com"); logger.info("Trying to retrieve mails from server " + getMailSource().getHostname()); this.session = createSession(getMailSource().getProtocol(), getMailSource().getAdditionalProperties(), isGmail, getMailSource().isAutoTrustSSLCertificates()); // Get a Store object store = session.getStore(); // Connect to the mail account store.connect(getMailSource().getHostname(), getMailSource().getPort(), getMailSource().getUsername(), getMailSource().getPassword()); Folder fldr; // Specifically for GMAIL ... if (isGmail) { fldr = store.getDefaultFolder(); } fldr = store.getFolder(folder); fldr.open(Folder.READ_WRITE); Message[] msgsArray; // Searches for mails not already read if (onlyUnread) { FlagTerm searchterms = new FlagTerm(new Flags(Flags.Flag.SEEN), false); msgsArray = fldr.search(searchterms); } else { msgsArray = fldr.getMessages(); } if (max > 0 && msgsArray.length > max) { msgsArray = (Message[]) ArrayUtils.subarray(msgsArray, 0, max); } messages = new ArrayList<Message>(Arrays.asList(msgsArray)); logger.info("Found " + messages.size() + " messages"); // Note: we leave the Store opened to allow reading returned Messages return messages; }
From source file:org.xwiki.platform.patchservice.impl.PositionImpl.java
/** * {@inheritDoc}//w ww. ja va 2 s .co m */ public String getTextBeforePosition(String text) { String[] rows = StringUtils.splitPreserveAllTokens(text, SEPARATOR); if (ArrayUtils.getLength(rows) <= this.row) { return StringUtils.defaultString(StringUtils.join(rows, SEPARATOR)) + (this.row == 0 ? "" : "\n"); } return StringUtils.join(ArrayUtils.subarray(rows, 0, this.row), SEPARATOR) + ((this.row > 0) ? SEPARATOR : "") + StringUtils.substring(rows[this.row], 0, this.column); }