Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MultiValueTable #829

Merged
merged 25 commits into from
Nov 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a877b23
improve MultiValueTable
venfernand Feb 12, 2023
573cee3
Merge branch 'next' into fred-multi-value-table-improvement
venfernand Apr 21, 2023
00f9ef2
restore previous public API of freenet/support/MultiValueTable.java
venfernand Oct 8, 2023
0525735
Merge branch 'next' into fred-multi-value-table-improvement
venfernand Oct 8, 2023
ab7e17c
fix code indentation in freenet/support/MultiValueTable.java
venfernand Oct 8, 2023
a9aae2d
Merge branch 'next' into fred-multi-value-table-improvement
venfernand Oct 20, 2023
0a32278
Fix comment in ToadletContextImpl.sendReplyHeaders()
venfernand Oct 20, 2023
7db50fd
Expand star imports in ToadletContextImpl
venfernand Oct 20, 2023
3bfbc44
Move assignment of FProxyFetchTracker.fetchers into the place where v…
venfernand Oct 20, 2023
c6f8d7f
Remove unused import from FProxyFetchTracker
venfernand Oct 20, 2023
3b5523d
Improve method FProxyFetchTracker.getFetchInProgress()
venfernand Oct 20, 2023
2eef2a0
Remove the MultiValueTable.removeAndGet() method
venfernand Oct 20, 2023
7f8ef91
Return a Collection from MultiValueTable.values()
venfernand Oct 20, 2023
2d85389
Make MultiValueTable.putAll() to accept sub-types
venfernand Oct 20, 2023
5573a5f
Change deprecation note in MultiValueTable.getArray() method Javadoc
venfernand Oct 21, 2023
c48a27b
Replace CopyOnWriteArrayList with unmodifiable list in MultiValueTable
venfernand Oct 20, 2023
98e1cf7
Improve immutability of values returned from MultiValueTable and docu…
venfernand Oct 21, 2023
7fed29f
Add deprecation notes for MultiValueTable.get(key) method
venfernand Oct 21, 2023
2217f1f
Restore previous behavior of MultiValueTable.getArray() method
venfernand Oct 21, 2023
f7d34e3
Restore previous behavior of MultiValueTable.getSync() and return a V…
venfernand Oct 22, 2023
117dad4
Remove redundant null check from RequestStatusCache.getShadowBucket()
venfernand Oct 22, 2023
e7ff0e4
Remove redundant null check from FProxyFetchTracker.getFetchInProgress()
venfernand Oct 22, 2023
b79a2a0
Merge branch 'next' into fred-multi-value-table-improvement
ArneBab Nov 30, 2024
36cd30b
Fix merge error
ArneBab Nov 30, 2024
643cbee
Fix merge error
ArneBab Nov 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restore previous behavior of MultiValueTable.getSync() and return a V…
…ector from there
venfernand committed Oct 22, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
commit f7d34e3d3e562164b60fdb978d3ba8958ae661fe
21 changes: 10 additions & 11 deletions src/freenet/support/MultiValueTable.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package freenet.support;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
ArneBab marked this conversation as resolved.
Show resolved Hide resolved
import java.util.concurrent.ConcurrentHashMap;

/**
@@ -173,12 +164,20 @@ public int countAll(K key) {
* Returns mapped value collection as raw {@link Object}
*
* @param key key mapping
* @return a new {@link Vector} of mapped values.
* For compatibility reasons this method returns a raw {@link Object},
* and the real type of returned value is {@link Vector}.
* The returned value is a new modifiable copy of mapped values.
* @deprecated this method was used in previous {@code synchronized} implementation variant.
* Use other {@link #getAllAsList(Object)})} method variant, which provides a typed {@link List} collection. *
*/
@Deprecated
public Object getSync(K key) {
return getAllAsList(key);
List<V> l = this.table.get(key);
if (l == null) {
return null;
}
return new Vector<>(l);
}

/**
42 changes: 39 additions & 3 deletions test/freenet/support/MultiValueTableTest.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, most of these tests are pretty horrible. 🙁 Coverage is pretty good, though, so they’ll do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that there is no need to check such trivial places?
Or those preparations of test collections are not very clear?

Original file line number Diff line number Diff line change
@@ -15,9 +15,29 @@
*/
package freenet.support;

import static org.junit.Assert.*;

import java.util.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.Vector;
import java.util.stream.Collectors;

import org.junit.Before;
@@ -295,6 +315,22 @@ public void testGetSync() {
}
}

@Test
public void getSyncMethodReturnsVectorObject() {
List<String> values = Arrays.asList("one", "two");
multiValueTable = new MultiValueTable<>();
multiValueTable.putAll(1, values);

Object object = multiValueTable.getSync(1);
assertThat(object, instanceOf(Vector.class));
assertEquals(new Vector<>(values), object);
}

@Test
public void getSyncMethodReturnsNullIfKeyIsMissing() {
assertNull(new MultiValueTable<>().getSync("notExistingKey"));
}

@Test
public void testGetIterateAll() {
for (Map.Entry<Integer, List<Object>> entry : sampleObjects.entrySet()) {