Skip to content

Commit

Permalink
Remove Deprecated Functions.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Mar 21, 2016
1 parent d738d33 commit 15ccf4c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 35 deletions.
Expand Up @@ -19,22 +19,16 @@
*/
package org.neo4j.function;

import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* Constructors for basic {@link Function} and {@link BiFunction} types
* @deprecated This class relies on deprecated interfaces, and will be retrofitted to work with the {@code java.util.function} interfaces in 3.0.
*/
public final class Functions
{
public static <From, To> Function<From,To> map( final Map<From,To> map )
{
return map::get;
}

public static <From, To> Function<From,To> withDefaults( final Function<From,To> defaults, final Function<From,
To> f )
Expand Down
Expand Up @@ -31,7 +31,6 @@
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.config.Setting;

import static org.neo4j.function.Functions.map;
import static org.neo4j.function.Functions.withDefaults;
import static org.neo4j.helpers.collection.MapUtil.stringMap;

Expand Down Expand Up @@ -71,7 +70,7 @@ public GraphDatabaseBuilder setConfig( Setting<?> setting, String value )
{
// Test if we can get this setting with an updated config
Map<String, String> testValue = stringMap( setting.name(), value );
setting.apply( withDefaults( map( config ), map( testValue ) ) );
setting.apply( withDefaults( config::get, testValue::get ) );

// No exception thrown, add it to existing config
config.put( setting.name(), value );
Expand Down
Expand Up @@ -23,7 +23,6 @@
import java.util.HashMap;
import java.util.Map;

import org.neo4j.function.Functions;
import org.neo4j.graphdb.config.Setting;
import org.neo4j.helpers.collection.Pair;

Expand All @@ -47,7 +46,7 @@ public void validate( Map<String, String> rawConfig )
{
for ( Setting<?> setting : settings.values() )
{
setting.apply( Functions.map( rawConfig ) );
setting.apply( rawConfig::get );
}
}

Expand Down
Expand Up @@ -25,7 +25,6 @@
import java.util.Map;
import java.util.function.Function;

import org.neo4j.function.Functions;
import org.neo4j.graphdb.config.Setting;

/**
Expand Down Expand Up @@ -57,7 +56,7 @@ public Map<String,String> apply( Map<String,String> config )
// For each system property, see if it passes validation
// If so, add it to result set
Map<String,String> result = new HashMap<String,String>( config );
Function<String,String> systemPropertiesFunction = Functions.map( systemProperties );
Function<String,String> systemPropertiesFunction = systemProperties::get;
for ( Map.Entry<Object,Object> prop : System.getProperties().entrySet() )
{
String key = (String) prop.getKey();
Expand Down
Expand Up @@ -19,33 +19,28 @@
*/
package org.neo4j.helpers;

import org.hamcrest.CoreMatchers;
import org.junit.Test;

import java.util.function.BiFunction;
import java.util.function.Function;

import org.hamcrest.CoreMatchers;
import org.junit.Test;

import org.neo4j.function.Functions;
import org.neo4j.kernel.configuration.Settings;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.neo4j.function.Functions.map;
import static org.neo4j.helpers.collection.MapUtil.stringMap;

public class FunctionsTest
{
@Test
public void testMap() throws Exception
{
assertThat( map( stringMap( "foo", "bar" ) ).apply( "foo" ), equalTo( "bar" ) );
}

@Test
public void testWithDefaults() throws Exception
{
assertThat( Functions.withDefaults( map( stringMap( "foo", "bar" ) ), Functions.<String, String>nullFunction() ).apply( "foo" ), equalTo( "bar" ) );
assertThat( Functions.withDefaults( map( stringMap( "foo", "bar" ) ), map( stringMap( "foo", "xyzzy" ) ) ).apply( "foo" ), equalTo( "xyzzy" ) );
assertThat( Functions.withDefaults( stringMap( "foo", "bar" )::get, Functions.<String,String>nullFunction() )
.apply( "foo" ), equalTo( "bar" ) );
assertThat( Functions.withDefaults( stringMap( "foo", "bar" )::get, stringMap( "foo", "xyzzy" )::get )
.apply( "foo" ), equalTo( "xyzzy" ) );
}

@Test
Expand Down
Expand Up @@ -19,11 +19,6 @@
*/
package org.neo4j.kernel.impl.store;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -33,6 +28,11 @@
import java.util.Random;
import java.util.Set;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.neo4j.graphdb.config.InvalidSettingException;
import org.neo4j.graphdb.config.Setting;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
Expand All @@ -49,7 +49,6 @@
import static java.util.Collections.singletonMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.neo4j.function.Functions.map;
import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;

public class TestDynamicStore
Expand Down Expand Up @@ -86,15 +85,15 @@ public void tearDown()
public void stringStoreCannotHaveZeroBlockSize()
{
Setting<Integer> setting = StoreFactory.Configuration.string_block_size;
setting.apply( map( singletonMap( setting.name(), "0" ) ) );
setting.apply( singletonMap( setting.name(), "0" )::get );
fail( "Illegal blocksize should throw exception" );
}

@Test( expected = InvalidSettingException.class )
public void arrayStoreCannotHaveZeroBlockSize() throws Exception
{
Setting<Integer> setting = StoreFactory.Configuration.array_block_size;
setting.apply( map( singletonMap( setting.name(), "0" ) ) );
setting.apply( singletonMap( setting.name(), "0" )::get );
fail( "Illegal blocksize should throw exception" );
}

Expand Down
Expand Up @@ -27,9 +27,8 @@
import org.neo4j.cluster.protocol.cluster.Cluster;
import org.neo4j.cluster.protocol.cluster.ClusterConfiguration;
import org.neo4j.cluster.protocol.cluster.ClusterListener;
import org.neo4j.function.Functions;
import org.neo4j.kernel.ha.cluster.modeswitch.HighAvailabilityModeSwitcher;
import org.neo4j.helpers.HostnamePort;
import org.neo4j.kernel.ha.cluster.modeswitch.HighAvailabilityModeSwitcher;
import org.neo4j.kernel.ha.com.master.Slave;
import org.neo4j.kernel.ha.com.master.SlaveFactory;
import org.neo4j.kernel.ha.com.master.Slaves;
Expand Down Expand Up @@ -86,7 +85,7 @@ public Iterable<Slave> getSlaves()
{
// Return all cluster members which are currently SLAVEs,
// are alive, and convert to Slave with a cache if possible
return map( withDefaults( slaveForMember(), Functions.map( slaves ) ),
return map( withDefaults( slaveForMember(), slaves::get ),
filter( inRole( HighAvailabilityModeSwitcher.SLAVE ),
clusterMembers.getAliveMembers() ) );
}
Expand Down

0 comments on commit 15ccf4c

Please sign in to comment.