@Override public E apply(E input) { return interner.intern(input); }
@Override public E apply(E input) { return interner.intern(input); }
public void setInterned(Properties p) { if (p != null) { this.interned = INTERNER.intern(p); } else { this.interned = p; } }
public void setInputFileFormatClass( final Class<? extends InputFormat> inputFileFormatClass) { if (inputFileFormatClass == null) { this.inputFileFormatClass = null; } else { this.inputFileFormatClass = (Class<? extends InputFormat>) CLASS_INTERNER.intern(inputFileFormatClass); } }
Protoclass forProto(Protoclass protoclass) { return protoclassInterner.intern(protoclass); } }
@Nullable private Map<String, Object> prepareLoadSpec(@Nullable Map<String, Object> loadSpec) { if (loadSpec == null) { return null; } // Load spec is just of 3 entries on average; HashMap/LinkedHashMap consumes much more memory than ArrayMap Map<String, Object> result = new Object2ObjectArrayMap<>(loadSpec.size()); for (Map.Entry<String, Object> e : loadSpec.entrySet()) { result.put(STRING_INTERNER.intern(e.getKey()), e.getValue()); } return result; }
private List<String> prepareDimensionsOrMetrics(@Nullable List<String> list, Interner<List<String>> interner) { if (list == null) { return ImmutableList.of(); } else { List<String> result = list .stream() .filter(s -> !Strings.isNullOrEmpty(s)) // dimensions & metrics are stored as canonical string values to decrease memory required for storing // large numbers of segments. .map(STRING_INTERNER::intern) // TODO replace with ImmutableList.toImmutableList() when updated to Guava 21+ .collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf)); return interner.intern(result); } }
public void setOutputFileFormatClass(final Class<?> outputFileFormatClass) { Class<? extends OutputFormat> outputClass = outputFileFormatClass == null ? null : HiveFileFormatUtils.getOutputFormatSubstitute(outputFileFormatClass); if (outputClass != null) { this.outputFileFormatClass = (Class<? extends HiveOutputFormat>) CLASS_INTERNER.intern(outputClass); } else { this.outputFileFormatClass = outputClass; } }
@SuppressWarnings("unchecked") @Value.Check protected T intern() { return (T) INTERNER.intern(this); } }
@Override public <E> Interner<E> create(Collection<E> contents) { Interner<E> interner = Interners.newWeakInterner(); for (E e : contents) { interner.intern(e); } return interner; } },
@Override public <E> Interner<E> create(Collection<E> contents) { Interner<E> interner = Interners.newStrongInterner(); for (E e : contents) { interner.intern(e); } return interner; } };
@Override public Integer load(Integer key) { return interner.get().intern(-key); } },
private SegmentId(String dataSource, Interval interval, String version, int partitionNum) { this.dataSource = STRING_INTERNER.intern(Objects.requireNonNull(dataSource)); this.intervalStartMillis = interval.getStartMillis(); this.intervalEndMillis = interval.getEndMillis(); this.intervalChronology = interval.getChronology(); // Versions are timestamp-based Strings, interning of them doesn't make sense. If this is not the case, interning // could be conditionally allowed via a system property. this.version = Objects.requireNonNull(version); this.partitionNum = partitionNum; this.hashCode = computeHashCode(); }
@Override public Map<Integer, Integer> loadAll(Iterable<? extends Integer> keys) { Map<Integer, Integer> result = new HashMap<>(); keys.forEach(key -> result.put(key, interner.get().intern(-key))); return result; } },
public void testWeak_afterGC() throws InterruptedException { Integer canonical = new Integer(5); Integer not = new Integer(5); Interner<Integer> pool = Interners.newWeakInterner(); assertSame(canonical, pool.intern(canonical)); WeakReference<Integer> signal = new WeakReference<>(canonical); canonical = null; // Hint to the JIT that canonical is unreachable GcFinalization.awaitClear(signal); assertSame(not, pool.intern(not)); }
public void testStrong_null() { Interner<String> pool = Interners.newStrongInterner(); try { pool.intern(null); fail(); } catch (NullPointerException ok) { } }
public void testWeak_null() { Interner<String> pool = Interners.newWeakInterner(); try { pool.intern(null); fail(); } catch (NullPointerException ok) { } }
private static Token internToken(Token t) { if (t == null) { return null; } if (t instanceof ImmutableCommonToken) { return TOKEN_CACHE.intern((ImmutableCommonToken) t); } else { t.setText(StringInternUtils.internIfNotNull(t.getText())); return t; } } }