it.unimi.dsi.fastutil.objects.Object2ObjectMap Java Examples
The following examples show how to use
it.unimi.dsi.fastutil.objects.Object2ObjectMap.
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); } }
Example #5
Source File: NpcClothingFeature.java From MineLittlePony with MIT License | 5 votes |
public <K> VillagerResourceMetadata.HatType getHatType(Object2ObjectMap<K, HatType> cache, String type, DefaultedRegistry<K> registry, K key) { if (cache.containsKey(key)) { return cache.get(key); // People often complain that villagers cause lag, // so let's do better than Mojang and rather NOT go // through all the lambda generations if we can avoid it. } return loadHatType(cache, type, registry, key); }
Example #6
Source File: Fastutil.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static <K, V> ObjectIterable<Object2ObjectMap.Entry<K, V>> fastIterable( @Nonnull final Object2ObjectMap<K, V> map) { final ObjectSet<Object2ObjectMap.Entry<K, V>> entries = map.object2ObjectEntrySet(); return entries instanceof Object2ObjectMap.FastEntrySet ? new ObjectIterable<Object2ObjectMap.Entry<K, V>>() { @SuppressWarnings("unchecked") public ObjectIterator<Object2ObjectMap.Entry<K, V>> iterator() { return ((Object2ObjectMap.FastEntrySet<K, V>) entries).fastIterator(); } } : entries; }
Example #7
Source File: RequestScopedMdc.java From armeria with Apache License 2.0 | 5 votes |
/** * Unbinds all request-scoped {@link MDC} properties from the specified {@link RequestContext}. * * @param ctx the {@link RequestContext} */ public static void clear(RequestContext ctx) { requireNonNull(ctx, "ctx"); synchronized (ctx) { final Object2ObjectMap<String, String> oldMap = getMap(ctx); if (!oldMap.isEmpty()) { ctx.setAttr(MAP, Object2ObjectMaps.emptyMap()); } } }
Example #8
Source File: FMStringFeatureMapModel.java From incubator-hivemall with Apache License 2.0 | 4 votes |
@Nonnull Object2ObjectMap<String, Entry> getMap() { return _map; }
Example #9
Source File: DistributedCacheLookupUDF.java From incubator-hivemall with Apache License 2.0 | 4 votes |
private static void loadValues(Object2ObjectMap<Object, Object> map, File file, PrimitiveObjectInspector keyOI, PrimitiveObjectInspector valueOI) throws IOException, SerDeException { if (!file.exists()) { return; } if (!file.getName().endsWith(".crc")) { if (file.isDirectory()) { for (File f : file.listFiles()) { loadValues(map, f, keyOI, valueOI); } } else { LazySimpleSerDe serde = HiveUtils.getKeyValueLineSerde(keyOI, valueOI); StructObjectInspector lineOI = (StructObjectInspector) serde.getObjectInspector(); StructField keyRef = lineOI.getStructFieldRef("key"); StructField valueRef = lineOI.getStructFieldRef("value"); PrimitiveObjectInspector keyRefOI = (PrimitiveObjectInspector) keyRef.getFieldObjectInspector(); PrimitiveObjectInspector valueRefOI = (PrimitiveObjectInspector) valueRef.getFieldObjectInspector(); BufferedReader reader = null; try { reader = HadoopUtils.getBufferedReader(file); String line; while ((line = reader.readLine()) != null) { Text lineText = new Text(line); Object lineObj = serde.deserialize(lineText); List<Object> fields = lineOI.getStructFieldsDataAsList(lineObj); Object f0 = fields.get(0); Object f1 = fields.get(1); Object k = keyRefOI.getPrimitiveJavaObject(f0); Object v = valueRefOI.getPrimitiveWritableObject(valueRefOI.copyObject(f1)); map.put(k, v); } } finally { IOUtils.closeQuietly(reader); } } } }
Example #10
Source File: RequestScopedMdc.java From armeria with Apache License 2.0 | 4 votes |
private static Object2ObjectMap<String, String> getMap(RequestContext ctx) { final Object2ObjectMap<String, String> map = ctx.ownAttr(MAP); return firstNonNull(map, Object2ObjectMaps.emptyMap()); }
Example #11
Source File: EmbeddingHandler.java From AffectiveTweets with GNU General Public License v3.0 | 2 votes |
/** * Gets the dictionary mapping the words to their vectors * * @return the dictionary. */ public Object2ObjectMap<String, AbstractDoubleList> getWordMap() { return wordMap; }