List of usage examples for org.apache.commons.lang ArrayUtils reverse
public static void reverse(boolean[] array)
Reverses the order of the given array.
From source file:com.flexive.ejb.beans.TreeEngineBean.java
/** * {@inheritDoc}// w w w . j av a 2 s.c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long[] getReverseIdChain(FxTreeMode mode, long id) throws FxApplicationException { long[] chain = getIdChain(mode, id); ArrayUtils.reverse(chain); return chain; }
From source file:msi.gaml.statements.SaveStatement.java
private static Geometry fixesPolygonCWS(final Geometry g) { if (g instanceof Polygon) { final Polygon p = (Polygon) g; final boolean clockwise = CGAlgorithms.isCCW(p.getExteriorRing().getCoordinates()); if (p.getNumInteriorRing() == 0) { return g; }/*w w w. j a v a 2 s . com*/ boolean change = false; final LinearRing[] holes = new LinearRing[p.getNumInteriorRing()]; final GeometryFactory geomFact = new GeometryFactory(); for (int i = 0; i < p.getNumInteriorRing(); i++) { final LinearRing hole = (LinearRing) p.getInteriorRingN(i); if (!clockwise && !CGAlgorithms.isCCW(hole.getCoordinates()) || clockwise && CGAlgorithms.isCCW(hole.getCoordinates())) { change = true; final Coordinate[] coords = hole.getCoordinates(); ArrayUtils.reverse(coords); final CoordinateSequence points = CoordinateArraySequenceFactory.instance().create(coords); holes[i] = new LinearRing(points, geomFact); } else { holes[i] = hole; } } if (change) { return geomFact.createPolygon((LinearRing) p.getExteriorRing(), holes); } } else if (g instanceof GeometryCollection) { final GeometryCollection gc = (GeometryCollection) g; boolean change = false; final GeometryFactory geomFact = new GeometryFactory(); final Geometry[] geometries = new Geometry[gc.getNumGeometries()]; for (int i = 0; i < gc.getNumGeometries(); i++) { final Geometry gg = gc.getGeometryN(i); if (gg instanceof Polygon) { geometries[i] = fixesPolygonCWS(gg); change = true; } else { geometries[i] = gg; } } if (change) { return geomFact.createGeometryCollection(geometries); } } return g; }
From source file:com.netscape.cmsutil.crypto.CryptoUtil.java
public static java.security.cert.X509Certificate[] sortCertificateChain( java.security.cert.X509Certificate[] certs, boolean reverse) throws Exception { certs = sortCertificateChain(certs); if (reverse) { ArrayUtils.reverse(certs); }//from www . j ava2 s. c o m return certs; }
From source file:foodsimulationmodel.pathmapping.Route.java
/** * Calculates the coordinates required to move an agent from their current position to the destination along a given * road. The algorithm to do this is as follows: * <ol>// w w w.j av a 2 s . c o m * <li>Starting from the destination coordinate, record each vertex and check inside the booundary of each line * segment until the destination point is found.</li> * <li>Return all but the last vertex, this is the route to the destination.</li> * </ol> * A boolean allows for two cases: heading towards a junction (the endpoint of the line) or heading away from the * endpoint of the line (this function can't be used to go to two midpoints on a line) * * @param currentCoord * @param destinationCoord * @param road * @param toJunction * whether or not we're travelling towards or away from a Junction * @param coordList * A list which will be populated with the coordinates that the agent should follow to move along the * road. * @param roadList * A list of roads associated with each coordinate. * @throws Exception */ private void getCoordsAlongRoad(Coordinate currentCoord, Coordinate destinationCoord, Road road, boolean toJunction, List<Coordinate> coordList) throws RoutingException { Route.checkNotNull(currentCoord, destinationCoord, road, coordList); double time = System.nanoTime(); Coordinate[] roadCoords = ContextManager.roadProjection.getGeometry(road).getCoordinates(); // Check that the either the destination or current coordinate are actually part of the road boolean currentCorrect = false, destinationCorrect = false; for (int i = 0; i < roadCoords.length; i++) { if (toJunction && destinationCoord.equals(roadCoords[i])) { destinationCorrect = true; break; } else if (!toJunction && currentCoord.equals(roadCoords[i])) { currentCorrect = true; break; } } // for if (!(destinationCorrect || currentCorrect)) { String roadCoordsString = ""; for (Coordinate c : roadCoords) roadCoordsString += c.toString() + " - "; throw new RoutingException("Neigher the origin or destination nor the current" + "coordinate are part of the road '" + road.toString() + "' (person '" + this.agent.toString() + "').\n" + "Road coords: " + roadCoordsString + "\n" + "\tOrigin: " + currentCoord.toString() + "\n" + "\tDestination: " + destinationCoord.toString() + " ( " + this.destinationAgent.toString() + " )\n " + "Heading " + (toJunction ? "to" : "away from") + " a junction, so " + (toJunction ? "destination" : "origin") + " should be part of a road segment"); } // Might need to reverse the order of the road coordinates if (toJunction && !destinationCoord.equals(roadCoords[roadCoords.length - 1])) { // If heading towards a junction, destination coordinate must be at end of road segment ArrayUtils.reverse(roadCoords); } else if (!toJunction && !currentCoord.equals(roadCoords[0])) { // If heading away form junction current coord must be at beginning of road segment ArrayUtils.reverse(roadCoords); } GeometryFactory geomFac = new GeometryFactory(); Point destinationPointGeom = geomFac.createPoint(destinationCoord); Point currentPointGeom = geomFac.createPoint(currentCoord); // If still false at end then algorithm hasn't worked boolean foundAllCoords = false; search: for (int i = 0; i < roadCoords.length - 1; i++) { Coordinate[] segmentCoords = new Coordinate[] { roadCoords[i], roadCoords[i + 1] }; // Draw a small buffer around the line segment and look for the coordinate within the buffer Geometry buffer = geomFac.createLineString(segmentCoords) .buffer(GlobalVars.GEOGRAPHY_PARAMS.BUFFER_DISTANCE.SMALL.dist); if (!toJunction) { /* If heading away from a junction, keep adding road coords until we find the destination */ coordList.add(roadCoords[i]); if (destinationPointGeom.within(buffer)) { coordList.add(destinationCoord); foundAllCoords = true; break search; } } else if (toJunction) { /* * If heading towards a junction: find the curent coord, add it to the route, then add all the remaining * coords which make up the road segment */ if (currentPointGeom.within(buffer)) { for (int j = i + 1; j < roadCoords.length; j++) { coordList.add(roadCoords[j]); } coordList.add(destinationCoord); foundAllCoords = true; break search; } } } // for if (foundAllCoords) { LOGGER.log(Level.FINER, "getCoordsAlongRoad (" + (0.000001 * (System.nanoTime() - time)) + "ms)"); return; } else { // If we get here then the route hasn't been created // A load of debugging info String error = "Route: getCoordsAlongRoad: could not find destination coordinates " + "along the road.\n\tHeading *" + (toJunction ? "towards" : "away from") + "* a junction.\n\t Person: " + this.agent.toString() + ")\n\tDestination building: " + destinationAgent.toString() + "\n\tRoad causing problems: " + road.toString() + "\n\tRoad vertex coordinates: " + Arrays.toString(roadCoords); throw new RoutingException(error); /* * Hack: ignore the error, printing a message and just returning the origin destination and coordinates. * This means agent will jump to/from the junction but I can't figure out why the fuck it occasionally * doesn't work!! It's so rare that hopefully this isn't a problem. */ // TempLogger.err("Route: getCoordsAlongRoad: error... (not debugging)."); // List<Coord> coords = new ArrayList<Coord>(); // coords.add(currentCoord); // coords.add(destinationCoord); // for (Coord c : coords) // this.roads.put(c, road); // Remember the roads each coord is // // part of // return coords; } }
From source file:foodsimulationmodel.pathmapping.Route.java
/** * Returns all the coordinates that describe how to travel along a path, restricted to road coordinates. In some * cases the route wont have an associated road, this occurs if the route is part of a transport network. In this * case just the origin and destination coordinates are added to the route. * /*from w w w .j a v a 2 s . c om*/ * @param shortestPath * @param startingJunction * The junction the path starts from, this is required so that the algorithm knows which road coordinate * to add first (could be first or last depending on the order that the road coordinates are stored * internally). * @return the coordinates as a mapping between the coord and its associated speed (i.e. how fast the agent can * travel to the next coord) which is dependent on the type of edge and the agent (e.g. * driving/walking/bus). LinkedHashMap is used to guarantee the insertion order of the coords is maintained. * @throws RoutingException */ private void getRouteBetweenJunctions(List<RepastEdge<Junction>> shortestPath, Junction startingJunction) throws RoutingException { double time = System.nanoTime(); if (shortestPath.size() < 1) { // This could happen if the agent's destination is on the same road // as the origin return; } // Lock the currentAgent so that NetworkEdge obejcts know what speed to use (depends on transport available to // the specific agent). synchronized (GlobalVars.TRANSPORT_PARAMS.currentBurglarLock) { GlobalVars.TRANSPORT_PARAMS.currentAgent = this.agent; // Iterate over all edges in the route adding coords and weights as appropriate NetworkEdge<Junction> e; Road r; // Use sourceFirst to represent whether or not the edge's source does actually represent the start of the // edge (agent could be going 'forwards' or 'backwards' over edge boolean sourceFirst; for (int i = 0; i < shortestPath.size(); i++) { e = (NetworkEdge<Junction>) shortestPath.get(i); if (i == 0) { // No coords in route yet, compare the source to the starting junction sourceFirst = (e.getSource().equals(startingJunction)) ? true : false; } else { // Otherwise compare the source to the last coord added to the list sourceFirst = (e.getSource().getCoords().equals(this.routeX.get(this.routeX.size() - 1))) ? true : false; } /* * Now add the coordinates describing how to move along the road. If there is no road associated with * the edge (i.e. it is a transport route) then just add the source/dest coords. Note that the shared * coordinates between two edges will be added twice, these must be removed later */ r = e.getRoad(); /* * Get the speed that the agent will be able to travel along this edge (depends on the transport * available to the agent and the edge). Some speeds will be < 1 if the agent shouldn't be using this * edge but doesn't have any other way of getting to the destination. in these cases set speed to 1 * (equivalent to walking). */ double speed = e.getSpeed(); if (speed < 1) speed = 1; if (r == null) { // No road associated with this edge (it is a // transport link) so just add source if (sourceFirst) { this.addToRoute(e.getSource().getCoords(), r, speed, "getRouteBetweenJunctions - no road"); this.addToRoute(e.getTarget().getCoords(), r, -1, "getRouteBetweenJunctions - no road"); // (Note speed = -1 used because we don't know the weight to the next // coordinate - this can be removed later) } else { this.addToRoute(e.getTarget().getCoords(), r, speed, "getRouteBetweenJunctions - no road"); this.addToRoute(e.getSource().getCoords(), r, -1, "getRouteBetweenJunctions - no road"); } } else { // This edge is a road, add all the coords which make up its geometry Coordinate[] roadCoords = ContextManager.roadProjection.getGeometry(r).getCoordinates(); if (roadCoords.length < 2) throw new RoutingException("Route.getRouteBetweenJunctions: for some reason road " + "'" + r.toString() + "' doesn't have at least two coords as part of its geometry (" + roadCoords.length + ")"); // Make sure the coordinates of the road are added in the correct order if (!sourceFirst) { ArrayUtils.reverse(roadCoords); } // Add all the road geometry's coords for (int j = 0; j < roadCoords.length; j++) { this.addToRoute(roadCoords[j], r, speed, "getRouteBetweenJuctions - on road"); // (Note that last coord will have wrong weight) } // for roadCoords.length } // if road!=null } // Check all lists are still the same size. assert this.roadsX.size() == this.routeX.size() && this.routeDescriptionX.size() == this.routeSpeedsX.size() && this.roadsX.size() == this.routeDescriptionX.size(); // Check all lists are still the same size. assert this.roadsX.size() == this.routeX.size() && this.routeDescriptionX.size() == this.routeSpeedsX.size() && this.roadsX.size() == this.routeDescriptionX.size(); // Finished! LOGGER.log(Level.FINER, "getRouteBetweenJunctions (" + (0.000001 * (System.nanoTime() - time)) + "ms"); return; } // synchronized }
From source file:au.org.emii.portal.composer.MapComposer.java
public void loadUserSession(String sessionid) { Scanner scanner = null;/*from w w w . j a va2s . c o m*/ try { String sfld = getSettingsSupplementary().getProperty(StringConstants.ANALYSIS_OUTPUT_DIR) + "session/" + sessionid; File sessfolder = new File(sfld); if (!sessfolder.exists()) { showMessage("Session information does not exist. Please provide a valid session id"); return; } scanner = new Scanner(new File(sfld + "/details.txt")); // first grab the zoom level and bounding box String[] mapdetails = scanner.nextLine().split(","); BoundingBox bb = new BoundingBox(); bb.setMinLongitude(Float.parseFloat(mapdetails[1])); bb.setMinLatitude(Float.parseFloat(mapdetails[2])); bb.setMaxLongitude(Float.parseFloat(mapdetails[3])); bb.setMaxLatitude(Float.parseFloat(mapdetails[4])); openLayersJavascript.setAdditionalScript(openLayersJavascript.zoomToBoundingBox(bb, true)); String[] scatterplotNames = null; while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.startsWith("scatterplotNames")) { scatterplotNames = line.substring(17).split("___"); } } ArrayUtils.reverse(scatterplotNames); // ignore fields not found XStream xstream = new XStream(new DomDriver()) { protected MapperWrapper wrapMapper(MapperWrapper next) { return new MapperWrapper(next) { public boolean shouldSerializeMember(Class definedIn, String fieldName) { if (definedIn == Object.class || !super.shouldSerializeMember(definedIn, fieldName)) System.out.println("faled to read: " + definedIn + ", " + fieldName); return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false; } }; } @Override public Object unmarshal(HierarchicalStreamReader reader) { Object o = super.unmarshal(reader); if (o instanceof BiocacheQuery) ((BiocacheQuery) o).getFullQ(false); return o; } @Override public Object unmarshal(HierarchicalStreamReader reader, Object root) { Object o = super.unmarshal(reader, root); if (o instanceof BiocacheQuery) ((BiocacheQuery) o).getFullQ(false); return o; } @Override public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) { Object o = super.unmarshal(reader, root, dataHolder); if (o instanceof BiocacheQuery) ((BiocacheQuery) o).getFullQ(false); return o; } }; PersistenceStrategy strategy = new FilePersistenceStrategy(new File(sfld), xstream); List list = new XmlArrayList(strategy); ListIterator it = list.listIterator(list.size()); int scatterplotIndex = 0; while (it.hasPrevious()) { Object o = it.previous(); MapLayer ml = null; if (o instanceof MapLayer) { ml = (MapLayer) o; LOGGER.debug("Loading " + ml.getName() + " -> " + ml.isDisplayed()); addUserDefinedLayerToMenu(ml, false); } else if (o instanceof ScatterplotDataDTO) { ScatterplotDataDTO spdata = (ScatterplotDataDTO) o; loadScatterplot(spdata, "My Scatterplot " + scatterplotIndex++); } if (ml != null) { addUserDefinedLayerToMenu(ml, true); } } } catch (Exception e) { try { File f = new File("/data/sessions/" + sessionid + ".txt"); PrintWriter pw = new PrintWriter(f); e.printStackTrace(pw); pw.close(); } catch (Exception ex) { } LOGGER.error("Unable to load session data", e); showMessage("Unable to load session data"); } finally { if (scanner != null) { scanner.close(); } try { File f = new File("/data/sessions/ok/" + sessionid + ".txt"); FileUtils.writeStringToFile(f, "ok"); } catch (Exception ex) { } } }
From source file:com.att.pirates.controller.ProjectController.java
private static String getRowDueDatePercentageString(String Percentage, String Duedate, String UpdatedByUUID, String uuid, String headerDueDate, boolean left, boolean validateThreshold) { String[] datecreatedList = Duedate.split(","); String[] percentageList = Percentage.split(","); String[] uuidList = UpdatedByUUID.split(","); SimpleDateFormat xFormat = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat yFormat = new SimpleDateFormat("MM/dd/yy"); if (datecreatedList == null || datecreatedList.length == 0) { return "NA"; }/*from ww w. ja v a 2 s .c o m*/ if (("NA".equalsIgnoreCase(datecreatedList[0])) || ("NA".equalsIgnoreCase(headerDueDate))) { return "NA"; } if (percentageList.length != datecreatedList.length) { //logger.error("Error, DateCreated count does not equal Percentage count"); return ""; } try { // mchan: added code to evaluate if the latest updated date fits in the threashold // get threshold info for user, 1 = noupdate, 2 = duein List<Threshold> thresholds = DataService.getEmployeeThresholds(uuid); String warningMsg = ""; if (thresholds != null && !thresholds.isEmpty() && validateThreshold) { // since we have a list of dates, we just need the max List<Integer> noupdates = new ArrayList<Integer>(); List<Integer> dueins = new ArrayList<Integer>(); String percent = percentageList[0]; BigDecimal d = new BigDecimal(percent.trim().replace("%", "")).divide(BigDecimal.valueOf(100)); if (d.compareTo(BigDecimal.ONE) == 0) { //logger.error(d + ", is exactly one"); } else if (d.compareTo(BigDecimal.ONE) == 1) { //logger.error(d + ", is greater than one"); } else if (d.compareTo(BigDecimal.ONE) == -1) { //logger.error(d + ", is less than one"); } for (Threshold t : thresholds) { // process NoUpdate if (PiratesConstants.NOUPDATE.equalsIgnoreCase(t.getThresholdType())) { try { noupdates.add(Integer.parseInt(t.getThresholdValue())); } catch (NumberFormatException ex) { //logger.error("Error parsing threshold value, type: NOUPDATE, value: " + t.getThresholdValue()); } } // process DueIn if (PiratesConstants.DUEIN.equalsIgnoreCase(t.getThresholdType())) { try { dueins.add(Integer.parseInt(t.getThresholdValue())); } catch (NumberFormatException ex) { //logger.error("Error parsing threshold value, type: DUEIN, value: " + t.getThresholdValue()); } } } // done parsing thresholds if (!noupdates.isEmpty() && (d.compareTo(BigDecimal.ONE) == -1) && (!"NA".equalsIgnoreCase(datecreatedList[0])) && validateThreshold) { // compare dates, last updated and today and then match it with the maxnoupdate and maxduein // last updated date Date lastUpdated = xFormat.parse(datecreatedList[0]); Date today = new Date(); if (lastUpdated.before(today)) { long diff = today.getTime() - lastUpdated.getTime(); int diffindays = (int) (diff / (24 * 60 * 60 * 1000)); Collections.sort(noupdates); Integer[] foo = noupdates.toArray(new Integer[noupdates.size()]); // now in descending order ArrayUtils.reverse(foo); for (Integer i : foo) { if (diffindays >= i) { warningMsg = "Status is static for more than " + String.valueOf(i) + " days! <br/>"; break; } } } else { warningMsg = "Today cannot be before LastUpdatedDate ??!"; } } // check artifact due in x number if days, but ignore NA if ((!dueins.isEmpty()) && (d.compareTo(BigDecimal.ONE) == -1) && (!"NA".equalsIgnoreCase(headerDueDate))) { Collections.sort(dueins); Date dueDate = xFormat.parse(headerDueDate); Date today = new Date(); if (today.before(dueDate)) { // logger.error("dueDate.getTime() is: " + dueDate.getTime()); // logger.error("today.getTime() is: " + today.getTime()); long diff = dueDate.getTime() - today.getTime(); int diffindays = (int) (diff / (24 * 60 * 60 * 1000)); // logger.error("dueDate.getTime() - today.getTime() is: " + diffindays); Collections.sort(dueins); Integer[] foo = dueins.toArray(new Integer[dueins.size()]); // now in descending order ArrayUtils.reverse(foo); for (Integer i : foo) { if (diffindays <= i) { warningMsg = warningMsg + "Artifact is due in " + (diffindays == 0 ? "less than a day" : String.valueOf(diffindays) + " days"); break; } } } else { // logger.error("header duedate is: " + dueDate); // logger.error("today is: " + today); // logger.error("Today is NOT before due date ??"); warningMsg = warningMsg + "Project overdue"; } } } // end processing thresholds int i = 0; // display in dropdown from greatest to least, so we need to revert the array StringBuilder selectHtml = new StringBuilder(); if (!warningMsg.isEmpty()) { selectHtml.append( "<div class='dropdown'> <button style='background-color: #FF8080' class='btn btn-default dropdown-toggle' type='button' id='dropdownMenu1' data-toggle='dropdown' aria-expanded='true'>"); } else { selectHtml.append( "<div class='dropdown'> <button class='btn btn-default dropdown-toggle' type='button' id='dropdownMenu1' data-toggle='dropdown' aria-expanded='true'>"); } selectHtml.append(yFormat.format(xFormat.parse(datecreatedList[0]))).append(" ") .append(percentageList[0]); selectHtml.append("<span class='caret'></span></button>"); selectHtml.append("<ul class='dropdown-menu' role='menu' aria-labelledby='dropdownMenu1'>"); for (String s : datecreatedList) { String tmplblBRduedate = yFormat.format(xFormat.parse(s)); // logger.error("DueDate is: " + tmplblBRduedate); String percentStr = percentageList[i]; String byuuidstr = uuidList[i]; String newUUID = getATTEmployeeObjectByUUID(byuuidstr).getFullName(); if (i == 0 && !warningMsg.isEmpty()) { if (!left) { // tooltip on the right side selectHtml.append("<li role='presentation'>") .append("<a role='menuitem' tabindex='-1' href='#'>").append(tmplblBRduedate) .append(" " + percentStr + " ") .append("<span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append(warningMsg).append("'></span>").append("</a>").append("</li>"); } else { // tooltip on left selectHtml.append( "<li role='presentation'><a role='menuitem' tabindex='-1' href='#'><span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append(warningMsg).append("'></span> ").append(tmplblBRduedate) .append(" " + percentStr + "</a> </li>"); } } else { if (!left) { // tooltip on the right side selectHtml.append("<li role='presentation'>") .append("<a role='menuitem' tabindex='-1' href='#'>").append(tmplblBRduedate) .append(" " + percentStr + " ") .append("<span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append("Last updated by: " + newUUID).append("'></span>").append("</a>") .append("</li>"); } else { selectHtml.append( "<li role='presentation'><a role='menuitem' tabindex='-1' href='#'><span class='glyphicon glyphicon-question-sign question' id='mytimestamp' data='") .append("Last updated by: " + newUUID).append("'></span> ") .append(tmplblBRduedate).append(" " + percentStr + "</a> </li>"); } } i++; } selectHtml.append("</ul>"); selectHtml.append("</div>"); return selectHtml.toString(); } catch (Exception ex) { logger.error(msgHeader + "Error occurred getRowDueDatePercentageString... " + ex.getMessage()); } return null; }
From source file:com.test.stringtest.StringUtils.java
/** * <p>Reverses a String that is delimited by a specific character.</p> * * <p>The Strings between the delimiters are not reversed. * Thus java.lang.String becomes String.lang.java (if the delimiter * is <code>'.'</code>).</p> * * <pre>// www. j av a2s .c o m * StringUtils.reverseDelimited(null, *) = null * StringUtils.reverseDelimited("", *) = "" * StringUtils.reverseDelimited("a.b.c", 'x') = "a.b.c" * StringUtils.reverseDelimited("a.b.c", ".") = "c.b.a" * </pre> * * @param str the String to reverse, may be null * @param separatorChar the separator character to use * @return the reversed String, <code>null</code> if null String input * @since 2.0 */ public static String reverseDelimited(String str, char separatorChar) { if (str == null) { return null; } // could implement manually, but simple way is to reuse other, // probably slower, methods. String[] strs = split(str, separatorChar); ArrayUtils.reverse(strs); return join(strs, separatorChar); }
From source file:com.yucheng.cmis.pub.util.NewStringUtils.java
/** * <p>Reverses a String that is delimited by a specific character.</p> * * <p>The Strings between the delimiters are not reversed. * Thus java.lang.String becomes String.lang.java (if the delimiter * is <code>"."</code>).</p> * * <pre>/* w w w .j a v a2 s .c om*/ * StringUtils.reverseDelimitedString(null, *) = null * StringUtils.reverseDelimitedString("",*) = "" * StringUtils.reverseDelimitedString("a.b.c", null) = "a.b.c" * StringUtils.reverseDelimitedString("a.b.c", ".") = "c.b.a" * </pre> * * @param str the String to reverse, may be null * @param separatorChars the separator characters to use, null treated as whitespace * @return the reversed String, <code>null</code> if null String input * @deprecated Use {@link #reverseDelimited(String, char)} instead. * This method is broken as the join doesn't know which char to use. * Method will be removed in Commons Lang 3.0. * */ public static String reverseDelimitedString(String str, String separatorChars) { if (str == null) { return null; } // could implement manually, but simple way is to reuse other, // probably slower, methods. String[] strs = split(str, separatorChars); ArrayUtils.reverse(strs); if (separatorChars == null) { return join(strs, ' '); } return join(strs, separatorChars); }
From source file:org.apache.cloudstack.storage.to.SnapshotObjectTO.java
public SnapshotObjectTO(SnapshotInfo snapshot) { this.path = snapshot.getPath(); this.setId(snapshot.getId()); VolumeInfo vol = snapshot.getBaseVolume(); if (vol != null) { this.volume = (VolumeObjectTO) vol.getTO(); this.setVmName(vol.getAttachedVmName()); }/*from w w w . j a v a2 s . c om*/ SnapshotInfo parentSnapshot = snapshot.getParent(); ArrayList<String> parentsArry = new ArrayList<String>(); if (parentSnapshot != null) { this.parentSnapshotPath = parentSnapshot.getPath(); while (parentSnapshot != null) { parentsArry.add(parentSnapshot.getPath()); parentSnapshot = parentSnapshot.getParent(); } parents = parentsArry.toArray(new String[parentsArry.size()]); ArrayUtils.reverse(parents); } this.dataStore = snapshot.getDataStore().getTO(); this.setName(snapshot.getName()); this.hypervisorType = snapshot.getHypervisorType(); this.quiescevm = false; }