Skip to content

Commit

Permalink
fix/738 Add missing methods to ImmutableMapFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh-Desale01 committed Oct 23, 2024
1 parent 538fff9 commit d7329c3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<component name="ProjectResources">
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="21" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
<component name="SvnBranchConfigurationManager">
Expand Down
8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.Map;

import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.MutableMap;

public interface ImmutableMapFactory
{
Expand Down Expand Up @@ -67,4 +69,12 @@ public interface ImmutableMapFactory
<K, V> ImmutableMap<K, V> ofAll(Map<? extends K, ? extends V> map);

<K, V> ImmutableMap<K, V> withAll(Map<? extends K, ? extends V> map);

<K, V> MutableMap<K, V> withMap(Map<? extends K, ? extends V> map);

<K, V> MutableMap<K, V> ofMapIterable(MapIterable<? extends K, ? extends V> mapIterable);

<K, V> MutableMap<K, V> withMapIterable(MapIterable<? extends K, ? extends V> mapIterable);


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
import java.util.Map;
import java.util.Objects;

import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.factory.map.ImmutableMapFactory;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;

@aQute.bnd.annotation.spi.ServiceProvider(ImmutableMapFactory.class)
public class ImmutableMapFactoryImpl implements ImmutableMapFactory
Expand Down Expand Up @@ -185,4 +189,24 @@ public <K, V> ImmutableMap<K, V> withAll(Map<? extends K, ? extends V> map)
throw new AssertionError();
}
}

@Override
public <K, V> MutableMap<K, V> withMap(Map<? extends K, ? extends V> map)
{
return UnifiedMap.newMap(map);
}

@Override
public <K, V> MutableMap<K, V> withMapIterable(MapIterable<? extends K, ? extends V> mapIterable)
{
MutableMap<K, V> output = Maps.mutable.withInitialCapacity(mapIterable.size());
mapIterable.forEachKeyValue(output::put);
return output;
}

@Override
public <K, V> MutableMap<K, V> ofMapIterable(MapIterable<? extends K, ? extends V> mapIterable)
{
return this.withMapIterable(mapIterable);
}
}

0 comments on commit d7329c3

Please sign in to comment.