本文整理匯總了Java中java.util.TreeMap.firstKey方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeMap.firstKey方法的具體用法?Java TreeMap.firstKey怎麽用?Java TreeMap.firstKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.TreeMap
的用法示例。
在下文中一共展示了TreeMap.firstKey方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findMinLightsCount
import java.util.TreeMap; //導入方法依賴的package包/類
static Result findMinLightsCount(List<Edge> edges) {
Node[] nodes = new Node[edges.size() + 1];
for (int i = 0; i < nodes.length; i++) {
nodes[i] = new Node();
}
for (Edge e : edges) {
nodes[e.node1 - 1].children.add(nodes[e.node2 - 1]);
nodes[e.node2 - 1].children.add(nodes[e.node1 - 1]);
}
transformToDirectedTree(nodes[0]);
TreeMap<Integer, Integer> lightsToVariantsCount = new TreeMap<>();
findMinLightsCount(nodes, 0, lightsToVariantsCount);
Result result = new Result(lightsToVariantsCount.firstKey(), lightsToVariantsCount.firstEntry().getValue());
return result;
}
示例2: testFirstKey
import java.util.TreeMap; //導入方法依賴的package包/類
public void testFirstKey()
{
// create two random treemaps and retrieve their first keys
TreeMap<Integer,Integer> tree1 = TreeMapFactory.getTree(TreeMapFactory.SIZE/2);
Comparable<Integer> firstkey1 = (Comparable<Integer>)tree1.firstKey();
TreeMap<Integer,Integer> tree2 = TreeMapFactory.getTree(TreeMapFactory.SIZE/2);
Comparable<Integer> firstkey2 = (Comparable<Integer>)tree2.firstKey();
// join them together and check the first key is correct
tree1.putAll(tree2);
if (firstkey1.compareTo((Integer)firstkey2) <= 0)
{
assertEquals(firstkey1, tree1.firstKey());
}
else
{
assertEquals(firstkey2, tree1.firstKey());
}
// put the smallest Integer in and see if it's the last key
tree1.put(new Integer(Integer.MIN_VALUE), null);
assertEquals(new Integer(Integer.MIN_VALUE), tree1.firstKey());
}
示例3: LinkDocHandler
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* コンストラクタ.
* @param srcHandler OEntityDocHandler
* @param tgtHandler OEntityDocHandler
*/
public LinkDocHandler(final EntitySetDocHandler srcHandler, final EntitySetDocHandler tgtHandler) {
this.cellId = srcHandler.getCellId();
this.boxId = srcHandler.getBoxId();
this.nodeId = srcHandler.getNodeId();
String srcType = srcHandler.getType();
String srcId = srcHandler.getId();
String tgtType = tgtHandler.getType();
String tgtId = tgtHandler.getId();
// ES 保存時の一意キー作成
TreeMap<String, String> tm = new TreeMap<String, String>();
tm.put(srcType, srcId);
tm.put(tgtType, tgtId);
this.ent1Type = tm.firstKey();
this.ent2Type = tm.lastKey();
this.ent1Key = tm.get(ent1Type);
this.ent2Key = tm.get(ent2Type);
this.id = this.createLinkId();
long dateTime = new Date().getTime();
this.published = dateTime;
this.updated = dateTime;
}
示例4: NtoNQueryParameter
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* コンストラクタ.
* @param srcHandler OEntityDocHandler
* @param targetSetName ターゲット側のEntitySet名
* @param targetEntityTypeId ターゲット側のEntityTypeID
*/
public NtoNQueryParameter(
final EntitySetDocHandler srcHandler,
final String targetSetName,
final String targetEntityTypeId) {
String srcSetName = srcHandler.getType();
String srcId = srcHandler.getId();
TreeMap<String, String> tm = new TreeMap<String, String>();
if (srcSetName.equals(UserDataODataProducer.USER_ODATA_NAMESPACE)) {
tm.put(srcHandler.getEntityTypeId(), srcId);
tm.put(targetEntityTypeId, "");
} else {
tm.put(srcSetName, srcId);
tm.put(targetSetName, "");
}
this.t1 = tm.firstKey();
this.t2 = tm.lastKey();
this.k1 = tm.get(t1);
this.k2 = tm.get(t2);
}
示例5: upgradeSettingsGeneric
import java.util.TreeMap; //導入方法依賴的package包/類
private static Set<String> upgradeSettingsGeneric(Map<String, TreeMap<Integer, SettingsDescription>> settings,
Map<String, Object> validatedSettingsMutable, Set<String> deletedSettingsMutable, int toVersion) {
for (Entry<String, TreeMap<Integer, SettingsDescription>> versions : settings.entrySet()) {
String settingName = versions.getKey();
TreeMap<Integer, SettingsDescription> versionedSettings = versions.getValue();
boolean isNewlyAddedSetting = versionedSettings.firstKey() == toVersion;
if (isNewlyAddedSetting) {
boolean wasHandledByCustomUpgrader = validatedSettingsMutable.containsKey(settingName);
if (wasHandledByCustomUpgrader) {
continue;
}
SettingsDescription setting = versionedSettings.get(toVersion);
if (setting == null) {
throw new AssertionError("First version of a setting must be non-null!");
}
upgradeSettingInsertDefault(validatedSettingsMutable, settingName, setting);
}
Integer highestVersion = versionedSettings.lastKey();
boolean isRemovedSetting = (highestVersion == toVersion && versionedSettings.get(highestVersion) == null);
if (isRemovedSetting) {
if (deletedSettingsMutable == null) {
deletedSettingsMutable = new HashSet<>();
}
upgradeSettingRemove(validatedSettingsMutable, deletedSettingsMutable, settingName);
}
}
return deletedSettingsMutable;
}
示例6: getMostFrequentOpenUDID
import java.util.TreeMap; //導入方法依賴的package包/類
private void getMostFrequentOpenUDID() {
if (mReceivedOpenUDIDs.isEmpty() == false) {
final TreeMap<String,Integer> sorted_OpenUDIDS = new TreeMap(new ValueComparator());
sorted_OpenUDIDS.putAll(mReceivedOpenUDIDs);
OpenUDID = sorted_OpenUDIDS.firstKey();
}
}
示例7: take
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* Remove a version tag from the map.
*/
public Map.Entry<VersionTag, T> take() {
if (tombstoneMap.isEmpty()) {
// if there are no more entries, return null;
return null;
} else {
// Otherwise, look at all of the members and find the tag with the
// lowest timestamp.
long lowestTimestamp = Long.MAX_VALUE;
TreeMap<VersionTag, T> lowestMap = null;
for (TreeMap<VersionTag, T> memberMap : tombstoneMap.values()) {
VersionTag firstTag = memberMap.firstKey();
long stamp = firstTag.getVersionTimeStamp();
if (stamp < lowestTimestamp) {
lowestTimestamp = stamp;
lowestMap = memberMap;
}
}
if (lowestMap == null) {
return null;
}
// Remove the lowest entry
Entry<VersionTag, T> result = lowestMap.firstEntry();
lowestMap.remove(result.getKey());
if (lowestMap.isEmpty()) {
// if this is the last entry from a given member,
// the map for that member
tombstoneMap.remove(result.getKey().getMemberID());
}
return result;
}
}
示例8: getTargetName
import java.util.TreeMap; //導入方法依賴的package包/類
/**
* 根據分片原始數據計算hash值,然後從hashingMap獲取目標數據名稱
*
* @param hashingMap
* @param shardingValue
* @return
*/
private static String getTargetName(TreeMap<Integer, String> hashingMap, String shardingValue) {
if (hashingMap.isEmpty()) {
return null;
}
//計算hash值
int hashKey = getHashing(shardingValue);
//獲取真實key,找比hashKey大或者等的key值,找不到則取最小的key
Integer realKey = hashingMap.ceilingKey(hashKey);
if (null == realKey) {
realKey = hashingMap.firstKey();
}
return hashingMap.get(realKey);
}
示例9: getInstantValue
import java.util.TreeMap; //導入方法依賴的package包/類
public final double getInstantValue(String key, long time, String newVal) {
TreeMap<Long, String> h = null;
if (!lastValues.containsKey(key)) {
h = new TreeMap<Long, String>();
lastValues.put(key, h);
} else
h = lastValues.get(key);
if (h.size() == 0) {
h.put(time, newVal);
return 0D;
}
if (h.size() == 2)
h.remove(h.firstKey());
h.put(time, newVal);
long first = h.firstKey();
long last = h.lastKey();
String s1 = h.get(first);
String s2 = h.get(last);
double d = 0D;
try {
d = Double.parseDouble(diffWithOverflowCheck(s2, s1));
} catch (Throwable t) {
d = 0D;
}
d = d / ((last - first) / 1000D);
return d;
// TreeMap<Long, String> h = null;
// if (!lastValues.containsKey(key)) {
// h = new TreeMap<Long, String>();
// lastValues.put(key, h);
// } else
// h = lastValues.get(key);
// h.put(time, newVal);
// if (h.size() == 1) return 0D;
// long first = h.firstKey();
// long last = h.lastKey();
// String s1 = h.get(first);
// String s2 = h.get(last);
// double d = 0D;
// try {
// d = Double.parseDouble(diffWithOverflowCheck(s2, s1));
// } catch (Throwable t) {
// d = 0D;
// }
// d = d / ((last - first) / 1000D);
// long diffTime = 60 * 1000;
// if (properties != null)
// diffTime = properties.geti("stat.interval", 60, "The interval to consider when computing the instant values") * 1000;
// if (diffTime <= 0) diffTime = 60 * 1000;
// if ((last - first) < diffTime) {
// h.clear();
// h.put(first, s1);
// h.put(last, s2);
// } else {
// long inner = last - diffTime;
// String ss = diffWithOverflowCheck(s2, s1);
// double dd = 0D;
// try { dd = Double.parseDouble(ss); } catch (Throwable t) { dd = 0D; }
// dd = dd * (inner - first) / (last - first);
// h.clear();
// h.put(inner, addWithOverflowCheck(s1, ""+dd));
// h.put(last, s2);
// }
// return d;
}