@Test public void fetchValuesWithEnumedAttributes() { SolrDocument doc = new SolrDocument(); doc.addField("judge", "Jan Kowalski|PRESIDING_JUDGE|REPORTING_JUDGE"); doc.addField("judge", "Adam Nowak|PRESIDING_JUDGE|UNKNOWN_ROLE"); List<Pair<String, List<JudgeRole>>> actual = fieldFetcher.fetchValuesWithEnumedAttributes(doc, JudgmentIndexField.JUDGE, JudgeRole.class); assertEquals(2, actual.size()); Pair<String, List<JudgeRole>> actualFirstJudge = actual.get(0); Pair<String, List<JudgeRole>> actualSecondJudge = actual.get(1); assertEquals("Jan Kowalski", actualFirstJudge.getLeft()); assertEquals(2, actualFirstJudge.getRight().size()); assertTrue(actualFirstJudge.getRight().contains(JudgeRole.PRESIDING_JUDGE)); assertTrue(actualFirstJudge.getRight().contains(JudgeRole.REPORTING_JUDGE)); assertEquals("Adam Nowak", actualSecondJudge.getLeft()); assertEquals(1, actualSecondJudge.getRight().size()); assertTrue(actualSecondJudge.getRight().contains(JudgeRole.PRESIDING_JUDGE)); }
public <E extends Enum<E>> List<Pair<String, List<E>>> fetchValuesWithEnumedAttributes(SolrDocument doc, F field, Class<E> allowedAttributes) { List<String> valuesStringList = fetchValues(doc, field.getFieldName()); List<Pair<String, List<E>>> valuesWithAttributes = Lists.newArrayList(); for (String valueString : valuesStringList) { String value = extractValue(valueString); List<String> attributes = extractAttributes(valueString); List<E> attributesEnums = convertAttributesToEnums(attributes, allowedAttributes); Pair<String, List<E>> pair = new ImmutablePair<String, List<E>>(value, attributesEnums); valuesWithAttributes.add(pair); } return valuesWithAttributes; }
SolrFieldFetcher { public <E extends Enum<E>> List<Pair<String, List<E>>> fetchValuesWithEnumedAttributes(SolrDocument doc, F field, Class<E> allowedAttributes) { List<String> valuesStringList = fetchValues(doc, field.getFieldName()); List<Pair<String, List<E>>> valuesWithAttributes = Lists.newArrayList(); for (String valueString : valuesStringList) { String value = extractValue(valueString); List<String> attributes = extractAttributes(valueString); List<E> attributesEnums = convertAttributesToEnums(attributes, allowedAttributes); Pair<String, List<E>> pair = new ImmutablePair<String, List<E>>(value, attributesEnums); valuesWithAttributes.add(pair); } return valuesWithAttributes; } }
SolrFieldFetcher { public <E extends Enum<E>> List<Pair<String, List<E>>> fetchValuesWithEnumedAttributes(SolrDocument doc, F field, Class<E> allowedAttributes) { List<String> valuesStringList = fetchValues(doc, field.getFieldName()); List<Pair<String, List<E>>> valuesWithAttributes = Lists.newArrayList(); for (String valueString : valuesStringList) { String value = extractValue(valueString); List<String> attributes = extractAttributes(valueString); List<E> attributesEnums = convertAttributesToEnums(attributes, allowedAttributes); Pair<String, List<E>> pair = new ImmutablePair<String, List<E>>(value, attributesEnums); valuesWithAttributes.add(pair); } return valuesWithAttributes; }  }
SolrFieldFetcher { public <E extends Enum<E>> List<Pair<String, List<E>>> fetchValuesWithEnumedAttributes(SolrDocument doc, F field, Class<E> allowedAttributes) { List<String> valuesStringList = fetchValues(doc, field.getFieldName()); List<Pair<String, List<E>>> valuesWithAttributes = Lists.newArrayList(); for (String valueString : valuesStringList) { String value = extractValue(valueString); List<String> attributes = extractAttributes(valueString); List<E> attributesEnums = convertAttributesToEnums(attributes, allowedAttributes); Pair<String, List<E>> pair = new ImmutablePair<String, List<E>>(value, attributesEnums); valuesWithAttributes.add(pair); } return valuesWithAttributes; }  String fetchValue(SolrDocument doc, F field); Long fetchLongValue(SolrDocument doc, F field); BigDecimal fetchCurrencyValue(SolrDocument doc, F field); LocalDate fetchDateValue(SolrDocument doc, F field); List<String> fetchValues(SolrDocument doc, F field); List<String> fetchValues(SolrDocument doc, F field, String postfix); List<Pair<String, List<String>>> fetchValuesWithAttributes(SolrDocument doc, F field); List<Pair<String, List<E>>> fetchValuesWithEnumedAttributes(SolrDocument doc, F field, Class<E> allowedAttributes); }
SolrFieldFetcher { public <E extends Enum<E>> List<Pair<String, List<E>>> fetchValuesWithEnumedAttributes(SolrDocument doc, F field, Class<E> allowedAttributes) { List<String> valuesStringList = fetchValues(doc, field.getFieldName()); List<Pair<String, List<E>>> valuesWithAttributes = Lists.newArrayList(); for (String valueString : valuesStringList) { String value = extractValue(valueString); List<String> attributes = extractAttributes(valueString); List<E> attributesEnums = convertAttributesToEnums(attributes, allowedAttributes); Pair<String, List<E>> pair = new ImmutablePair<String, List<E>>(value, attributesEnums); valuesWithAttributes.add(pair); } return valuesWithAttributes; }  String fetchValue(SolrDocument doc, F field); Long fetchLongValue(SolrDocument doc, F field); BigDecimal fetchCurrencyValue(SolrDocument doc, F field); LocalDate fetchDateValue(SolrDocument doc, F field); List<String> fetchValues(SolrDocument doc, F field); List<String> fetchValues(SolrDocument doc, F field, String postfix); List<Pair<String, List<String>>> fetchValuesWithAttributes(SolrDocument doc, F field); List<Pair<String, List<E>>> fetchValuesWithEnumedAttributes(SolrDocument doc, F field, Class<E> allowedAttributes);  }