/** */ @Override public Table countByCategory(String columnName) { Table t = Table.create("Column: " + columnName); StringColumn categories = StringColumn.create("Category"); IntColumn counts = IntColumn.create("Count"); Short2IntMap valueToCount = new Short2IntOpenHashMap(); for (short next : values) { if (valueToCount.containsKey(next)) { valueToCount.put(next, valueToCount.get(next) + 1); } else { valueToCount.put(next, 1); } } for (Map.Entry<Short, Integer> entry : valueToCount.short2IntEntrySet()) { categories.append(getValueForKey(entry.getKey())); counts.append(entry.getValue()); } if (countMissing() > 0) { categories.append("* missing values"); counts.append(countMissing()); } t.addColumns(categories); t.addColumns(counts); return t; }
@Override public boolean contains(final Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof Short2IntMap.Entry) { final Short2IntMap.Entry e = (Short2IntMap.Entry) o; final short k = e.getShortKey(); return map.containsKey(k) && ((map.get(k)) == (e.getIntValue())); } final Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; final Object key = e.getKey(); if (key == null || !(key instanceof Short)) return false; final short k = ((Short) (key)).shortValue(); final Object value = e.getValue(); if (value == null || !(value instanceof Integer)) return false; return map.containsKey(k) && ((map.get(k)) == (((Integer) (value)).intValue())); }
/** * Returns the value to which the specified key is mapped, or the * {@code defaultValue} if this map contains no mapping for the key. * * @param key * the key. * @param defaultValue * the default mapping of the key. * * @return the value to which the specified key is mapped, or the * {@code defaultValue} if this map contains no mapping for the key. * * @see java.util.Map#getOrDefault(Object, Object) * @since 8.0.0 */ default int getOrDefault(final short key, final int defaultValue) { final int v; return ((v = get(key)) != defaultReturnValue() || containsKey(key)) ? v : defaultValue; } /**
final java.util.function.BiFunction<? super Short, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int oldValue = get(key), drv = defaultReturnValue(); if (oldValue == drv && !containsKey(key)) return drv;
final java.util.function.IntFunction<? extends Integer> mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v;
final java.util.function.BiFunction<? super Short, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int oldValue = get(key), drv = defaultReturnValue(); final boolean contained = oldValue != drv || containsKey(key); final Integer newValue = remappingFunction.apply(Short.valueOf(key),
final java.util.function.BiFunction<? super Integer, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int oldValue = get(key), drv = defaultReturnValue(); final int newValue; if (oldValue != drv || containsKey(key)) {
/** * Removes the entry for the specified key only if it is currently mapped to the * specified value. * * @param key * key with which the specified value is associated. * @param value * value expected to be associated with the specified key. * * @return {@code true} if the value was removed. * * @see java.util.Map#remove(Object, Object) * @since 8.0.0 */ default boolean remove(final short key, final int value) { final int curValue = get(key); if (!((curValue) == (value)) || (curValue == defaultReturnValue() && !containsKey(key))) return false; remove(key); return true; } /**
/** * Replaces the entry for the specified key only if currently mapped to the * specified value. * * @param key * key with which the specified value is associated. * @param oldValue * value expected to be associated with the specified key. * @param newValue * value to be associated with the specified key. * * @return {@code true} if the value was replaced. * * @see java.util.Map#replace(Object, Object, Object) * @since 8.0.0 */ default boolean replace(final short key, final int oldValue, final int newValue) { final int curValue = get(key); if (!((curValue) == (oldValue)) || (curValue == defaultReturnValue() && !containsKey(key))) return false; put(key, newValue); return true; } /**
/** * If the specified key is not already associated with a value, associates it * with the given value and returns the {@linkplain #defaultReturnValue() * default return value}, else returns the current value. * * @param key * key with which the specified value is to be associated. * @param value * value to be associated with the specified key. * * @return the previous value associated with the specified key, or the * {@linkplain #defaultReturnValue() default return value} if there was * no mapping for the key. * * @see java.util.Map#putIfAbsent(Object, Object) * @since 8.0.0 */ default int putIfAbsent(final short key, final int value) { final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v; put(key, value); return drv; } /**
final int v = get(key); if (v != defaultReturnValue() || containsKey(key)) return v;
final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v;
/** */ @Override public Table countByCategory(String columnName) { Table t = Table.create("Column: " + columnName); StringColumn categories = StringColumn.create("Category"); IntColumn counts = IntColumn.create("Count"); Short2IntMap valueToCount = new Short2IntOpenHashMap(); for (short next : values) { if (valueToCount.containsKey(next)) { valueToCount.put(next, valueToCount.get(next) + 1); } else { valueToCount.put(next, 1); } } for (Map.Entry<Short, Integer> entry : valueToCount.short2IntEntrySet()) { categories.append(getValueForKey(entry.getKey())); counts.append(entry.getValue()); } if (countMissing() > 0) { categories.append("* missing values"); counts.append(countMissing()); } t.addColumns(categories); t.addColumns(counts); return t; }