当前位置: 首页>>代码示例>>Java>>正文


Java TreeMap.firstKey方法代码示例

本文整理汇总了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;
}
 
开发者ID:lagodiuk,项目名称:spoj,代码行数:20,代码来源:VOCV_Brute_Force.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:26,代码来源:TreeMapAPITest.java

示例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;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:29,代码来源:LinkDocHandler.java

示例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);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:27,代码来源:LinkDocHandler.java

示例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;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:32,代码来源:Settings.java

示例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();
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:OpenUDID_manager.java

示例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;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:36,代码来源:OrderedTombstoneMap.java

示例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);
}
 
开发者ID:ilifan,项目名称:smart-framework,代码行数:21,代码来源:ConsistentHashingMapping.java

示例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;
    }
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:69,代码来源:StatisticsHandler.java


注:本文中的java.util.TreeMap.firstKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。