Skip to content

Commit

Permalink
Minor clean-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Dec 1, 2018
1 parent e5a6806 commit 31daad4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
Expand Up @@ -45,16 +45,18 @@ public Stream<RetrieveResult> retrieve( @Name( value = "section" ) String sectio
throws InvalidArgumentsException
{
String upperSection = section.toUpperCase();
if ( upperSection.equals( GraphCountsSection.name ) )
switch ( upperSection )
{
case GraphCountsSection.NAME:
return GraphCountsSection.collect( dataCollector.kernel, Anonymizer.PLAIN_TEXT );
}
if ( upperSection.equals( TokensSection.name ) )
{

case TokensSection.NAME:
return TokensSection.collect( dataCollector.kernel );

default:
throw new InvalidArgumentsException( String.format( "Unknown retrieve section '%s', known sections are ['%s', '%s']",
section, GraphCountsSection.NAME, TokensSection.NAME ) );
}
throw new InvalidArgumentsException( String.format( "Unknown retrieve section '%s', known sections are ['%s', '%s']",
section, GraphCountsSection.name, TokensSection.name ) );
}

@Admin
Expand Down
Expand Up @@ -20,11 +20,13 @@
package org.neo4j.internal.collector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.neo4j.helpers.collection.Iterators;
Expand All @@ -49,9 +51,13 @@
* planner has when planning, meaning that the data from this section could be used to investigate
* planning problems.
*/
class GraphCountsSection
final class GraphCountsSection
{
static final String name = "GRAPH COUNTS";
static final String NAME = "GRAPH COUNTS";

private GraphCountsSection()
{ // only static functionality
}

static Stream<RetrieveResult> collect( Kernel kernel, Anonymizer anonymizer )
{
Expand All @@ -66,7 +72,7 @@ static Stream<RetrieveResult> collect( Kernel kernel, Anonymizer anonymizer )
data.put( "indexes", indexes( tokens, tx.schemaRead(), anonymizer ) );
data.put( "constraints", constraints( tokens, tx.schemaRead(), anonymizer ) );

return Stream.of( new RetrieveResult( "GRAPH COUNTS", data ) );
return Stream.of( new RetrieveResult( NAME, data ) );
}
catch ( TransactionFailureException | IndexNotFoundKernelException e )
{
Expand Down Expand Up @@ -147,9 +153,12 @@ private static List<Map<String,Object>> indexes( TokenRead tokens, SchemaRead sc
{
IndexReference index = iterator.next();

Map<String,Object> data = new HashMap<>( 4 );
data.put( "labels", map( index.schema().getEntityTokenIds(), id -> anonymizer.label( tokenLookup.labelGetName( id ), id ) ) );
data.put( "properties", map( index.schema().getPropertyIds(), id -> anonymizer.propertyKey( tokenLookup.propertyKeyGetName( id ), id ) ) );
Map<String,Object> data = new HashMap<>();
data.put( "labels", map( index.schema().getEntityTokenIds(),
id -> anonymizer.label( tokenLookup.labelGetName( id ), id ) ) );

data.put( "properties", map( index.schema().getPropertyIds(),
id -> anonymizer.propertyKey( tokenLookup.propertyKeyGetName( id ), id ) ) );

Register.DoubleLongRegister register = Registers.newDoubleLongRegister();
schemaRead.indexUpdatesAndSize( index, register );
Expand Down Expand Up @@ -179,7 +188,8 @@ private static List<Map<String,Object>> constraints( TokenRead tokens, SchemaRea

int labelId = constraint.schema().getEntityTokenIds()[0];
data.put( "label", anonymizer.label( tokenLookup.labelGetName( labelId ), labelId ) );
data.put( "properties", map( constraint.schema().getPropertyIds(), id -> anonymizer.propertyKey( tokenLookup.propertyKeyGetName( id ), id ) ) );
data.put( "properties", map( constraint.schema().getPropertyIds(),
id -> anonymizer.propertyKey( tokenLookup.propertyKeyGetName( id ), id ) ) );
data.put( "type", constraintType( constraint ) );

constraints.add( data );
Expand All @@ -190,12 +200,7 @@ private static List<Map<String,Object>> constraints( TokenRead tokens, SchemaRea

private static List<String> map( int[] ids, IntFunction<String> f )
{
List<String> x = new ArrayList<>( ids.length );
for ( int id : ids )
{
x.add( f.apply( id ) );
}
return x;
return Arrays.stream(ids).mapToObj( f ).collect( Collectors.toList());
}

private static String constraintType( ConstraintDescriptor constraint )
Expand Down
Expand Up @@ -31,9 +31,13 @@
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.internal.kernel.api.security.LoginContext;

class TokensSection
final class TokensSection
{
static final String name = "TOKENS";
static final String NAME = "TOKENS";

private TokensSection()
{ // only static methods
}

static Stream<RetrieveResult> collect( Kernel kernel )
{
Expand All @@ -54,7 +58,7 @@ static Stream<RetrieveResult> collect( Kernel kernel )
data.put( "labels", labels );
data.put( "relationshipTypes", relationshipTypes );
data.put( "propertyKeys", propertyKeys );
return Stream.of( new RetrieveResult( "TOKENS", data ) );
return Stream.of( new RetrieveResult( NAME, data ) );
}
catch ( TransactionFailureException e )
{
Expand Down

0 comments on commit 31daad4

Please sign in to comment.