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:de.tudarmstadt.ukp.dkpro.core.io.bincas.BinaryCasReader.java
@Override public void getNext(CAS aCAS) throws IOException, CollectionException { Resource res = nextFile();/*from ww w .j a va 2s. co m*/ InputStream is = null; try { is = CompressionUtils.getInputStream(res.getLocation(), res.getInputStream()); BufferedInputStream bis = new BufferedInputStream(is); TypeSystemImpl ts = null; // Check if this is original UIMA CAS format or DKPro Core format bis.mark(10); DataInputStream dis = new DataInputStream(bis); byte[] dkproHeader = new byte[] { 'D', 'K', 'P', 'r', 'o', '1' }; byte[] header = new byte[dkproHeader.length]; dis.read(header); // If it is DKPro Core format, read the type system if (Arrays.equals(header, dkproHeader)) { ObjectInputStream ois = new ObjectInputStream(bis); CASMgrSerializer casMgrSerializer = (CASMgrSerializer) ois.readObject(); ts = casMgrSerializer.getTypeSystem(); ts.commit(); } else { bis.reset(); } if (ts == null) { // Check if this is a UIMA binary CAS stream byte[] uimaHeader = new byte[] { 'U', 'I', 'M', 'A' }; byte[] header4 = new byte[uimaHeader.length]; System.arraycopy(header, 0, header4, 0, header4.length); if (header4[0] != 'U') { ArrayUtils.reverse(header4); } // If it is not a UIMA binary CAS stream, assume it is output from // SerializedCasWriter if (!Arrays.equals(header4, uimaHeader)) { ObjectInputStream ois = new ObjectInputStream(bis); CASCompleteSerializer serializer = (CASCompleteSerializer) ois.readObject(); deserializeCASComplete(serializer, (CASImpl) aCAS); } else { // Since there was no type system, it must be type 0 or 4 deserializeCAS(aCAS, bis); } } else { // Only format 6 can have type system information deserializeCAS(aCAS, bis, ts, null); } } catch (ResourceInitializationException e) { throw new IOException(e); } catch (ClassNotFoundException e) { throw new IOException(e); } finally { closeQuietly(is); } }
From source file:com.chrischurchwell.jukeit.material.blocks.RecordPlayer.java
public RecordPlayer() { super(JukeIt.getInstance(), "Record Player", 5); //load custom designs. int n = 0;// www . j a v a 2 s.c o m //reverse the disc color values so that NONE is the first in the array DiscColor[] discs = DiscColor.values(); ArrayUtils.reverse(discs); for (DiscColor disc : discs) { for (RPNeedle needle : RPNeedle.values()) { for (RPIndicator indicator : RPIndicator.values()) { RecordPlayerDesign d = new RecordPlayerDesign(needle, disc, indicator); designIds.put(d.getDesignTypeId(), n); this.setBlockDesign(d, n); n++; } } } //load recipes setRecipe(); }
From source file:edu.stevens.cpe.reservoir.translate.HSA.java
/** * Decode the spike trains with the current filter. * @param spiketrains// w w w . j av a2 s .co m */ @Override public double[] decode(double[] spiketrains) { int width = spiketrains.length;//+ filter.length -1; double[] output = new double[width]; //Be non-invasive, make copy double[] spikes = Arrays.copyOf(spiketrains, spiketrains.length); //ArrayUtils.pad(spiketrains, filter.length, true);//new double [width]; ArrayUtils.reverse(spikes); int shiftIndex = spikes.length - 1; for (int k = 0; k < width; k++) { double sum = 0; for (int j = 0; j < filter.length; j++) { if (shiftIndex + j < spikes.length) {// && shiftIndex + j >=0 ){ sum += spikes[shiftIndex + j] * filter[j]; } else { break; } } output[k] = sum; shiftIndex--; } return output; }
From source file:io.fluo.webindex.core.models.URL.java
public static String reverseHost(String host) { String[] hostArgs = host.split("\\."); ArrayUtils.reverse(hostArgs); StringBuilder sb = new StringBuilder(); for (int i = 0; i < hostArgs.length - 1; i++) { sb.append(hostArgs[i]);//from w w w . j av a 2 s . c o m sb.append("."); } sb.append(hostArgs[hostArgs.length - 1]); if (host.endsWith(".")) { sb.append("."); } return sb.toString(); }
From source file:fr.paris.lutece.plugins.directory.web.DoRemoveAsynchronousFile.java
/** * Removes the uploaded fileItem. <br /> * This method is called by the JSP/*w w w.jav a 2 s .c o m*/ * <b>jsp/site/plugins/directory/DoRemoveFile.jsp</b> * because this method is also used in front office in other module * (module-workflow-editrecord). * @param request the request * @return JSON * @category CALLED_BY_JS (directoryupload.js) */ public String doRemoveAsynchronousUploadedFile(HttpServletRequest request) { String strSessionId = request.getSession().getId(); String strIdEntry = request.getParameter(PARAMETER_ID_ENTRY); String strFieldIndex = request.getParameter(PARAMETER_FIELD_INDEX); String strErrorMessage = I18nService.getLocalizedString(PROPERTY_MESSAGE_ERROR_REMOVING_FILE, request.getLocale()); if (StringUtils.isBlank(strIdEntry) || StringUtils.isBlank(strFieldIndex)) { return JSONUtils.buildJsonError(strErrorMessage).toString(); } // parse json JSON jsonFieldIndexes = JSONSerializer.toJSON(strFieldIndex); if (!jsonFieldIndexes.isArray()) { return JSONUtils.buildJsonError(strErrorMessage).toString(); } JSONArray jsonArrayFieldIndexers = (JSONArray) jsonFieldIndexes; int[] tabFieldIndex = new int[jsonArrayFieldIndexers.size()]; for (int nIndex = 0; nIndex < jsonArrayFieldIndexers.size(); nIndex++) { try { tabFieldIndex[nIndex] = Integer.parseInt(jsonArrayFieldIndexers.getString(nIndex)); } catch (NumberFormatException nfe) { return JSONUtils.buildJsonError(strErrorMessage).toString(); } } // inverse order (removing using index - remove greater first to keep order) Arrays.sort(tabFieldIndex); ArrayUtils.reverse(tabFieldIndex); for (int nFieldIndex : tabFieldIndex) { DirectoryAsynchronousUploadHandler.getHandler().removeFileItem(strIdEntry, strSessionId, nFieldIndex); } return JSONUtils.buildJsonSuccess(strIdEntry, strSessionId).toString(); }
From source file:me.yongshang.cbfm.test.CBFMTest.java
@Test public void testBytes() { // System.out.println(Arrays.toString("Brand#13".getBytes())); // System.out.println(Arrays.toString(", even theodolites. regular, final theodolites eat after the carefully pending foxes. furiously regular deposits sleep slyly. carefully bold realms above the ironic dependencies haggle careful".getBytes() )); System.out.println("name1: " + Arrays.toString("Jack".getBytes())); System.out.println("\t" + Arrays.toString(Binary.fromString("Jack").getBytes())); System.out.println("name2: " + Arrays.toString("Jason".getBytes())); System.out.println("name3: " + Arrays.toString("James".getBytes())); System.out.println("name4: " + Arrays.toString("Someone".getBytes())); System.out.println("name5: " + Arrays.toString("Customer#000000003".getBytes())); System.out.println("name6: " + Arrays.toString("MG9kdTD2WBHm".getBytes())); System.out.println("name7: " + Arrays.toString("11-719-748-3364".getBytes())); System.out.println("name8: " + Arrays.toString( " deposits eat slyly ironic, even instructions. express foxes detect slyly. blithely even accounts abov" .getBytes()));//from w w w . j a v a 2 s . c o m System.out.println("age1: " + Arrays.toString(ByteBuffer.allocate(4).putInt(21).array())); byte[] age1 = ByteBuffer.allocate(4).putInt(21).array(); ArrayUtils.reverse(age1); System.out.println("\t" + Arrays.toString(age1)); System.out.println("age2: " + Arrays.toString(ByteBuffer.allocate(4).putInt(35).array())); System.out.println("age3: " + Arrays.toString(ByteBuffer.allocate(4).putInt(40).array())); System.out.println("age4: " + Arrays.toString(ByteBuffer.allocate(4).putInt(35).array())); System.out.println("balance1: " + Arrays.toString(ByteBuffer.allocate(8).putDouble(1000).array())); byte[] balance1 = ByteBuffer.allocate(8).putDouble(1000).array(); ArrayUtils.reverse(balance1); System.out.println("\t" + Arrays.toString(balance1)); System.out.println("balance2: " + Arrays.toString(ByteBuffer.allocate(8).putDouble(5000).array())); System.out.println("balance3: " + Arrays.toString(ByteBuffer.allocate(8).putDouble(2000).array())); System.out.println("balance4: " + Arrays.toString(ByteBuffer.allocate(8).putDouble(3000).array())); }
From source file:com.github.gdfm.shobaidogu.StatsUtils.java
/** * Compute a proxy to Ideal Discount Cumulative Gain for a relevance vector. This method simply sorts the entries by * decreasing relevance before computing a normal DCG. * //from w ww. jav a 2s. c om * @param relevance * vector or relevance values. * @return IDCG. */ public static double[] computeIDCG(double[] relevance) { checkNotNull(relevance); checkArgument(relevance.length > 0); double[] idcg = Arrays.copyOf(relevance, relevance.length); Arrays.sort(idcg); ArrayUtils.reverse(idcg); idcg = computeDCG(idcg); return idcg; }
From source file:com.github.kuben.realshopping.Config.java
public static void initialize() { server = Bukkit.getServer();//from ww w. jav a2 s .c om if (server.getWorld("world") != null) { hellLoc = new Location(server.getWorld("world"), 0, 0, 0); jailLoc = new Location(server.getWorld("world"), 0, 0, 0); dropLoc = new Location(server.getWorld("world"), 0, 0, 0); } else { hellLoc = new Location(server.getWorlds().get(0), 0, 0, 0); jailLoc = new Location(server.getWorlds().get(0), 0, 0, 0); dropLoc = new Location(server.getWorlds().get(0), 0, 0, 0); } debug = false; cartEnabledW = new HashSet<String>(); debug = false; keepstolen = false; langpack = "default"; punishment = "none"; pstorecreate = 0.0; enableSelling = true; enableDoors = false; disableDrop = true; disableCrafting = true; disableBuckets = true; disableEnderchests = true; autoprotect = true; allowFillChests = true; enableAI = false; deliveryZones = 0; autoUpdate = 0; zoneArray = new Zone[0]; notTimespan = 10000; statTimespan = 604800; cleanStatsOld = 2592000; updateFreq = 3600; reporterPeriod = 3600; maxPendingNots = 200; maxPendingNotsPerUser = 20; File f = new File(RealShopping.MANDIR); if (!f.exists()) f.mkdir(); FileInputStream fstream; BufferedReader br; if (curVal == 2) {//Initialize Setting values from here. If curVal is something other than 2, they have already been initailized. Setting.values();//This is the first time Setting is called, hence all the settings are initialized and they render the correct orderValues. } int notInConfig = curVal - 1; try { f = new File(RealShopping.MANDIR + "realshopping.properties"); if (f.exists()) { fstream = new FileInputStream(f); br = new BufferedReader(new InputStreamReader(fstream)); String s; while ((s = br.readLine()) != null) {// Read realshopping.properties notInConfig -= readConfigLine(s); } fstream.close(); br.close(); } if (!f.exists() || notInConfig > 0) { if (!f.exists()) f.createNewFile(); PrintWriter pW = new PrintWriter( new BufferedWriter(new FileWriter(RealShopping.MANDIR + "realshopping.properties", true))); //Look for missing lines and append them to the file Setting[] vals = Setting.values(); ArrayUtils.reverse(vals);//Check for highest values first for (Setting s : vals) { if (s.orderValue > notInConfig) continue;//Continue if line is in config pW.println(s.configString + ":" + s.returnVar()); notInConfig -= s.orderValue; } pW.close(); //Read the file all over again, and save every line as reading if (notInConfig >= 1) { fstream = new FileInputStream(f); br = new BufferedReader(new InputStreamReader(fstream)); File tempF = new File(RealShopping.MANDIR + "tempproperties"); tempF.createNewFile(); pW = new PrintWriter(tempF); String s; int i = 0; while ((s = br.readLine()) != null) { if (i == 0) { pW.println("Properties file for RealShopping " + RealShopping.VERSION); pW.println("## Do not edit above line!"); pW.println("## The rest of a line after a hashtag is a comment and will be ignored."); pW.println("#"); } if (s.length() >= 33 && s.substring(0, 33).equals("Properties file for RealShopping ")) { } else if (s.length() >= 26 && s.substring(0, 26).trim().equals("## Do not edit above line!")) { } else if (s.length() >= 71 && s.substring(0, 71).trim().equals( "## The rest of a line after a hashtag is a comment and will be ignored.")) { } else if (s.length() >= 1 && s.substring(0, 1).trim().equals("#")) { } else pW.println(s); i++; } pW.close(); fstream.close(); br.close(); if (f.delete()) { if (tempF.renameTo(f)) notInConfig -= 1; else RealShopping.loginfo( "Couldn't save tempproperties as realshopping.properties (Error #202)"); } else { RealShopping .loginfo("Couldn't save tempproperties as realshopping.properties (Error #201)"); } } } } catch (FileNotFoundException e) { e.printStackTrace(); RealShopping.loginfo("Failed while reading realshopping.properties. Default properties loaded."); } catch (IOException e) { e.printStackTrace(); RealShopping.loginfo("Failed while reading realshopping.properties. Default properties loaded."); } }
From source file:com.trickl.pca.HallMarshallMartin.java
private int[] getEigenvalueSortOrder(DoubleMatrix1D eigenvalues) { int[] sortorder = new int[eigenvalues.size()]; for (int i = 0, end = eigenvalues.size(); i < end; ++i) { sortorder[i] = i;/*from w w w . j a v a2 s. co m*/ } Permutator permutator = new PairedPermutator(sortorder); sorter.setPermutator(permutator); sorter.sort(eigenvalues.toArray(), 0, eigenvalues.size()); ArrayUtils.reverse(sortorder); return sortorder; }
From source file:msi.gama.util.path.GamaSpatialPath.java
@Override public void init(final IGraph<IShape, IShape> g, final IShape start, final IShape target, final IList<? extends IShape> _edges, final boolean modify_edges) { super.init(g, start, target, _edges, modify_edges); source = start;// w w w . ja v a2 s.c o m this.target = target; this.graph = g; this.segments = GamaListFactory.create(Types.GEOMETRY); realObjects = new THashMap<>(); graphVersion = 0; final Geometry firstLine = _edges == null || _edges.isEmpty() ? null : _edges.get(0).getInnerGeometry(); GamaPoint pt = null, pt0 = null, pt1 = null; if (firstLine != null) { final GamaPoint[] firstLinePoints = GeometryUtils.getPointsOf(firstLine); pt0 = firstLinePoints[0]; pt1 = firstLinePoints[firstLinePoints.length - 1]; } if (firstLine != null && _edges != null && pt0 != null && pt1 != null) { if (_edges.size() > 1) { final IShape secondLine = _edges.get(1).getGeometry(); pt = pt0.euclidianDistanceTo(secondLine) > pt1.euclidianDistanceTo(secondLine) ? pt0 : pt1; } else { final IShape lineEnd = edges.get(edges.size() - 1); final GamaPoint falseTarget = (GamaPoint) _closest_point_to(getEndVertex().getLocation(), lineEnd); pt = start.euclidianDistanceTo(pt0) < falseTarget.euclidianDistanceTo(pt0) ? pt0 : pt1; } if (graph != null) { graphVersion = graph.getVersion(); } int cpt = 0; for (final IShape edge : _edges) { if (modify_edges) { final IAgent ag = edge instanceof IAgent ? (IAgent) edge : null; final GamaPoint[] points = getPointsOf(edge); final Geometry geom = edge.getInnerGeometry(); Geometry geom2; final GamaPoint c0 = points[0]; final GamaPoint c1 = points[points.length - 1]; IShape edge2 = null; final GamaPoint[] coords = getContourCoordinates(geom).toCoordinateArray().clone(); if ((g == null || !g.isDirected()) && pt.distance(c0) > pt.distance(c1)) { ArrayUtils.reverse(coords); pt = c0; } else { pt = c1; } final ICoordinates cc = GEOMETRY_FACTORY.getCoordinateSequenceFactory().create(coords, false); geom2 = GEOMETRY_FACTORY.createLineString(cc); // geom2 = geom.reverse(); edge2 = new GamaShape(geom2); if (cpt == 0 && !source.equals(pt)) { GamaPoint falseSource = source.getLocation().toGamaPoint(); if (source.euclidianDistanceTo(edge2) > min(0.01, edge2.getPerimeter() / 1000)) { falseSource = (GamaPoint) _closest_point_to(source, edge2); falseSource.z = zVal(falseSource, edge2); } edge2 = split_at(edge2, falseSource).get(1); } if (cpt == _edges.size() - 1 && !target.equals(edge2.getInnerGeometry() .getCoordinates()[edge2.getInnerGeometry().getNumPoints() - 1])) { GamaPoint falseTarget = target.getLocation().toGamaPoint(); if (target.euclidianDistanceTo(edge2) > Math.min(0.01, edge2.getPerimeter() / 1000)) { falseTarget = (GamaPoint) Punctal._closest_point_to(target, edge2); falseTarget.z = zVal(falseTarget, edge2); } edge2 = split_at(edge2, falseTarget).get(0); } if (ag != null) { realObjects.put(edge2.getGeometry(), ag); } else { realObjects.put(edge2.getGeometry(), edge); } segments.add(edge2.getGeometry()); } else { segments.add(edge.getGeometry()); } cpt++; // segmentsInGraph.put(agents, agents); } } }