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


Java Arrays.binarySearch方法代碼示例

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


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

示例1: nearest

import java.util.Arrays; //導入方法依賴的package包/類
public int nearest (int line, boolean backward) {
    if (isEmpty()) {
        return -1;
    }
    if (last == 0) {
        return keys[last];
    }
    if (line < keys[0]) {
        return backward ? keys[last] : keys[0];
    }
    if (line > keys[last]) {
        return backward ? keys[last] : keys[0];
    }
    int idx = Arrays.binarySearch(keys, line);
    if (idx < 0) {
        idx = -idx + (backward ? -2 :- 1);
        if (idx > last) {
            idx = backward ? last : 0;
        } else if (idx < 0) {
            idx = backward ? last : 0;
        }
    }
    return keys[idx];
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:IntMap.java

示例2: retainAll

import java.util.Arrays; //導入方法依賴的package包/類
/** {@inheritDoc} */
public boolean retainAll( int[] array ) {
    boolean changed = false;
    Arrays.sort( array );
    int[] set = _set;
    byte[] states = _states;

    _autoCompactTemporaryDisable = true;
    for ( int i = set.length; i-- > 0; ) {
        if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) {
            removeAt( i );
            changed = true;
        }
    }
    _autoCompactTemporaryDisable = false;

    return changed;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:19,代碼來源:TIntHashSet.java

示例3: getDx

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Returns the first derivation at x.
 * 
 * @param x
 * @return the first derivation at x
 */
public double getDx(double x) {
  if (len.length == 0 || len.length == 1) {
    return 0;
  }

  int index = Arrays.binarySearch(len, x);
  if (index < 0) {
    index = -(index + 1) - 1;
  }

  return b[index] + 2 * c[index] * (x - len[index]) + 3 * d[index] * Math.pow(x - len[index], 2);
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:19,代碼來源:mxSpline1D.java

示例4: forNamePrimitive

import java.util.Arrays; //導入方法依賴的package包/類
protected static Class forNamePrimitive(String name) {
    if (name.length() <= 8) {
        int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);
        if (p >= 0) {
            return PRIMITIVES[p];
        }
    }
    return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:ReflectionUtil.java

示例5: hasRole

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Does the user represented by this Principal possess the specified role?
 *
 * @param role Role to be tested
 */
public boolean hasRole(String role) {

    if("*".equals(role)) // Special 2.4 role meaning everyone
        return true;
    if (role == null)
        return (false);
    return (Arrays.binarySearch(roles, role) >= 0);

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:15,代碼來源:GenericPrincipal.java

示例6: printAll

import java.util.Arrays; //導入方法依賴的package包/類
public static void printAll(int[] a) {
    int N = a.length;
    Arrays.sort(a);
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int k = Arrays.binarySearch(a, -(a[i] + a[j]));
            if (k > j) StdOut.println(a[i] + " " + a[j] + " " + a[k]);
        }
    }
}
 
開發者ID:wz12406,項目名稱:accumulate,代碼行數:11,代碼來源:ThreeSumFast.java

示例7: count

import java.util.Arrays; //導入方法依賴的package包/類
public static int count(int[] a) {
    int N = a.length;
    Arrays.sort(a);
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int k = Arrays.binarySearch(a, -(a[i] + a[j]));
            if (k > j) cnt++;
        }
    }
    return cnt;
}
 
開發者ID:wz12406,項目名稱:accumulate,代碼行數:13,代碼來源:ThreeSumFast.java

