Java Code Examples for org.apache.commons.collections4.MultiValuedMap#put()

The following examples show how to use org.apache.commons.collections4.MultiValuedMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingEntriesMethod_thenReturningMappings() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");

    Collection<Entry<String, String>> entries = (Collection<Entry<String, String>>) map.entries();
    
    for(Map.Entry<String,String> entry : entries) {
        assertThat(entry.getKey()).contains("fruits");
        assertTrue(entry.getValue().equals("apple") || entry.getValue().equals("orange") );
    }
}
 
Example 2
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingKeysMethod_thenReturningAllKeys() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("vehicles", "car");
    map.put("vehicles", "bike");
    
    MultiSet<String> keys = map.keys();
    
    assertThat((keys)).contains("fruits", "vehicles");

}
 
Example 3
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingSizeMethod_thenReturningElementCount() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("vehicles", "car");
    map.put("vehicles", "bike");
    
    assertEquals(4, map.size());
}
 
Example 4
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingIsEmptyMethod_thenReturningFalse() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("vehicles", "car");
    map.put("vehicles", "bike");
    
    assertFalse(map.isEmpty());
}
 
Example 5
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingContainsValueMethod_thenReturningTrue() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("vehicles", "car");
    map.put("vehicles", "bike");
    
    assertTrue(map.containsValue("orange"));
}
 
Example 6
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingContainsKeyMethod_thenReturningTrue() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("vehicles", "car");
    map.put("vehicles", "bike");
    
    assertTrue(map.containsKey("fruits"));
}
 
Example 7
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void givenUnmodifiableMultiValuedMap_whenInserting_thenThrowingException() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    MultiValuedMap<String, String> immutableMap = MultiMapUtils.unmodifiableMultiValuedMap(map);
    
    immutableMap.put("fruits", "banana");

}
 
Example 8
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenHashSetValuedHashMap_whenPuttingTwiceTheSame_thenReturningOneValue() {
    MultiValuedMap<String, String> map = new HashSetValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "apple");
  
    assertThat((Collection<String>) map.get("fruits")).containsExactly("apple");
}
 
Example 9
Source File: MapMultipleValuesUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenHashSetValuedHashMap_whenPuttingTwiceTheSame_thenReturningOneValue() {
    MultiValuedMap<String, String> map = new HashSetValuedHashMap<>();
    map.put("key1", "value1");
    map.put("key1", "value1");
    assertThat((Collection<String>) map.get("key1"))
      .containsExactly("value1");
}
 
Example 10
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingValuesMethod_thenReturningAllValues() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();

    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("vehicles", "car");
    map.put("vehicles", "bike");
    
    assertThat(((Collection<String>) map.values())).contains("apple", "orange", "car", "bike");
}
 
Example 11
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingKeySetMethod_thenReturningAllKeys() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("vehicles", "car");
    map.put("vehicles", "bike");
    
    Set<String> keys = map.keySet();
    
    assertThat(keys).contains("fruits", "vehicles");

}
 
Example 12
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenArrayListValuedHashMap_whenPuttingDoubleValues_thenReturningAllValues() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("fruits", "apple");
    map.put("fruits", "orange");
    map.put("fruits", "orange");
    
    assertThat((Collection<String>) map.get("fruits")).containsExactly("apple", "orange", "orange");
}
 
Example 13
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenGettingValueUsingGetMethod_thenReturningValue() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
  
    map.put("fruits", "apple");
    
    assertThat((Collection<String>) map.get("fruits")).containsExactly("apple");
}
 
Example 14
Source File: MapMultipleValuesUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void givenUnmodifiableMultiValuedMap_whenInserting_thenThrowingException() {
    MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
    map.put("key1", "value1");
    map.put("key1", "value2");
    MultiValuedMap<String, String> immutableMap =
      MultiMapUtils.unmodifiableMultiValuedMap(map);
    immutableMap.put("key1", "value3");
}
 
Example 15
Source File: ReportService.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public MultiValuedMap<Integer, PointCountResult> reportPointsFrequency() {
    MultiValuedMap<Integer, PointCountResult> map = new ArrayListValuedHashMap<>();

    final List<PointCountResult> resultList = this.betRepository.countNumberOfPointsByUser();
    for (PointCountResult pointCountResult : resultList) {
        map.put(pointCountResult.getPoints(), pointCountResult);
    }

    return map;
}
 
