Java Code Examples for org.apache.commons.lang.ArrayUtils#reverse()

The following examples show how to use org.apache.commons.lang.ArrayUtils#reverse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 7 votes vote down vote up
protected GenericResponse call(GenericRequest genericRequest) throws TechnicalConnectorException {
   SOAPConnection conn = null;
   Handler[] chain = genericRequest.getHandlerchain();

   GenericResponse var6;
   try {
      SOAPMessageContext request = this.createSOAPMessageCtx(genericRequest);
      request.putAll(genericRequest.getRequestMap());
      request.put("javax.xml.ws.handler.message.outbound", true);
      executeHandlers(chain, request);
      conn = scf.createConnection();
      SOAPMessageContext reply = createSOAPMessageCtx(conn.call(request.getMessage(), generateEndpoint(request)));
      reply.putAll(genericRequest.getRequestMap());
      reply.put("javax.xml.ws.handler.message.outbound", false);
      ArrayUtils.reverse(chain);
      executeHandlers(chain, reply);
      var6 = new GenericResponse(reply.getMessage());
   } catch (Exception var10) {
      throw translate(var10);
   } finally {
      ConnectorIOUtils.closeQuietly((Object)conn);
   }

   return var6;
}
 
Example 2
Source File: CSVApisUtil.java    From sofa-acts with Apache License 2.0 6 votes vote down vote up
/**
 * get .csv file path based on the class
 *
 * @param objClass
 * @param csvPath
 * @return
 */
private static String getCsvFileName(Class<?> objClass, String csvPath) {

    if (isWrapClass(objClass)) {
        LOG.warn("do nothing when simple type");
        return null;
    }
    String[] paths = csvPath.split("/");
    ArrayUtils.reverse(paths);

    String className = objClass.getSimpleName() + ".csv";

    if (!StringUtils.equals(className, paths[0])) {
        csvPath = StringUtils.replace(csvPath, paths[0], className);
    }

    return csvPath;
}
 
Example 3
Source File: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
protected GenericResponse call(GenericRequest genericRequest) throws TechnicalConnectorException {
   SOAPConnection conn = null;
   Handler[] chain = genericRequest.getHandlerchain();

   GenericResponse var6;
   try {
      SOAPMessageContext request = this.createSOAPMessageCtx(genericRequest);
      request.putAll(genericRequest.getRequestMap());
      request.put("javax.xml.ws.handler.message.outbound", true);
      executeHandlers(chain, request);
      conn = scf.createConnection();
      SOAPMessageContext reply = createSOAPMessageCtx(conn.call(request.getMessage(), generateEndpoint(request)));
      reply.putAll(genericRequest.getRequestMap());
      reply.put("javax.xml.ws.handler.message.outbound", false);
      ArrayUtils.reverse(chain);
      executeHandlers(chain, reply);
      var6 = new GenericResponse(reply.getMessage());
   } catch (Exception var10) {
      throw translate(var10);
   } finally {
      ConnectorIOUtils.closeQuietly((Object)conn);
   }

   return var6;
}
 
Example 4
Source File: SliceNDGenerator.java    From dawnsci with Eclipse Public License 1.0 6 votes vote down vote up
private static int[] getDimensionSortingArray(final int rank, final int[] incrementOrder) {
	final int[] full = new int[rank];
	int[] rev = incrementOrder.clone();
	ArrayUtils.reverse(rev);
	
	for (int i = rank-1,j = 0; i > 0; i--) {
		if (!ArrayUtils.contains(incrementOrder, i)) {
			full[j++] = i;
		}
	}
	
	for (int i = rank - incrementOrder.length; i < rank; i++) {
		full[i] = rev[incrementOrder.length+i-rank];
	}
	
	return full;
}
 
Example 5
Source File: ThreadFilter.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
private void invertSelection() {
  int[] selectedIndices = jList.getSelectedIndices();
  ArrayList<Integer> inverted = new ArrayList<>();
  for (int i = 0; i < listModel.getSize(); i++) {
    inverted.add(i);
  }
  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);
}
 
Example 6
Source File: SnapshotObjectTO.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
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());
    }

    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;
}
 
