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

The following are Jave code examples for showing how to use indexOf() of the org.apache.commons.lang.ArrayUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: calendar-based-microsim   File: ArrayHandler.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 2
Project: BUbiNG   File: BURL.java   View Source Code Vote up 5 votes
/** 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);
}
 
Example 3
Project: BUbiNG   File: BURL.java   View Source Code Vote up 5 votes
/** 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;
}
 
Example 4
Project: ditb   File: TestBaseLoadBalancer.java   View Source Code Vote up 4 votes
@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]);
}
 
Example 5
Project: lams   File: ExceptionUtils.java   View Source Code Vote up 2 votes
/**
 * <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;
    }
}