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


Java SortedMap.clear方法代码示例

本文整理汇总了Java中java.util.SortedMap.clear方法的典型用法代码示例。如果您正苦于以下问题:Java SortedMap.clear方法的具体用法?Java SortedMap.clear怎么用?Java SortedMap.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.SortedMap的用法示例。


在下文中一共展示了SortedMap.clear方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTailMapClearThrough

import java.util.SortedMap; //导入方法依赖的package包/类
public void testTailMapClearThrough() {
  final SortedMap<K, V> map;
  try {
    map = makePopulatedMap();
  } catch (UnsupportedOperationException e) {
    return;
  }
  int oldSize = map.size();
  if (map.size() < 2 || !supportsClear) {
    return;
  }
  Iterator<Entry<K, V>> iterator = map.entrySet().iterator();
  iterator.next(); // advance
  Entry<K, V> secondEntry = iterator.next();
  K key = secondEntry.getKey();
  SortedMap<K, V> subMap = map.tailMap(key);
  int subMapSize = subMap.size();
  subMap.clear();
  assertEquals(map.size(), oldSize - subMapSize);
  assertTrue(subMap.isEmpty());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:SortedMapInterfaceTest.java

示例2: testSubRowClearAndPut

import java.util.SortedMap; //导入方法依赖的package包/类
public void testSubRowClearAndPut() {
  table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  SortedMap<Integer, Character> row = (SortedMap<Integer, Character>) table.row("foo");
  SortedMap<Integer, Character> subRow = row.tailMap(2);
  assertEquals(ImmutableMap.of(1, 'a', 3, 'c'), row);
  assertEquals(ImmutableMap.of(3, 'c'), subRow);
  table.remove("foo", 3);
  assertEquals(ImmutableMap.of(1, 'a'), row);
  assertEquals(ImmutableMap.of(), subRow);
  table.remove("foo", 1);
  assertEquals(ImmutableMap.of(), row);
  assertEquals(ImmutableMap.of(), subRow);
  table.put("foo", 2, 'b');
  assertEquals(ImmutableMap.of(2, 'b'), row);
  assertEquals(ImmutableMap.of(2, 'b'), subRow);
  row.clear();
  assertEquals(ImmutableMap.of(), row);
  assertEquals(ImmutableMap.of(), subRow);
  table.put("foo", 5, 'x');
  assertEquals(ImmutableMap.of(5, 'x'), row);
  assertEquals(ImmutableMap.of(5, 'x'), subRow);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:23,代码来源:TreeBasedTableTest.java

示例3: testHeadMapContents

import java.util.SortedMap; //导入方法依赖的package包/类
/**
 * headMap returns map with keys in requested range
 */
public void testHeadMapContents() {
    ConcurrentNavigableMap map = map5();
    SortedMap sm = map.headMap(four);
    assertTrue(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(four, map.firstKey());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ConcurrentSkipListSubMapTest.java

示例4: testDescendingHeadMapContents

import java.util.SortedMap; //导入方法依赖的package包/类
/**
 * headMap returns map with keys in requested range
 */
public void testDescendingHeadMapContents() {
    ConcurrentNavigableMap map = dmap5();
    SortedMap sm = map.headMap(m4);
    assertTrue(sm.containsKey(m1));
    assertTrue(sm.containsKey(m2));
    assertTrue(sm.containsKey(m3));
    assertFalse(sm.containsKey(m4));
    assertFalse(sm.containsKey(m5));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m1, k);
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(m4, map.firstKey());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ConcurrentSkipListSubMapTest.java

示例5: testHeadMapContents

import java.util.SortedMap; //导入方法依赖的package包/类
/**
 * headMap returns map with keys in requested range
 */
public void testHeadMapContents() {
    NavigableMap map = map5();
    SortedMap sm = map.headMap(four);
    assertTrue(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(four, map.firstKey());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:TreeSubMapTest.java

示例6: testDescendingHeadMapContents

import java.util.SortedMap; //导入方法依赖的package包/类
/**
 * headMap returns map with keys in requested range
 */
public void testDescendingHeadMapContents() {
    NavigableMap map = dmap5();
    SortedMap sm = map.headMap(m4);
    assertTrue(sm.containsKey(m1));
    assertTrue(sm.containsKey(m2));
    assertTrue(sm.containsKey(m3));
    assertFalse(sm.containsKey(m4));
    assertFalse(sm.containsKey(m5));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m1, k);
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(m4, map.firstKey());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:TreeSubMapTest.java

示例7: readMap

import java.util.SortedMap; //导入方法依赖的package包/类
/**
 * Reads a stored mapped from the JSON object and populates the data
 * structure
 * 
 * @param <U>
 * @param <V>
 * @param map
 * @param name
 * @param key_map
 * @param object
 * @throws JSONException
 */
@SuppressWarnings("unchecked")
protected <U, V> void readMap(SortedMap<U, V> map, String name, Map<String, U> key_map, Class<?> value_class, JSONObject object) throws JSONException {
    map.clear();
    JSONObject jsonObject = object.getJSONObject(name);
    Iterator<String> keys = jsonObject.keys();
    boolean first = true;
    while (keys.hasNext()) {
        String key_name = keys.next();
        U key_object = null;
        V value = null;

        if (value_class.equals(Long.class)) {
            value = (V) new Long(jsonObject.getLong(key_name));
        } else {
            value = (V) jsonObject.get(key_name);
        }
        key_object = key_map.get(key_name);
        if (key_object == null) {
            LOG.warn("Failed to retrieve key object '" + key_name + "' for " + name);
            if (LOG.isDebugEnabled() && first) {
                LOG.warn(jsonObject.toString(2));
            }
            first = false;
            continue;
        }
        map.put(key_object, value);
    } // FOR
    LOG.debug("Added " + map.size() + " values to " + name);
    return;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:43,代码来源:AbstractStatistics.java

示例8: append

import java.util.SortedMap; //导入方法依赖的package包/类
public boolean append(@Nonnull AppendEntries appendEntries) {

        final long prevLogIndex = appendEntries.getPrevLogIndex();
        final long prevLogTerm = appendEntries.getPrevLogTerm();
        final List<Entry> entries = appendEntries.getEntriesList();

        EntryMeta previousEntry = entryIndex.get(prevLogIndex);
        if ((previousEntry == null) || (previousEntry.term != prevLogTerm)) {
            LOGGER.debug("Append prevLogIndex {} prevLogTerm {} previousEntry {}", prevLogIndex, prevLogTerm, previousEntry);
            return false;
        }

        SortedMap<Long, EntryMeta> old = this.entryIndex.tailMap(prevLogIndex + 1);
        for (EntryMeta e : old.values()) {
            try {
                LOGGER.debug("Deleting {}", e.index);
                journal.delete(e.location);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        old.clear();
        lastLogIndex = prevLogIndex;

        for (Entry entry : entries) {
            storeEntry(++lastLogIndex, entry);
        }

        return true;

    }
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:32,代码来源:DefaultRaftLog.java


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