All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.virtdata.libbasics.shared.formatting.Format Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.libbasics.shared.formatting;

import io.virtdata.annotations.Categories;
import io.virtdata.annotations.Category;
import io.virtdata.annotations.Example;
import io.virtdata.annotations.ThreadSafeMapper;

import java.util.function.Function;

/**
 * Apply the Java String.format method to an incoming object.
 * @see Java 8 String.format(...) javadoc
 * Note: This function can often be quite slow, so more direct methods are generally preferrable.
 */
@ThreadSafeMapper
@Categories(Category.conversion)
public class Format implements Function {

    private final String format;

    @Example({"Format('Y')","Yield the formatted year from a Java date object."})
    public Format(String format) {
        this.format = format;
    }

    @Override
    public String apply(Object o) {
        return String.format(format,o);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy