static Object parseTermExpression(String s) { int len = s.length(); if (len == 1) { char ch = s.charAt(0); if (ch == WILDCARD) { return new ValidationError("Missing prefix for wildcard " + WILDCARD); } Term term = new Term(new char[] {ch}, 0, 1, null); return Arrays.asList(term); } List<Term> terms = new LinkedList<>(); for (String part : s.split("\\s+")) { if (part.length() > 0) { terms.add(parseTerm(part)); } } return terms; }
for (String token: synonymString.split("\\s+")) { if (token.length() > 0) { Term term = parseTerm(token); if (term.getMaxPlaceHolderRef() > 1) { return new ValidationError("Max. wild card reference is 1: " + line);
@Test public void testThatWildcardOnlyTermIsNotAllowed() throws Exception { try { LineParser.parseTerm("*"); fail("Wildcard-only term must not be allowed"); } catch (IllegalArgumentException e) { // expected } }
@Test public void testThatWildcardOnlyTermIsNotAllowedWithFieldName() throws Exception { try { LineParser.parseTerm("f1:*"); fail("Wildcard-only term must not be allowed with fieldname"); } catch (IllegalArgumentException e) { // expected } }
@Test public void testThatWildcardOnlyTermIsNotAllowedWithFieldNames() throws Exception { try { LineParser.parseTerm("{f1,f2}:*"); fail("Wildcard-only term must not be allowed with fieldname"); } catch (IllegalArgumentException e) { // expected } }
@Test public void testParseSingleLetterPrefix() throws Exception { assertThat(LineParser.parseTerm("a*"), prefix("a")); }
@Test public void testParsePrefixWithFieldName() throws Exception { assertThat(LineParser.parseTerm("f1:abc*"), prefix("abc", "f1")); }
@Test public void testParseTermWithFieldNamesContainingSpace() throws Exception { assertThat(LineParser.parseTerm("{ f1 , f2 }:abc"), term("abc", "f1", "f2")); }
@Test public void testParsePrefixWithFieldNames() throws Exception { assertThat(LineParser.parseTerm("{f1,f2}:abc*"), prefix("abc", "f1", "f2")); }
@Test public void testParseSingleLetterValueWithFieldName() throws Exception { Term term = LineParser.parseTerm("f1:a"); assertEquals(1, term.length()); assertArrayEquals(new char[] {'a'},new char[] {term.charAt(0)}); assertFalse(term instanceof PrefixTerm); assertEquals(Arrays.asList("f1"), term.getFieldNames()); }
@Test public void testParseTermWithFieldName() throws Exception { Term term = LineParser.parseTerm("f1:abc"); assertEquals(3, term.length()); assertArrayEquals(new char[] {'a', 'b', 'c'},new char[] {term.charAt(0), term.charAt(1), term.charAt(2)}); assertFalse(term instanceof PrefixTerm); assertEquals(Arrays.asList("f1"), term.getFieldNames()); }
@Test public void testParseSingleLetterValue() throws Exception { Term term = LineParser.parseTerm("a"); assertEquals(1, term.length()); assertArrayEquals(new char[] {'a'},new char[] {term.charAt(0)}); assertFalse(term instanceof PrefixTerm); assertNull(term.getFieldNames()); }
@Test public void testParsePrefixOnly() { Term term = LineParser.parseTerm("abc*"); assertEquals(3, term.length()); assertArrayEquals(new char[] {'a', 'b', 'c'},new char[] {term.charAt(0), term.charAt(1), term.charAt(2)}); assertTrue(term instanceof PrefixTerm); assertNull(term.getFieldNames()); }
@Test public void testParseTermValueOnly() { Term term = LineParser.parseTerm("abc"); assertEquals(3, term.length()); assertArrayEquals(new char[] {'a', 'b', 'c'},new char[] {term.charAt(0), term.charAt(1), term.charAt(2)}); assertFalse(term instanceof PrefixTerm); assertNull(term.getFieldNames()); }
@Test public void testParseTermWithFieldNames() throws Exception { Term term = LineParser.parseTerm("{f1,f2}:abc"); assertEquals(3, term.length()); assertArrayEquals(new char[] {'a', 'b', 'c'},new char[] {term.charAt(0), term.charAt(1), term.charAt(2)}); assertFalse(term instanceof PrefixTerm); assertThat(term.getFieldNames(), containsInAnyOrder("f1", "f2")); }