Example 16
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 5 votes vote down vote up
public void removePredictions(Recommender aRecommender)
{
    // Remove incoming predictions
    if (incomingPredictions != null) {
        incomingPredictions.removePredictions(aRecommender.getId());
    }

    // Remove active predictions
    if (activePredictions != null) {
        activePredictions.removePredictions(aRecommender.getId());
    }

    // Remove trainedModel
    contexts.remove(aRecommender);

    // Remove from activeRecommenders map.
    // We have to do this, otherwise training and prediction continues for the
    // recommender when a new task is triggered.
    MultiValuedMap<AnnotationLayer, EvaluatedRecommender> newActiveRecommenders = 
            new HashSetValuedHashMap<>();
    MapIterator<AnnotationLayer, EvaluatedRecommender> it = activeRecommenders
            .mapIterator();

    while (it.hasNext()) {
        AnnotationLayer layer = it.next();
        EvaluatedRecommender rec = it.getValue();
        if (!rec.getRecommender().equals(aRecommender)) {
            newActiveRecommenders.put(layer, rec);
        }
    }
    
    setActiveRecommenders(newActiveRecommenders);
}
 
Example 17
Source File: PrimitiveUimaIndexingSupport.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public MultiValuedMap<String, String> indexFeatureValue(String aFieldPrefix,
        AnnotationFS aAnnotation, String aFeaturePrefix, AnnotationFeature aFeature)
{
    FeatureSupport<?> featSup = featureSupportRegistry.getFeatureSupport(aFeature);
    String featureValue = featSup.renderFeatureValue(aFeature, aAnnotation);
    MultiValuedMap<String, String> values = new HashSetValuedHashMap<String, String>();
    if (isEmpty(featureValue)) {
        return values;
    }
    values.put(featureIndexName(aFieldPrefix, aFeaturePrefix, aFeature),
            featureValue);
    return values;
}
 
Example 18
Source File: SleighAssemblerBuilder.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Invert a name table to a map suitable for use with {@link AssemblyStringMapTerminal}
 * 
 * @param ns the name symbol
 * @return the inverted string map
 */
protected MultiValuedMap<String, Integer> invNameSymbol(NameSymbol ns) {
	MultiValuedMap<String, Integer> result = new HashSetValuedHashMap<>();
	int index = -1;
	for (String name : ns.getNameTable()) {
		index++;
		if (name != null) {
			result.put(name, index);
		}
	}
	return result;
}
 
Example 19
Source File: LearningCurveChartPanel.java    From inception with Apache License 2.0 4 votes vote down vote up
/**
 * Fetches a number of latest evaluation scores from the database and save it in the map
 * corresponding to each recommender for which the scores have been logged in the database
 * 
 * @return
 */
