org.apache.commons.collections4.MultiValuedMap Java Examples

The following examples show how to use org.apache.commons.collections4.MultiValuedMap. 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: PointsFrequencyController.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@GetMapping
public String show(Model model) {
    MultiValuedMap<Integer, PointCountResult> map = reportService.reportPointsFrequency();

    if (map.isEmpty()) {
        webMessageUtil.addInfoMsg(model, "pointsfrequency.noData");
        return PAGE_INFO_POINTS_FREQ;
    }

    List<Integer> pointsList = new ArrayList<>(map.keySet());
    Collections.reverse(pointsList);

    PointsFrequencyCommand command = new PointsFrequencyCommand(map);

    model.addAttribute("pointsFrequencyCommand", command);
    return PAGE_INFO_POINTS_FREQ;
}
 
Example #3
Source File: TupleGenerator.java    From tcases with MIT License 6 votes vote down vote up
/**
 * Return a map that associates each value property with the set of bindings that provide it.
 */
private MultiValuedMap<String,VarBindingDef> createPropertyProviders( FunctionInputDef inputDef)
  {
  propertyProviders_ = MultiMapUtils.newListValuedHashMap();
  for( VarDefIterator varDefs = new VarDefIterator( inputDef.getVarDefs()); varDefs.hasNext(); )
    {
    VarDef varDef = varDefs.next();
    for( Iterator<VarValueDef> values = varDef.getValidValues(); values.hasNext(); )
      {
      VarValueDef value = values.next();
      if( value.hasProperties())
        {
        VarBindingDef binding = new VarBindingDef( varDef, value);
        for( Iterator<String> properties = value.getProperties().iterator(); properties.hasNext(); )
          {
          propertyProviders_.put( properties.next(), binding);
          }
        }
      }
    }

  return propertyProviders_;
  }
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingRemoveMethod_thenReturningUpdatedMap() {
    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");
    
    map.remove("fruits");
    
    assertThat(((Collection<String>) map.values())).contains("car", "bike");

}
 
Example #10
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingRemoveMappingMethod_thenReturningUpdatedMapAfterMappingRemoved() {
    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");
    
    map.removeMapping("fruits", "apple");
    
    assertThat(((Collection<String>) map.values())).contains("orange", "car", "bike");
}
 
Example #11
Source File: MultiValuedMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMultiValuesMap_whenUsingClearMethod_thenReturningEmptyMap() {
    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");
    
    map.clear();
  
    assertTrue(map.isEmpty());
}
 
Example #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
Source File: MapMultipleValuesUnitTest.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("key1", "value1");
    map.put("key1", "value2");
    map.put("key1", "value2");
    assertThat((Collection<String>) map.get("key1"))
      .containsExactly("value1", "value2", "value2");
}
 
Example #20
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 #21
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 #22
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public List<EvaluatedRecommender> getActiveRecommenders(User aUser, AnnotationLayer aLayer)
{
    RecommendationState state = getState(aUser.getUsername(), aLayer.getProject());
    synchronized (state) {
        MultiValuedMap<AnnotationLayer, EvaluatedRecommender> activeRecommenders = 
                state.getActiveRecommenders();
        return new ArrayList<>(activeRecommenders.get(aLayer));
    }
}
 
Example #23
Source File: SleighAssemblerBuilder.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Invert a varnode list to a map suitable for use with {@link AssemblyStringMapTerminal}
 * 
 * @param vnlist the varnode list symbol
 * @return the inverted string map
 */
protected MultiValuedMap<String, Integer> invVarnodeList(VarnodeListSymbol vnlist) {
	MultiValuedMap<String, Integer> result = new HashSetValuedHashMap<>();
	int index = -1;
	for (VarnodeSymbol vnsym : vnlist.getVarnodeTable()) {
		index++;
		if (vnsym != null) {
			// nulls are _ in the spec, meaning the index is undefined.
			result.put(vnsym.getName(), index);
		}
	}
	return result;
}
 
Example #24
Source File: MtasUimaParser.java    From inception with Apache License 2.0 5 votes vote down vote up
private int indexFeatures(AnnotationFS aAnnotation, String aLayer, String aPrefix, Range aRange,
        int aMtasId, int aFSAddress)
{
    int mtasId = aMtasId;

    // If there are no features on the layer, do not attempt to index them
    List<AnnotationFeature> features = layerFeatures.get(aAnnotation.getType().getName());
    if (features == null) {
        return mtasId;
    }
    
    // Iterate over the features of this layer and index them one-by-one
    for (AnnotationFeature feature : features) {
        Optional<FeatureIndexingSupport> fis = featureIndexingSupportRegistry
                .getIndexingSupport(feature);
        if (fis.isPresent()) {
            MultiValuedMap<String, String> fieldsAndValues = fis.get()
                    .indexFeatureValue(aLayer, aAnnotation, aPrefix, feature);
            for (Entry<String, String> e : fieldsAndValues.entries()) {
                indexFeatureValue(e.getKey(), e.getValue(), mtasId++,
                        aAnnotation.getBegin(), aAnnotation.getEnd(), aRange, aFSAddress);
            }
            
            LOG.trace("FEAT[{}-{}]: {}", aRange.getBegin(), aRange.getEnd(), fieldsAndValues);
        }
    }
    
    return mtasId;
}
 
Example #25
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 #26
Source File: LearningCurveChartPanel.java    From inception with Apache License 2.0 5 votes vote down vote up
/**
 * Returns chart data wrapped in LearningCurve
 */
private LearningCurve renderChart()
{
    LOG.debug("SELECTED METRIC IS " + selectedMetric);
    MultiValuedMap<String, Double> recommenderScoreMap = getLatestScores();

    if (CollectionUtils.isEmpty(recommenderScoreMap.keys())) {
        LOG.debug("Cannot plot the learning curve because there are no scores. Project: {}",
                model.getObject().getProject());
        return null;
    }

    Map<String,String> curveData = new HashMap<String,String>();
    LearningCurve learningCurve = new LearningCurve();

    // iterate over recommenderScoreMap to create data
    for (String recommenderName : recommenderScoreMap.keySet()) {
        // extract the scores from the recommenderScoreMap. The format of data is a comma
        // separated string of scores(each score is Double cast-able) to be. 
        // Example 2.3, 4.5 ,6, 5, 3, 9,
        String data = recommenderScoreMap.get(recommenderName).stream().map(Object::toString)
                .collect(Collectors.joining(", "));
        
        curveData.put(recommenderName,data);
        
        learningCurve.setCurveData(curveData);
        
        // the Curve is not allowed to have more points as compared to MAX_POINTS_TO_PLOT. This
        // is how many scores we have retrieved from the database
        int[] intArray = IntStream.range(0, MAX_POINTS_TO_PLOT).map(i -> i).toArray();
        String xaxisValues =  substring(Arrays.toString(intArray), 1, -1)  ;
        
        learningCurve.setXaxis(xaxisValues);
    }

    return learningCurve;
}
 
Example #27
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public void setActiveRecommenders(User aUser, AnnotationLayer aLayer,
        List<EvaluatedRecommender> aRecommenders)
{
    RecommendationState state = getState(aUser.getUsername(), aLayer.getProject());
    synchronized (state) {
        MultiValuedMap<AnnotationLayer, EvaluatedRecommender> activeRecommenders = state
                .getActiveRecommenders();
        activeRecommenders.remove(aLayer);
        activeRecommenders.putAll(aLayer, aRecommenders);
    }
}
 
Example #28
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 #29
Source File: PointsFrequencyCommand.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public PointsFrequencyCommand(MultiValuedMap<Integer, PointCountResult> map) {
	List<Integer> pointsList = new ArrayList<>(map.keySet());
	Collections.reverse(pointsList);

	for (Integer points : pointsList) {
		if (points > 0) {
			Collection<PointCountResult> collection = map.get(points);
			PointsFrequency pointsFrequency = new PointsFrequency(points, new ArrayList<>(collection));
			resultList.add(pointsFrequency);	
		}			
	}
}
 
Example #30
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;
}