本文整理汇总了Java中java.util.SortedMap.firstKey方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMap.firstKey方法的具体用法?Java SortedMap.firstKey怎么用?Java SortedMap.firstKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedMap
的用法示例。
在下文中一共展示了SortedMap.firstKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printFrameSizeHistogram
import java.util.SortedMap; //导入方法依赖的package包/类
private static void printFrameSizeHistogram(List<Integer> frameSizes) {
final int step = 1000;
SortedMap<Integer,Integer> frameSizeCounts = new TreeMap<>();
int maxKeyLen = 0;
for (int fs : frameSizes) {
int key = (int)Math.round((double)fs / step);
maxKeyLen = Math.max(Integer.toString(key * step).length(), maxKeyLen);
if (!frameSizeCounts.containsKey(key))
frameSizeCounts.put(key, 0);
frameSizeCounts.put(key, frameSizeCounts.get(key) + 1);
}
for (int i = frameSizeCounts.firstKey(); i < frameSizeCounts.lastKey(); i++) {
if (!frameSizeCounts.containsKey(i))
frameSizeCounts.put(i, 0);
}
List<String> frameSizeLabels = new ArrayList<>();
List<Double> frameSizeValues = new ArrayList<>();
for (Map.Entry<Integer,Integer> entry : frameSizeCounts.entrySet()) {
frameSizeLabels.add(String.format("%" + maxKeyLen + "d", entry.getKey() * step));
frameSizeValues.add((double)entry.getValue());
}
printNormalizedBarGraph("Frame sizes (bytes)", frameSizeLabels, frameSizeValues);
}
示例2: 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;
}
示例3: get
import java.util.SortedMap; //导入方法依赖的package包/类
public T get(String value) {
long hash = hashFunction.hashString(value, UTF8).asLong();
if (!circle.containsKey(hash)) {
SortedMap<Long, T> tailMap = circle.tailMap(hash);
hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey();
}
return circle.get(hash);
}
示例4: routeNode
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* with a specified key, route the nearest Node instance in the current hash ring
* @param objectKey the object key to find a nearest Node
* @return
*/
public T routeNode(String objectKey) {
if (ring.isEmpty()) {
return null;
}
Long hashVal = hashFunction.hash(objectKey);
SortedMap<Long,VirtualNode<T>> tailMap = ring.tailMap(hashVal);
Long nodeHashVal = !tailMap.isEmpty() ? tailMap.firstKey() : ring.firstKey();
return ring.get(nodeHashVal).getPhysicalNode();
}
示例5: previousQuestion
import java.util.SortedMap; //导入方法依赖的package包/类
private ActionForward previousQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
AnswerForm answerForm = (AnswerForm) form;
Integer questionSeqID = answerForm.getQuestionSeqID();
String sessionMapID = answerForm.getSessionMapID();
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
.getAttribute(sessionMapID);
SortedMap<Integer, AnswerDTO> surveyItemMap = getQuestionList(sessionMap);
ActionErrors errors = getAnswer(request, surveyItemMap.get(questionSeqID));
if (!errors.isEmpty()) {
return mapping.getInputForward();
}
SortedMap<Integer, AnswerDTO> subMap = surveyItemMap.headMap(questionSeqID);
if (subMap.isEmpty()) {
questionSeqID = surveyItemMap.firstKey();
} else {
questionSeqID = subMap.lastKey();
}
// get current question index of total questions
int currIdx = new ArrayList<Integer>(surveyItemMap.keySet()).indexOf(questionSeqID) + 1;
answerForm.setCurrentIdx(currIdx);
if (questionSeqID.equals(surveyItemMap.firstKey())) {
answerForm.setPosition(SurveyConstants.POSITION_FIRST);
} else {
answerForm.setPosition(SurveyConstants.POSITION_INSIDE);
}
answerForm.setQuestionSeqID(questionSeqID);
return mapping.findForward(SurveyConstants.SUCCESS);
}
示例6: retake
import java.util.SortedMap; //导入方法依赖的package包/类
private ActionForward retake(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
AnswerForm answerForm = (AnswerForm) form;
Integer questionSeqID = answerForm.getQuestionSeqID();
String sessionMapID = answerForm.getSessionMapID();
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
.getAttribute(sessionMapID);
SortedMap<Integer, AnswerDTO> surveyItemMap = getQuestionList(sessionMap);
Collection<AnswerDTO> surveyItemList = surveyItemMap.values();
if ( surveyItemList.size() < 2 || ( questionSeqID != null && questionSeqID > 0 ) ) {
answerForm.setPosition(SurveyConstants.POSITION_ONLY_ONE);
} else {
answerForm.setPosition(SurveyConstants.POSITION_FIRST);
}
if ( questionSeqID == null || questionSeqID <= 0 ) {
Boolean onePage = (Boolean) sessionMap.get(SurveyConstants.ATTR_SHOW_ON_ONE_PAGE);
if ( ! onePage && surveyItemList.size() > 0) {
answerForm.setQuestionSeqID(surveyItemMap.firstKey());
questionSeqID = surveyItemMap.firstKey();
}
}
// get current question index of total questions
int currIdx = new ArrayList<Integer>(surveyItemMap.keySet()).indexOf(questionSeqID) + 1;
answerForm.setCurrentIdx(currIdx);
return mapping.findForward(SurveyConstants.SUCCESS);
}
示例7: getAssignedRealNode
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* 根据hash因子获取分配的真实节点
*
* @param factor
* @return
*/
public String getAssignedRealNode(Object factor) {
if (nodes.size() <= 1)
return JobContext.getContext().getNodeId();
Long key = hash(factor.toString());
SortedMap<Long, String> tailMap = nodes.tailMap(key);
if (tailMap.isEmpty()) {
key = nodes.firstKey();
} else {
key = tailMap.firstKey();
}
return nodes.get(key);
}
示例8: sekectForKey
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Sekect for key.
*
* @param hash
* the hash
* @return the provider
*/
private Provider sekectForKey(long hash) {
Provider provider = virtualNodes.get(hash);
if (provider == null) {
SortedMap<Long, Provider> tailMap = virtualNodes.tailMap(hash);
if (tailMap.isEmpty()) {
hash = virtualNodes.firstKey();
} else {
hash = tailMap.firstKey();
}
provider = virtualNodes.get(hash);
}
return provider;
}
示例9: 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;
}
示例10: removeMinFromReplica
import java.util.SortedMap; //导入方法依赖的package包/类
private static void removeMinFromReplica(
SortedMap<Integer, AtomicInteger> replica,
int minValue) {
Integer replicatedMinValue = replica.firstKey();
assertEquals(replicatedMinValue, (Integer) minValue);
removeFromReplica(replica, replicatedMinValue);
}
示例11: getErrorsGE
import java.util.SortedMap; //导入方法依赖的package包/类
public synchronized List<ErrorDescription> getErrorsGE(int offset) {
try {
int index = findPositionGE(Utilities.getRowStart(doc, offset));
if (index < 0) return Collections.emptyList();
while (index < knownPositions.size()) {
Position current = knownPositions.get(index++).get();
if (current == null) {
continue;
}
List<ErrorDescription> errors = line2Errors.get(current);
if (errors != null) {
SortedMap<Integer, List<ErrorDescription>> sortedErrors = new TreeMap<Integer, List<ErrorDescription>>();
for (ErrorDescription ed : errors) {
List<ErrorDescription> errs = sortedErrors.get(ed.getRange().getBegin().getOffset());
if (errs == null) {
sortedErrors.put(ed.getRange().getBegin().getOffset(), errs = new LinkedList<ErrorDescription>());
}
errs.add(ed);
}
SortedMap<Integer, List<ErrorDescription>> tail = sortedErrors.tailMap(offset);
if (!tail.isEmpty()) {
Integer k = tail.firstKey();
return new ArrayList<ErrorDescription>(sortedErrors.get(k));
}
}
}
return Collections.emptyList();
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
return Collections.emptyList();
}
}
示例12: getImage
import java.util.SortedMap; //导入方法依赖的package包/类
public BufferedImage getImage(SortedMap<Integer, String> map) throws MapIsNullException {
if (map == null) {
throw new MapIsNullException();
}
BufferedImage bImg = new BufferedImage(BUFFERED_IMAGE_MAX_X, BUFFERED_IMAGE_MAX_Y, BufferedImage.TYPE_INT_ARGB);
Graphics2D cg = (Graphics2D) bImg.getGraphics();
cg.setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
cg.setBackground(Color.WHITE);
//cg.setStroke(new BasicStroke(2));
cg.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
int min = map.firstKey();
int max = map.lastKey();
int fontSize = cg.getFont().getSize() / 2;
cg.fillRect(0, 0, BUFFERED_IMAGE_MAX_X, BUFFERED_IMAGE_MAX_Y);
cg.setPaint(Color.BLACK);
Map<String, IntPair> descPosMap = new HashMap();
Map<String, Color> descColMap = new HashMap();
for (int i = max - min; i >= 0; i--) {
int num_bit = i + min;
String numString = Integer.toString(num_bit);
if (!map.containsKey(num_bit)) {
cg.setPaint(Color.lightGray);
cg.fillRect(PADDING + i * SQUARE_FACTOR_X * fontSize, PADDING, SQUARE_FACTOR_X * fontSize, SQUARE_FACTOR_Y * fontSize);
cg.setPaint(Color.BLACK);
} else {
String description = map.get(num_bit);
IntPair stringPosition;
int descriptionExists = 0;
if (description.length() > 0) {
if (!descPosMap.keySet().contains(description)) {
stringPosition = new IntPair(PADDING + i * SQUARE_FACTOR_X * fontSize, 30 + SQUARE_FACTOR_Y * fontSize + descPosMap.size() * 3 * fontSize);
descPosMap.put(description, stringPosition);
cg.setColor(Color.WHITE);
cg.fillRect(stringPosition.getX(), stringPosition.getY() - fontSize, description.length() * fontSize, 2 * fontSize);
Color descColor = palette.getColor((double) i / (max - min));
descColMap.put(description, descColor);
cg.setColor(descColor);
cg.drawString(description, stringPosition.getX(), stringPosition.getY() + fontSize);
} else {
descriptionExists = 1;
stringPosition = descPosMap.get(description);
cg.setColor(descColMap.get(description));
cg.drawLine(
stringPosition.getX() + fontSize,
stringPosition.getY() - fontSize * 2,
PADDING + i * SQUARE_FACTOR_X * fontSize + fontSize,
stringPosition.getY() - fontSize * 2
);
}
cg.drawLine(
PADDING + i * SQUARE_FACTOR_X * fontSize + fontSize,
stringPosition.getY() - fontSize * (1 + descriptionExists),
PADDING + i * SQUARE_FACTOR_X * fontSize + fontSize,
PADDING + SQUARE_FACTOR_Y * fontSize
);
}
}
cg.drawRect(PADDING + i * SQUARE_FACTOR_X * fontSize, PADDING, SQUARE_FACTOR_X * fontSize, SQUARE_FACTOR_Y * fontSize);
cg.drawString(numString, PADDING + fontSize + i * SQUARE_FACTOR_X * fontSize, PADDING + 3 * fontSize);
cg.setColor(Color.BLACK);
}
BufferedImage returned_bImg = bImg.getSubimage(
0,
0,
2 * BUFFERED_IMAGE_PADDING + (max - min + 1) * SQUARE_FACTOR_X * fontSize + map.get(map.lastKey()).length() * fontSize,
DRAW_BOARD_Y);
return returned_bImg;
}
示例13: testNodeFailoverDeadServerParsing
import java.util.SortedMap; //导入方法依赖的package包/类
@Test
public void testNodeFailoverDeadServerParsing() throws Exception {
LOG.debug("testNodeFailoverDeadServerParsing");
conf.setBoolean(HConstants.ZOOKEEPER_USEMULTI, true);
final Server server = new DummyServer("ec2-54-234-230-108.compute-1.amazonaws.com");
ReplicationQueues repQueues =
ReplicationFactory.getReplicationQueues(server.getZooKeeper(), conf, server);
repQueues.init(server.getServerName().toString());
// populate some znodes in the peer znode
files.add("log1");
files.add("log2");
for (String file : files) {
repQueues.addLog("1", file);
}
// create 3 DummyServers
Server s1 = new DummyServer("ip-10-8-101-114.ec2.internal");
Server s2 = new DummyServer("ec2-107-20-52-47.compute-1.amazonaws.com");
Server s3 = new DummyServer("ec2-23-20-187-167.compute-1.amazonaws.com");
// simulate three servers fail sequentially
ReplicationQueues rq1 =
ReplicationFactory.getReplicationQueues(s1.getZooKeeper(), s1.getConfiguration(), s1);
rq1.init(s1.getServerName().toString());
SortedMap<String, SortedSet<String>> testMap =
rq1.claimQueues(server.getServerName().getServerName());
ReplicationQueues rq2 =
ReplicationFactory.getReplicationQueues(s2.getZooKeeper(), s2.getConfiguration(), s2);
rq2.init(s2.getServerName().toString());
testMap = rq2.claimQueues(s1.getServerName().getServerName());
ReplicationQueues rq3 =
ReplicationFactory.getReplicationQueues(s3.getZooKeeper(), s3.getConfiguration(), s3);
rq3.init(s3.getServerName().toString());
testMap = rq3.claimQueues(s2.getServerName().getServerName());
ReplicationQueueInfo replicationQueueInfo = new ReplicationQueueInfo(testMap.firstKey());
List<String> result = replicationQueueInfo.getDeadRegionServers();
// verify
assertTrue(result.contains(server.getServerName().getServerName()));
assertTrue(result.contains(s1.getServerName().getServerName()));
assertTrue(result.contains(s2.getServerName().getServerName()));
server.abort("", null);
}
示例14: asString
import java.util.SortedMap; //导入方法依赖的package包/类
private static String asString(SortedMap<Long, ?> map) {
return map.isEmpty()? "[]": "[" + map.firstKey() + ".." + map.lastKey() + "]";
}
示例15: removeInterval
import java.util.SortedMap; //导入方法依赖的package包/类
/**
* Removes a resource for the specified interval
*
* @param reservationInterval the interval for which the resource is to be
* removed
* @param capacity the resource to be removed
* @return true if removal is successful, false otherwise
*/
public boolean removeInterval(ReservationInterval reservationInterval,
ReservationRequest capacity) {
Resource totCap =
Resources.multiply(capacity.getCapability(),
(float) capacity.getNumContainers());
if (totCap.equals(ZERO_RESOURCE)) {
return true;
}
writeLock.lock();
try {
long startKey = reservationInterval.getStartTime();
long endKey = reservationInterval.getEndTime();
// update the start key
NavigableMap<Long, Resource> ticks =
cumulativeCapacity.headMap(endKey, false);
// Decrease all the capacities of overlapping intervals
SortedMap<Long, Resource> overlapSet = ticks.tailMap(startKey);
if (overlapSet != null && !overlapSet.isEmpty()) {
Resource updatedCapacity = Resource.newInstance(0, 0, 0);
long currentKey = -1;
for (Iterator<Entry<Long, Resource>> overlapEntries =
overlapSet.entrySet().iterator(); overlapEntries.hasNext();) {
Entry<Long, Resource> entry = overlapEntries.next();
currentKey = entry.getKey();
updatedCapacity = Resources.subtract(entry.getValue(), totCap);
// update each entry between start and end key
cumulativeCapacity.put(currentKey, updatedCapacity);
}
// Remove the first overlap entry if it is same as previous after
// updation
Long firstKey = overlapSet.firstKey();
if (isSameAsPrevious(firstKey, overlapSet.get(firstKey))) {
cumulativeCapacity.remove(firstKey);
}
// Remove the next entry if it is same as end entry after updation
if ((currentKey != -1) && (isSameAsNext(currentKey, updatedCapacity))) {
cumulativeCapacity.remove(cumulativeCapacity.higherKey(currentKey));
}
}
return true;
} finally {
writeLock.unlock();
}
}