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

nl.vpro.domain.api.SimpleTextMatcher Maven / Gradle / Ivy

Go to download

Contains the objects used by the Frontend API, like forms and result objects

There is a newer version: 8.3.3
Show newest version
/*
 * Copyright (C) 2016 All rights reserved
 * VPRO The Netherlands
 */
package nl.vpro.domain.api;

import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Pattern;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import nl.vpro.domain.api.jackson.SimpleTextMatcherJson;
import nl.vpro.domain.api.validation.ValidTextMatcher;

/**
 * @author Michiel Meeuwissen
 * @since 4.6
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "simpleMatcherType")
@JsonSerialize(using = SimpleTextMatcherJson.Serializer.class)
@JsonDeserialize(using = SimpleTextMatcherJson.Deserializer.class)
@ValidTextMatcher
public class SimpleTextMatcher extends AbstractTextMatcher {

    @XmlAttribute
    @Pattern(regexp = "^AUTO|$")
    @Getter
    @Setter
    protected String fuzziness;

    public static final SimpleMatchType DEFAULT_MATCHTYPE = SimpleMatchType.TEXT;

    public static SimpleTextMatcher must(String value) {
        return must(value, DEFAULT_MATCHTYPE);
    }

    public static SimpleTextMatcher should(String value) {
        return should(value, DEFAULT_MATCHTYPE);
    }

    public static SimpleTextMatcher not(String value) {
        return not(value, DEFAULT_MATCHTYPE);
    }


    public static SimpleTextMatcher must(String value, SimpleMatchType type) {
        return value == null ? null : new SimpleTextMatcher(value, Match.MUST, type);
    }

    public static SimpleTextMatcher should(String value, SimpleMatchType type) {
        return value == null ? null : new SimpleTextMatcher(value, Match.SHOULD, type);
    }

    public static SimpleTextMatcher not(String value, SimpleMatchType type) {
        return value == null ? null : new SimpleTextMatcher(value, Match.NOT, type);
    }


    @XmlAttribute
    private SimpleMatchType matchType;

    public SimpleTextMatcher( ) {
        this(null);
    }

    public SimpleTextMatcher(String value) {
        this(value, (Match) null);
    }

    public SimpleTextMatcher(String value, Match match) {
        this(value, match, null);
    }

    @lombok.Builder
    public SimpleTextMatcher(String value, Match match, SimpleMatchType matchType) {
        super(value);
        this.match = match == DEFAULT_MATCH ? null : match;
        this.matchType = matchType == SimpleMatchType.TEXT ? null : matchType;
    }

    public SimpleTextMatcher(String value, SimpleMatchType matchType) {
        this(value, null, matchType);
    }

    @Override
    public SimpleMatchType getMatchType() {
        return matchType == null ? DEFAULT_MATCHTYPE : matchType;
    }

    @Override
    public void setMatchType(SimpleMatchType matchType) {
        this.matchType = matchType;
    }

    @Override
    public SimpleTextMatcher toLowerCase() {
        return new SimpleTextMatcher(lowerCaseValue(), match, matchType);

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy