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

org.simpleflatmapper.map.CaseInsensitiveEndsWithPredicate Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.map;

import org.simpleflatmapper.util.Named;
import org.simpleflatmapper.util.OrManyPredicate;
import org.simpleflatmapper.util.Predicate;

public final class CaseInsensitiveEndsWithPredicate implements Predicate>, Named {
    private final String end;

    private CaseInsensitiveEndsWithPredicate(String name) {
        this.end = name;
    }

    @Override
    public boolean test(FieldKey fieldKey) {
        String name = fieldKey.getName();

        if (name.length() < this.end.length()) return false;

        //    public boolean regionMatches(boolean ignoreCase, int toffset,
        //            String other, int ooffset, int len) {
        return name.regionMatches(true, name.length() - end.length(), end, 0, end.length() );
    }

    @Override
    public String getName() {
        return end;
    }

    @Override
    public String toString() {
        return "CaseInsensitiveEndsWithPredicate{" +
                "name='" + end + '\'' +
                '}';
    }

    public static CaseInsensitiveEndsWithPredicate of(String name) {
        return new CaseInsensitiveEndsWithPredicate(name);
    }

    public static Predicate> any(String... name) {
        CaseInsensitiveEndsWithPredicate[] predicates = new CaseInsensitiveEndsWithPredicate[name.length];

        for (int i = 0; i < name.length; i++) {
            String n = name[i];
            predicates[i] = CaseInsensitiveEndsWithPredicate.of(n);
        }

        return new OrManyPredicate>(predicates);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy