enum Action {
ADD('+', Long::sum),
SUBTRACT('-', (op1, op2) -> op1 - op2),
DIVIDE('/', (op1, op2) -> op1 / op2),
MULTIPLY('*', (op1, op2) -> op1 * op2);
final char code;
final BiFunction<Long, Long, Long> func;
static final Map<Character, Action> OPS = Arrays.stream(Action.values())
.collect(Collectors.toUnmodifiableMap(it -> it.code, it -> it));
Action(char code, BiFunction<Long, Long, Long> func) {
this.code = code;
this.func = func;
}
BiFunction<Long, Long, Long> invert(boolean isPrev) {
switch (this) {
case ADD: return (op1, op2) -> op2 - op1;
case MULTIPLY: return (op1, op2) -> op2 / op1;
case SUBTRACT: return isPrev ? ADD.func : this.func;
case DIVIDE: return isPrev ? MULTIPLY.func : this.func;
default: return null;
}
}
}
почему хэштег перенаправляет на vc.ru
дошло, наконец.
а вот не знаю, кстати, почему теги при вставке - не заворачиваются автоматом на адрес dtf.
поправил вручную, спс.
а куда должен? это тег с vc, чтобы удобней было записи здесь по нему искать.