本文整理汇总了Java中java.util.SortedMap.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMap.isEmpty方法的具体用法?Java SortedMap.isEmpty怎么用?Java SortedMap.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedMap
的用法示例。
在下文中一共展示了SortedMap.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: route
import java.util.SortedMap; //导入方法依赖的package包/类
public String route(int jobId, ArrayList<String> addressList) {
// ------A1------A2-------A3------
// -----------J1------------------
TreeMap<Long, String> addressRing = new TreeMap<Long, String>();
for (String address: addressList) {
for (int i = 0; i < VIRTUAL_NODE_NUM; i++) {
long addressHash = hash("SHARD-" + address + "-NODE-" + i);
addressRing.put(addressHash, address);
}
}
long jobHash = hash(String.valueOf(jobId));
SortedMap<Long, String> lastRing = addressRing.tailMap(jobHash);
if (!lastRing.isEmpty()) {
return lastRing.get(lastRing.firstKey());
}
return addressRing.firstEntry().getValue();
}
示例2: transformLettersListIntoTurn
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Returns the structure turn to be sent to the game
*
* @param letters The letters to be played
* @param startLine The line of the first letter of the played letters
* @param startColumn The column of the first letter of the played letters
* @param horizontal True if the letters are disposed horizontally, false otherwise
* @param checkBoardLetters True if we must check if letters have already been disposed with the given letters
* @param board The actual board
*
* @return the structure turn
*/
protected static SortedMap<BoardPosition, LetterInterface> transformLettersListIntoTurn(List<LetterInterface> letters, int startLine, int startColumn, boolean horizontal, boolean checkBoardLetters, BoardInterface board) {
SortedMap<BoardPosition, LetterInterface> turn = new TreeMap<>();
for (int i = 0; i < letters.size(); i++) {
short line, column;
if (horizontal) {
line = (short) startLine;
column = (short) (startColumn + i);
} else {
line = (short) (startLine + i);
column = (short) startColumn;
}
if (line < 0 || line >= BoardInterface.BOARD_SIZE || column < 0 || column >= BoardInterface.BOARD_SIZE) {
return null;
}
if (!checkBoardLetters || null == board.getLetters().get(line).get(column)) {
turn.put(new BoardPosition(line, column), letters.get(i));
}
}
return !turn.isEmpty() ? turn : null;
}
示例3: getPrefixWords
import java.util.SortedMap; //导入方法依赖的package包/类
/**
*
* @param sen sen.length() greater than 0
* @param start at first start = 0
* @param dic
*/
private static LinkedList<Integer> getPrefixWords(String sen,int start,Dictionary dic){
LinkedList<Integer> wl = new LinkedList<>();
if(start == sen.length())
return wl;
for(int i=start+1;i<=sen.length();i++){
String w = sen.substring(start,i);
SortedMap<String,Double> map = dic.prefixMap(w);
if(map.isEmpty()){
//we find a new word! Its length maybe larger than 1.
if(i==start+1){
wl.add(i); //this new word's length is 1.
}else{ //this new word's length is larger than 1.
if(wl.indexOf(i-1) == -1)
wl.add(i-1);
}
return wl;
}
if(map.containsKey(w)){
wl.add(i);
}else{
if(i==sen.length())
wl.add(i); //we find a new word! Its length maybe larger than 1.
}
}
return wl;
}
示例4: getFirstEnabled
import java.util.SortedMap; //导入方法依赖的package包/类
public T getFirstEnabled() {
SortedMap<String, T> map = enabled.getAsMap();
if (map.isEmpty()) {
return null;
} else {
return map.get(map.firstKey());
}
}
示例5: getReservationsAtTime
import java.util.SortedMap; //导入方法依赖的package包/类
@Override
public Set<ReservationAllocation> getReservationsAtTime(long tick) {
ReservationInterval searchInterval =
new ReservationInterval(tick, Long.MAX_VALUE);
readLock.lock();
try {
SortedMap<ReservationInterval, Set<InMemoryReservationAllocation>> reservations =
currentReservations.headMap(searchInterval, true);
if (!reservations.isEmpty()) {
Set<ReservationAllocation> flattenedReservations =
new HashSet<ReservationAllocation>();
for (Set<InMemoryReservationAllocation> reservationEntries : reservations
.values()) {
for (InMemoryReservationAllocation reservation : reservationEntries) {
if (reservation.getEndTime() > tick) {
flattenedReservations.add(reservation);
}
}
}
return Collections.unmodifiableSet(flattenedReservations);
} else {
return Collections.emptySet();
}
} finally {
readLock.unlock();
}
}
示例6: selectForKey
import java.util.SortedMap; //导入方法依赖的package包/类
private Invoker<T> selectForKey(long hash) {
Invoker<T> invoker;
Long key = hash;
if (!virtualInvokers.containsKey(key)) {
SortedMap<Long, Invoker<T>> tailMap = virtualInvokers.tailMap(key);
if (tailMap.isEmpty()) {
key = virtualInvokers.firstKey();
} else {
key = tailMap.firstKey();
}
}
invoker = virtualInvokers.get(key);
return invoker;
}
示例7: checkForProblems
import java.util.SortedMap; //导入方法依赖的package包/类
private void checkForProblems(SortedMap<String,SortedSet<String>> problems, String msg, String testName, Map<String,String> pseudoTests) {
if (!problems.isEmpty()) {
StringBuilder message = new StringBuilder(msg);
for (Map.Entry<String, SortedSet<String>> entry : problems.entrySet()) {
message.append("\nProblems found for module ").append(entry.getKey()).append(": ").append(entry.getValue());
}
pseudoTests.put(testName, message.toString());
} else {
pseudoTests.put(testName, null);
}
}
示例8: findPath2
import java.util.SortedMap; //导入方法依赖的package包/类
private ASTPath findPath2 (List<ASTItem> path, int offset) {
TreeMap<Integer,ASTItem> childrenMap = getChildrenMap ();
SortedMap<Integer,ASTItem> headMap = childrenMap.headMap (new Integer (offset + 1));
if (headMap.isEmpty ())
return ASTPath.create (path);
Integer key = headMap.lastKey ();
ASTItem item = childrenMap.get (key);
ASTPath path2 = item.findPath (path, offset);
if (path2 == null)
return ASTPath.create (path);
return path2;
}
示例9: getShardInfo
import java.util.SortedMap; //导入方法依赖的package包/类
public S getShardInfo(byte[] key) {
SortedMap<Long, S> tail = nodes.tailMap(algo.hash(key));
if (tail.isEmpty()) {
return nodes.get(nodes.firstKey());
}
return tail.get(tail.firstKey());
}
示例10: floor
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Return the largest key in the table <= k.
*/
public Key floor(Key k) {
if (st.containsKey(k)) return k;
// does not include key if present (!)
SortedMap<Key, Value> head = st.headMap(k);
if (head.isEmpty()) return null;
else return head.lastKey();
}
示例11: sekectForKey
import java.util.SortedMap; //导入方法依赖的package包/类
private Invoker<T> sekectForKey(long hash) {
Invoker<T> invoker;
Long key = hash;
if (!virtualInvokers.containsKey(key)) {
SortedMap<Long, Invoker<T>> tailMap = virtualInvokers.tailMap(key);
if (tailMap.isEmpty()) {
key = virtualInvokers.firstKey();
} else {
key = tailMap.firstKey();
}
}
invoker = virtualInvokers.get(key);
return invoker;
}
示例12: processKeyMap
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* process not null parameters for parameters map
* @param map
* @param process
*/
private void processKeyMap(@NonNull SortedMap<String, String> map,
@NonNull ProcessNotNullMapParameters process){
if (!map.isEmpty()) {
for (Map.Entry<String, String> entry : map.entrySet()) {
if (entry.getValue() != null && !entry.getValue().isEmpty())
process.process(entry.getKey().toString(), entry.getValue());
}
}
}
示例13: getForegroundAppPackageName
import java.util.SortedMap; //导入方法依赖的package包/类
@SuppressWarnings("WrongConstant")
public static String getForegroundAppPackageName(Context context) {
UsageStatsManager manager = (UsageStatsManager) context.getSystemService("usagestats");
long time = System.currentTimeMillis();
List<UsageStats> list = manager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,
time - 1000 * 1000, time);
if (list != null && !list.isEmpty()) {
SortedMap<Long, UsageStats> map = new TreeMap<>();
for (UsageStats stats : list) {
map.put(stats.getLastTimeUsed(), stats);
}
if (!map.isEmpty()) {
return map.get(map.lastKey()).getPackageName();
}
}
return null;
}
示例14: archiveCompletedReservations
import java.util.SortedMap; //导入方法依赖的package包/类
@Override
public void archiveCompletedReservations(long tick) {
// Since we are looking for old reservations, read lock is optimal
LOG.debug("Running archival at time: {}", tick);
List<InMemoryReservationAllocation> expiredReservations =
new ArrayList<InMemoryReservationAllocation>();
readLock.lock();
// archive reservations and delete the ones which are beyond
// the reservation policy "window"
try {
long archivalTime = tick - policy.getValidWindow();
ReservationInterval searchInterval =
new ReservationInterval(archivalTime, archivalTime);
SortedMap<ReservationInterval, Set<InMemoryReservationAllocation>> reservations =
currentReservations.headMap(searchInterval, true);
if (!reservations.isEmpty()) {
for (Set<InMemoryReservationAllocation> reservationEntries : reservations
.values()) {
for (InMemoryReservationAllocation reservation : reservationEntries) {
if (reservation.getEndTime() <= archivalTime) {
expiredReservations.add(reservation);
}
}
}
}
} finally {
readLock.unlock();
}
if (expiredReservations.isEmpty()) {
return;
}
// Need write lock only if there are any reservations to be deleted
writeLock.lock();
try {
for (InMemoryReservationAllocation expiredReservation : expiredReservations) {
removeReservation(expiredReservation);
}
} finally {
writeLock.unlock();
}
}
示例15: ceil
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Return the smallest key in the table >= k.
*/
public Key ceil(Key k) {
SortedMap<Key, Value> tail = st.tailMap(k);
if (tail.isEmpty()) return null;
else return tail.firstKey();
}