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:org.wso2.carbon.registry.extensions.utils.CommonUtil.java
public static void applyDefaultLifeCycle(Registry registry, Resource resource, String path, String defaultLifeCycle) throws RegistryException { if (defaultLifeCycle != null && !defaultLifeCycle.isEmpty()) { String[] lifeCycles = defaultLifeCycle.split(","); ArrayUtils.reverse(lifeCycles); if (CurrentSession.getLocalPathMap() != null && !Boolean.valueOf(CurrentSession.getLocalPathMap().get(CommonConstants.ARCHIEVE_UPLOAD))) { for (String lifeCycle : lifeCycles) { if (StringUtils.isNotEmpty(lifeCycle)) { registry.associateAspect(resource.getId(), lifeCycle); }// w w w . ja v a 2s. c o m } } else { for (String lifeCycle : lifeCycles) { if (StringUtils.isNotEmpty(lifeCycle)) { registry.associateAspect(path, lifeCycle); } } } } }
From source file:parquet.avro.AvroWriteSupport.java
private void writeImpalaTimestamp(RecordConsumer recordConsumer, Long nanoseconds) { long milliseconds = nanoseconds / NANO_MILLI_CONV; JDateTime jdt = new JDateTime(milliseconds); // Get nanoseconds of the day and get bytes (little-endian format) long seconds_of_day = jdt.getMillisOfDay() / MILLI_SECOND_CONV; long nanoseconds_fraction_of_second = nanoseconds % NANO_CONV; long nanoseconds_of_day = seconds_of_day * NANO_CONV + nanoseconds_fraction_of_second; byte[] b_ns = Longs.toByteArray(nanoseconds_of_day); ArrayUtils.reverse(b_ns); // Get Julian Day and get bytes (little-endian format) byte[] b_julian_days = Ints.toByteArray(jdt.getJulianDayNumber()); ArrayUtils.reverse(b_julian_days);/*from w w w . ja v a 2 s . co m*/ // Fill buffer ByteBuffer buf = ByteBuffer.allocate(12); buf.put(b_ns).put(b_julian_days).flip(); // Write recordConsumer.addBinary(Binary.fromByteBuffer(buf)); }
From source file:piuk.blockchain.android.Hash.java
public void reverse() { ArrayUtils.reverse(hash); }
From source file:piuk.blockchain.android.MyRemoteWallet.java
public static List<MyTransactionOutPoint> getUnspentOutputPoints(String[] from) throws Exception { StringBuffer buffer = new StringBuffer(WebROOT + "unspent?active="); int ii = 0;// w w w. j a v a 2 s . co m for (String address : from) { buffer.append(address); if (ii < from.length - 1) buffer.append("|"); ++ii; } List<MyTransactionOutPoint> outputs = new ArrayList<MyTransactionOutPoint>(); String response = fetchURL(buffer.toString()); Map<String, Object> root = (Map<String, Object>) JSONValue.parse(response); List<Map<String, Object>> outputsRoot = (List<Map<String, Object>>) root.get("unspent_outputs"); for (Map<String, Object> outDict : outputsRoot) { byte[] hashBytes = Hex.decode((String) outDict.get("tx_hash")); ArrayUtils.reverse(hashBytes); Sha256Hash txHash = new Sha256Hash(hashBytes); int txOutputN = ((Number) outDict.get("tx_output_n")).intValue(); BigInteger value = BigInteger.valueOf(((Number) outDict.get("value")).longValue()); byte[] scriptBytes = Hex.decode((String) outDict.get("script")); int confirmations = ((Number) outDict.get("confirmations")).intValue(); //Contrstuct the output MyTransactionOutPoint outPoint = new MyTransactionOutPoint(txHash, txOutputN, value, scriptBytes); outPoint.setConfirmations(confirmations); outputs.add(outPoint); } return outputs; }
From source file:pl.otros.logview.filter.MultipleSelectionFilter.java
private void invertSelection() { int[] selectedIndices = jList.getSelectedIndices(); ArrayList<Integer> inverted = new ArrayList<>(); for (int i = 0; i < listModel.getSize(); i++) { inverted.add(i);//from w w w .j a v a2 s. c o m } Arrays.sort(selectedIndices); ArrayUtils.reverse(selectedIndices); for (int selectedIndex : selectedIndices) { inverted.remove(selectedIndex); } int[] invertedArray = new int[inverted.size()]; for (int i = 0; i < inverted.size(); i++) { invertedArray[i] = inverted.get(i); } jList.setSelectedIndices(invertedArray); }
From source file:pl.otros.logview.filter.ThreadFilter.java
private void invertSelection() { int[] selectedIndices = jList.getSelectedIndices(); ArrayList<Integer> inverted = new ArrayList<Integer>(); for (int i = 0; i < listModel.getSize(); i++) { inverted.add(i);//ww w . j av a2 s . c om } Arrays.sort(selectedIndices); ArrayUtils.reverse(selectedIndices); for (int selectedIndex : selectedIndices) { inverted.remove(selectedIndex); } int[] invertedArray = new int[inverted.size()]; for (int i = 0; i < inverted.size(); i++) { invertedArray[i] = inverted.get(i); } jList.setSelectedIndices(invertedArray); }
From source file:playground.johannes.sna.util.TXTWriter.java
public static void writeMap(TDoubleDoubleHashMap map, String keyCol, String valCol, String file, boolean descending) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(keyCol);/*from w w w . ja va2s . c om*/ writer.write(TAB); writer.write(valCol); writer.newLine(); double[] keys = map.keys(); Arrays.sort(keys); if (descending) ArrayUtils.reverse(keys); for (double key : keys) { writer.write(String.valueOf(key)); writer.write(TAB); writer.write(String.valueOf(map.get(key))); writer.newLine(); } writer.close(); }
From source file:repastcity3.environment.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>/*from w w w.j a v a 2 s. co 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.destinationBuilding.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: " + destinationBuilding.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:scoring.MPScore.java
public void scoreBoard(int board) { ArrayList<BoardData> bd = bridgetournamentcontroller.BridgeTorunamentController.ac.bdata.get(board); ArrayList<Integer> MP_NS = new ArrayList<Integer>(); ArrayList<Integer> MP_EW = new ArrayList<Integer>(); boolean VULNS = false; boolean VULEW = false; int tmpPlus = 0; while (true) { if (board + tmpPlus == 1) { VULNS = false;/*w ww . j a va 2 s. co m*/ VULEW = false; break; } if (board + tmpPlus == 2) { VULNS = true; VULEW = false; break; } if (board + tmpPlus == 3) { VULNS = false; VULEW = true; break; } if (board + tmpPlus == 4) { VULNS = true; VULEW = true; break; } if (board + tmpPlus == 5) { VULNS = true; VULEW = false; break; } if (board + tmpPlus == 6) { VULNS = false; VULEW = true; break; } if (board + tmpPlus == 7) { VULNS = true; VULEW = true; break; } if (board + tmpPlus == 8) { VULNS = false; VULEW = false; break; } if (board + tmpPlus == 9) { VULNS = false; VULEW = true; break; } if (board + tmpPlus == 10) { VULNS = true; VULEW = true; break; } if (board + tmpPlus == 11) { VULNS = false; VULEW = false; break; } if (board + tmpPlus == 12) { VULNS = true; VULEW = false; break; } if (board + tmpPlus == 13) { VULNS = true; VULEW = true; break; } if (board + tmpPlus == 14) { VULNS = false; VULEW = false; break; } if (board + tmpPlus == 15) { VULNS = true; VULEW = false; break; } if (board + tmpPlus == 16) { VULNS = false; VULEW = true; break; } tmpPlus += 16; } for (int i = 0; i < bd.size(); i++) { String contract; if (bd.get(i).contractResult >= 1) contract = bd.get(i).contractSize + bd.get(i).contractType + bd.get(i).contractDeclarer + "+" + bd.get(i).contractResult; else contract = bd.get(i).contractSize + bd.get(i).contractType + bd.get(i).contractDeclarer + "" + bd.get(i).contractResult; contract.replaceAll("0", "="); int score = cs.scoreNS(contract, VULNS, VULEW, bd.get(i).contractMultiplier); if (bd.get(i).contractLine == "NS") { MP_NS.add(score); MP_EW.add(score * -1); } if (bd.get(i).contractLine == "EW") { MP_NS.add(score * -1); MP_EW.add(score); } } Integer[] scoreNS = MP_NS.toArray(new Integer[MP_NS.size()]); Arrays.sort(scoreNS); ArrayUtils.reverse(scoreNS); Integer[] scoreEW = MP_EW.toArray(new Integer[MP_EW.size()]); Arrays.sort(scoreEW); ArrayUtils.reverse(scoreEW); HashMap<Integer, Integer> MP_GIVE_NS = new HashMap<Integer, Integer>(); int MP = 0; for (int i = 0; i < scoreNS.length; i++) { for (int a = i + 1; a < scoreNS.length; a++) { if (scoreNS[i] > scoreNS[a]) MP += 2; if (scoreNS[i] == scoreNS[a]) MP += 1; } MP_GIVE_NS.put(scoreNS[i], MP); MP = 0; } HashMap<Integer, Integer> MP_GIVE_EW = new HashMap<Integer, Integer>(); MP = 0; for (int i = 0; i < scoreEW.length; i++) { for (int a = i + 1; a < scoreEW.length; a++) { if (scoreEW[i] > scoreEW[a]) MP += 2; if (scoreEW[i] == scoreEW[a]) MP += 1; } MP_GIVE_EW.put(scoreEW[i], MP); MP = 0; } System.out.println("NS"); System.out.println(Arrays.toString(scoreNS)); for (Integer name : MP_GIVE_NS.keySet()) { String key = name.toString(); String value = MP_GIVE_NS.get(name).toString(); System.out.println(key + " -> " + value); } System.out.println("EW"); System.out.println(Arrays.toString(scoreEW)); for (Integer name : MP_GIVE_EW.keySet()) { String key = name.toString(); String value = MP_GIVE_EW.get(name).toString(); System.out.println(key + " -> " + value); } for (int i = 0; i < bd.size(); i++) { int PairNS = bd.get(i).pairNS; int PairEW = bd.get(i).pairEW; String contract; if (bd.get(i).contractResult >= 1) contract = bd.get(i).contractSize + bd.get(i).contractType + bd.get(i).contractDeclarer + "+" + bd.get(i).contractResult; else contract = bd.get(i).contractSize + bd.get(i).contractType + bd.get(i).contractDeclarer + "" + bd.get(i).contractResult; contract.replaceAll("0", "="); int score = cs.scoreNS(contract, VULNS, VULEW, bd.get(i).contractMultiplier); String dec = bd.get(i).contractLine; if (dec == "NS") { double NSOLD = 0; if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairNS) != null) NSOLD = bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairNS); double EWOLD = 0; if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairEW) != null) EWOLD = bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairEW); if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairNS) != null) bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.remove(PairNS); if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairEW) != null) bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.remove(PairEW); NSOLD += MP_GIVE_NS.get(score); EWOLD += MP_GIVE_EW.get(score * -1); bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.put(PairNS, NSOLD); bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.put(PairEW, EWOLD); } if (dec == "EW") { double NSOLD = 0; if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairNS) != null) NSOLD = bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairNS); double EWOLD = 0; if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairEW) != null) EWOLD = bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairEW); if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairNS) != null) bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.remove(PairNS); if (bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.get(PairEW) != null) bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.remove(PairEW); EWOLD += MP_GIVE_EW.get(score); NSOLD += MP_GIVE_NS.get(score * -1); bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.put(PairNS, NSOLD); bridgetournamentcontroller.BridgeTorunamentController.ac.pm.score.put(PairEW, EWOLD); } } }
From source file:uk.ac.diamond.scisoft.analysis.fitting.functions.Polynomial.java
/** * Find all roots//from www . ja v a2 s . c o m * @param coeffs * @return all roots or null if there is any problem finding the roots */ public static Complex[] findRoots(double... coeffs) { double[] reverse = coeffs.clone(); ArrayUtils.reverse(reverse); double max = Double.NEGATIVE_INFINITY; for (double r : reverse) { max = Math.max(max, Math.abs(r)); } for (int i = 0; i < reverse.length; i++) { reverse[i] /= max; } org.ddogleg.solver.Polynomial p = org.ddogleg.solver.Polynomial.wrap(reverse); PolynomialRoots rf = PolynomialOps.createRootFinder(p.computeDegree(), RootFinderType.EVD); if (rf.process(p)) { // reorder to NumPy's roots output List<Complex64F> rts = rf.getRoots(); Complex[] out = new Complex[rts.size()]; int i = 0; for (Complex64F r : rts) { out[i++] = new Complex(r.getReal(), r.getImaginary()); } return sort(out); } return null; }