|
| 1 | +/* |
| 2 | + * SSSOM-Java - SSSOM library for Java |
| 3 | + * Copyright © 2025 Damien Goutte-Gattat |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.incenp.obofoundry.sssom.transform; |
| 20 | + |
| 21 | +import java.util.List; |
| 22 | +import java.util.function.Function; |
| 23 | + |
| 24 | +/** |
| 25 | + * Represents a simple format modifier function that does not take any argument. |
| 26 | + * <p> |
| 27 | + * This class is intended to allow creating simple modifiers without having to |
| 28 | + * create a new dedicated class. For example, to create a modifier that turns |
| 29 | + * its input into lowercase: |
| 30 | + * |
| 31 | + * <pre> |
| 32 | + * new SimpleStringModifierFunction("lower", (input) -> input.toLowerCase()); |
| 33 | + * </pre> |
| 34 | + */ |
| 35 | +public class SimpleStringModifierFunction extends BaseStringModifierFunction { |
| 36 | + |
| 37 | + private String name; |
| 38 | + private Function<String, String> func; |
| 39 | + |
| 40 | + /** |
| 41 | + * Creates a new instance. |
| 42 | + * |
| 43 | + * @param name The name of the modifier function to create. |
| 44 | + * @param func The implementation of the function. |
| 45 | + */ |
| 46 | + public SimpleStringModifierFunction(String name, Function<String, String> func) { |
| 47 | + this.name = name; |
| 48 | + this.func = func; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public String getName() { |
| 53 | + return name; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public String getSignature() { |
| 58 | + return ""; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + protected String apply(Object value, List<String> extra) { |
| 63 | + return func.apply(value.toString()); |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments