/** * Used to void some problems where the logical condition appeared before the first term * * @param firstOne * @return */ private String toString(boolean firstOne) { StringBuilder sb = new StringBuilder(); if (this.searchTerms.size() > 0) { // in this case, the field will be used as a logical operator because the term is complex boolean first = true; Iterator<EuropeanaSearchTerm> searchTermsIt = this.searchTerms.iterator(); while (searchTermsIt.hasNext()) { EuropeanaSearchTerm searchTerm = searchTermsIt.next(); String searchTermStr; if (first == true) { searchTermStr = searchTerm.toString(first); first = false; } else { searchTermStr = searchTerm.toString(); } sb.append(searchTermStr); if (searchTermsIt.hasNext()) { sb.append(" "); } } return sb.toString(); } else { if ((this.operator != null) && (firstOne == false)) { sb.append(this.operator).append(" "); } String operandStr = super.toString(); sb.append(this.field).append(": ").append(operandStr); return sb.toString(); } }
/** * Concatenates another search term to the current one, transforming the current one in a complex * SerachTerm (one that is composed of multiple search terms separated by logical conditions) * * @param europeanaOperator * @param searchTerm */ public void addSearchTerm(String europeanaOperator, EuropeanaSearchTerm searchTerm) { EuropeanaSearchTerm newSearchTerm = new EuropeanaSearchTerm(searchTerm); newSearchTerm.operator = europeanaOperator; if (this.searchTerms.size() > 0) { this.searchTerms.add(newSearchTerm); } else { this.operator = null; EuropeanaSearchTerm currentSearchTerm = new EuropeanaSearchTerm(this); this.searchTerms.add(currentSearchTerm); this.searchTerms.add(newSearchTerm); } }