当前位置: 首页>>代码示例>>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;未经允许,请勿转载。