本文整理汇总了Java中java.util.AbstractMap类的典型用法代码示例。如果您正苦于以下问题:Java AbstractMap类的具体用法?Java AbstractMap怎么用?Java AbstractMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractMap类属于java.util包,在下文中一共展示了AbstractMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iterator
import java.util.AbstractMap; //导入依赖的package包/类
private Iterator<Map.Entry<K, V>> iterator(final int pos, final boolean reverse) {
return new Iterator<Map.Entry<K, V>>() {
int currentPos = pos;
@Override
public boolean hasNext() {
return reverse ? currentPos >= 0 : currentPos < keys.length;
}
@Override
public Map.Entry<K, V> next() {
final K key = keys[currentPos];
final V value = values[currentPos];
currentPos = reverse ? currentPos - 1 : currentPos + 1;
return new AbstractMap.SimpleImmutableEntry<>(key, value);
}
@Override
public void remove() {
throw new UnsupportedOperationException("Can't remove elements from ImmutableSortedMap");
}
};
}
示例2: shouldBuildClient
import java.util.AbstractMap; //导入依赖的package包/类
@Test
public void shouldBuildClient() {
final String query = "info_hash={infohash}&peer_id={peerid}&supportcrypto=1&port={port}&azudp={port}&uploaded={uploaded}&downloaded={downloaded}&left={left}&corrupt=0&event={event}&numwant={numwant}&no_peer_id=1&compact=1&key={key}&azver=3";
final List<BitTorrentClientConfig.HttpHeader> requestHeaders = Arrays.asList(
new HttpHeader("User-Agent", "Azureus 5.7.5.0;{os};1.8.0_66"),
new HttpHeader("Connection", "close"),
new HttpHeader("Accept-Encoding", "gzip"),
new HttpHeader("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
);
final PeerIdGenerator peerIdGenerator = PeerIdGeneratorTest.createDefault();
final KeyGenerator keyGenerator = KeyGeneratorTest.createDefault();
final BitTorrentClientConfig config = new BitTorrentClientConfig(peerIdGenerator, query, keyGenerator, defaultUrlEncoder, requestHeaders, 200, 0);
final BitTorrentClient client = config.createClient();
assertThat(client.getHeaders()).isEqualTo(requestHeaders.stream()
.map(header -> new AbstractMap.SimpleEntry<>(header.getName(), header.getValue()))
.collect(Collectors.toList())
);
assertThat(client.getQuery()).isEqualTo(query);
//noinspection OptionalGetWithoutIsPresent
assertThat(client.getKey(null, RequestEvent.STARTED).get()).isEqualTo(keyGenerator.getKey(null, RequestEvent.STARTED));
assertThat(client.getPeerId(null, RequestEvent.STARTED)).isEqualTo(peerIdGenerator.getPeerId(null, RequestEvent.STARTED));
assertThat(client.getNumwant(RequestEvent.STARTED)).isEqualTo(200);
}
示例3: forEachRemaining
import java.util.AbstractMap; //导入依赖的package包/类
public void forEachRemaining(Consumer<? super Map.Entry<K,V>> action) {
if (action == null) throw new NullPointerException();
Comparator<? super K> cmp = comparator;
K f = fence;
Node<K,V> e = current;
current = null;
for (; e != null; e = e.next) {
K k; Object v;
if ((k = e.key) != null && f != null && cpr(cmp, f, k) <= 0)
break;
if ((v = e.value) != null && v != e) {
@SuppressWarnings("unchecked") V vv = (V)v;
action.accept
(new AbstractMap.SimpleImmutableEntry<K,V>(k, vv));
}
}
}
示例4: createSlidingModeSnapshots
import java.util.AbstractMap; //导入依赖的package包/类
public Set<ModeStructureSnapshot.SlidingModeSnapshot> createSlidingModeSnapshots() {
Set<ModeStructureSnapshot.SlidingModeSnapshot> result =
new HashSet<ModeStructureSnapshot.SlidingModeSnapshot>();
for (Map.Entry<ModeImpl, String> curEntry: slidingModes2Sides.entrySet()) {
final ModeImpl key = curEntry.getKey();
AbstractMap<TopComponent, Integer> lazy = new AbstractMap<TopComponent, Integer>() {
Map<TopComponent, Integer> delegate;
@Override
public Set<Entry<TopComponent, Integer>> entrySet() {
if (delegate == null) {
delegate = getSlideInSizes(key);
}
return delegate.entrySet();
}
};
result.add(new ModeStructureSnapshot.SlidingModeSnapshot(
curEntry.getKey(), curEntry.getValue(), lazy
));
}
return result;
}
示例5: tryHandleReference0
import java.util.AbstractMap; //导入依赖的package包/类
private <T> T tryHandleReference0(T o) {
if (o instanceof RedissonReference) {
return fromReference(o);
} else if (o instanceof ScoredEntry && ((ScoredEntry) o).getValue() instanceof RedissonReference) {
ScoredEntry<?> se = ((ScoredEntry<?>) o);
return (T) new ScoredEntry(se.getScore(), fromReference(se.getValue()));
} else if (o instanceof ScanObjectEntry) {
ScanObjectEntry keyScan = (ScanObjectEntry) o;
Object obj = tryHandleReference0(keyScan.getObj());
return obj != keyScan.getObj() ? (T) new ScanObjectEntry(keyScan.getBuf(), obj) : o;
} else if (o instanceof Map.Entry) {
Map.Entry old = (Map.Entry) o;
Object key = tryHandleReference0(old.getKey());
Object value = tryHandleReference0(old.getValue());
return value != old.getValue() || key != old.getKey()
? (T) new AbstractMap.SimpleEntry(key, value)
: o;
} else {
return o;
}
}
示例6: runTest
import java.util.AbstractMap; //导入依赖的package包/类
@Override
public Map.Entry<Boolean, String> runTest() {
Boolean pass = Boolean.FALSE;
String message = null;
try {
ResponderId ridByKeyIdBytes =
new ResponderId(INV_EXPLICIT_TAG_KEY_ID);
throw new RuntimeException("Expected IOException not thrown");
} catch (IOException ioe) {
// Make sure it's the IOException we're looking for
if (ioe.getMessage().contains("Invalid ResponderId content")) {
pass = Boolean.TRUE;
} else {
ioe.printStackTrace(System.out);
message = ioe.getClass().getName();
}
} catch (Exception e) {
e.printStackTrace(System.out);
message = e.getClass().getName();
}
return new AbstractMap.SimpleEntry<>(pass, message);
}
示例7: testStringCodec
import java.util.AbstractMap; //导入依赖的package包/类
@Test
public void testStringCodec() {
Config config = createConfig();
config.setCodec(StringCodec.INSTANCE);
RedissonClient redisson = Redisson.create(config);
RMap<String, String> rmap = redisson.getMap("TestRMap01");
rmap.put("A", "1");
rmap.put("B", "2");
Iterator<Map.Entry<String, String>> iterator = rmap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> next = iterator.next();
assertThat(next).isIn(new AbstractMap.SimpleEntry("A", "1"), new AbstractMap.SimpleEntry("B", "2"));
}
redisson.shutdown();
}
示例8: getNearEntry
import java.util.AbstractMap; //导入依赖的package包/类
/**
* Submap version of ConcurrentSkipListMap.getNearEntry
*/
Map.Entry<K,V> getNearEntry(K key, int rel) {
Comparator<? super K> cmp = m.comparator;
if (isDescending) { // adjust relation for direction
if ((rel & LT) == 0)
rel |= LT;
else
rel &= ~LT;
}
if (tooLow(key, cmp))
return ((rel & LT) != 0) ? null : lowestEntry();
if (tooHigh(key, cmp))
return ((rel & LT) != 0) ? highestEntry() : null;
for (;;) {
Node<K,V> n = m.findNear(key, rel, cmp);
if (n == null || !inBounds(n.key, cmp))
return null;
K k = n.key;
V v = n.getValidValue();
if (v != null)
return new AbstractMap.SimpleImmutableEntry<K,V>(k, v);
}
}
示例9: replaceWithLink
import java.util.AbstractMap; //导入依赖的package包/类
public CharSequence replaceWithLink(CharSequence source, String param, ArrayList<Integer> uids, AbstractMap<Integer, TLRPC.User> usersDict) {
int start = TextUtils.indexOf(source, param);
if (start >= 0) {
SpannableStringBuilder names = new SpannableStringBuilder("");
for (int a = 0; a < uids.size(); a++) {
TLRPC.User user = null;
if (usersDict != null) {
user = usersDict.get(uids.get(a));
}
if (user == null) {
user = MessagesController.getInstance().getUser(uids.get(a));
}
if (user != null) {
String name = UserObject.getUserName(user);
start = names.length();
if (names.length() != 0) {
names.append(", ");
}
names.append(name);
names.setSpan(new URLSpanNoUnderlineBold("" + user.id), start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return TextUtils.replace(source, new String[]{param}, new CharSequence[]{names});
}
return source;
}
示例10: getNearEntry
import java.util.AbstractMap; //导入依赖的package包/类
/**
* Submap version of ConcurrentSkipListMap.getNearEntry.
*/
Map.Entry<K,V> getNearEntry(K key, int rel) {
Comparator<? super K> cmp = m.comparator;
if (isDescending) { // adjust relation for direction
if ((rel & LT) == 0)
rel |= LT;
else
rel &= ~LT;
}
if (tooLow(key, cmp))
return ((rel & LT) != 0) ? null : lowestEntry();
if (tooHigh(key, cmp))
return ((rel & LT) != 0) ? highestEntry() : null;
for (;;) {
Node<K,V> n = m.findNear(key, rel, cmp);
if (n == null || !inBounds(n.key, cmp))
return null;
K k = n.key;
V v = n.getValidValue();
if (v != null)
return new AbstractMap.SimpleImmutableEntry<K,V>(k, v);
}
}
示例11: testMissingSetting
import java.util.AbstractMap; //导入依赖的package包/类
public void testMissingSetting() throws InterruptedException {
String collector = randomAsciiOfLength(5);
Set<AbstractMap.SimpleEntry<String, String>> entries = new HashSet<>();
entries.add(new AbstractMap.SimpleEntry<>("monitor.jvm.gc.collector." + collector + ".warn", randomPositiveTimeValue()));
entries.add(new AbstractMap.SimpleEntry<>("monitor.jvm.gc.collector." + collector + ".info", randomPositiveTimeValue()));
entries.add(new AbstractMap.SimpleEntry<>("monitor.jvm.gc.collector." + collector + ".debug", randomPositiveTimeValue()));
Settings.Builder builder = Settings.builder();
// drop a random setting or two
for (@SuppressWarnings("unchecked") AbstractMap.SimpleEntry<String, String> entry : randomSubsetOf(randomIntBetween(1, 2), entries.toArray(new AbstractMap.SimpleEntry[0]))) {
builder.put(entry.getKey(), entry.getValue());
}
// we should get an exception that a setting is missing
execute(builder.build(), (command, interval, name) -> null, e -> {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), containsString("missing gc_threshold for [monitor.jvm.gc.collector." + collector + "."));
}, true, null);
}
示例12: getProfessionIdsAndNamesSortedById
import java.util.AbstractMap; //导入依赖的package包/类
public static List<Map.Entry<Integer, String>> getProfessionIdsAndNamesSortedById()
{
List<Map.Entry<Integer, String>> professions = new ArrayList<Map.Entry<Integer, String>>();
for (VillagerRegistry.VillagerProfession profession : ForgeRegistries.VILLAGER_PROFESSIONS.getValues())
{
@SuppressWarnings("deprecation")
int id = VillagerRegistry.getId(profession);
String name = profession.getRegistryName().toString();
professions.add(new AbstractMap.SimpleEntry<Integer, String>(id, name));
}
Collections.sort(professions, new Comparator<Map.Entry<Integer, String>>()
{
@Override
public int compare(Map.Entry<Integer, String> o1, Map.Entry<Integer, String> o2)
{
return o1.getKey() - o2.getKey();
}
});
return professions;
}
示例13: getFields
import java.util.AbstractMap; //导入依赖的package包/类
public static final <T> List<Map.Entry<Field, SQLField>> getFields(Class<? extends T> clazz, FieldType fieldType) {
if (clazz == null || !clazz.isAnnotationPresent(SQLTable.class) || fieldType == null) {
return new ArrayList<>();
}
return Arrays.asList(clazz.getFields()).stream().filter((field) -> field.isAnnotationPresent(SQLField.class)).map((field) -> new AbstractMap.SimpleEntry<>(field, field.getAnnotation(SQLField.class))).filter((field) -> {
switch (fieldType) {
case NONE:
return false;
case SEND:
return field.getValue().send();
case RECEIVE:
return field.getValue().receive();
case REMOVE:
return field.getValue().primaryKey();
case ALL:
return true;
default:
return false;
}
}).sorted((field_1, field_2) -> field_1.getValue().index() - field_2.getValue().index()).collect(Collectors.toList());
}
示例14: issueDpnAvailabilityNotification
import java.util.AbstractMap; //导入依赖的package包/类
/**
* Issue a DPN Availability Notification
* @param dpnAvailability - DPN
*/
static public void issueDpnAvailabilityNotification(DpnAvailability dpnAvailability){
for(ClientIdentifier clientId : FpcServiceImpl.clientIdList){
Long notificationId = NotificationInfo.next();
Notify notif = new NotifyBuilder()
.setNotificationId(new NotificationId(notificationId))
.setTimestamp(BigInteger.valueOf(System.currentTimeMillis()))
.setValue(dpnAvailability)
.build();
String streamString = fpcCodecUtils.notificationToJsonString(Notify.class,
(DataObject) notif,
true);
streamString = streamString.replace("\n", "");
streamString = "event:application/json;/notification\ndata:"+streamString+"\n";
try {
NotificationService.blockingQueue.put(new AbstractMap.SimpleEntry<String,String>(clientId.getInt64().toString(),streamString));
} catch (InterruptedException e) {
ErrorLog.logError(e.getLocalizedMessage(),e.getStackTrace());
}
}
}
示例15: testsForHashMapNullValuesForbidden
import java.util.AbstractMap; //导入依赖的package包/类
private static Test testsForHashMapNullValuesForbidden() {
return wrappedHashMapTests(new WrappedHashMapGenerator() {
@Override Map<String, String> wrap(final HashMap<String, String> map) {
if (map.containsValue(null)) {
throw new NullPointerException();
}
return new AbstractMap<String, String>() {
@Override public Set<Map.Entry<String, String>> entrySet() {
return map.entrySet();
}
@Override public String put(String key, String value) {
checkNotNull(value);
return map.put(key, value);
}
};
}
}, "HashMap w/out null values", ALLOWS_NULL_KEYS);
}