@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 void loadAnnotations(String annotationFilename) { try { LineIterator lines = new LineIterator(new FastBufferedReader(new FileReader(annotationFilename))); for (MutableString line : lines.allLines()) { if (line.startsWith("#")) continue; String tokens[] = line.toString().split("\t"); final String chromosome = tokens[0]; int position = Integer.parseInt(tokens[1]); // convert to zero-based position used by goby/variationanalysis: position -= 1; Int2ObjectAVLTreeMap<Annotation> perPositionMap = annotations.getOrDefault(chromosome, new Int2ObjectAVLTreeMap<>()); Annotation a = new Annotation(); a.position = position; a.toBase = tokens.length >= 3 ? tokens[2] : null; a.frequency = tokens.length >= 4 ? Float.parseFloat(tokens[3]) : null; perPositionMap.put(position, a); annotations.put(chromosome, perPositionMap); } } catch (FileNotFoundException e) { throw new RuntimeException("Unable to find annotation filename:" + annotationFilename, e); } }
@Override public boolean containsKey(final Object k) { return findKey(k) != -1; } @Override
@Override public void clear() { Object2ObjectArrayMap.this.clear(); } };
/** * Creates a new empty array map copying the entries of a given map. * * @param m * a map. */ public Object2ObjectArrayMap(final Map<? extends K, ? extends V> m) { this(m.size()); putAll(m); } /**
private boolean isAnnotated(String referenceId, int position) { return annotations.getOrDefault(referenceId, new Int2ObjectAVLTreeMap<Annotation>()).getOrDefault(position, null)!=null; } private Annotation getAnnotation(String referenceId, int position) {
@Override public boolean contains(final Object v) { return containsValue(v); } @Override
@Override @SuppressWarnings("unchecked") public V put(K k, V v) { final int oldKey = findKey(k); if (oldKey != -1) { final V oldValue = (V) value[oldKey]; value[oldKey] = v; return oldValue; } if (size == key.length) { final Object[] newKey = new Object[size == 0 ? 2 : size * 2]; final Object[] newValue = new Object[size == 0 ? 2 : size * 2]; for (int i = size; i-- != 0;) { newKey[i] = key[i]; newValue[i] = value[i]; } key = newKey; value = newValue; } key[size] = k; value[size] = v; size++; return defRetValue; } @Override
@Override public void clear() { Object2ObjectArrayMap.this.clear(); } };
/** * Creates a new empty array map copying the entries of a given map. * * @param m * a map. */ public Object2ObjectArrayMap(final Object2ObjectMap<K, V> m) { this(m.size()); putAll(m); } /**
private Annotation getAnnotation(String referenceId, int position) { return annotations.getOrDefault(referenceId, new Int2ObjectAVLTreeMap<Annotation>()).get(position); } }
this.shutdownAccessLogWriterOnStop = shutdownAccessLogWriterOnStop; this.channelOptions = Collections.unmodifiableMap( new Object2ObjectArrayMap<>(requireNonNull(channelOptions, "channelOptions"))); this.childChannelOptions = Collections.unmodifiableMap( new Object2ObjectArrayMap<>(requireNonNull(childChannelOptions, "childChannelOptions"))); this.clientAddressSources = ImmutableList.copyOf( requireNonNull(clientAddressSources, "clientAddressSources"));
@Override @SuppressWarnings("unchecked") public V remove(final Object k) { final int oldPos = findKey(k); if (oldPos == -1) return defRetValue; final V oldValue = (V) value[oldPos]; final int tail = size - oldPos - 1; System.arraycopy(key, oldPos + 1, key, oldPos, tail); System.arraycopy(value, oldPos + 1, value, oldPos, tail); size--; key[size] = null; value[size] = null; return oldValue; } @Override
public Trie put(IString key, Trie trie) { if (map == null) { map = new Object2ObjectArrayMap<IString, Trie>(); // map = new Object2ObjectOpenHashMap<IString,Trie>(); // map = new HashMap<IString,Trie>(); } return map.put(key, trie); }
@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; }