Java Code Examples for it.unimi.dsi.fastutil.objects.Object2ObjectMap#size()
The following examples show how to use
it.unimi.dsi.fastutil.objects.Object2ObjectMap#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestScopedMdc.java From armeria with Apache License 2.0 | 6 votes |
/** * Returns the {@link Map} of all request-scoped {@link MDC} properties bound to the specified * {@link RequestContext}. * * @param ctx the {@link RequestContext} * * @return the {@link Map} that contains all request-scoped {@link MDC} properties. * An empty {@link Map} if there are no request-scoped {@link MDC} properties. */ public static Map<String, String> getAll(RequestContext ctx) { requireNonNull(ctx, "ctx"); final Object2ObjectMap<String, String> map = getMap(ctx); final RequestContext rootCtx = ctx.root(); if (rootCtx == null || rootCtx == ctx) { return map; } final Object2ObjectMap<String, String> rootMap = getMap(rootCtx); if (rootMap.isEmpty()) { return map; } if (map.isEmpty()) { return rootMap; } final Object2ObjectMap<String, String> merged = new Object2ObjectOpenHashMap<>(rootMap.size() + map.size()); merged.putAll(rootMap); merged.putAll(map); return merged; }
Example 2
Source File: RequestScopedMdc.java From armeria with Apache License 2.0 | 6 votes |
/** * Binds the specified request-scoped {@link MDC} property to the specified {@link RequestContext}. * * @param ctx the {@link RequestContext} * @param key the key of the request-scoped {@link MDC} property * @param value the value of the request-scoped {@link MDC} property */ public static void put(RequestContext ctx, String key, @Nullable String value) { requireNonNull(ctx, "ctx"); requireNonNull(key, "key"); synchronized (ctx) { final Object2ObjectMap<String, String> oldMap = getMap(ctx); final Object2ObjectMap<String, String> newMap; if (oldMap.isEmpty()) { newMap = Object2ObjectMaps.singleton(key, value); } else { final Object2ObjectMap<String, String> tmp = new Object2ObjectOpenHashMap<>(oldMap.size() + 1); tmp.putAll(oldMap); tmp.put(key, value); newMap = Object2ObjectMaps.unmodifiable(tmp); } ctx.setAttr(MAP, newMap); } }
Example 3
Source File: RequestScopedMdc.java From armeria with Apache License 2.0 | 6 votes |
/** * Binds the specified request-scoped {@link MDC} properties to the specified {@link RequestContext}. * * @param ctx the {@link RequestContext} * @param map the {@link Map} that contains the request-scoped {@link MDC} properties */ public static void putAll(RequestContext ctx, Map<String, String> map) { requireNonNull(ctx, "ctx"); requireNonNull(map, "map"); if (map.isEmpty()) { return; } synchronized (ctx) { final Object2ObjectMap<String, String> oldMap = getMap(ctx); final Object2ObjectMap<String, String> newMap; if (oldMap.isEmpty()) { newMap = new Object2ObjectOpenHashMap<>(map); } else { newMap = new Object2ObjectOpenHashMap<>(oldMap.size() + map.size()); newMap.putAll(oldMap); newMap.putAll(map); } ctx.setAttr(MAP, Object2ObjectMaps.unmodifiable(newMap)); } }
Example 4
Source File: RequestScopedMdc.java From armeria with Apache License 2.0 | 6 votes |
/** * Unbinds the specified request-scoped {@link MDC} property from the specified {@link RequestContext}. * * @param ctx the {@link RequestContext} * @param key the key of the request-scoped {@link MDC} property to unbind */ public static void remove(RequestContext ctx, String key) { requireNonNull(ctx, "ctx"); requireNonNull(key, "key"); synchronized (ctx) { final Object2ObjectMap<String, String> oldMap = getMap(ctx); if (!oldMap.containsKey(key)) { return; } final Object2ObjectMap<String, String> newMap; if (oldMap.size() == 1) { newMap = Object2ObjectMaps.emptyMap(); } else { final Object2ObjectOpenHashMap<String, String> tmp = new Object2ObjectOpenHashMap<>(oldMap); tmp.remove(key); newMap = Object2ObjectMaps.unmodifiable(tmp); } ctx.setAttr(MAP, newMap); } }