示例8: getFrameForTimestampMs

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Gets the frame index for specified timestamp.
 *
 * @param frameTimestampsMs an array of timestamps generated by {@link #getFrameForTimestampMs)}
 * @param timestampMs the timestamp
 * @return the frame index for the timestamp or the last frame number if the timestamp is outside
 *    the duration of the entire animation
 */
public int getFrameForTimestampMs(int frameTimestampsMs[], int timestampMs) {
  int index = Arrays.binarySearch(frameTimestampsMs, timestampMs);
  if (index < 0) {
    return -index - 1 - 1;
  } else {
    return index;
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:AnimatedDrawableUtil.java

示例9: commandStartIndex

import java.util.Arrays; //導入方法依賴的package包/類
@Override
int commandStartIndex() {
  int start = Arrays.binarySearch(mCommandMaxBottom, mClippingRect.left);
  // We don't care whether we matched or not, but positive indices are helpful. The binary search
  // returns ~index in the case that it isn't a match, so reverse that here.
  return start < 0 ? ~start : start;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:8,代碼來源:HorizontalDrawCommandManager.java

示例10: setZoom

import java.util.Arrays; //導入方法依賴的package包/類
public void setZoom(double z) {
  if (z <= 0.0) {
    // This should never happen, it's just a kludge to make sure that
    // we continue having valid data even if our caller is wrong.
    z = Double.MIN_VALUE;
  }

  cur = Arrays.binarySearch(levels, z);
  if (cur < 0) {
    // if z is not a level, set cur to the next level > z
    cur = -cur-1;

    // check whether we are close to a level
    if (cur < levels.length && Math.abs(z - levels[cur]) < 0.005) {
      custom = -1;
    }
    else if (cur > 0 && Math.abs(z - levels[cur-1]) < 0.005) {
      --cur;
      custom = -1;
    }
    else {
      custom = z;
    }
  }
  else {
    // custom is negative when we are in a predefined zoom level
    custom = -1;
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:30,代碼來源:Zoomer.java

示例11: nextEntry

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Get the key which follows the passed key, or -1.  Will wrap around 0.
 */
public int nextEntry (int entry) {
    int result = -1;
    if (!isEmpty()) {
        int idx = Arrays.binarySearch (keys, entry);
        if (idx >= 0) {
            result = idx == keys.length -1 ? keys[0] : keys[idx+1];
        }
    }
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:IntMap.java

示例12: doTestEntityOrdering

import java.util.Arrays; //導入方法依賴的package包/類
private void doTestEntityOrdering(boolean computeInsertionPoint) throws Exception {
	Entity e = new Entity(MacAddress.of(10L), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
	IEntityClass ec = createNiceMock(IEntityClass.class);
	Device d = new Device(deviceManager, 1L, e, ec);

	int expectedLength = 1;
	Long[] macs = new Long[] {  5L,  // new first element
			15L,  // new last element
			7L,  // insert in middle
			12L,  // insert in middle
			6L,  // insert at idx 1
			14L,  // insert at idx length-2
			1L,
			20L
	};

	for (Long mac: macs) {
		e = new Entity(MacAddress.of(mac), VlanVid.ZERO, IPv4Address.NONE, IPv6Address.NONE, DatapathId.NONE, OFPort.ZERO, Entity.NO_DATE);
		int insertionPoint;
		if (computeInsertionPoint) {
			insertionPoint = -(Arrays.binarySearch(d.entities, e)+1);
		} else {
			insertionPoint = -1;
		}
		d = deviceManager.allocateDevice(d, e, insertionPoint);
		expectedLength++;
		assertEquals(expectedLength, d.entities.length);
		for (int i = 0; i < d.entities.length-1; i++)
			assertEquals(-1, d.entities[i].compareTo(d.entities[i+1]));
	}
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:32,代碼來源:DeviceManagerImplTest.java

示例13: getOffset

import java.util.Arrays; //導入方法依賴的package包/類
/**
 * Gets the offset applicable at the specified instant in these rules.
 * <p>
 * The mapping from an instant to an offset is simple, there is only
 * one valid offset for each instant.
 * This method returns that offset.
 *
 * @param instant  the instant to find the offset for, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the offset, not null
 */
public ZoneOffset getOffset(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    long epochSec = instant.getEpochSecond();
    // check if using last rules
    if (lastRules.length > 0 &&
            epochSec > savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
        int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        ZoneOffsetTransition trans = null;
        for (int i = 0; i < transArray.length; i++) {
            trans = transArray[i];
            if (epochSec < trans.toEpochSecond()) {
                return trans.getOffsetBefore();
            }
        }
        return trans.getOffsetAfter();
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    }
    return wallOffsets[index + 1];
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:40,代碼來源:ZoneRules.java

示例14: binarySearch

import java.util.Arrays; //導入方法依賴的package包/類
@Override
public final int binarySearch(int start, int end, Long value) {
    return Arrays.binarySearch(values, start, end, value);
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:5,代碼來源:DenseArrayOfLongs.java

示例15: adjacent

import java.util.Arrays; //導入方法依賴的package包/類
private int adjacent(int n, int bias) {
    int hit = Arrays.binarySearch(breaks, n);
    int offset = (hit < 0 ? (bias < 0 ? -1 : -2) : 0);
    return checkhit(Math.abs(hit) + bias + offset);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:WhitespaceBasedBreakIterator.java


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