/** */ @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; }
/** * Replaces the entry for the specified key only if it is currently mapped to * some value. * * @param key * key with which the specified value is 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#replace(Object, Object) * @since 8.0.0 */ default int replace(final short key, final int value) { return containsKey(key) ? put(key, value) : defaultReturnValue(); } /**
put(key, newVal); return newVal;
return drv; int newValue = (mappedValue).intValue(); put(key, newValue); return newValue;
put(key, newVal); return newVal;
newValue = value; put(key, newValue); return newValue;
/** * 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; } /**
return v; int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue;
return drv; int newValue = mappingFunction.get(key); put(key, newValue); return newValue;
/** */ @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; }