List of usage examples for org.apache.commons.lang3 ArrayUtils reverse
public static void reverse(final boolean[] array)
Reverses the order of the given array.
This method does nothing for a null input array.
From source file:com.kdmanalytics.toif.util.MemberUtil.java
/** * find suitable resources/*from www .j a v a 2 s .c o m*/ * * @param member * @param file * @return * @throws CoreException */ public static IResource findMembers(IResource member, IFileGroup file) throws CoreException { String name = file.getName(); String path = file.getPath(); path = path.replace("\\", "/"); String[] pathArray = path.split("/"); ArrayUtils.reverse(pathArray); List<IResource> result = new ArrayList<IResource>(); List<IResource> toDo = new ArrayList<IResource>(); toDo.add(member); while (!toDo.isEmpty()) { IResource resource = toDo.remove(0); if (resource instanceof IContainer) { for (IResource iResource : ((IContainer) resource).members()) { toDo.add(iResource); } } result.add(resource); } ResourceMatch match = new ResourceMatch(); for (IResource iResource : result) { if (iResource == null) { continue; } if (iResource.getName().equals(name)) { IPath ipath = iResource.getLocation(); String stringPath = ipath.toString(); stringPath = stringPath.replace("\\", "/"); String[] resourcePathArray = stringPath.split("/"); ArrayUtils.reverse(resourcePathArray); int smallestSize = (pathArray.length < resourcePathArray.length) ? pathArray.length : resourcePathArray.length; for (int i = 0; i < smallestSize; i++) { if (pathArray[i].equals(resourcePathArray[i])) { if (i >= match.getScore()) { match = new ResourceMatch(iResource, i); } } else { break; } } } } return match.getIResource(); }
From source file:com.kdmanalytics.toif.report.internal.util.MemberUtil.java
/** * find suitable resources/*from w w w .j a va2 s . c om*/ * * @param member * @param file * @return * @throws CoreException */ public static IResource findMembers(IResource member, IFileGroup file) throws CoreException { String name = file.getName(); String path = file.getPath(); path = path.replace("\\", "/"); String[] pathArray = path.split("/"); ArrayUtils.reverse(pathArray); List<IResource> result = new ArrayList<IResource>(); List<IResource> toDo = new ArrayList<IResource>(); toDo.add(member); while (!toDo.isEmpty()) { IResource resource = toDo.remove(0); if (resource instanceof IContainer) { for (IResource iResource : ((IContainer) resource).members()) { toDo.add(iResource); } } result.add(resource); } ResourceMatch match = new ResourceMatch(); for (IResource iResource : result) { if (iResource == null) { continue; } if (iResource.getName().equals(name)) { IPath ipath = iResource.getLocation(); String stringPath = ipath.toString(); stringPath = stringPath.replace("\\", "/"); String[] resourcePathArray = stringPath.split("/"); ArrayUtils.reverse(resourcePathArray); int smallestSize = (pathArray.length < resourcePathArray.length) ? pathArray.length : resourcePathArray.length; for (int i = 0; i < smallestSize; i++) { if (pathArray[i].equals(resourcePathArray[i])) { if (i >= match.getScore()) { match = new ResourceMatch(iResource, i); System.err.println(stringPath); } } else { break; } } } } return match.getIResource(); }
From source file:flens.util.MVELUtil.java
public static String reverseHostname(String hostname) { String[] parts = hostname.split("[.]"); ArrayUtils.reverse(parts); return StringUtils.join(parts, "."); }
From source file:com.kotcrab.vis.editor.module.physicseditor.util.Clipper.java
public static Vector2[][] polygonize(Polygonizer polygonizer, Vector2[] points) { Vector2[][] polygons = null;// ww w . j av a2s . c om if (PolygonUtils.isPolygonCCW(points)) ArrayUtils.reverse(points); switch (polygonizer) { case EWJORDAN: polygons = EwjordanDecomposer.decompose(points); break; case BAYAZIT: Array<Vector2> tmpPoints = new Array<Vector2>(points.length); tmpPoints.addAll(points); Array<Array<Vector2>> tmpPolygons; try { tmpPolygons = BayazitDecomposer.ConvexPartition(tmpPoints); } catch (Exception ex) { tmpPolygons = null; } if (tmpPolygons != null) { polygons = new Vector2[tmpPolygons.size][]; for (int i = 0; i < tmpPolygons.size; i++) { polygons[i] = new Vector2[tmpPolygons.get(i).size]; for (int ii = 0; ii < tmpPolygons.get(i).size; ii++) polygons[i][ii] = new Vector2(tmpPolygons.get(i).get(ii)); } } break; } if (polygons != null) polygons = sliceForMax8Vertices(polygons); return polygons; }
From source file:com.joyent.manta.client.PruneEmpytParentDirectoryStrategy.java
/** * This will delete empty parent directories up to the root. * * @param client - A valid client.//from w ww .j a v a2 s. c o m * @param path - THe complete path that you want to start with. * @param limit - The limit of directories to delete. * @throws IOException - this is thrown from */ static void pruneParentDirectories(final MantaClient client, final MantaHttpHeaders headers, final String path, final int limit) throws IOException { // First thing first, delete the child directory. client.delete(path, headers, null); // Generating all parent paths. String[] directories = MantaUtils.writeablePrefixPaths(path); ArrayUtils.reverse(directories); // Removing first element, because we have already deleted it. directories = ArrayUtils.remove(directories, 0); int actualLimit = limit; if (actualLimit > directories.length || actualLimit == PRUNE_ALL_PARENTS) { actualLimit = directories.length; } for (int i = 0; i < actualLimit; i++) { try { LOG.debug("************ Deleting Index : " + i + " name " + directories[i]); client.delete(directories[i], headers, null); } catch (MantaClientHttpResponseException responseException) { if (responseException.getServerCode().equals(MantaErrorCode.RESOURCE_NOT_FOUND_ERROR)) { continue; } else if (responseException.getServerCode() != MantaErrorCode.DIRECTORY_NOT_EMPTY_ERROR) { throw responseException; } } } }
From source file:com.aqnote.app.wifianalyzer.wifi.model.WiFiUtils.java
public static String convertIpAddress(int ipAddress) { try {//from w w w . j a va 2s . com byte[] bytes = BigInteger.valueOf(ipAddress).toByteArray(); ArrayUtils.reverse(bytes); return InetAddress.getByAddress(bytes).getHostAddress(); } catch (Exception e) { return StringUtils.EMPTY; } }
From source file:com.denimgroup.threadfix.util.SimilarityCalculator.java
public static int calculateSimilarity(@NotNull String filePath1, @NotNull String filePath2) { String cleaned1 = filePath1.replaceAll("\\\\", "/"); String cleaned2 = filePath2.replaceAll("\\\\", "/"); String[] filePath1Split = cleaned1.split("/"); String[] filePath2Split = cleaned2.split("/"); if (cleaned1.equals(cleaned2)) { return filePath1Split.length; }/*from w w w.jav a 2 s. co m*/ ArrayUtils.reverse(filePath1Split); ArrayUtils.reverse(filePath2Split); int index = 0; for (; index < filePath1Split.length; index++) { if (index > filePath2Split.length - 1) { break; } if (!filePath1Split[index].equals(filePath2Split[index])) { break; } } return index; }
From source file:eu.operando.operandoapp.wifi.model.WiFiUtils.java
public static String convertIpAddress(int ipAddress) { byte[] bytes = BigInteger.valueOf(ipAddress).toByteArray(); ArrayUtils.reverse(bytes); try {//from w w w . j a v a2 s . c o m return InetAddress.getByAddress(bytes).getHostAddress(); } catch (UnknownHostException e) { return StringUtils.EMPTY; } }
From source file:com.codebutler.farebot.card.desfire.files.ValueDesfireFile.java
ValueDesfireFile(int fileId, DesfireFileSettings fileSettings, byte[] fileData) { super(fileId, fileSettings, fileData); byte[] myData = ArrayUtils.clone(fileData); ArrayUtils.reverse(myData); mValue = Utils.byteArrayToInt(myData); }
From source file:com.codebutler.farebot.card.desfire.settings.StandardDesfireFileSettings.java
StandardDesfireFileSettings(ByteArrayInputStream stream) { super(stream); byte[] buf = new byte[3]; stream.read(buf, 0, buf.length);/*from w w w . j a va 2 s. c om*/ ArrayUtils.reverse(buf); mFileSize = Utils.byteArrayToInt(buf); }