本文整理汇总了C++中LinkedHashMap::entrySet方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkedHashMap::entrySet方法的具体用法?C++ LinkedHashMap::entrySet怎么用?C++ LinkedHashMap::entrySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedHashMap
的用法示例。
在下文中一共展示了LinkedHashMap::entrySet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testEntrySetIterator
void LinkedHashMapTest::testEntrySetIterator() {
LinkedHashMap<int, std::string> map;
populateMap(map);
int count = 0;
Pointer< Iterator<MapEntry<int, std::string> > > iterator(map.entrySet().iterator());
while (iterator->hasNext()) {
MapEntry<int, std::string> entry = iterator->next();
CPPUNIT_ASSERT_EQUAL(count, entry.getKey());
CPPUNIT_ASSERT_EQUAL(Integer::toString(count), entry.getValue());
count++;
}
CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
iterator.reset(map.entrySet().iterator());
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw an IllegalStateException",
iterator->remove(),
IllegalStateException);
count = 0;
while (iterator->hasNext()) {
iterator->next();
iterator->remove();
count++;
}
CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw an IllegalStateException",
iterator->remove(),
IllegalStateException);
}
示例2: testOrderedEntrySet
void LinkedHashMapTest::testOrderedEntrySet() {
int i;
int size = 100;
{
LinkedHashMap<int, std::string> map;
populateMap(map, size);
Set<MapEntry<int, std::string> >& set = map.entrySet();
Pointer< Iterator<MapEntry<int, std::string> > > iter(set.iterator());
CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 1", map.size() == set.size());
for (i = 0; iter->hasNext(); i++) {
MapEntry<int, std::string> entry = iter->next();
int key = entry.getKey();
CPPUNIT_ASSERT_MESSAGE("Returned incorrect entry set 1", key == i);
}
}
LinkedHashMap<int, std::string> map2(200, .75f, true);
populateMap(map2, size);
Set<MapEntry<int, std::string> >& set = map2.entrySet();
Pointer< Iterator<MapEntry<int, std::string> > > iter(set.iterator());
CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 2", map2.size() == set.size());
for (i = 0; i < size && iter->hasNext(); i++) {
MapEntry<int, std::string> entry = iter->next();
int key = entry.getKey();
CPPUNIT_ASSERT_MESSAGE("Returned incorrect entry set 2", key == i);
}
/* fetch the even numbered entries to affect traversal order */
int p = 0;
for (i = 0; i < size; i += 2) {
std::string ii = map2.get(i);
p = p + Integer::parseInt(ii);
}
CPPUNIT_ASSERT_EQUAL_MESSAGE("invalid sum of even numbers", 2450, p);
set = map2.entrySet();
iter.reset(set.iterator());
CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size 3", map2.size() == set.size());
for (i = 1; i < size && iter->hasNext(); i += 2) {
MapEntry<int, std::string> entry = iter->next();
int key = entry.getKey();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect entry set 3", key, i);
}
for (i = 0; i < size && iter->hasNext(); i += 2) {
MapEntry<int, std::string> entry = iter->next();
int key = entry.getKey();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Returned incorrect entry set 4", key, i);
}
CPPUNIT_ASSERT_MESSAGE("Entries left to iterate on", !iter->hasNext());
}
示例3: testEntrySet
void LinkedHashMapTest::testEntrySet() {
LinkedHashMap<int, std::string> hashMap;
for (int i = 0; i < 50; i++) {
hashMap.put(i, Integer::toString(i));
}
Set<MapEntry<int, std::string> >& set = hashMap.entrySet();
Pointer< Iterator<MapEntry<int, std::string> > > iterator(set.iterator());
CPPUNIT_ASSERT_MESSAGE("Returned set of incorrect size", hashMap.size() == set.size());
while (iterator->hasNext()) {
MapEntry<int, std::string> entry = iterator->next();
CPPUNIT_ASSERT_MESSAGE("Returned incorrect entry set",
hashMap.containsKey(entry.getKey()) && hashMap.containsValue(entry.getValue()));
}
iterator.reset(set.iterator());
set.remove(iterator->next());
CPPUNIT_ASSERT_EQUAL_MESSAGE("Remove on set didn't take", 49, set.size());
}