當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayUtils.indexOf方法代碼示例

本文整理匯總了Java中org.apache.commons.lang.ArrayUtils.indexOf方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayUtils.indexOf方法的具體用法?Java ArrayUtils.indexOf怎麽用?Java ArrayUtils.indexOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang.ArrayUtils的用法示例。


在下文中一共展示了ArrayUtils.indexOf方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: removeValueInArray

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * removes elements equal to a specified value from an original array.
 * 
 * @param tmparray
 *            the original integer array.
 * @param remVal
 *            the value to be removed.
 * @return subset of the original array (with out elements equal to the
 *         specified value)
 */
public static int[] removeValueInArray(int[] tmparray, int remVal) {
	int[] finarray = null;
	if (tmparray == null) {
		return finarray;
       }
	int[] idxVal = null;
	for (int i = 0; i < tmparray.length; i++) {
		if (tmparray[i] == remVal) {
			idxVal = ArrayUtils.add(idxVal, i);
           }
       }
	if (idxVal == null) {
		return tmparray;
       }
	int[] idxRemain = null;
	for (int i = 0; i < tmparray.length; i++) {
		if (ArrayUtils.indexOf(idxVal, i) == -1) {
			idxRemain = ArrayUtils.add(idxRemain, i);
           }
       }

	if (idxRemain == null) {
		return finarray;
       }

	finarray = extractArray(tmparray, idxRemain);

	return finarray;
}
 
開發者ID:smart-facility,項目名稱:calendar-based-microsim,代碼行數:40,代碼來源:ArrayHandler.java

示例2: hostFromSchemeAndAuthority

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/** Extracts the host part from a scheme+authority by removing the scheme, the user info and the port number.
 *
 * @param schemeAuthority a scheme+authority.
 * @return the host part.
 */
public static String hostFromSchemeAndAuthority(final byte[] schemeAuthority){
	final int length = schemeAuthority.length;
	final int startOfAuthority = ArrayUtils.indexOf(schemeAuthority, (byte)':') + 3;
	int atPosition;
	for(atPosition = startOfAuthority; atPosition < length; atPosition++) if (schemeAuthority[atPosition] == (byte)'@') break;
	final int startOfHost = atPosition != length ? atPosition + 1 : startOfAuthority;

	int endOfHost;
	for(endOfHost = startOfHost; endOfHost < length; endOfHost++) if (schemeAuthority[endOfHost] == (byte)':') break;
	final char[] host = new char[endOfHost - startOfHost];
	for(int i = startOfHost; i < endOfHost; i++) host[i - startOfHost] = (char)schemeAuthority[i];
	return new String(host);
}
 
開發者ID:LAW-Unimi,項目名稱:BUbiNG,代碼行數:19,代碼來源:BURL.java

示例3: startOfHost

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/** Finds the start of the host part in a URL.
 *
 * @param url a byte-array representation of a BUbiNG URL.
 * @return the starting position of the host in the given url.
 */
public static final int startOfHost(final byte[] url) {
	final int startOfAuthority = ArrayUtils.indexOf(url, (byte)':') + 3;
	final int endOfAuthority = ArrayUtils.indexOf(url, (byte)'/', startOfAuthority);
	int atPosition;
	for(atPosition = startOfAuthority; atPosition < endOfAuthority; atPosition++) if (url[atPosition] == (byte)'@') break;
	return atPosition != endOfAuthority ? atPosition + 1 : startOfAuthority;
}
 
開發者ID:LAW-Unimi,項目名稱:BUbiNG,代碼行數:13,代碼來源:BURL.java

示例4: testClusterRegionLocations

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
@Test (timeout=180000)
public void testClusterRegionLocations() {
  // tests whether region locations are handled correctly in Cluster
  List<ServerName> servers = getListOfServerNames(randomServers(10, 10));
  List<HRegionInfo> regions = randomRegions(101);
  Map<ServerName, List<HRegionInfo>> clusterState = new HashMap<ServerName, List<HRegionInfo>>();

  assignRegions(regions, servers, clusterState);

  // mock block locality for some regions
  RegionLocationFinder locationFinder = mock(RegionLocationFinder.class);
  // block locality: region:0   => {server:0}
  //                 region:1   => {server:0, server:1}
  //                 region:42 => {server:4, server:9, server:5}
  when(locationFinder.getTopBlockLocations(regions.get(0))).thenReturn(
    Lists.newArrayList(servers.get(0)));
  when(locationFinder.getTopBlockLocations(regions.get(1))).thenReturn(
    Lists.newArrayList(servers.get(0), servers.get(1)));
  when(locationFinder.getTopBlockLocations(regions.get(42))).thenReturn(
    Lists.newArrayList(servers.get(4), servers.get(9), servers.get(5)));
  when(locationFinder.getTopBlockLocations(regions.get(43))).thenReturn(
    Lists.newArrayList(ServerName.valueOf("foo", 0, 0))); // this server does not exists in clusterStatus

  BaseLoadBalancer.Cluster cluster = new Cluster(clusterState, null, locationFinder, null);

  int r0 = ArrayUtils.indexOf(cluster.regions, regions.get(0)); // this is ok, it is just a test
  int r1 = ArrayUtils.indexOf(cluster.regions, regions.get(1));
  int r10 = ArrayUtils.indexOf(cluster.regions, regions.get(10));
  int r42 = ArrayUtils.indexOf(cluster.regions, regions.get(42));
  int r43 = ArrayUtils.indexOf(cluster.regions, regions.get(43));

  int s0 = cluster.serversToIndex.get(servers.get(0).getHostAndPort());
  int s1 = cluster.serversToIndex.get(servers.get(1).getHostAndPort());
  int s4 = cluster.serversToIndex.get(servers.get(4).getHostAndPort());
  int s5 = cluster.serversToIndex.get(servers.get(5).getHostAndPort());
  int s9 = cluster.serversToIndex.get(servers.get(9).getHostAndPort());

  // region 0 locations
  assertEquals(1, cluster.regionLocations[r0].length);
  assertEquals(s0, cluster.regionLocations[r0][0]);

  // region 1 locations
  assertEquals(2, cluster.regionLocations[r1].length);
  assertEquals(s0, cluster.regionLocations[r1][0]);
  assertEquals(s1, cluster.regionLocations[r1][1]);

  // region 10 locations
  assertEquals(0, cluster.regionLocations[r10].length);

  // region 42 locations
  assertEquals(3, cluster.regionLocations[r42].length);
  assertEquals(s4, cluster.regionLocations[r42][0]);
  assertEquals(s9, cluster.regionLocations[r42][1]);
  assertEquals(s5, cluster.regionLocations[r42][2]);

  // region 43 locations
  assertEquals(1, cluster.regionLocations[r43].length);
  assertEquals(-1, cluster.regionLocations[r43][0]);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:60,代碼來源:TestBaseLoadBalancer.java

示例5: isCauseMethodName

import org.apache.commons.lang.ArrayUtils; //導入方法依賴的package包/類
/**
 * <p>Tests if the list of method names used in the search for <code>Throwable</code>
 * objects include the given name.</p>
 * 
 * @param methodName  the methodName to search in the list.
 * @return if the list of method names used in the search for <code>Throwable</code>
 *  objects include the given name.
 * @since 2.1
 */
public static boolean isCauseMethodName(String methodName) {
    synchronized(CAUSE_METHOD_NAMES_LOCK) {
        return ArrayUtils.indexOf(CAUSE_METHOD_NAMES, methodName) >= 0;
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:ExceptionUtils.java


注:本文中的org.apache.commons.lang.ArrayUtils.indexOf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。