org.apache.commons.collections4.multimap.ArrayListValuedHashMap Java Examples
The following examples show how to use
org.apache.commons.collections4.multimap.ArrayListValuedHashMap.
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 |
@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 |
@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 #3
Source File: MapMultipleValuesUnitTest.java From tutorials with MIT License | 5 votes |
@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 #4
Source File: MapMultipleValuesUnitTest.java From tutorials with MIT License | 5 votes |
@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 #5
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #6
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #7
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #8
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #9
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #10
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #11
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #13
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #14
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #15
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #16
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 5 votes |
@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 #17
Source File: ReportService.java From fredbet with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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 #18
Source File: LearningCurveChartPanel.java From inception with Apache License 2.0 | 4 votes |
/** * 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 #19
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenMultiValuesMap_whenPuttingMultipleValuesUsingPutAllMethod_thenReturningAllValues() { MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>(); map.putAll("vehicles", Arrays.asList("car", "bike")); assertThat((Collection<String>) map.get("vehicles")).containsExactly("car", "bike"); }
Example #20
Source File: InternalSimplePortData.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void init() throws ComponentNotReadyException { super.init(); records = new ArrayListValuedHashMap<>(); }
Example #21
Source File: InternalComplexPortData.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void init() throws ComponentNotReadyException { super.init(); records = new ArrayListValuedHashMap<>(); }
Example #22
Source File: MultiValuedMapUnitTest.java From tutorials with MIT License | 3 votes |
@Test public void givenMultiValuesMap_whenPuttingMultipleValuesUsingPutMethod_thenReturningAllValues() { MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>(); map.put("fruits", "apple"); map.put("fruits", "orange"); assertThat((Collection<String>) map.get("fruits")).containsExactly("apple", "orange"); }