Example 7
Source File: UncompressedBitmap.java    From systemds with Apache License 2.0 5 votes vote down vote up
public void sortValuesByFrequency() {
	int numVals = getNumValues();
	int numCols = getNumColumns();

	double[] freq = new double[numVals];
	int[] pos = new int[numVals];

	// populate the temporary arrays
	for(int i = 0; i < numVals; i++) {
		freq[i] = getNumOffsets(i);
		pos[i] = i;
	}

	// sort ascending and reverse (descending)
	SortUtils.sortByValue(0, numVals, freq, pos);
	ArrayUtils.reverse(pos);

	// create new value and offset list arrays
	double[] lvalues = new double[numVals * numCols];
	IntArrayList[] loffsets = new IntArrayList[numVals];
	for(int i = 0; i < numVals; i++) {
		System.arraycopy(_values, pos[i] * numCols, lvalues, i * numCols, numCols);
		loffsets[i] = _offsetsLists[pos[i]];
	}
	_values = lvalues;
	_offsetsLists = loffsets;
}
 
Example 8
Source File: CSVHelper.java    From sofa-acts with Apache License 2.0 5 votes vote down vote up
/**
 * get csv name
 *
 * @param objClass
 * @param csvPath
 * @return
 */
public static String getCsvFileName(Class<?> objClass, String csvPath) {

    String[] paths = csvPath.split("/");
    ArrayUtils.reverse(paths);

    String className = objClass.getSimpleName() + ".csv";

    if (!StringUtils.equals(className, paths[0])) {
        csvPath = StringUtils.replace(csvPath, paths[0], className);
    }

    return csvPath;
}
 
Example 9
Source File: GamaCoordinateSequence.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Turns this sequence of coordinates into a clockwise orientation. Only done for rings (as it may change the
 * definition of line strings)
 *
 * @param points
 * @return
 */
@Override
public void ensureClockwiseness() {
	if (!isRing(points)) { return; }
	if (signedArea(points) <= 0) {
		ArrayUtils.reverse(points);
	}
}
 
Example 10
Source File: CmsVoteTopicAct.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@RequestMapping("/vote_topic/o_update.do")
public String update(CmsVoteTopic bean,Integer[] subPriority,Integer[] subTopicId,
		String[] itemTitle, Integer[] itemVoteCount,
		Integer[] itemPriority, Integer pageNo, HttpServletRequest request,
		ModelMap model) {
	WebErrors errors = validateUpdate(bean.getId(), request);
	if (errors.hasErrors()) {
		return errors.showErrorPage(model);
	}
	ArrayUtils.reverse(subPriority);
	ArrayUtils.reverse(subTopicId);
	List<String>subTitleList=getSubTitlesParam(request);
	List<Integer>subTypeIds=getSubTypeIdsParam(request);
//	Integer[]subPrioritys=getSubPrioritysParam(request);
	Set<CmsVoteSubTopic>subTopics=getSubTopics(subTopicId, subTitleList,subPriority, subTypeIds);
	bean = manager.update(bean);
	subTopicMng.update(subTopics,bean);
	List<List<CmsVoteItem>>voteItems=getSubtopicItems(itemTitle, itemVoteCount, itemPriority);
	List<CmsVoteSubTopic>subTopicSet=subTopicMng.findByVoteTopic(bean.getId());
	for(int i=0;i<voteItems.size();i++){
		if(voteItems.get(i).size()<=0){
			voteItems.remove(i);
		}
	}
	for(int i=0;i<subTopicSet.size();i++){
		CmsVoteSubTopic voteSubTopic= subTopicSet.get(i);
		if(voteSubTopic.getType()!=3&&voteItems.size()>=subTopicSet.size()){
			voteItemMng.update(voteItems.get(i),voteSubTopic);
		}
	}
	log.info("update CmsVoteTopic id={}.", bean.getId());
	cmsLogMng.operating(request, "cmsVoteTopic.log.update", "id="
			+ bean.getId() + ";title=" + bean.getTitle());
	return list(pageNo, request, model);
}
 
Example 11
Source File: EthereumUtil.java    From hadoopcryptoledger with Apache License 2.0 5 votes vote down vote up
private static long convertIndicatorToRLPSize(byte[] indicator) {
	byte[] rawDataNumber= Arrays.copyOfRange(indicator, 1, indicator.length);
	ArrayUtils.reverse(rawDataNumber);
	long RLPSize = 0;
	for (int i=0;i<rawDataNumber.length;i++) {
		RLPSize += (rawDataNumber[i] & 0xFF) * Math.pow(256, i);
	}
	return RLPSize;
}
 
Example 12
Source File: PrintUtils.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public static String reverseHex(final String input) {
	final String[] chunked = new String[input.length() / 2];
	int position = 0;
	for (int i = 0; i < input.length(); i += 2) {
		chunked[position] = input.substring(position * 2, position * 2 + 2);
		++position;
	}
	ArrayUtils.reverse((Object[]) chunked);
	return StringUtils.join((Object[]) chunked);
}
 
Example 13
Source File: ColumnGroupPartitionerBinPacking.java    From systemds with Apache License 2.0 5 votes vote down vote up
@Override
public List<int[]> partitionColumns(List<Integer> groupCols, HashMap<Integer, GroupableColInfo> groupColsInfo) {
	// obtain column weights
	int[] items = new int[groupCols.size()];
	double[] itemWeights = new double[groupCols.size()];
	for(int i = 0; i < groupCols.size(); i++) {
		int col = groupCols.get(i);
		items[i] = col;
		itemWeights[i] = groupColsInfo.get(col).cardRatio;
	}

	// run first fit heuristic over sequences of at most MAX_COL_FIRST_FIT
	// items to ensure robustness for matrices with many columns due to O(n^2)
	List<IntArrayList> bins = new ArrayList<>();
	for(int i = 0; i < items.length; i += MAX_COL_FIRST_FIT) {
		// extract sequence of items and item weights
		int iu = Math.min(i + MAX_COL_FIRST_FIT, items.length);
		int[] litems = Arrays.copyOfRange(items, i, iu);
		double[] litemWeights = Arrays.copyOfRange(itemWeights, i, iu);

		// sort items (first fit decreasing)
		if(FIRST_FIT_DEC) {
			SortUtils.sortByValue(0, litems.length, litemWeights, litems);
			ArrayUtils.reverse(litems);
			ArrayUtils.reverse(litemWeights);
		}

		// partition columns via bin packing
		bins.addAll(packFirstFit(litems, litemWeights));
	}

	// extract native int arrays for individual bins
	return bins.stream().map(b -> b.extractValues(true)).collect(Collectors.toList());
}
 
Example 14
Source File: UncompressedBitmap.java    From systemds with Apache License 2.0 5 votes vote down vote up
public void sortValuesByFrequency() {
	int numVals = getNumValues();
	int numCols = getNumColumns();
	
	double[] freq = new double[numVals];
	int[] pos = new int[numVals];
	
	//populate the temporary arrays
	for(int i=0; i<numVals; i++) {
		freq[i] = getNumOffsets(i);
		pos[i] = i;
	}
	
	//sort ascending and reverse (descending)
	SortUtils.sortByValue(0, numVals, freq, pos);
	ArrayUtils.reverse(pos);
	
	//create new value and offset list arrays
	double[] lvalues = new double[numVals*numCols];
	IntArrayList[] loffsets = new IntArrayList[numVals];
	for(int i=0; i<numVals; i++) {
		System.arraycopy(_values, pos[i]*numCols, lvalues, i*numCols, numCols);
		loffsets[i] = _offsetsLists[pos[i]];
	}
	_values = lvalues;
	_offsetsLists = loffsets;
}
 
Example 15
Source File: PsiUtils.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
private static @NotNull
Optional<PsiDirectory> getDirectoryWithRootPackageFor(final @NotNull PsiJavaFile file) {
    String packageName = file.getPackageName();
    String[] packageSequence;

    if ("".equals(packageName)) {
        packageSequence = new String[0];
    } else {
        packageSequence = packageName.split("\\.");
    }

    ArrayUtils.reverse(packageSequence);

    PsiDirectory directory = file.getParent();
    if (directory == null) {
        throw new IllegalStateException("File has no parent directory");
    }

    for (String packagePart : packageSequence) {
        if (!packagePart.equals(directory.getName())) {
            return Optional.empty();
        }

        directory = directory.getParentDirectory();
        if (directory == null) {
            return Optional.empty();
        }
    }

    return Optional.of(directory);
}
 
Example 16
Source File: EthereumUtil.java    From hadoopcryptoledger with Apache License 2.0 4 votes vote down vote up
private static byte[] encodeRLPList(List<byte[]> rawElementList) {
	byte[] result;
	int totalSize=0;
	if ((rawElementList==null) || (rawElementList.size()==0)) {
		return new byte[] {(byte) 0xc0};
	}
	for (int i=0;i<rawElementList.size();i++) {
		totalSize+=rawElementList.get(i).length;
	}
	int currentPosition=0;
	if (totalSize<=55) {
		result = new byte[1+totalSize];
		result[0]=(byte) (0xc0+totalSize);
		currentPosition=1;
	} else {
		ByteBuffer bb = ByteBuffer.allocate(4);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		bb.putInt(totalSize);
		byte[] intArray = bb.array();
		int intSize=0;
		for (int i=0;i<intArray.length;i++) {
			if (intArray[i]==0) {
				break;
			} else {
				intSize++;
			}
		}
		 result = new byte[1+intSize+totalSize];
		 result[0]=(byte) (0xf7+intSize);
		 byte[] rawDataNumber= Arrays.copyOfRange(intArray, 0, intSize);
			ArrayUtils.reverse(rawDataNumber);
		
			for (int i=0;i<rawDataNumber.length;i++) {
			
				result[1+i]=rawDataNumber[i];
			}
	
		 currentPosition=1+intSize;
	}
	// copy list items
	for (int i=0;i<rawElementList.size();i++) {
		byte[] currentElement=rawElementList.get(i);
		for (int j=0;j<currentElement.length;j++) {
			result[currentPosition]=currentElement[j];
			currentPosition++;
		}
	}
	return result;
}
 
Example 17
Source File: OrderByTest.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * Ensure that results are returned in the correct descending order, when specified
 * 1. Insert a number of entities and add them to an array
 * 2. Query for the entities in descending order
 * 3. Validate that the order is correct
 *
 * @throws IOException
 */
@Test
public void orderByReturnCorrectResults() throws IOException {

    String collectionName = "peppers";
    int size = 20;
    Entity[] entities = new Entity[size];

    Entity actor = new Entity();
    actor.put("displayName", "Erin");
    Entity props = new Entity();
    props.put("actor", actor);
    props.put("verb", "go");
    props.put("content", "bragh");
    //1. Insert a number of entities and add them to an array
    for (int i = 0; i < size; i++) {
        props.put("ordinal", i);
        Entity e = this.app().collection(collectionName).post(props);
        entities[i] = e;
        logger.info(String.valueOf(e.get("uuid").toString()));
        logger.info(String.valueOf(Long.parseLong(entities[0].get("created").toString())));
    }

    waitForQueueDrainAndRefreshIndex(750);


    ArrayUtils.reverse(entities);
    long lastCreated = Long.parseLong(entities[0].get("created").toString());
    //2. Query for the entities in descending order
    String errorQuery = String.format("select * where created <= %d order by created desc", lastCreated);
    int index = 0;

    QueryParameters params = new QueryParameters().setQuery(errorQuery);
    Collection coll = this.app().collection(collectionName).get(params);
    //3. Validate that the order is correct
    do {
        int returnSize = coll.getResponse().getEntityCount();
        //loop through the current page of results
        for (int i = 0; i < returnSize; i++, index++) {
            assertEquals( ( entities[index] ).get( "uuid" ).toString(),
                coll.getResponse().getEntities().get(i).get("uuid").toString());
        }
        //grab the next page of results
        coll = this.app().collection(collectionName).getNextPage(coll, params, true);
    }
    while (coll.getCursor() != null);
}
 
Example 18
Source File: SortOrderFIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static Object[][] reverse(Object[][] rows) {
    Object[][] reversedArray = new Object[rows.length][];
    System.arraycopy(rows, 0, reversedArray, 0, rows.length);
    ArrayUtils.reverse(reversedArray);
    return reversedArray;
}
 
Example 19
Source File: DescColumnSortOrderTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static Object[][] reverse(Object[][] rows) {
    Object[][] reversedArray = new Object[rows.length][];
    System.arraycopy(rows, 0, reversedArray, 0, rows.length);
    ArrayUtils.reverse(reversedArray);
    return reversedArray;
}
 
Example 20
Source File: HologramFrame.java    From ProjectAres with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Creates a new {@link HologramFrame} with the specified content.
 *
 * @param content The content to be displayed
 */
public HologramFrame(String... content) {
    ArrayUtils.reverse(content);
    this.content = Arrays.asList(content);
}