Module jakarta.data

Interface NotLike

All Superinterfaces:
Constraint<String>

public interface NotLike extends Constraint<String>

A constraint that requires not matching a pattern.

A parameter-based repository method can impose a constraint on an entity attribute by defining a method parameter that is of type NotLike or is annotated @Is(NotLike.class) and is of type String. For example,


 @Find
 List<Car> matchVIN(@By(_Car.VIN) NotLike pattern);

 @Find
 List<Car> ofMakeNotModel(@By(_Car.MAKE) String manufacturer,
                          @By(_Car.MODEL) @Is(NotLike.class) String excludePattern,
                          Order<Car> sorts);

 ...

 found = cars.matchVIN(NotLike.prefix("1GM"));

 found = cars.ofMakeNotModel("Jakarta Motors",
                             "%Hybrid%",
                             Order.by(_Car.price.desc()));
 

Repository methods can also accept NotLike constraints at run time in the form of a Restriction on a TextExpression. For example,


 @Find
 List<Car> searchAll(Restriction<Car> restrict, Order<Car> sorts);

 ...

 found = cars.searchAll(Restrict.all(_Car.make.equalTo("Jakarta Motors"),
                                     _Car.model.notContains("Electric"),
                                     _Car.model.notEndsWith("EV")),
                        Order.by(_Car.model.asc(),
                                 _Car.year.desc(),
                                 _Car.price.asc()));
 

The entity and static metamodel for the code examples within this class are shown in the Attribute Javadoc.

Since:
1.1
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    The escape character to use for the pattern().
    static NotLike
    literal(String value)
    Requires that the constraint target not consist of the same characters as the given value.
    An expression that evaluates to a pattern against which the constraint target must not match.
    static NotLike
    pattern(TextExpression<?> pattern, char escape)
    Requires that the constraint target not match the given pattern expression, in which _ and % represent wildcards and the given character represents escape.
    static NotLike
    pattern(String pattern)
    Requires that the constraint target not match the given pattern, in which _ and % represent wildcards.
    static NotLike
    pattern(String pattern, char charWildcard, char stringWildcard)
    Requires that the constraint target not match the given pattern, in which the given characters represent wildcards.
    static NotLike
    pattern(String pattern, char charWildcard, char stringWildcard, char escape)
    Requires that the constraint target not match the given pattern, in which the given characters represent wildcards and escape.
    static NotLike
    prefix(String prefix)
    Requires that the constraint target not begin with the given prefix.
    static NotLike
    substring(String substring)
    Requires that the constraint target not contain the given substring.
    static NotLike
    suffix(String suffix)
    Requires that the constraint target not end with the given suffix.

    Methods inherited from interface jakarta.data.constraint.Constraint

    negate
  • Method Details

    • pattern

      static NotLike pattern(String pattern)

      Requires that the constraint target not match the given pattern, in which _ and % represent wildcards. The supplied pattern has no escape character.

      For example, the following requires that the VIN number not have JHM as its first 3 character positions and E in character position 7.

      
           found = cars.matchVIN(NotLike.pattern("JHM___E%"));
       
      Parameters:
      pattern - a pattern in which _ matches a single character and % matches 0 or more characters.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the pattern is null.
    • pattern

      static NotLike pattern(String pattern, char charWildcard, char stringWildcard)

      Requires that the constraint target not match the given pattern, in which the given characters represent wildcards. The supplied pattern has no escape character.

      For example, the following requires that the VIN number not have JHM as its first 3 character positions and F in character position 7.

      
           found = cars.matchVIN(NotLike.pattern("JHM???F*", '?', '*'));
       
      Parameters:
      pattern - a pattern that can include the given wildcard characters.
      charWildcard - wildcard that represents any single character.
      stringWildcard - wildcard that represents 0 or more characters.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the pattern is null.
    • pattern

      static NotLike pattern(String pattern, char charWildcard, char stringWildcard, char escape)

      Requires that the constraint target not match the given pattern, in which the given characters represent wildcards and escape.

      For example, the following requires that the VIN number not have JHM as its first 3 character positions and C in character position 7.

      
           found = cars.matchVIN(Like.pattern("JHM---^CC", '-', 'C', '^'));
       
      Parameters:
      pattern - a pattern that can include the given wildcard characters and escape character.
      charWildcard - wildcard that represents any single character.
      stringWildcard - wildcard that represents 0 or more characters.
      escape - escape character.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the pattern is null.
    • pattern

      static NotLike pattern(TextExpression<?> pattern, char escape)

      Requires that the constraint target not match the given pattern expression, in which _ and % represent wildcards and the given character represents escape.

      Parameters:
      pattern - an expression representing a pattern that can include the given escape character.
      escape - escape character.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the pattern expression is null.
    • prefix

      static NotLike prefix(String prefix)

      Requires that the constraint target not begin with the given prefix.

      For example, the following requires that the first 3 positions of a VIN number are not the characters JTP.

      
           found = cars.matchVIN(NotLike.prefix("JTP"));
       
      Parameters:
      prefix - text that the beginning characters of the constraint target must not match.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the prefix is null.
    • substring

      static NotLike substring(String substring)

      Requires that the constraint target not contain the given substring.

      For example, the following requires that the entity attribute value not contain the character string Hybrid,

      
           found = cars.ofModel(NotLike.substring("Hybrid"));
       
      Parameters:
      substring - text that must not be contained in the constraint target.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the substring is null.
    • suffix

      static NotLike suffix(String suffix)

      Requires that the constraint target not end with the given suffix.

      For example, the following requires that the entity attribute value not end with the characters EV,

      
           found = cars.ofModel(NotLike.suffix("EV"));
       
      Parameters:
      suffix - text that the ending characters of the constraint target must not match.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the suffix is null.
    • literal

      static NotLike literal(String value)

      Requires that the constraint target not consist of the same characters as the given value. A repository method that does not require the flexibility of allowing different types of NotLike constraints should use the NotEqualTo constraint instead.

      For example, the following requires a VIN number to exactly match,

      
           found = cars.ofModel(NotLike.literal("J-150"));
       
      Parameters:
      value - a value that must not match the constraint target.
      Returns:
      a NotLike constraint.
      Throws:
      NullPointerException - if the literal value is null.
    • escape

      char escape()

      The escape character to use for the pattern(). The pattern is assigned an escape character even if the application did not supply one when requesting the NotLike constraint.

      Returns:
      the escape character.
    • pattern

      TextExpression<?> pattern()

      An expression that evaluates to a pattern against which the constraint target must not match.

      Any custom wildcards that were supplied appear as _ and % within the pattern, with the escape character used to indicate where characters are interpreted literally rather than as wildcards or escape.

      For example, NotLike.pattern("is --.-*% of", '-', '*', '^')" is represented as is __._%^% of where ^ is the escape character.

      Returns:
      an expression representing the pattern.