private MultiValuedMap<String, Double> getLatestScores()
{
    // we want to plot RecommenderEvaluationResultEvent for the learning curve. The
    // value of the event
    String eventType = "RecommenderEvaluationResultEvent";

    List<LoggedEvent> loggedEvents = new ArrayList<LoggedEvent>();
    
    List<Recommender> listEnabledRecommenders = recommendationService
            .listEnabledRecommenders(model.getObject().getProject());

    if (listEnabledRecommenders.isEmpty()) {
        LOG.warn("The project has no enabled recommender");
    }
    
    for (Recommender recommender : listEnabledRecommenders) {
        List<LoggedEvent> tempLoggedEvents = eventRepo.listLoggedEventsForRecommender(
                model.getObject().getProject(), model.getObject().getUser().getUsername(),
                eventType, MAX_POINTS_TO_PLOT, recommender.getId());
        
        // we want to show the latest record on the right side of the graph
        Collections.reverse(tempLoggedEvents);
        
        loggedEvents.addAll(tempLoggedEvents);
    }
            
    if (CollectionUtils.isEmpty(loggedEvents)) {
        return new ArrayListValuedHashMap<String, Double>();
    }

    MultiValuedMap<String, Double> recommenderScoreMap = new ArrayListValuedHashMap<>();

    // iterate over the logged events to extract the scores and map it against its corresponding
    // recommender.
    for (LoggedEvent loggedEvent : loggedEvents) {
        String detailJson = loggedEvent.getDetails();
        try {
            Details detail = fromJsonString(Details.class, detailJson);

            // If the log is inconsistent and we do not have an ID for some reason, then we
            // have to skip it
            if (detail.recommenderId == null) {
                continue;
            }
            
            //do not include the scores from disabled recommenders
            Optional<Recommender> recommenderIfActive = recommendationService
                    .getEnabledRecommender(detail.recommenderId);
            if (!recommenderIfActive.isPresent()) {
                continue;
            }

            // sometimes score values NaN. Can result into error while rendering the graph on UI
            double score;
            
            switch (selectedMetric ) {
            case Accuracy:
                score = detail.accuracy;
                break;
            case Precision:
                score = detail.precision;
                break;
            case Recall:
                score = detail.recall;
                break;
            case F1:
                score = detail.f1;
                break;
            default:
                score = detail.accuracy;
            }
            
            if (!Double.isFinite(score)) {
                continue;
            }
            
            //recommenderIfActive only has one member
            recommenderScoreMap.put(recommenderIfActive.get().getName(), score);
        }
        catch (IOException e) {
            LOG.error("Invalid logged Event detail. Skipping record with logged event id: "
                    + loggedEvent.getId(), e);
        }
    }
    return recommenderScoreMap;
}
 
Example 20
Source File: ConceptFeatureIndexingSupport.java    From inception with Apache License 2.0 4 votes vote down vote up
@Override
public MultiValuedMap<String, String> indexFeatureValue(String aFieldPrefix,
        AnnotationFS aAnnotation, String aFeaturePrefix, AnnotationFeature aFeature)
{
    // Returns KB IRI label after checking if the
    // feature type is associated with KB and feature value is not null
    FeatureSupport<?> featSup = featureSupportRegistry.getFeatureSupport(aFeature);
    KBHandle featureObject = featSup.getFeatureValue(aFeature, aAnnotation);
    MultiValuedMap<String, String> values = new HashSetValuedHashMap<String, String>();
    
    // Feature value is not set
    if (featureObject == null) {
        return values;
    }

    // Get object from the KB
    Optional<KBObject> kbObject = kbService.readItem(aFeature.getProject(),
            WebAnnoCasUtil.getFeature(aAnnotation, aFeature.getName()));

    if (!kbObject.isPresent()) {
        return values;
    }

    String field = aFieldPrefix;
    
    // Indexing <layer>.<feature>-exact=<UI label>
    values.put(featureIndexName(field, aFeaturePrefix, aFeature),
            featureObject.getUiLabel());
    // Indexing <layer>.<feature>=<UI label>
    values.put(field + ATTRIBUTE_SEP + aFeature.getUiName(),
            featureObject.getUiLabel());
    // Indexing: <layer>.<feature>-exact=<URI>
    values.put(featureIndexName(field, aFeaturePrefix, aFeature),
            featureObject.getIdentifier());
    // Indexing: <layer>.<feature>=<URI>
    values.put(field + ATTRIBUTE_SEP + aFeature.getUiName(), featureObject.getIdentifier());

    // The following fields are used by the mentions panes on the KB page in order to find all
    // mentions of a given resource irrespective of which layer/feature they are linked to.
    // Indexing: KB.Entity=<UI label>
    values.put(KB_ENTITY, featureObject.getUiLabel());
    // Indexing: KB.Entity=<URI>
    values.put(KB_ENTITY, featureObject.getIdentifier());
    
    // Indexing super concepts with type super.concept 
    KBObject kbObj = kbObject.get();
    List<KBHandle> listParentConcepts = kbService.getParentConceptList(kbObj.getKB(),
            kbObj.getIdentifier(), false);
    for (KBHandle parentConcept : listParentConcepts) {
        if (hasImplicitNamespace(kbObj.getKB(), parentConcept.getIdentifier())) {
            continue;
        }
        values.put(field + aFeaturePrefix + ATTRIBUTE_SEP + aFeature.getUiName(),
                parentConcept.getUiLabel());
    }
    
    return values;
}