Flow matching for specific conditions

I am looking for a Java library that allows you to map a sequence of objects, potentially mixing with types like hamcrest.

Ideally, I would like to write a test that can verify that iterability contains a sequence that will look like a regular expression, but for objects, not characters:

assertThat(myList).inSequence(oneOrMore(any()),zeroOrMore(equals(MyObject)));

Mockito with validation is close to what I would like, but some simple matches are missing (e.g. zeroOrMore)

Alexander

+5
source share
3 answers

, , , , .

public boolean matchObjects() {
    Object a = new Object();
    Object b = new Object();
    Object c = new Object();
    Object d = new Object();
    ArrayList<Object> arrayList = new ArrayList<Object>();
    arrayList.add(a);
    arrayList.add(b);
    arrayList.add(c);
    arrayList.add(b);
    arrayList.add(d);
    Iterable<Object> iterable = arrayList;
    String result = "";
    for (Object object : iterable) {
        if (object.equals(a))
            result += "a";
        else if (object.equals(b))
            result += "b";
        else if (object.equals(c))
            result += "c";
        else if (object.equals(d))
            result += "d";
        else
            result += "x";
    }
    Pattern pattern = Pattern.compile("a.*b");
    return pattern.matcher(result).find();
}
+4

google ObjRegex. , , . , - #, , .

+3

, : , . , . , , - . , , , String ( ) API .

+1

All Articles