repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
iansrobinson/neode
src/test/java/org/neo4j/neode/DatasetTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.event.TransactionData; import org.neo4j.graphdb.event.TransactionEventHandler; import org.neo4j.neode.logging.Log; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals;
package org.neo4j.neode; public class DatasetTest { @Test public void shouldExecuteBatchesInSeparateTransactions() throws Exception { // given TransactionCounter transactionCounter = new TransactionCounter();
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/DatasetTest.java import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.event.TransactionData; import org.neo4j.graphdb.event.TransactionEventHandler; import org.neo4j.neode.logging.Log; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; package org.neo4j.neode; public class DatasetTest { @Test public void shouldExecuteBatchesInSeparateTransactions() throws Exception { // given TransactionCounter transactionCounter = new TransactionCounter();
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/test/java/org/neo4j/neode/DatasetTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.event.TransactionData; import org.neo4j.graphdb.event.TransactionEventHandler; import org.neo4j.neode.logging.Log; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals;
package org.neo4j.neode; public class DatasetTest { @Test public void shouldExecuteBatchesInSeparateTransactions() throws Exception { // given TransactionCounter transactionCounter = new TransactionCounter(); GraphDatabaseService db = Db.impermanentDb(); db.registerTransactionEventHandler( transactionCounter );
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/DatasetTest.java import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.event.TransactionData; import org.neo4j.graphdb.event.TransactionEventHandler; import org.neo4j.neode.logging.Log; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; package org.neo4j.neode; public class DatasetTest { @Test public void shouldExecuteBatchesInSeparateTransactions() throws Exception { // given TransactionCounter transactionCounter = new TransactionCounter(); GraphDatabaseService db = Db.impermanentDb(); db.registerTransactionEventHandler( transactionCounter );
DatasetManager executor = new DatasetManager( db, SysOutLog.INSTANCE );
iansrobinson/neode
src/test/java/org/neo4j/neode/DatasetTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.event.TransactionData; import org.neo4j.graphdb.event.TransactionEventHandler; import org.neo4j.neode.logging.Log; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals;
{ return numberOfIterations; } @Override public int batchSize() { return batchSize; } @Override public void execute( int iteration ) { db.createNode(); callCount++; } @Override public String description() { return "Dummy batch command"; } @Override public String shortDescription() { return ""; } @Override
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/DatasetTest.java import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.event.TransactionData; import org.neo4j.graphdb.event.TransactionEventHandler; import org.neo4j.neode.logging.Log; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; { return numberOfIterations; } @Override public int batchSize() { return batchSize; } @Override public void execute( int iteration ) { db.createNode(); callCount++; } @Override public String description() { return "Dummy batch command"; } @Override public String shortDescription() { return ""; } @Override
public void onBegin( Log log )
iansrobinson/neode
src/main/java/org/neo4j/neode/RelateNodesBatchCommand.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // }
import org.neo4j.graphdb.Node; import org.neo4j.neode.logging.Log;
return sourceNodes.size(); } @Override public int batchSize() { return batchSize; } @Override public void execute( int iteration ) { Node currentNode = sourceNodes.getNodeByPosition( iteration ); totalRels += targetNodesStrategy .addRelationshipsToCurrentNode( currentNode, targetNodes, iteration ); } @Override public String description() { return String.format( "Creating '%s' relationships.", shortDescription() ); } @Override public String shortDescription() { return targetNodesStrategy.description( sourceNodes.labelName() ); } @Override
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // Path: src/main/java/org/neo4j/neode/RelateNodesBatchCommand.java import org.neo4j.graphdb.Node; import org.neo4j.neode.logging.Log; return sourceNodes.size(); } @Override public int batchSize() { return batchSize; } @Override public void execute( int iteration ) { Node currentNode = sourceNodes.getNodeByPosition( iteration ); totalRels += targetNodesStrategy .addRelationshipsToCurrentNode( currentNode, targetNodes, iteration ); } @Override public String description() { return String.format( "Creating '%s' relationships.", shortDescription() ); } @Override public String shortDescription() { return targetNodesStrategy.description( sourceNodes.labelName() ); } @Override
public void onBegin( Log log )
iansrobinson/neode
src/main/java/org/neo4j/neode/TargetNodesStrategy.java
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // }
import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution;
package org.neo4j.neode; public class TargetNodesStrategy {
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution; package org.neo4j.neode; public class TargetNodesStrategy {
public static SetNumberOfNodes getExisting( NodeCollection nodeCollection,
iansrobinson/neode
src/main/java/org/neo4j/neode/TargetNodesStrategy.java
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // }
import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution;
package org.neo4j.neode; public class TargetNodesStrategy { public static SetNumberOfNodes getExisting( NodeCollection nodeCollection,
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution; package org.neo4j.neode; public class TargetNodesStrategy { public static SetNumberOfNodes getExisting( NodeCollection nodeCollection,
ProbabilityDistribution probabilityDistribution )
iansrobinson/neode
src/main/java/org/neo4j/neode/TargetNodesStrategy.java
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // }
import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution;
package org.neo4j.neode; public class TargetNodesStrategy { public static SetNumberOfNodes getExisting( NodeCollection nodeCollection, ProbabilityDistribution probabilityDistribution ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection, probabilityDistribution ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes getExisting( NodeCollection nodeCollection ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection,
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution; package org.neo4j.neode; public class TargetNodesStrategy { public static SetNumberOfNodes getExisting( NodeCollection nodeCollection, ProbabilityDistribution probabilityDistribution ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection, probabilityDistribution ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes getExisting( NodeCollection nodeCollection ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection,
normalDistribution() );
iansrobinson/neode
src/main/java/org/neo4j/neode/TargetNodesStrategy.java
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // }
import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution;
package org.neo4j.neode; public class TargetNodesStrategy { public static SetNumberOfNodes getExisting( NodeCollection nodeCollection, ProbabilityDistribution probabilityDistribution ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection, probabilityDistribution ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes getExisting( NodeCollection nodeCollection ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection, normalDistribution() ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes getExisting( GraphQuery graphQuery ) { QueryBasedGetExistingNodes targetNodesSource = new QueryBasedGetExistingNodes( graphQuery ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes queryBasedGetOrCreate( NodeSpecification nodeSpecification, GraphQuery graphQuery ) { QueryBasedGetOrCreateNodes targetNodesSource = new QueryBasedGetOrCreateNodes( nodeSpecification,
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java import java.util.Set; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.normalDistribution; package org.neo4j.neode; public class TargetNodesStrategy { public static SetNumberOfNodes getExisting( NodeCollection nodeCollection, ProbabilityDistribution probabilityDistribution ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection, probabilityDistribution ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes getExisting( NodeCollection nodeCollection ) { GetExistingUniqueNodes targetNodesSource = new GetExistingUniqueNodes( nodeCollection, normalDistribution() ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes getExisting( GraphQuery graphQuery ) { QueryBasedGetExistingNodes targetNodesSource = new QueryBasedGetExistingNodes( graphQuery ); return new TargetNodesStrategyBuilder( targetNodesSource ); } public static SetNumberOfNodes queryBasedGetOrCreate( NodeSpecification nodeSpecification, GraphQuery graphQuery ) { QueryBasedGetOrCreateNodes targetNodesSource = new QueryBasedGetOrCreateNodes( nodeSpecification,
new SparseNodeListGenerator( graphQuery, 1.0, flatDistribution() ) );
iansrobinson/neode
src/main/java/org/neo4j/neode/probabilities/FlatProbabilityDistributionUnique.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // }
import org.neo4j.neode.Range;
package org.neo4j.neode.probabilities; class FlatProbabilityDistributionUnique extends BaseUniqueProbabilityDistribution {
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // Path: src/main/java/org/neo4j/neode/probabilities/FlatProbabilityDistributionUnique.java import org.neo4j.neode.Range; package org.neo4j.neode.probabilities; class FlatProbabilityDistributionUnique extends BaseUniqueProbabilityDistribution {
protected int getNextNumber( Range minMax )
iansrobinson/neode
src/main/java/org/neo4j/neode/ExecuteAllCommandsBatchCommand.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // }
import org.neo4j.neode.logging.Log;
} @Override public int batchSize() { throw new IllegalAccessError(); } @Override public void execute( int iteration ) { for ( BatchCommand<NodeCollection> command : commands ) { command.execute( iteration ); } } @Override public String description() { throw new IllegalAccessError(); } @Override public String shortDescription() { throw new IllegalAccessError(); } @Override
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // Path: src/main/java/org/neo4j/neode/ExecuteAllCommandsBatchCommand.java import org.neo4j.neode.logging.Log; } @Override public int batchSize() { throw new IllegalAccessError(); } @Override public void execute( int iteration ) { for ( BatchCommand<NodeCollection> command : commands ) { command.execute( iteration ); } } @Override public String description() { throw new IllegalAccessError(); } @Override public String shortDescription() { throw new IllegalAccessError(); } @Override
public void onBegin( Log log )
iansrobinson/neode
src/test/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistributionTest.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // }
import java.util.List; import org.junit.Test; import org.neo4j.neode.Range; import static org.junit.Assert.assertEquals; import static org.neo4j.neode.Range.minMax;
package org.neo4j.neode.probabilities; public class BaseUniqueProbabilityDistributionTest { @Test public void shouldThrowExceptionIfPossibleRangeSmallerThanMaxNumberOfResults() throws Exception { // given ProbabilityDistribution probabilityDistribution = new DummyProbabilityDistribution(); try { // when
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // Path: src/test/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistributionTest.java import java.util.List; import org.junit.Test; import org.neo4j.neode.Range; import static org.junit.Assert.assertEquals; import static org.neo4j.neode.Range.minMax; package org.neo4j.neode.probabilities; public class BaseUniqueProbabilityDistributionTest { @Test public void shouldThrowExceptionIfPossibleRangeSmallerThanMaxNumberOfResults() throws Exception { // given ProbabilityDistribution probabilityDistribution = new DummyProbabilityDistribution(); try { // when
probabilityDistribution.generateList( minMax( 0, 2 ), minMax( 1, 1 ) );
iansrobinson/neode
src/test/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistributionTest.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // }
import java.util.List; import org.junit.Test; import org.neo4j.neode.Range; import static org.junit.Assert.assertEquals; import static org.neo4j.neode.Range.minMax;
package org.neo4j.neode.probabilities; public class BaseUniqueProbabilityDistributionTest { @Test public void shouldThrowExceptionIfPossibleRangeSmallerThanMaxNumberOfResults() throws Exception { // given ProbabilityDistribution probabilityDistribution = new DummyProbabilityDistribution(); try { // when probabilityDistribution.generateList( minMax( 0, 2 ), minMax( 1, 1 ) ); } catch ( IllegalArgumentException e ) { // then assertEquals( "(range.difference() + 1) must be greater or equal to numberOfResultsRange.max() " + "[numberOfResultsRange: Range{min=0, max=2}, range: Range{min=1, max=1}]", e.getMessage() ); } } @Test public void shouldAllowForZeroNumbersToBeGenerated() throws Exception { // given ProbabilityDistribution probabilityDistribution = new DummyProbabilityDistribution(); // when List<Integer> results = probabilityDistribution.generateList( minMax( 0, 0 ), minMax( 0, 1 ) ); // then assertEquals( 0, results.size() ); } private class DummyProbabilityDistribution extends BaseUniqueProbabilityDistribution { @Override
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // Path: src/test/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistributionTest.java import java.util.List; import org.junit.Test; import org.neo4j.neode.Range; import static org.junit.Assert.assertEquals; import static org.neo4j.neode.Range.minMax; package org.neo4j.neode.probabilities; public class BaseUniqueProbabilityDistributionTest { @Test public void shouldThrowExceptionIfPossibleRangeSmallerThanMaxNumberOfResults() throws Exception { // given ProbabilityDistribution probabilityDistribution = new DummyProbabilityDistribution(); try { // when probabilityDistribution.generateList( minMax( 0, 2 ), minMax( 1, 1 ) ); } catch ( IllegalArgumentException e ) { // then assertEquals( "(range.difference() + 1) must be greater or equal to numberOfResultsRange.max() " + "[numberOfResultsRange: Range{min=0, max=2}, range: Range{min=1, max=1}]", e.getMessage() ); } } @Test public void shouldAllowForZeroNumbersToBeGenerated() throws Exception { // given ProbabilityDistribution probabilityDistribution = new DummyProbabilityDistribution(); // when List<Integer> results = probabilityDistribution.generateList( minMax( 0, 0 ), minMax( 0, 1 ) ); // then assertEquals( 0, results.size() ); } private class DummyProbabilityDistribution extends BaseUniqueProbabilityDistribution { @Override
protected int getNextNumber( Range minMax )
iansrobinson/neode
src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // }
import org.neo4j.neode.Range; import java.util.List; import java.util.Random;
/* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.probabilities; public abstract class ProbabilityDistribution { private static final Random RANDOM_INSTANCE = new Random(); public static ProbabilityDistribution flatDistribution() { return new FlatProbabilityDistributionUnique(); } public static ProbabilityDistribution normalDistribution() { return new NormalProbabilityDistributionUnique(); } private final Random random; protected ProbabilityDistribution() { this.random = RANDOM_INSTANCE; }
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java import org.neo4j.neode.Range; import java.util.List; import java.util.Random; /* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.probabilities; public abstract class ProbabilityDistribution { private static final Random RANDOM_INSTANCE = new Random(); public static ProbabilityDistribution flatDistribution() { return new FlatProbabilityDistributionUnique(); } public static ProbabilityDistribution normalDistribution() { return new NormalProbabilityDistributionUnique(); } private final Random random; protected ProbabilityDistribution() { this.random = RANDOM_INSTANCE; }
public abstract List<Integer> generateList( Range sizeRange, Range range );
iansrobinson/neode
src/test/java/org/neo4j/neode/CreateUniqueNodesTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse;
package org.neo4j.neode; public class CreateUniqueNodesTest { @Test public void shouldCreateNewNodes() throws Exception { // given
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/CreateUniqueNodesTest.java import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; package org.neo4j.neode; public class CreateUniqueNodesTest { @Test public void shouldCreateNewNodes() throws Exception { // given
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/test/java/org/neo4j/neode/CreateUniqueNodesTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse;
package org.neo4j.neode; public class CreateUniqueNodesTest { @Test public void shouldCreateNewNodes() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); Label user = DynamicLabel.label("user"); try ( Transaction tx = db.beginTx() ) { CreateUniqueNodes command = new CreateUniqueNodes(
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/CreateUniqueNodesTest.java import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; package org.neo4j.neode; public class CreateUniqueNodesTest { @Test public void shouldCreateNewNodes() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); Label user = DynamicLabel.label("user"); try ( Transaction tx = db.beginTx() ) { CreateUniqueNodes command = new CreateUniqueNodes(
new NodeSpecification( user, Collections.<Property>emptyList(), db ) );
iansrobinson/neode
src/main/java/org/neo4j/neode/Range.java
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // }
import org.neo4j.neode.probabilities.ProbabilityDistribution;
if ( max < min ) { throw new IllegalArgumentException( "Max must be greater or equal to min" ); } this.min = min; this.max = max; } public int min() { return min; } public int max() { return max; } public int difference() { return max - min; } public boolean isInRange( int value ) { return value >= min() && value <= max; }
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // Path: src/main/java/org/neo4j/neode/Range.java import org.neo4j.neode.probabilities.ProbabilityDistribution; if ( max < min ) { throw new IllegalArgumentException( "Max must be greater or equal to min" ); } this.min = min; this.max = max; } public int min() { return min; } public int max() { return max; } public int difference() { return max - min; } public boolean isInRange( int value ) { return value >= min() && value <= max; }
public int getRandom( ProbabilityDistribution probabilityDistribution )
iansrobinson/neode
src/main/java/org/neo4j/neode/interfaces/InitialDatasetDefinition.java
// Path: src/main/java/org/neo4j/neode/DatasetManager.java // public class DatasetManager // { // private final GraphDatabaseService db; // private final Log log; // // public DatasetManager( GraphDatabaseService db, Log log ) // { // this.db = db; // this.log = log; // } // // public NodeSpecification nodeSpecification( String label, Property... properties ) // { // return new NodeSpecification( label, asList( properties ), db ); // } // // public RelationshipSpecification relationshipSpecification( String label, Property... properties ) // { // return relationshipSpecification( withName( label ), properties ); // } // // public RelationshipSpecification relationshipSpecification( RelationshipType relationshipType, // Property... properties ) // { // return new RelationshipSpecification( relationshipType, asList( properties ), db ); // } // // public Dataset newDataset( String description ) // { // return new Dataset( description, db, log ); // } // }
import org.neo4j.neode.DatasetManager;
package org.neo4j.neode.interfaces; public interface InitialDatasetDefinition<PARAMETERS> {
// Path: src/main/java/org/neo4j/neode/DatasetManager.java // public class DatasetManager // { // private final GraphDatabaseService db; // private final Log log; // // public DatasetManager( GraphDatabaseService db, Log log ) // { // this.db = db; // this.log = log; // } // // public NodeSpecification nodeSpecification( String label, Property... properties ) // { // return new NodeSpecification( label, asList( properties ), db ); // } // // public RelationshipSpecification relationshipSpecification( String label, Property... properties ) // { // return relationshipSpecification( withName( label ), properties ); // } // // public RelationshipSpecification relationshipSpecification( RelationshipType relationshipType, // Property... properties ) // { // return new RelationshipSpecification( relationshipType, asList( properties ), db ); // } // // public Dataset newDataset( String description ) // { // return new Dataset( description, db, log ); // } // } // Path: src/main/java/org/neo4j/neode/interfaces/InitialDatasetDefinition.java import org.neo4j.neode.DatasetManager; package org.neo4j.neode.interfaces; public interface InitialDatasetDefinition<PARAMETERS> {
void createDataset( DatasetManager datasetManager, PARAMETERS parameters );
iansrobinson/neode
src/test/java/org/neo4j/neode/RelationshipUniquenessTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.DynamicRelationshipType; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class RelationshipUniquenessTest { @Test public void uniqueSingleDirectionShouldNotCreateNewRelationshipIfRelationshipAlreadyExists() throws Exception { // given
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/RelationshipUniquenessTest.java import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.DynamicRelationshipType; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class RelationshipUniquenessTest { @Test public void uniqueSingleDirectionShouldNotCreateNewRelationshipIfRelationshipAlreadyExists() throws Exception { // given
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/test/java/org/neo4j/neode/RelationshipUniquenessTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.DynamicRelationshipType; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class RelationshipUniquenessTest { @Test public void uniqueSingleDirectionShouldNotCreateNewRelationshipIfRelationshipAlreadyExists() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); DynamicRelationshipType friend_of = withName( "FRIEND_OF" ); Node firstNode; try (Transaction tx = db.beginTx()) { firstNode = db.createNode(); Node secondNode = db.createNode(); firstNode.createRelationshipTo( secondNode, friend_of ); RelationshipSpecification relationshipSpecification = new RelationshipSpecification( friend_of,
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/RelationshipUniquenessTest.java import java.util.Collections; import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.DynamicRelationshipType; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class RelationshipUniquenessTest { @Test public void uniqueSingleDirectionShouldNotCreateNewRelationshipIfRelationshipAlreadyExists() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); DynamicRelationshipType friend_of = withName( "FRIEND_OF" ); Node firstNode; try (Transaction tx = db.beginTx()) { firstNode = db.createNode(); Node secondNode = db.createNode(); firstNode.createRelationshipTo( secondNode, friend_of ); RelationshipSpecification relationshipSpecification = new RelationshipSpecification( friend_of,
Collections.<Property>emptyList(), db );
iansrobinson/neode
src/main/java/org/neo4j/neode/Commands.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // }
import java.util.ArrayList; import java.util.List; import org.neo4j.neode.logging.Log;
package org.neo4j.neode; class Commands { private final List<BatchCommand<NodeCollection>> commands; private final CommandSelectionStrategy commandSelectionStrategy; Commands( List<BatchCommand<NodeCollection>> commands, CommandSelectionStrategy commandSelectionStrategy ) { this.commands = commands; this.commandSelectionStrategy = commandSelectionStrategy; } public BatchCommand<NodeCollection> nextCommand() { return commandSelectionStrategy.nextCommand( commands ); } public List<NodeCollection> results() { List<NodeCollection> results = new ArrayList<NodeCollection>(); for ( BatchCommand<NodeCollection> command : commands ) { results.add( command.results() ); } return results; }
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // Path: src/main/java/org/neo4j/neode/Commands.java import java.util.ArrayList; import java.util.List; import org.neo4j.neode.logging.Log; package org.neo4j.neode; class Commands { private final List<BatchCommand<NodeCollection>> commands; private final CommandSelectionStrategy commandSelectionStrategy; Commands( List<BatchCommand<NodeCollection>> commands, CommandSelectionStrategy commandSelectionStrategy ) { this.commands = commands; this.commandSelectionStrategy = commandSelectionStrategy; } public BatchCommand<NodeCollection> nextCommand() { return commandSelectionStrategy.nextCommand( commands ); } public List<NodeCollection> results() { List<NodeCollection> results = new ArrayList<NodeCollection>(); for ( BatchCommand<NodeCollection> command : commands ) { results.add( command.results() ); } return results; }
public void onBegin( Log log )
iansrobinson/neode
src/main/java/org/neo4j/neode/interfaces/SetRelationshipInfo.java
// Path: src/main/java/org/neo4j/neode/RelationshipSpecification.java // public class RelationshipSpecification // { // private final RelationshipType relationshipType; // private final List<Property> properties; // private final GraphDatabaseService db; // // RelationshipSpecification( RelationshipType relationshipType, List<Property> properties, GraphDatabaseService db ) // { // this.relationshipType = relationshipType; // this.properties = properties; // this.db = db; // } // // Relationship createRelationship( Node startNode, Node endNode, int iteration ) // { // Relationship rel = startNode.createRelationshipTo( endNode, relationshipType ); // // for ( Property property : properties ) // { // property.setProperty( rel, relationshipType.name(), iteration ); // } // // return rel; // } // // String label() // { // return relationshipType.name(); // } // // Expander expander( Direction direction ) // { // return expanderForTypes( relationshipType, direction ); // } // }
import org.neo4j.graphdb.Direction; import org.neo4j.neode.RelationshipSpecification;
/* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.interfaces; public interface SetRelationshipInfo {
// Path: src/main/java/org/neo4j/neode/RelationshipSpecification.java // public class RelationshipSpecification // { // private final RelationshipType relationshipType; // private final List<Property> properties; // private final GraphDatabaseService db; // // RelationshipSpecification( RelationshipType relationshipType, List<Property> properties, GraphDatabaseService db ) // { // this.relationshipType = relationshipType; // this.properties = properties; // this.db = db; // } // // Relationship createRelationship( Node startNode, Node endNode, int iteration ) // { // Relationship rel = startNode.createRelationshipTo( endNode, relationshipType ); // // for ( Property property : properties ) // { // property.setProperty( rel, relationshipType.name(), iteration ); // } // // return rel; // } // // String label() // { // return relationshipType.name(); // } // // Expander expander( Direction direction ) // { // return expanderForTypes( relationshipType, direction ); // } // } // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipInfo.java import org.neo4j.graphdb.Direction; import org.neo4j.neode.RelationshipSpecification; /* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.interfaces; public interface SetRelationshipInfo {
SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification, Direction direction );
iansrobinson/neode
src/test/java/org/neo4j/neode/SparseNodeListGeneratorTest.java
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // }
import java.util.Collections; import java.util.List; import org.junit.Test; import org.neo4j.graphdb.Node; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when;
package org.neo4j.neode; public class SparseNodeListGeneratorTest { @Test public void shouldReturnSparseListOfExistingNodes() throws Exception { // given Node currentNode = mock( Node.class ); GraphQuery query = mock( GraphQuery.class ); Node node0 = mock( Node.class ); Node node1 = mock( Node.class ); when( query.execute( currentNode ) ).thenReturn( asList( node0, node1 ) );
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // Path: src/test/java/org/neo4j/neode/SparseNodeListGeneratorTest.java import java.util.Collections; import java.util.List; import org.junit.Test; import org.neo4j.graphdb.Node; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; package org.neo4j.neode; public class SparseNodeListGeneratorTest { @Test public void shouldReturnSparseListOfExistingNodes() throws Exception { // given Node currentNode = mock( Node.class ); GraphQuery query = mock( GraphQuery.class ); Node node0 = mock( Node.class ); Node node1 = mock( Node.class ); when( query.execute( currentNode ) ).thenReturn( asList( node0, node1 ) );
ProbabilityDistribution probabilityDistribution = mock( ProbabilityDistribution.class );
iansrobinson/neode
src/main/java/org/neo4j/neode/RandomCommandSelectionStrategy.java
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // }
import java.util.List; import org.neo4j.neode.probabilities.ProbabilityDistribution;
package org.neo4j.neode; class RandomCommandSelectionStrategy implements CommandSelectionStrategy {
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // Path: src/main/java/org/neo4j/neode/RandomCommandSelectionStrategy.java import java.util.List; import org.neo4j.neode.probabilities.ProbabilityDistribution; package org.neo4j.neode; class RandomCommandSelectionStrategy implements CommandSelectionStrategy {
private final ProbabilityDistribution probabilityDistribution;
iansrobinson/neode
src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // }
import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create;
package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception {
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // } // Path: src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create; package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception {
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // }
import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create;
package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb();
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // } // Path: src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create; package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb();
Log log = new Log()
iansrobinson/neode
src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // }
import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create;
package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb(); Log log = new Log() { @Override public void write( String value ) { // Do nothing } }; DatasetManager dsm = new DatasetManager( db, log ); Dataset dataset = dsm.newDataset( "Execute All Test" ); NodeSpecification user = dsm.nodeSpecification( "user" ); NodeSpecification workAddress = dsm.nodeSpecification( "work address" ); NodeSpecification homeAddress = dsm.nodeSpecification( "home address" ); RelationshipSpecification work_address = dsm.relationshipSpecification( "WORK_ADDRESS" ); RelationshipSpecification home_address = dsm.relationshipSpecification( "HOME_ADDRESS" );
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // } // Path: src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create; package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb(); Log log = new Log() { @Override public void write( String value ) { // Do nothing } }; DatasetManager dsm = new DatasetManager( db, log ); Dataset dataset = dsm.newDataset( "Execute All Test" ); NodeSpecification user = dsm.nodeSpecification( "user" ); NodeSpecification workAddress = dsm.nodeSpecification( "work address" ); NodeSpecification homeAddress = dsm.nodeSpecification( "home address" ); RelationshipSpecification work_address = dsm.relationshipSpecification( "WORK_ADDRESS" ); RelationshipSpecification home_address = dsm.relationshipSpecification( "HOME_ADDRESS" );
NodeCollection users = user.create( 2 ).update( dataset );
iansrobinson/neode
src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // }
import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create;
package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb(); Log log = new Log() { @Override public void write( String value ) { // Do nothing } }; DatasetManager dsm = new DatasetManager( db, log ); Dataset dataset = dsm.newDataset( "Execute All Test" ); NodeSpecification user = dsm.nodeSpecification( "user" ); NodeSpecification workAddress = dsm.nodeSpecification( "work address" ); NodeSpecification homeAddress = dsm.nodeSpecification( "home address" ); RelationshipSpecification work_address = dsm.relationshipSpecification( "WORK_ADDRESS" ); RelationshipSpecification home_address = dsm.relationshipSpecification( "HOME_ADDRESS" ); NodeCollection users = user.create( 2 ).update( dataset ); users.createRelationshipsTo(
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // } // Path: src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create; package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb(); Log log = new Log() { @Override public void write( String value ) { // Do nothing } }; DatasetManager dsm = new DatasetManager( db, log ); Dataset dataset = dsm.newDataset( "Execute All Test" ); NodeSpecification user = dsm.nodeSpecification( "user" ); NodeSpecification workAddress = dsm.nodeSpecification( "work address" ); NodeSpecification homeAddress = dsm.nodeSpecification( "home address" ); RelationshipSpecification work_address = dsm.relationshipSpecification( "WORK_ADDRESS" ); RelationshipSpecification home_address = dsm.relationshipSpecification( "HOME_ADDRESS" ); NodeCollection users = user.create( 2 ).update( dataset ); users.createRelationshipsTo(
all(
iansrobinson/neode
src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // }
import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create;
package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb(); Log log = new Log() { @Override public void write( String value ) { // Do nothing } }; DatasetManager dsm = new DatasetManager( db, log ); Dataset dataset = dsm.newDataset( "Execute All Test" ); NodeSpecification user = dsm.nodeSpecification( "user" ); NodeSpecification workAddress = dsm.nodeSpecification( "work address" ); NodeSpecification homeAddress = dsm.nodeSpecification( "home address" ); RelationshipSpecification work_address = dsm.relationshipSpecification( "WORK_ADDRESS" ); RelationshipSpecification home_address = dsm.relationshipSpecification( "HOME_ADDRESS" ); NodeCollection users = user.create( 2 ).update( dataset ); users.createRelationshipsTo( all( create( workAddress ) .numberOfTargetNodes( 2 ) .relationship( work_address )
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // // Path: src/main/java/org/neo4j/neode/ChoiceOfTargetNodesStrategy.java // public static ChoiceOfTargetNodesStrategy all( TargetNodesStrategy... targetNodeStrategies ) // { // return new ChooseAllTargetNodesStrategies( asList( targetNodeStrategies ) ); // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // Path: src/main/java/org/neo4j/neode/TargetNodesStrategy.java // public static SetNumberOfNodes create( NodeSpecification nodeSpecification ) // { // CreateUniqueNodes targetNodesSource = new CreateUniqueNodes( nodeSpecification ); // return new TargetNodesStrategyBuilder( targetNodesSource ); // } // Path: src/test/java/org/neo4j/neode/ChooseAllTargetNodesStrategiesTest.java import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.logging.Log; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.neo4j.graphdb.DynamicRelationshipType.withName; import static org.neo4j.neode.ChoiceOfTargetNodesStrategy.all; import static org.neo4j.neode.Range.exactly; import static org.neo4j.neode.TargetNodesStrategy.create; package org.neo4j.neode; public class ChooseAllTargetNodesStrategiesTest { @Test public void shouldExecuteAllCommandsForEachNode() throws Exception { GraphDatabaseService db = Db.impermanentDb(); Log log = new Log() { @Override public void write( String value ) { // Do nothing } }; DatasetManager dsm = new DatasetManager( db, log ); Dataset dataset = dsm.newDataset( "Execute All Test" ); NodeSpecification user = dsm.nodeSpecification( "user" ); NodeSpecification workAddress = dsm.nodeSpecification( "work address" ); NodeSpecification homeAddress = dsm.nodeSpecification( "home address" ); RelationshipSpecification work_address = dsm.relationshipSpecification( "WORK_ADDRESS" ); RelationshipSpecification home_address = dsm.relationshipSpecification( "HOME_ADDRESS" ); NodeCollection users = user.create( 2 ).update( dataset ); users.createRelationshipsTo( all( create( workAddress ) .numberOfTargetNodes( 2 ) .relationship( work_address )
.relationshipConstraints( exactly( 1 ) ),
iansrobinson/neode
src/test/java/org/neo4j/neode/statistics/GraphStatisticsTest.java
// Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode.statistics; public class GraphStatisticsTest { @Test public void shouldAddNewNodeWithNoRelationships() throws Exception { // given
// Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/statistics/GraphStatisticsTest.java import java.util.Iterator; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode.statistics; public class GraphStatisticsTest { @Test public void shouldAddNewNodeWithNoRelationships() throws Exception { // given
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/test/java/org/neo4j/neode/RelationshipInfoTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class RelationshipInfoTest { private static final RelationshipSpecification relationshipSpecification =
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/RelationshipInfoTest.java import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class RelationshipInfoTest { private static final RelationshipSpecification relationshipSpecification =
new RelationshipSpecification( withName( "FRIEND" ), Collections.<Property>emptyList(),
iansrobinson/neode
src/test/java/org/neo4j/neode/RelationshipInfoTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class RelationshipInfoTest { private static final RelationshipSpecification relationshipSpecification = new RelationshipSpecification( withName( "FRIEND" ), Collections.<Property>emptyList(),
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/RelationshipInfoTest.java import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class RelationshipInfoTest { private static final RelationshipSpecification relationshipSpecification = new RelationshipSpecification( withName( "FRIEND" ), Collections.<Property>emptyList(),
Db.impermanentDb() );
iansrobinson/neode
src/test/java/org/neo4j/neode/NodeCollectionTest.java
// Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.neode.test.Db; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat;
package org.neo4j.neode; public class NodeCollectionTest { @Test public void shouldReturnNodeByPosition() throws Exception {
// Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/NodeCollectionTest.java import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import org.junit.Test; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.neode.test.Db; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; package org.neo4j.neode; public class NodeCollectionTest { @Test public void shouldReturnNodeByPosition() throws Exception {
Db.usingSampleDataset(new Db.WithSampleDataset() {
iansrobinson/neode
src/test/java/org/neo4j/neode/properties/NonIndexablePropertyTest.java
// Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.helpers.collection.IteratorUtil; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull;
package org.neo4j.neode.properties; public class NonIndexablePropertyTest { @Test public void shouldSetPropertyValue() throws Exception { // given PropertyValueGenerator generator = new PropertyValueGenerator() { @Override public Object generateValue( PropertyContainer propertyContainer, String nodeLabel, int iteration ) { return "value"; } };
// Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/properties/NonIndexablePropertyTest.java import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.helpers.collection.IteratorUtil; import org.neo4j.neode.test.Db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; package org.neo4j.neode.properties; public class NonIndexablePropertyTest { @Test public void shouldSetPropertyValue() throws Exception { // given PropertyValueGenerator generator = new PropertyValueGenerator() { @Override public Object generateValue( PropertyContainer propertyContainer, String nodeLabel, int iteration ) { return "value"; } };
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/main/java/org/neo4j/neode/statistics/AsciiDocFormatter.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // }
import java.util.Map; import org.neo4j.neode.logging.Log;
package org.neo4j.neode.statistics; public class AsciiDocFormatter implements GraphStatisticsFormatter {
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // Path: src/main/java/org/neo4j/neode/statistics/AsciiDocFormatter.java import java.util.Map; import org.neo4j.neode.logging.Log; package org.neo4j.neode.statistics; public class AsciiDocFormatter implements GraphStatisticsFormatter {
private final Log log;
iansrobinson/neode
src/main/java/org/neo4j/neode/interfaces/UpdateDataset.java
// Path: src/main/java/org/neo4j/neode/Dataset.java // public class Dataset // { // private final String description; // private final GraphDatabaseService db; // private final Log log; // private final long runStartTime; // // Dataset( String description, GraphDatabaseService db, Log log ) // { // this.description = description; // this.db = db; // this.log = log; // runStartTime = System.nanoTime(); // log.write( String.format( "Begin [%s]\n", description ) ); // } // // <T> T execute( BatchCommand<T> command ) // { // long startTime = System.nanoTime(); // // log.write( String.format( "Begin [%s Iterations: %s, BatchSize: %s]", // command.description(), command.numberOfIterations(), command.batchSize() ) ); // command.onBegin( log ); // for ( int iteration = 0; iteration < command.numberOfIterations(); iteration += command.batchSize() ) // { // doExecute( iteration, command, startTime ); // } // command.onEnd( log ); // log.write( String.format( "End [%s] %s\n", command.description(), elapsedTime( startTime ) ) ); // // return command.results(); // } // // public void end() // { // log.write( String.format( "Store [%s]\n\nEnd [%s] %s\n", // ((GraphDatabaseAPI) db).getStoreDir(), description, elapsedTime( runStartTime ) ) ); // } // // GraphDatabaseService db() // { // return db; // } // // private void doExecute( int startIteration, BatchCommand command, long startTime ) // { // log.write( String.format( " [Beginning " + startIteration + " of " + command.numberOfIterations() + // ", '%s'] %s", command.shortDescription(), elapsedTime( startTime ) ) ); // // try (Transaction tx = db.beginTx()) { // for (int iteration = startIteration; iterationIsInRange(startIteration, command, // iteration); iteration++) { // command.execute(iteration); // tx.success(); // } // } // // } // // private static boolean iterationIsInRange( int startIteration, BatchCommand command, int iteration ) // { // return iteration < (startIteration + command.batchSize()) && iteration < command.numberOfIterations(); // } // // private static String elapsedTime( long startTime ) // { // String ms = String.valueOf( (System.nanoTime() - startTime) / 1000000 ); // return String.format( "(elapsed: %s ms)", ms ); // } // }
import org.neo4j.neode.Dataset;
package org.neo4j.neode.interfaces; public interface UpdateDataset<T> {
// Path: src/main/java/org/neo4j/neode/Dataset.java // public class Dataset // { // private final String description; // private final GraphDatabaseService db; // private final Log log; // private final long runStartTime; // // Dataset( String description, GraphDatabaseService db, Log log ) // { // this.description = description; // this.db = db; // this.log = log; // runStartTime = System.nanoTime(); // log.write( String.format( "Begin [%s]\n", description ) ); // } // // <T> T execute( BatchCommand<T> command ) // { // long startTime = System.nanoTime(); // // log.write( String.format( "Begin [%s Iterations: %s, BatchSize: %s]", // command.description(), command.numberOfIterations(), command.batchSize() ) ); // command.onBegin( log ); // for ( int iteration = 0; iteration < command.numberOfIterations(); iteration += command.batchSize() ) // { // doExecute( iteration, command, startTime ); // } // command.onEnd( log ); // log.write( String.format( "End [%s] %s\n", command.description(), elapsedTime( startTime ) ) ); // // return command.results(); // } // // public void end() // { // log.write( String.format( "Store [%s]\n\nEnd [%s] %s\n", // ((GraphDatabaseAPI) db).getStoreDir(), description, elapsedTime( runStartTime ) ) ); // } // // GraphDatabaseService db() // { // return db; // } // // private void doExecute( int startIteration, BatchCommand command, long startTime ) // { // log.write( String.format( " [Beginning " + startIteration + " of " + command.numberOfIterations() + // ", '%s'] %s", command.shortDescription(), elapsedTime( startTime ) ) ); // // try (Transaction tx = db.beginTx()) { // for (int iteration = startIteration; iterationIsInRange(startIteration, command, // iteration); iteration++) { // command.execute(iteration); // tx.success(); // } // } // // } // // private static boolean iterationIsInRange( int startIteration, BatchCommand command, int iteration ) // { // return iteration < (startIteration + command.batchSize()) && iteration < command.numberOfIterations(); // } // // private static String elapsedTime( long startTime ) // { // String ms = String.valueOf( (System.nanoTime() - startTime) / 1000000 ); // return String.format( "(elapsed: %s ms)", ms ); // } // } // Path: src/main/java/org/neo4j/neode/interfaces/UpdateDataset.java import org.neo4j.neode.Dataset; package org.neo4j.neode.interfaces; public interface UpdateDataset<T> {
T update( Dataset dataset, int batchSize );
iansrobinson/neode
src/test/java/org/neo4j/neode/NodeSpecificationTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull;
package org.neo4j.neode; public class NodeSpecificationTest { @Test public void shouldCreateNewNode() throws Exception { // given
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/NodeSpecificationTest.java import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; package org.neo4j.neode; public class NodeSpecificationTest { @Test public void shouldCreateNewNode() throws Exception { // given
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/test/java/org/neo4j/neode/NodeSpecificationTest.java
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull;
package org.neo4j.neode; public class NodeSpecificationTest { @Test public void shouldCreateNewNode() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); Label user = DynamicLabel.label("user"); Node node; try ( Transaction tx = db.beginTx() ) {
// Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/NodeSpecificationTest.java import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; package org.neo4j.neode; public class NodeSpecificationTest { @Test public void shouldCreateNewNode() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); Label user = DynamicLabel.label("user"); Node node; try ( Transaction tx = db.beginTx() ) {
NodeSpecification nodeSpecification = new NodeSpecification( user, Collections.<Property>emptyList(), db );
iansrobinson/neode
src/main/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistribution.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // }
import java.util.ArrayList; import java.util.List; import org.neo4j.neode.Range; import static org.neo4j.neode.Range.exactly;
package org.neo4j.neode.probabilities; abstract class BaseUniqueProbabilityDistribution extends ProbabilityDistribution { @Override
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // Path: src/main/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistribution.java import java.util.ArrayList; import java.util.List; import org.neo4j.neode.Range; import static org.neo4j.neode.Range.exactly; package org.neo4j.neode.probabilities; abstract class BaseUniqueProbabilityDistribution extends ProbabilityDistribution { @Override
public final List<Integer> generateList( Range sizeRange, Range range )
iansrobinson/neode
src/main/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistribution.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // }
import java.util.ArrayList; import java.util.List; import org.neo4j.neode.Range; import static org.neo4j.neode.Range.exactly;
package org.neo4j.neode.probabilities; abstract class BaseUniqueProbabilityDistribution extends ProbabilityDistribution { @Override public final List<Integer> generateList( Range sizeRange, Range range ) { if ( (range.difference() + 1) < sizeRange.max() ) { throw new IllegalArgumentException( String.format( "(range.difference() + 1) must be greater or equal to numberOfResultsRange.max() " + "[numberOfResultsRange: %s, range: %s]", sizeRange, range ) ); } int numberOfResults = (sizeRange.difference() == 0) ? sizeRange.max() : sizeRange.min() + random().nextInt( sizeRange.difference() ); List<Integer> generatedNumbers = new ArrayList<Integer>( numberOfResults ); while ( generatedNumbers.size() < numberOfResults ) { int nextNumber = getNextNumber( range ); if ( range.isInRange( nextNumber ) && !generatedNumbers.contains( nextNumber ) ) { generatedNumbers.add( nextNumber ); } } return generatedNumbers; } @Override public final List<Integer> generateList( int size, Range range ) {
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/Range.java // public static Range exactly( int count ) // { // return new Range( count, count ); // } // Path: src/main/java/org/neo4j/neode/probabilities/BaseUniqueProbabilityDistribution.java import java.util.ArrayList; import java.util.List; import org.neo4j.neode.Range; import static org.neo4j.neode.Range.exactly; package org.neo4j.neode.probabilities; abstract class BaseUniqueProbabilityDistribution extends ProbabilityDistribution { @Override public final List<Integer> generateList( Range sizeRange, Range range ) { if ( (range.difference() + 1) < sizeRange.max() ) { throw new IllegalArgumentException( String.format( "(range.difference() + 1) must be greater or equal to numberOfResultsRange.max() " + "[numberOfResultsRange: %s, range: %s]", sizeRange, range ) ); } int numberOfResults = (sizeRange.difference() == 0) ? sizeRange.max() : sizeRange.min() + random().nextInt( sizeRange.difference() ); List<Integer> generatedNumbers = new ArrayList<Integer>( numberOfResults ); while ( generatedNumbers.size() < numberOfResults ) { int nextNumber = getNextNumber( range ); if ( range.isInRange( nextNumber ) && !generatedNumbers.contains( nextNumber ) ) { generatedNumbers.add( nextNumber ); } } return generatedNumbers; } @Override public final List<Integer> generateList( int size, Range range ) {
return generateList( exactly( size ), range );
iansrobinson/neode
src/main/java/org/neo4j/neode/TargetNodesStrategyBuilder.java
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipConstraints.java // public interface SetRelationshipConstraints // { // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy relationshipConstraints( Range cardinality ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy exactlyOneRelationship(); // // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipInfo.java // public interface SetRelationshipInfo // { // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification, Direction direction ); // // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // }
import org.neo4j.graphdb.Direction; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.interfaces.SetRelationshipConstraints; import org.neo4j.neode.interfaces.SetRelationshipInfo; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution;
/* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode; public class TargetNodesStrategyBuilder implements SetNumberOfNodes, SetRelationshipInfo, SetRelationshipConstraints { private final TargetNodesSource targetNodesSource; private Range nodeRange;
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipConstraints.java // public interface SetRelationshipConstraints // { // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy relationshipConstraints( Range cardinality ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy exactlyOneRelationship(); // // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipInfo.java // public interface SetRelationshipInfo // { // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification, Direction direction ); // // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // Path: src/main/java/org/neo4j/neode/TargetNodesStrategyBuilder.java import org.neo4j.graphdb.Direction; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.interfaces.SetRelationshipConstraints; import org.neo4j.neode.interfaces.SetRelationshipInfo; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; /* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode; public class TargetNodesStrategyBuilder implements SetNumberOfNodes, SetRelationshipInfo, SetRelationshipConstraints { private final TargetNodesSource targetNodesSource; private Range nodeRange;
private ProbabilityDistribution targetNodesProbabilityDistribution;
iansrobinson/neode
src/main/java/org/neo4j/neode/TargetNodesStrategyBuilder.java
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipConstraints.java // public interface SetRelationshipConstraints // { // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy relationshipConstraints( Range cardinality ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy exactlyOneRelationship(); // // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipInfo.java // public interface SetRelationshipInfo // { // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification, Direction direction ); // // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // }
import org.neo4j.graphdb.Direction; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.interfaces.SetRelationshipConstraints; import org.neo4j.neode.interfaces.SetRelationshipInfo; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution;
/* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode; public class TargetNodesStrategyBuilder implements SetNumberOfNodes, SetRelationshipInfo, SetRelationshipConstraints { private final TargetNodesSource targetNodesSource; private Range nodeRange; private ProbabilityDistribution targetNodesProbabilityDistribution; private RelationshipInfo relationshipInfo; TargetNodesStrategyBuilder( TargetNodesSource targetNodesSource ) { this.targetNodesSource = targetNodesSource; } @Override public SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ) { nodeRange = Range.exactly( numberOfNodes );
// Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java // public interface SetNumberOfNodes // { // SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes ); // // SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution ); // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipConstraints.java // public interface SetRelationshipConstraints // { // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( Range cardinality, // ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy relationshipConstraints( Range cardinality ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution, // RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( RelationshipUniqueness relationshipUniqueness ); // // TargetNodesStrategy relationshipConstraints( ProbabilityDistribution probabilityDistribution ); // // TargetNodesStrategy exactlyOneRelationship(); // // } // // Path: src/main/java/org/neo4j/neode/interfaces/SetRelationshipInfo.java // public interface SetRelationshipInfo // { // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification, Direction direction ); // // SetRelationshipConstraints relationship( RelationshipSpecification relationshipSpecification ); // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // Path: src/main/java/org/neo4j/neode/TargetNodesStrategyBuilder.java import org.neo4j.graphdb.Direction; import org.neo4j.neode.interfaces.SetNumberOfNodes; import org.neo4j.neode.interfaces.SetRelationshipConstraints; import org.neo4j.neode.interfaces.SetRelationshipInfo; import org.neo4j.neode.probabilities.ProbabilityDistribution; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; /* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode; public class TargetNodesStrategyBuilder implements SetNumberOfNodes, SetRelationshipInfo, SetRelationshipConstraints { private final TargetNodesSource targetNodesSource; private Range nodeRange; private ProbabilityDistribution targetNodesProbabilityDistribution; private RelationshipInfo relationshipInfo; TargetNodesStrategyBuilder( TargetNodesSource targetNodesSource ) { this.targetNodesSource = targetNodesSource; } @Override public SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ) { nodeRange = Range.exactly( numberOfNodes );
this.targetNodesProbabilityDistribution = flatDistribution();
iansrobinson/neode
src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // }
import org.neo4j.neode.Range; import org.neo4j.neode.probabilities.ProbabilityDistribution;
/* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.interfaces; public interface SetNumberOfNodes { SetRelationshipInfo numberOfTargetNodes( int numberOfNodes );
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java import org.neo4j.neode.Range; import org.neo4j.neode.probabilities.ProbabilityDistribution; /* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.interfaces; public interface SetNumberOfNodes { SetRelationshipInfo numberOfTargetNodes( int numberOfNodes );
SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes );
iansrobinson/neode
src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // }
import org.neo4j.neode.Range; import org.neo4j.neode.probabilities.ProbabilityDistribution;
/* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.interfaces; public interface SetNumberOfNodes { SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes );
// Path: src/main/java/org/neo4j/neode/Range.java // public class Range // { // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // // public static Range exactly( int count ) // { // return new Range( count, count ); // } // // private final int min; // private final int max; // // private Range( int min, int max ) // { // if ( min < 0 ) // { // throw new IllegalArgumentException( "Min must be greater or equal to 0" ); // } // // if ( max < min ) // { // throw new IllegalArgumentException( "Max must be greater or equal to min" ); // } // // this.min = min; // this.max = max; // } // // public int min() // { // return min; // } // // public int max() // { // return max; // } // // public int difference() // { // return max - min; // } // // public boolean isInRange( int value ) // { // return value >= min() && value <= max; // } // // public int getRandom( ProbabilityDistribution probabilityDistribution ) // { // if ( difference() == 0 ) // { // return min(); // } // return probabilityDistribution.generateSingle( this ); // } // // @Override // public String toString() // { // return "Range{" + // "min=" + min + // ", max=" + max + // '}'; // } // // @Override // public boolean equals( Object o ) // { // if ( this == o ) // { // return true; // } // if ( o == null || getClass() != o.getClass() ) // { // return false; // } // // Range range = (Range) o; // // return max == range.max && min == range.min; // } // // @Override // public int hashCode() // { // int result = min; // result = 31 * result + max; // return result; // } // } // // Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // Path: src/main/java/org/neo4j/neode/interfaces/SetNumberOfNodes.java import org.neo4j.neode.Range; import org.neo4j.neode.probabilities.ProbabilityDistribution; /* * Copyright (C) 2012 Neo Technology * All rights reserved */ package org.neo4j.neode.interfaces; public interface SetNumberOfNodes { SetRelationshipInfo numberOfTargetNodes( int numberOfNodes ); SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes );
SetRelationshipInfo numberOfTargetNodes( Range numberOfNodes, ProbabilityDistribution probabilityDistribution );
iansrobinson/neode
src/main/java/org/neo4j/neode/RelationshipConstraints.java
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // }
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.probabilities.ProbabilityDistribution;
package org.neo4j.neode; class RelationshipConstraints { private final Range cardinality; private final RelationshipUniqueness relationshipUniqueness;
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public abstract class ProbabilityDistribution // { // private static final Random RANDOM_INSTANCE = new Random(); // // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // // public static ProbabilityDistribution normalDistribution() // { // return new NormalProbabilityDistributionUnique(); // } // // private final Random random; // // protected ProbabilityDistribution() // { // this.random = RANDOM_INSTANCE; // } // // public abstract List<Integer> generateList( Range sizeRange, Range range ); // // public abstract List<Integer> generateList( int size, Range range ); // // public abstract int generateSingle( Range range ); // // public abstract String description(); // // protected final Random random() // { // return random; // } // } // Path: src/main/java/org/neo4j/neode/RelationshipConstraints.java import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.neode.probabilities.ProbabilityDistribution; package org.neo4j.neode; class RelationshipConstraints { private final Range cardinality; private final RelationshipUniqueness relationshipUniqueness;
private final ProbabilityDistribution probabilityDistribution;
iansrobinson/neode
src/main/java/org/neo4j/neode/RandomTargetNodesStrategy.java
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // }
import java.util.List; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution;
package org.neo4j.neode; class RandomTargetNodesStrategy extends ChoiceOfTargetNodesStrategy { protected RandomTargetNodesStrategy( List<TargetNodesStrategy> targetNodeseStrategies ) { super( targetNodeseStrategies ); } @Override protected Commands doCreateCommandSelector( List<BatchCommand<NodeCollection>> commands ) {
// Path: src/main/java/org/neo4j/neode/probabilities/ProbabilityDistribution.java // public static ProbabilityDistribution flatDistribution() // { // return new FlatProbabilityDistributionUnique(); // } // Path: src/main/java/org/neo4j/neode/RandomTargetNodesStrategy.java import java.util.List; import static org.neo4j.neode.probabilities.ProbabilityDistribution.flatDistribution; package org.neo4j.neode; class RandomTargetNodesStrategy extends ChoiceOfTargetNodesStrategy { protected RandomTargetNodesStrategy( List<TargetNodesStrategy> targetNodeseStrategies ) { super( targetNodeseStrategies ); } @Override protected Commands doCreateCommandSelector( List<BatchCommand<NodeCollection>> commands ) {
return new Commands( commands, new RandomCommandSelectionStrategy( flatDistribution() ) );
iansrobinson/neode
src/test/java/org/neo4j/neode/RangeTest.java
// Path: src/main/java/org/neo4j/neode/Range.java // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // }
import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.neo4j.neode.Range.minMax;
package org.neo4j.neode; public class RangeTest { @Test public void shouldThrowExceptionIfMaxIsLessThan() throws Exception { try { // when
// Path: src/main/java/org/neo4j/neode/Range.java // public static Range minMax( int min, int max ) // { // return new Range( min, max ); // } // Path: src/test/java/org/neo4j/neode/RangeTest.java import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.neo4j.neode.Range.minMax; package org.neo4j.neode; public class RangeTest { @Test public void shouldThrowExceptionIfMaxIsLessThan() throws Exception { try { // when
Range.minMax( 1, 0 );
iansrobinson/neode
src/main/java/org/neo4j/neode/Dataset.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // }
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Transaction; import org.neo4j.kernel.EmbeddedGraphDatabase; import org.neo4j.kernel.GraphDatabaseAPI; import org.neo4j.neode.logging.Log;
package org.neo4j.neode; public class Dataset { private final String description; private final GraphDatabaseService db;
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // Path: src/main/java/org/neo4j/neode/Dataset.java import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Transaction; import org.neo4j.kernel.EmbeddedGraphDatabase; import org.neo4j.kernel.GraphDatabaseAPI; import org.neo4j.neode.logging.Log; package org.neo4j.neode; public class Dataset { private final String description; private final GraphDatabaseService db;
private final Log log;
iansrobinson/neode
src/test/java/org/neo4j/neode/RelateNodesBatchCommandBuilderTest.java
// Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class RelateNodesBatchCommandBuilderTest { @Test public void shouldRelateNodes() throws Exception { // given
// Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/RelateNodesBatchCommandBuilderTest.java import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class RelateNodesBatchCommandBuilderTest { @Test public void shouldRelateNodes() throws Exception { // given
GraphDatabaseService db = Db.impermanentDb();
iansrobinson/neode
src/test/java/org/neo4j/neode/RelateNodesBatchCommandBuilderTest.java
// Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class RelateNodesBatchCommandBuilderTest { @Test public void shouldRelateNodes() throws Exception { // given GraphDatabaseService db = Db.impermanentDb();
// Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/RelateNodesBatchCommandBuilderTest.java import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class RelateNodesBatchCommandBuilderTest { @Test public void shouldRelateNodes() throws Exception { // given GraphDatabaseService db = Db.impermanentDb();
DatasetManager dsm = new DatasetManager( db, SysOutLog.INSTANCE );
iansrobinson/neode
src/test/java/org/neo4j/neode/RelateNodesBatchCommandBuilderTest.java
// Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // }
import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class RelateNodesBatchCommandBuilderTest { @Test public void shouldRelateNodes() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); DatasetManager dsm = new DatasetManager( db, SysOutLog.INSTANCE ); Dataset dataset = dsm.newDataset( "Test" );
// Path: src/main/java/org/neo4j/neode/logging/SysOutLog.java // public final class SysOutLog implements Log // { // public static final Log INSTANCE = new SysOutLog(); // // private SysOutLog() // { // } // // @Override // public void write( String value ) // { // System.out.println( value ); // } // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // // Path: src/test/java/org/neo4j/neode/test/Db.java // public final class Db // { // private Db() // { // } // // public static GraphDatabaseService impermanentDb() // { // Map<String, String> params = new HashMap<String, String>(); // params.put( "online_backup_enabled", "false" ); // // return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( params ).newGraphDatabase(); // } // // public static GraphDatabaseService tempDb() // { // return new GraphDatabaseFactory().newEmbeddedDatabase( createTempDatabaseDir().getAbsolutePath() ); // } // // private static File createTempDatabaseDir() // { // // File d; // try // { // d = File.createTempFile( "datasetbuilder-", "dir" ); // System.out.println( String.format( "Created a new Neo4j database at [%s]", d.getAbsolutePath() ) ); // } // catch ( IOException e ) // { // throw new RuntimeException( e ); // } // if ( !d.delete() ) // { // throw new RuntimeException( "temp config directory pre-delete failed" ); // } // if ( !d.mkdirs() ) // { // throw new RuntimeException( "temp config directory not created" ); // } // d.deleteOnExit(); // return d; // } // // public static void usingSampleDataset( WithSampleDataset f ) // { // GraphDatabaseService db = Db.impermanentDb(); // Node firstNode, secondNode, thirdNode; // try ( Transaction tx = db.beginTx() ) // { // firstNode = db.createNode(); // secondNode = db.createNode(); // thirdNode = db.createNode(); // tx.success(); // } // // try ( Transaction tx = db.beginTx() ) // { // f.execute( db, firstNode, secondNode, thirdNode ); // tx.success(); // } // db.shutdown(); // } // // public interface WithSampleDataset // { // public void execute( GraphDatabaseService db, Node firstNode, Node secondNode, Node thirdNode ); // } // // // } // Path: src/test/java/org/neo4j/neode/RelateNodesBatchCommandBuilderTest.java import java.util.Collections; import org.junit.Test; import org.neo4j.graphdb.*; import org.neo4j.neode.logging.SysOutLog; import org.neo4j.neode.properties.Property; import org.neo4j.neode.test.Db; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class RelateNodesBatchCommandBuilderTest { @Test public void shouldRelateNodes() throws Exception { // given GraphDatabaseService db = Db.impermanentDb(); DatasetManager dsm = new DatasetManager( db, SysOutLog.INSTANCE ); Dataset dataset = dsm.newDataset( "Test" );
NodeCollection users = new NodeSpecification( "user", Collections.<Property>emptyList(), db )
iansrobinson/neode
src/main/java/org/neo4j/neode/DatasetManager.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // }
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.RelationshipType; import org.neo4j.neode.logging.Log; import org.neo4j.neode.properties.Property; import static java.util.Arrays.asList; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class DatasetManager { private final GraphDatabaseService db;
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // Path: src/main/java/org/neo4j/neode/DatasetManager.java import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.RelationshipType; import org.neo4j.neode.logging.Log; import org.neo4j.neode.properties.Property; import static java.util.Arrays.asList; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class DatasetManager { private final GraphDatabaseService db;
private final Log log;
iansrobinson/neode
src/main/java/org/neo4j/neode/DatasetManager.java
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // }
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.RelationshipType; import org.neo4j.neode.logging.Log; import org.neo4j.neode.properties.Property; import static java.util.Arrays.asList; import static org.neo4j.graphdb.DynamicRelationshipType.withName;
package org.neo4j.neode; public class DatasetManager { private final GraphDatabaseService db; private final Log log; public DatasetManager( GraphDatabaseService db, Log log ) { this.db = db; this.log = log; }
// Path: src/main/java/org/neo4j/neode/logging/Log.java // public interface Log // { // void write( String value ); // } // // Path: src/main/java/org/neo4j/neode/properties/Property.java // public abstract class Property // { // public static Property property( String name ) // { // return new NonIndexableProperty( name, new CounterBasedStringPropertyValueGenerator() ); // } // // public static Property property( String name, PropertyValueGenerator generator ) // { // return new NonIndexableProperty( name, generator ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, String... labelNames ) // { // return indexableProperty( db,label, name, new CounterBasedStringPropertyValueGenerator(), labelNames ); // } // // public static Property indexableProperty( GraphDatabaseService db, String label, String name, PropertyValueGenerator generator, String... labelNames ) // { // return new IndexableProperty( db,label,name, generator, labelNames ); // } // // public abstract void setProperty(PropertyContainer propertyContainer, String label, // int iteration); // } // Path: src/main/java/org/neo4j/neode/DatasetManager.java import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.RelationshipType; import org.neo4j.neode.logging.Log; import org.neo4j.neode.properties.Property; import static java.util.Arrays.asList; import static org.neo4j.graphdb.DynamicRelationshipType.withName; package org.neo4j.neode; public class DatasetManager { private final GraphDatabaseService db; private final Log log; public DatasetManager( GraphDatabaseService db, Log log ) { this.db = db; this.log = log; }
public NodeSpecification nodeSpecification( String label, Property... properties )
Bombe/WoTNS
src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java
// Path: src/main/java/net/pterodactylus/wotns/freenet/plugin/PluginException.java // public class PluginException extends WebOfTrustException { // // /** // * Creates a new plugin exception. // */ // public PluginException() { // super(); // } // // /** // * Creates a new plugin exception. // * // * @param message // * The message of the exception // */ // public PluginException(String message) { // super(message); // } // // /** // * Creates a new plugin exception. // * // * @param cause // * The cause of the exception // */ // public PluginException(Throwable cause) { // super(cause); // } // // /** // * Creates a new plugin exception. // * // * @param message // * The message of the exception // * @param cause // * The cause of the exception // */ // public PluginException(String message, Throwable cause) { // super(message, cause); // } // // }
import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.wotns.freenet.plugin.PluginException;
/* * Sone - IdentityManager.java - Copyright © 2010 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.pterodactylus.wotns.freenet.wot; /** * The identity manager takes care of loading and storing identities, their * contexts, and properties. It does so in a way that does not expose errors via * exceptions but it only logs them and tries to return sensible defaults. * <p> * It is also responsible for polling identities from the Web of Trust plugin * and notifying registered {@link IdentityListener}s when {@link Identity}s and * {@link OwnIdentity}s are discovered or disappearing. * * @author <a href="mailto:[email protected]">David ‘Bombe’ Roden</a> */ public class IdentityManager extends AbstractService { /** Object used for synchronization. */ private final Object syncObject = new Object() { /* inner class for better lock names. */ }; /** The logger. */ private static final Logger logger = Logging.getLogger(IdentityManager.class); /** The event manager. */ private final IdentityListenerManager identityListenerManager = new IdentityListenerManager(); /** The Web of Trust connector. */ private final WebOfTrustConnector webOfTrustConnector; /** The context to filter for. */ private volatile String context; /** The currently known own identities. */ /* synchronize access on syncObject. */ private Map<String, OwnIdentity> currentOwnIdentities = new HashMap<String, OwnIdentity>(); /** The currently trusted identities. */ private Map<OwnIdentity, Collection<Identity>> currentTrustedIdentities = new HashMap<OwnIdentity, Collection<Identity>>(); /** * Creates a new identity manager. * * @param webOfTrustConnector * The Web of Trust connector */ public IdentityManager(WebOfTrustConnector webOfTrustConnector) { super("Sone Identity Manager", false); this.webOfTrustConnector = webOfTrustConnector; } // // LISTENER MANAGEMENT // /** * Adds a listener for identity events. * * @param identityListener * The listener to add */ public void addIdentityListener(IdentityListener identityListener) { identityListenerManager.addListener(identityListener); } /** * Removes a listener for identity events. * * @param identityListener * The listener to remove */ public void removeIdentityListener(IdentityListener identityListener) { identityListenerManager.removeListener(identityListener); } // // ACCESSORS // /** * Sets the context to filter own identities and trusted identities for. * * @param context * The context to filter for, or {@code null} to not filter */ public void setContext(String context) { this.context = context; } /** * Returns whether the Web of Trust plugin could be reached during the last * try. * * @return {@code true} if the Web of Trust plugin is connected, {@code * false} otherwise */ public boolean isConnected() { try { webOfTrustConnector.ping(); return true;
// Path: src/main/java/net/pterodactylus/wotns/freenet/plugin/PluginException.java // public class PluginException extends WebOfTrustException { // // /** // * Creates a new plugin exception. // */ // public PluginException() { // super(); // } // // /** // * Creates a new plugin exception. // * // * @param message // * The message of the exception // */ // public PluginException(String message) { // super(message); // } // // /** // * Creates a new plugin exception. // * // * @param cause // * The cause of the exception // */ // public PluginException(Throwable cause) { // super(cause); // } // // /** // * Creates a new plugin exception. // * // * @param message // * The message of the exception // * @param cause // * The cause of the exception // */ // public PluginException(String message, Throwable cause) { // super(message, cause); // } // // } // Path: src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.wotns.freenet.plugin.PluginException; /* * Sone - IdentityManager.java - Copyright © 2010 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.pterodactylus.wotns.freenet.wot; /** * The identity manager takes care of loading and storing identities, their * contexts, and properties. It does so in a way that does not expose errors via * exceptions but it only logs them and tries to return sensible defaults. * <p> * It is also responsible for polling identities from the Web of Trust plugin * and notifying registered {@link IdentityListener}s when {@link Identity}s and * {@link OwnIdentity}s are discovered or disappearing. * * @author <a href="mailto:[email protected]">David ‘Bombe’ Roden</a> */ public class IdentityManager extends AbstractService { /** Object used for synchronization. */ private final Object syncObject = new Object() { /* inner class for better lock names. */ }; /** The logger. */ private static final Logger logger = Logging.getLogger(IdentityManager.class); /** The event manager. */ private final IdentityListenerManager identityListenerManager = new IdentityListenerManager(); /** The Web of Trust connector. */ private final WebOfTrustConnector webOfTrustConnector; /** The context to filter for. */ private volatile String context; /** The currently known own identities. */ /* synchronize access on syncObject. */ private Map<String, OwnIdentity> currentOwnIdentities = new HashMap<String, OwnIdentity>(); /** The currently trusted identities. */ private Map<OwnIdentity, Collection<Identity>> currentTrustedIdentities = new HashMap<OwnIdentity, Collection<Identity>>(); /** * Creates a new identity manager. * * @param webOfTrustConnector * The Web of Trust connector */ public IdentityManager(WebOfTrustConnector webOfTrustConnector) { super("Sone Identity Manager", false); this.webOfTrustConnector = webOfTrustConnector; } // // LISTENER MANAGEMENT // /** * Adds a listener for identity events. * * @param identityListener * The listener to add */ public void addIdentityListener(IdentityListener identityListener) { identityListenerManager.addListener(identityListener); } /** * Removes a listener for identity events. * * @param identityListener * The listener to remove */ public void removeIdentityListener(IdentityListener identityListener) { identityListenerManager.removeListener(identityListener); } // // ACCESSORS // /** * Sets the context to filter own identities and trusted identities for. * * @param context * The context to filter for, or {@code null} to not filter */ public void setContext(String context) { this.context = context; } /** * Returns whether the Web of Trust plugin could be reached during the last * try. * * @return {@code true} if the Web of Trust plugin is connected, {@code * false} otherwise */ public boolean isConnected() { try { webOfTrustConnector.ping(); return true;
} catch (PluginException pe1) {
Bombe/WoTNS
src/main/java/net/pterodactylus/wotns/template/IdentityAccessor.java
// Path: src/main/java/net/pterodactylus/wotns/freenet/wot/Identity.java // public interface Identity { // // /** // * Returns the ID of the identity. // * // * @return The ID of the identity // */ // public String getId(); // // /** // * Returns the nickname of the identity. // * // * @return The nickname of the identity // */ // public String getNickname(); // // /** // * Returns the request URI of the identity. // * // * @return The request URI of the identity // */ // public String getRequestUri(); // // /** // * Returns all contexts of this identity. // * // * @return All contexts of this identity // */ // public Set<String> getContexts(); // // /** // * Returns whether this identity has the given context. // * // * @param context // * The context to check for // * @return {@code true} if this identity has the given context, // * {@code false} otherwise // */ // public boolean hasContext(String context); // // /** // * Returns all properties of this identity. // * // * @return All properties of this identity // */ // public Map<String, String> getProperties(); // // /** // * Returns the value of the property with the given name. // * // * @param name // * The name of the property // * @return The value of the property // */ // public String getProperty(String name); // // /** // * Retrieves the trust that this identity receives from the given own // * identity. If this identity is not in the own identity’s trust tree, a // * {@link Trust} is returned that has all its elements set to {@code null}. // * If the trust can not be retrieved, {@code null} is returned. // * // * @param ownIdentity // * The own identity to get the trust for // * @return The trust assigned to this identity, or {@code null} if the trust // * could not be retrieved // */ // public Trust getTrust(OwnIdentity ownIdentity); // // } // // Path: src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java // public class IdentityTargets implements Iterable<Entry<String, String>> { // // /** The identity being scanned. */ // private final Identity identity; // // /** The located targets. */ // private final Map<String, String> targets = new HashMap<String, String>(); // // /** // * Creates a new target scanner for the given identity. // * // * @param identity // * The identity to scan for targets // */ // public IdentityTargets(Identity identity) { // this.identity = identity; // } // // // // // ACCESSORS // // // // /** // * Returns the targets of the identity. // * // * @return The targets defined in the identity // */ // public Map<String, String> getTargets() { // scanForTargets(); // return Collections.unmodifiableMap(targets); // } // // /** // * Returns the target with the given name. // * // * @param name // * The name of the target // * @return The target // */ // public String getTarget(String name) { // scanForTargets(); // return targets.get(name); // } // // // // // PRIVATE METHODS // // // // /** // * Re-scans the identity for targets. // */ // private void scanForTargets() { // synchronized (targets) { // targets.clear(); // for (Entry<String, String> property : identity.getProperties().entrySet()) { // if (property.getKey().startsWith("tns.")) { // targets.put(property.getKey().substring(4), property.getValue()); // } // } // } // } // // // // // ITERABLE METHODS // // // // /** // * {@inheritDoc} // */ // @Override // public Iterator<Entry<String, String>> iterator() { // synchronized (targets) { // scanForTargets(); // return new HashMap<String, String>(targets).entrySet().iterator(); // } // } // // }
import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.wotns.freenet.wot.Identity; import net.pterodactylus.wotns.main.IdentityTargets;
/* * WoTNS - IdentityAccessor.java - Copyright © 2011 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.pterodactylus.wotns.template; /** * {@link Accessor} implementation that can expose {@link IdentityTargets} for * an {@link Identity}. * * @author <a href="mailto:[email protected]">David ‘Bombe’ Roden</a> */ public class IdentityAccessor extends ReflectionAccessor { /** * {@inheritDoc} */ @Override public Object get(TemplateContext templateContext, Object object, String member) {
// Path: src/main/java/net/pterodactylus/wotns/freenet/wot/Identity.java // public interface Identity { // // /** // * Returns the ID of the identity. // * // * @return The ID of the identity // */ // public String getId(); // // /** // * Returns the nickname of the identity. // * // * @return The nickname of the identity // */ // public String getNickname(); // // /** // * Returns the request URI of the identity. // * // * @return The request URI of the identity // */ // public String getRequestUri(); // // /** // * Returns all contexts of this identity. // * // * @return All contexts of this identity // */ // public Set<String> getContexts(); // // /** // * Returns whether this identity has the given context. // * // * @param context // * The context to check for // * @return {@code true} if this identity has the given context, // * {@code false} otherwise // */ // public boolean hasContext(String context); // // /** // * Returns all properties of this identity. // * // * @return All properties of this identity // */ // public Map<String, String> getProperties(); // // /** // * Returns the value of the property with the given name. // * // * @param name // * The name of the property // * @return The value of the property // */ // public String getProperty(String name); // // /** // * Retrieves the trust that this identity receives from the given own // * identity. If this identity is not in the own identity’s trust tree, a // * {@link Trust} is returned that has all its elements set to {@code null}. // * If the trust can not be retrieved, {@code null} is returned. // * // * @param ownIdentity // * The own identity to get the trust for // * @return The trust assigned to this identity, or {@code null} if the trust // * could not be retrieved // */ // public Trust getTrust(OwnIdentity ownIdentity); // // } // // Path: src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java // public class IdentityTargets implements Iterable<Entry<String, String>> { // // /** The identity being scanned. */ // private final Identity identity; // // /** The located targets. */ // private final Map<String, String> targets = new HashMap<String, String>(); // // /** // * Creates a new target scanner for the given identity. // * // * @param identity // * The identity to scan for targets // */ // public IdentityTargets(Identity identity) { // this.identity = identity; // } // // // // // ACCESSORS // // // // /** // * Returns the targets of the identity. // * // * @return The targets defined in the identity // */ // public Map<String, String> getTargets() { // scanForTargets(); // return Collections.unmodifiableMap(targets); // } // // /** // * Returns the target with the given name. // * // * @param name // * The name of the target // * @return The target // */ // public String getTarget(String name) { // scanForTargets(); // return targets.get(name); // } // // // // // PRIVATE METHODS // // // // /** // * Re-scans the identity for targets. // */ // private void scanForTargets() { // synchronized (targets) { // targets.clear(); // for (Entry<String, String> property : identity.getProperties().entrySet()) { // if (property.getKey().startsWith("tns.")) { // targets.put(property.getKey().substring(4), property.getValue()); // } // } // } // } // // // // // ITERABLE METHODS // // // // /** // * {@inheritDoc} // */ // @Override // public Iterator<Entry<String, String>> iterator() { // synchronized (targets) { // scanForTargets(); // return new HashMap<String, String>(targets).entrySet().iterator(); // } // } // // } // Path: src/main/java/net/pterodactylus/wotns/template/IdentityAccessor.java import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.wotns.freenet.wot.Identity; import net.pterodactylus.wotns.main.IdentityTargets; /* * WoTNS - IdentityAccessor.java - Copyright © 2011 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.pterodactylus.wotns.template; /** * {@link Accessor} implementation that can expose {@link IdentityTargets} for * an {@link Identity}. * * @author <a href="mailto:[email protected]">David ‘Bombe’ Roden</a> */ public class IdentityAccessor extends ReflectionAccessor { /** * {@inheritDoc} */ @Override public Object get(TemplateContext templateContext, Object object, String member) {
Identity identity = (Identity) object;
Bombe/WoTNS
src/main/java/net/pterodactylus/wotns/template/IdentityAccessor.java
// Path: src/main/java/net/pterodactylus/wotns/freenet/wot/Identity.java // public interface Identity { // // /** // * Returns the ID of the identity. // * // * @return The ID of the identity // */ // public String getId(); // // /** // * Returns the nickname of the identity. // * // * @return The nickname of the identity // */ // public String getNickname(); // // /** // * Returns the request URI of the identity. // * // * @return The request URI of the identity // */ // public String getRequestUri(); // // /** // * Returns all contexts of this identity. // * // * @return All contexts of this identity // */ // public Set<String> getContexts(); // // /** // * Returns whether this identity has the given context. // * // * @param context // * The context to check for // * @return {@code true} if this identity has the given context, // * {@code false} otherwise // */ // public boolean hasContext(String context); // // /** // * Returns all properties of this identity. // * // * @return All properties of this identity // */ // public Map<String, String> getProperties(); // // /** // * Returns the value of the property with the given name. // * // * @param name // * The name of the property // * @return The value of the property // */ // public String getProperty(String name); // // /** // * Retrieves the trust that this identity receives from the given own // * identity. If this identity is not in the own identity’s trust tree, a // * {@link Trust} is returned that has all its elements set to {@code null}. // * If the trust can not be retrieved, {@code null} is returned. // * // * @param ownIdentity // * The own identity to get the trust for // * @return The trust assigned to this identity, or {@code null} if the trust // * could not be retrieved // */ // public Trust getTrust(OwnIdentity ownIdentity); // // } // // Path: src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java // public class IdentityTargets implements Iterable<Entry<String, String>> { // // /** The identity being scanned. */ // private final Identity identity; // // /** The located targets. */ // private final Map<String, String> targets = new HashMap<String, String>(); // // /** // * Creates a new target scanner for the given identity. // * // * @param identity // * The identity to scan for targets // */ // public IdentityTargets(Identity identity) { // this.identity = identity; // } // // // // // ACCESSORS // // // // /** // * Returns the targets of the identity. // * // * @return The targets defined in the identity // */ // public Map<String, String> getTargets() { // scanForTargets(); // return Collections.unmodifiableMap(targets); // } // // /** // * Returns the target with the given name. // * // * @param name // * The name of the target // * @return The target // */ // public String getTarget(String name) { // scanForTargets(); // return targets.get(name); // } // // // // // PRIVATE METHODS // // // // /** // * Re-scans the identity for targets. // */ // private void scanForTargets() { // synchronized (targets) { // targets.clear(); // for (Entry<String, String> property : identity.getProperties().entrySet()) { // if (property.getKey().startsWith("tns.")) { // targets.put(property.getKey().substring(4), property.getValue()); // } // } // } // } // // // // // ITERABLE METHODS // // // // /** // * {@inheritDoc} // */ // @Override // public Iterator<Entry<String, String>> iterator() { // synchronized (targets) { // scanForTargets(); // return new HashMap<String, String>(targets).entrySet().iterator(); // } // } // // }
import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.wotns.freenet.wot.Identity; import net.pterodactylus.wotns.main.IdentityTargets;
/* * WoTNS - IdentityAccessor.java - Copyright © 2011 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.pterodactylus.wotns.template; /** * {@link Accessor} implementation that can expose {@link IdentityTargets} for * an {@link Identity}. * * @author <a href="mailto:[email protected]">David ‘Bombe’ Roden</a> */ public class IdentityAccessor extends ReflectionAccessor { /** * {@inheritDoc} */ @Override public Object get(TemplateContext templateContext, Object object, String member) { Identity identity = (Identity) object; if ("targets".equals(member)) {
// Path: src/main/java/net/pterodactylus/wotns/freenet/wot/Identity.java // public interface Identity { // // /** // * Returns the ID of the identity. // * // * @return The ID of the identity // */ // public String getId(); // // /** // * Returns the nickname of the identity. // * // * @return The nickname of the identity // */ // public String getNickname(); // // /** // * Returns the request URI of the identity. // * // * @return The request URI of the identity // */ // public String getRequestUri(); // // /** // * Returns all contexts of this identity. // * // * @return All contexts of this identity // */ // public Set<String> getContexts(); // // /** // * Returns whether this identity has the given context. // * // * @param context // * The context to check for // * @return {@code true} if this identity has the given context, // * {@code false} otherwise // */ // public boolean hasContext(String context); // // /** // * Returns all properties of this identity. // * // * @return All properties of this identity // */ // public Map<String, String> getProperties(); // // /** // * Returns the value of the property with the given name. // * // * @param name // * The name of the property // * @return The value of the property // */ // public String getProperty(String name); // // /** // * Retrieves the trust that this identity receives from the given own // * identity. If this identity is not in the own identity’s trust tree, a // * {@link Trust} is returned that has all its elements set to {@code null}. // * If the trust can not be retrieved, {@code null} is returned. // * // * @param ownIdentity // * The own identity to get the trust for // * @return The trust assigned to this identity, or {@code null} if the trust // * could not be retrieved // */ // public Trust getTrust(OwnIdentity ownIdentity); // // } // // Path: src/main/java/net/pterodactylus/wotns/main/IdentityTargets.java // public class IdentityTargets implements Iterable<Entry<String, String>> { // // /** The identity being scanned. */ // private final Identity identity; // // /** The located targets. */ // private final Map<String, String> targets = new HashMap<String, String>(); // // /** // * Creates a new target scanner for the given identity. // * // * @param identity // * The identity to scan for targets // */ // public IdentityTargets(Identity identity) { // this.identity = identity; // } // // // // // ACCESSORS // // // // /** // * Returns the targets of the identity. // * // * @return The targets defined in the identity // */ // public Map<String, String> getTargets() { // scanForTargets(); // return Collections.unmodifiableMap(targets); // } // // /** // * Returns the target with the given name. // * // * @param name // * The name of the target // * @return The target // */ // public String getTarget(String name) { // scanForTargets(); // return targets.get(name); // } // // // // // PRIVATE METHODS // // // // /** // * Re-scans the identity for targets. // */ // private void scanForTargets() { // synchronized (targets) { // targets.clear(); // for (Entry<String, String> property : identity.getProperties().entrySet()) { // if (property.getKey().startsWith("tns.")) { // targets.put(property.getKey().substring(4), property.getValue()); // } // } // } // } // // // // // ITERABLE METHODS // // // // /** // * {@inheritDoc} // */ // @Override // public Iterator<Entry<String, String>> iterator() { // synchronized (targets) { // scanForTargets(); // return new HashMap<String, String>(targets).entrySet().iterator(); // } // } // // } // Path: src/main/java/net/pterodactylus/wotns/template/IdentityAccessor.java import net.pterodactylus.util.template.Accessor; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.wotns.freenet.wot.Identity; import net.pterodactylus.wotns.main.IdentityTargets; /* * WoTNS - IdentityAccessor.java - Copyright © 2011 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.pterodactylus.wotns.template; /** * {@link Accessor} implementation that can expose {@link IdentityTargets} for * an {@link Identity}. * * @author <a href="mailto:[email protected]">David ‘Bombe’ Roden</a> */ public class IdentityAccessor extends ReflectionAccessor { /** * {@inheritDoc} */ @Override public Object get(TemplateContext templateContext, Object object, String member) { Identity identity = (Identity) object; if ("targets".equals(member)) {
return new IdentityTargets(identity).getTargets();
stackify/stackify-api-java
src/main/java/com/stackify/api/common/lang/Throwables.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // }
import java.util.ArrayList; import java.util.List; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.lang; /** * Utility class for converting a Throwable object to an ErrorItem object * * @author Eric Martin */ public class Throwables { /** * Returns the Throwable's cause chain as a list. The first entry is the Throwable followed by the cause chain. * @param throwable The Throwable * @return The Throwable and its cause chain */ public static List<Throwable> getCausalChain(final Throwable throwable) { if (throwable == null) { throw new NullPointerException("Throwable is null"); } List<Throwable> causes = new ArrayList<Throwable>(); causes.add(throwable); Throwable cause = throwable.getCause(); while ((cause != null) && (!causes.contains(cause))) { causes.add(cause); cause = cause.getCause(); } return causes; } /** * Converts a Throwable to an ErrorItem * @param logMessage The log message (can be null) * @param t The Throwable to be converted * @return The ErrorItem */
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // } // Path: src/main/java/com/stackify/api/common/lang/Throwables.java import java.util.ArrayList; import java.util.List; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.lang; /** * Utility class for converting a Throwable object to an ErrorItem object * * @author Eric Martin */ public class Throwables { /** * Returns the Throwable's cause chain as a list. The first entry is the Throwable followed by the cause chain. * @param throwable The Throwable * @return The Throwable and its cause chain */ public static List<Throwable> getCausalChain(final Throwable throwable) { if (throwable == null) { throw new NullPointerException("Throwable is null"); } List<Throwable> causes = new ArrayList<Throwable>(); causes.add(throwable); Throwable cause = throwable.getCause(); while ((cause != null) && (!causes.contains(cause))) { causes.add(cause); cause = cause.getCause(); } return causes; } /** * Converts a Throwable to an ErrorItem * @param logMessage The log message (can be null) * @param t The Throwable to be converted * @return The ErrorItem */
public static ErrorItem toErrorItem(final String logMessage, final Throwable t) {
stackify/stackify-api-java
src/main/java/com/stackify/api/common/lang/Throwables.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // }
import java.util.ArrayList; import java.util.List; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame;
ErrorItem.Builder child = builders.get(i); parent.innerError(child.build()); } // return the assembled original error return builders.get(0).build(); } /** * Converts a Throwable to an ErrorItem * @param t The Throwable to be converted * @return The ErrorItem */ public static ErrorItem toErrorItem(final Throwable t) { return toErrorItem(null, t); } /** * Converts a Throwable to an ErrorItem.Builder and ignores the cause * @param logMessage The log message * @param t The Throwable to be converted * @return The ErrorItem.Builder without the innerError populated */ private static ErrorItem.Builder toErrorItemBuilderWithoutCause(final String logMessage, final Throwable t) { ErrorItem.Builder builder = ErrorItem.newBuilder(); builder.message(toErrorItemMessage(logMessage, t.getMessage())); builder.errorType(t.getClass().getCanonicalName());
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // } // Path: src/main/java/com/stackify/api/common/lang/Throwables.java import java.util.ArrayList; import java.util.List; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame; ErrorItem.Builder child = builders.get(i); parent.innerError(child.build()); } // return the assembled original error return builders.get(0).build(); } /** * Converts a Throwable to an ErrorItem * @param t The Throwable to be converted * @return The ErrorItem */ public static ErrorItem toErrorItem(final Throwable t) { return toErrorItem(null, t); } /** * Converts a Throwable to an ErrorItem.Builder and ignores the cause * @param logMessage The log message * @param t The Throwable to be converted * @return The ErrorItem.Builder without the innerError populated */ private static ErrorItem.Builder toErrorItemBuilderWithoutCause(final String logMessage, final Throwable t) { ErrorItem.Builder builder = ErrorItem.newBuilder(); builder.message(toErrorItemMessage(logMessage, t.getMessage())); builder.errorType(t.getClass().getCanonicalName());
List<TraceFrame> stackFrames = new ArrayList<TraceFrame>();
stackify/stackify-api-java
src/test/java/com/stackify/api/common/http/HttpClientTest.java
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // }
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.stackify.api.common.ApiConfiguration;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.http; /** * HttpClient JUnit Test * @author Eric Martin */ @RunWith(PowerMockRunner.class) @PrepareForTest({HttpClient.class, URL.class}) public class HttpClientTest { /** * testPost * @throws Exception */ @Test public void testPost() throws Exception { URL url = PowerMockito.mock(URL.class); PowerMockito.whenNew(URL.class).withArguments(Mockito.anyString()).thenReturn(url); HttpURLConnection connection = PowerMockito.mock(HttpURLConnection.class); PowerMockito.when(url.openConnection(Proxy.NO_PROXY)).thenReturn(connection); ByteArrayOutputStream postBody = new ByteArrayOutputStream(); PowerMockito.when(connection.getOutputStream()).thenReturn(postBody); ByteArrayInputStream contents = new ByteArrayInputStream("world".getBytes()); PowerMockito.when(connection.getInputStream()).thenReturn(contents); PowerMockito.when(connection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // } // Path: src/test/java/com/stackify/api/common/http/HttpClientTest.java import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.stackify.api.common.ApiConfiguration; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.http; /** * HttpClient JUnit Test * @author Eric Martin */ @RunWith(PowerMockRunner.class) @PrepareForTest({HttpClient.class, URL.class}) public class HttpClientTest { /** * testPost * @throws Exception */ @Test public void testPost() throws Exception { URL url = PowerMockito.mock(URL.class); PowerMockito.whenNew(URL.class).withArguments(Mockito.anyString()).thenReturn(url); HttpURLConnection connection = PowerMockito.mock(HttpURLConnection.class); PowerMockito.when(url.openConnection(Proxy.NO_PROXY)).thenReturn(connection); ByteArrayOutputStream postBody = new ByteArrayOutputStream(); PowerMockito.when(connection.getOutputStream()).thenReturn(postBody); ByteArrayInputStream contents = new ByteArrayInputStream("world".getBytes()); PowerMockito.when(connection.getInputStream()).thenReturn(contents); PowerMockito.when(connection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
HttpClient httpClient = new HttpClient(Mockito.mock(ApiConfiguration.class));
stackify/stackify-api-java
src/main/java/com/stackify/api/common/log/ServletLogContext.java
// Path: src/main/java/com/stackify/api/WebRequestDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class WebRequestDetail { // // /** // * User IP address // */ // @JsonProperty("UserIPAddress") // private String userIpAddress; // // /** // * HTTP method // */ // @JsonProperty("HttpMethod") // private String httpMethod; // // /** // * Request protocol // */ // @JsonProperty("RequestProtocol") // private String requestProtocol; // // /** // * Request URL // */ // @JsonProperty("RequestUrl") // private String requestUrl; // // /** // * Request URL root // */ // @JsonProperty("RequestUrlRoot") // private String requestUrlRoot; // // /** // * Referral URL // */ // @JsonProperty("ReferralUrl") // private String referralUrl; // // /** // * Headers // */ // @JsonProperty("Headers") // private Map<String, String> headers; // // /** // * Cookies // */ // @JsonProperty("Cookies") // private Map<String, String> cookies; // // /** // * Query string parameters // */ // @JsonProperty("QueryString") // private Map<String, String> queryString; // // /** // * Form post data // */ // @JsonProperty("PostData") // private Map<String, String> postData; // // /** // * Session data // */ // @JsonProperty("SessionData") // private Map<String, String> sessionData; // // /** // * Raw post data // */ // @JsonProperty("PostDataRaw") // private String postDataRaw; // // /** // * MVC action // */ // @JsonProperty("MVCAction") // private String mvcAction; // // /** // * MVC controller // */ // @JsonProperty("MVCController") // private String mvcController; // // /** // * MVC area // */ // @JsonProperty("MVCArea") // private String mvcArea; // // }
import org.slf4j.helpers.BasicMDCAdapter; import org.slf4j.spi.MDCAdapter; import com.fasterxml.jackson.databind.ObjectMapper; import com.stackify.api.WebRequestDetail;
} } /** * @return The user from the logging context */ public static String getUser() { String value = MDC.get(USER); if ((value != null) && (0 < value.length())) { return value; } return null; } /** * Sets the user in the logging context * @param user The user */ public static void putUser(final String user) { if ((user != null) && (0 < user.length())) { MDC.put(USER, user); } } /** * @return The web request from the logging context */
// Path: src/main/java/com/stackify/api/WebRequestDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class WebRequestDetail { // // /** // * User IP address // */ // @JsonProperty("UserIPAddress") // private String userIpAddress; // // /** // * HTTP method // */ // @JsonProperty("HttpMethod") // private String httpMethod; // // /** // * Request protocol // */ // @JsonProperty("RequestProtocol") // private String requestProtocol; // // /** // * Request URL // */ // @JsonProperty("RequestUrl") // private String requestUrl; // // /** // * Request URL root // */ // @JsonProperty("RequestUrlRoot") // private String requestUrlRoot; // // /** // * Referral URL // */ // @JsonProperty("ReferralUrl") // private String referralUrl; // // /** // * Headers // */ // @JsonProperty("Headers") // private Map<String, String> headers; // // /** // * Cookies // */ // @JsonProperty("Cookies") // private Map<String, String> cookies; // // /** // * Query string parameters // */ // @JsonProperty("QueryString") // private Map<String, String> queryString; // // /** // * Form post data // */ // @JsonProperty("PostData") // private Map<String, String> postData; // // /** // * Session data // */ // @JsonProperty("SessionData") // private Map<String, String> sessionData; // // /** // * Raw post data // */ // @JsonProperty("PostDataRaw") // private String postDataRaw; // // /** // * MVC action // */ // @JsonProperty("MVCAction") // private String mvcAction; // // /** // * MVC controller // */ // @JsonProperty("MVCController") // private String mvcController; // // /** // * MVC area // */ // @JsonProperty("MVCArea") // private String mvcArea; // // } // Path: src/main/java/com/stackify/api/common/log/ServletLogContext.java import org.slf4j.helpers.BasicMDCAdapter; import org.slf4j.spi.MDCAdapter; import com.fasterxml.jackson.databind.ObjectMapper; import com.stackify.api.WebRequestDetail; } } /** * @return The user from the logging context */ public static String getUser() { String value = MDC.get(USER); if ((value != null) && (0 < value.length())) { return value; } return null; } /** * Sets the user in the logging context * @param user The user */ public static void putUser(final String user) { if ((user != null) && (0 < user.length())) { MDC.put(USER, user); } } /** * @return The web request from the logging context */
public static WebRequestDetail getWebRequest() {
stackify/stackify-api-java
src/test/java/com/stackify/api/common/log/ServletLogContextTest.java
// Path: src/main/java/com/stackify/api/WebRequestDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class WebRequestDetail { // // /** // * User IP address // */ // @JsonProperty("UserIPAddress") // private String userIpAddress; // // /** // * HTTP method // */ // @JsonProperty("HttpMethod") // private String httpMethod; // // /** // * Request protocol // */ // @JsonProperty("RequestProtocol") // private String requestProtocol; // // /** // * Request URL // */ // @JsonProperty("RequestUrl") // private String requestUrl; // // /** // * Request URL root // */ // @JsonProperty("RequestUrlRoot") // private String requestUrlRoot; // // /** // * Referral URL // */ // @JsonProperty("ReferralUrl") // private String referralUrl; // // /** // * Headers // */ // @JsonProperty("Headers") // private Map<String, String> headers; // // /** // * Cookies // */ // @JsonProperty("Cookies") // private Map<String, String> cookies; // // /** // * Query string parameters // */ // @JsonProperty("QueryString") // private Map<String, String> queryString; // // /** // * Form post data // */ // @JsonProperty("PostData") // private Map<String, String> postData; // // /** // * Session data // */ // @JsonProperty("SessionData") // private Map<String, String> sessionData; // // /** // * Raw post data // */ // @JsonProperty("PostDataRaw") // private String postDataRaw; // // /** // * MVC action // */ // @JsonProperty("MVCAction") // private String mvcAction; // // /** // * MVC controller // */ // @JsonProperty("MVCController") // private String mvcController; // // /** // * MVC area // */ // @JsonProperty("MVCArea") // private String mvcArea; // // }
import java.util.UUID; import org.junit.Assert; import org.junit.Test; import com.stackify.api.WebRequestDetail;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * ServletLogContextTest * @author Eric Martin */ public class ServletLogContextTest { /** * testTransactionId */ @Test public void testTransactionId() { Assert.assertNull(ServletLogContext.getTransactionId()); ServletLogContext.clear(); String id = UUID.randomUUID().toString(); ServletLogContext.putTransactionId(id); Assert.assertEquals(id, ServletLogContext.getTransactionId()); ServletLogContext.clear(); Assert.assertNull(ServletLogContext.getTransactionId()); } /** * testUser */ @Test public void testUser() { Assert.assertNull(ServletLogContext.getUser()); ServletLogContext.clear(); String user = UUID.randomUUID().toString(); ServletLogContext.putUser(user); Assert.assertEquals(user, ServletLogContext.getUser()); ServletLogContext.clear(); Assert.assertNull(ServletLogContext.getUser()); } /** * testWebRequest */ @Test public void testWebRequest() { Assert.assertNull(ServletLogContext.getWebRequest()); ServletLogContext.clear();
// Path: src/main/java/com/stackify/api/WebRequestDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class WebRequestDetail { // // /** // * User IP address // */ // @JsonProperty("UserIPAddress") // private String userIpAddress; // // /** // * HTTP method // */ // @JsonProperty("HttpMethod") // private String httpMethod; // // /** // * Request protocol // */ // @JsonProperty("RequestProtocol") // private String requestProtocol; // // /** // * Request URL // */ // @JsonProperty("RequestUrl") // private String requestUrl; // // /** // * Request URL root // */ // @JsonProperty("RequestUrlRoot") // private String requestUrlRoot; // // /** // * Referral URL // */ // @JsonProperty("ReferralUrl") // private String referralUrl; // // /** // * Headers // */ // @JsonProperty("Headers") // private Map<String, String> headers; // // /** // * Cookies // */ // @JsonProperty("Cookies") // private Map<String, String> cookies; // // /** // * Query string parameters // */ // @JsonProperty("QueryString") // private Map<String, String> queryString; // // /** // * Form post data // */ // @JsonProperty("PostData") // private Map<String, String> postData; // // /** // * Session data // */ // @JsonProperty("SessionData") // private Map<String, String> sessionData; // // /** // * Raw post data // */ // @JsonProperty("PostDataRaw") // private String postDataRaw; // // /** // * MVC action // */ // @JsonProperty("MVCAction") // private String mvcAction; // // /** // * MVC controller // */ // @JsonProperty("MVCController") // private String mvcController; // // /** // * MVC area // */ // @JsonProperty("MVCArea") // private String mvcArea; // // } // Path: src/test/java/com/stackify/api/common/log/ServletLogContextTest.java import java.util.UUID; import org.junit.Assert; import org.junit.Test; import com.stackify.api.WebRequestDetail; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * ServletLogContextTest * @author Eric Martin */ public class ServletLogContextTest { /** * testTransactionId */ @Test public void testTransactionId() { Assert.assertNull(ServletLogContext.getTransactionId()); ServletLogContext.clear(); String id = UUID.randomUUID().toString(); ServletLogContext.putTransactionId(id); Assert.assertEquals(id, ServletLogContext.getTransactionId()); ServletLogContext.clear(); Assert.assertNull(ServletLogContext.getTransactionId()); } /** * testUser */ @Test public void testUser() { Assert.assertNull(ServletLogContext.getUser()); ServletLogContext.clear(); String user = UUID.randomUUID().toString(); ServletLogContext.putUser(user); Assert.assertEquals(user, ServletLogContext.getUser()); ServletLogContext.clear(); Assert.assertNull(ServletLogContext.getUser()); } /** * testWebRequest */ @Test public void testWebRequest() { Assert.assertNull(ServletLogContext.getWebRequest()); ServletLogContext.clear();
WebRequestDetail wrd = WebRequestDetail.newBuilder().build();
stackify/stackify-api-java
src/test/java/com/stackify/api/common/ApiConfigurationTest.java
// Path: src/main/java/com/stackify/api/EnvironmentDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class EnvironmentDetail { // // /** // * Device name // */ // @JsonProperty("DeviceName") // private String deviceName; // // /** // * Application name // */ // @JsonProperty("AppName") // private String appName; // // /** // * Application location // */ // @JsonProperty("AppLocation") // private String appLocation; // // /** // * Custom application name // */ // @JsonProperty("ConfiguredAppName") // private String configuredAppName; // // /** // * Custom application environment // */ // @JsonProperty("ConfiguredEnvironmentName") // private String configuredEnvironmentName; // // }
import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import com.stackify.api.EnvironmentDetail;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common; /** * ApiConfiguration JUnit Test * @author Eric Martin */ public class ApiConfigurationTest { /** * testBuilder */ @Test public void testBuilder() { String apiUrl = "url"; String apiKey = "key"; String application = "app"; String environment = "env";
// Path: src/main/java/com/stackify/api/EnvironmentDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class EnvironmentDetail { // // /** // * Device name // */ // @JsonProperty("DeviceName") // private String deviceName; // // /** // * Application name // */ // @JsonProperty("AppName") // private String appName; // // /** // * Application location // */ // @JsonProperty("AppLocation") // private String appLocation; // // /** // * Custom application name // */ // @JsonProperty("ConfiguredAppName") // private String configuredAppName; // // /** // * Custom application environment // */ // @JsonProperty("ConfiguredEnvironmentName") // private String configuredEnvironmentName; // // } // Path: src/test/java/com/stackify/api/common/ApiConfigurationTest.java import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import com.stackify.api.EnvironmentDetail; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common; /** * ApiConfiguration JUnit Test * @author Eric Martin */ public class ApiConfigurationTest { /** * testBuilder */ @Test public void testBuilder() { String apiUrl = "url"; String apiKey = "key"; String application = "app"; String environment = "env";
EnvironmentDetail envDetail = Mockito.mock(EnvironmentDetail.class);
stackify/stackify-api-java
src/test/java/com/stackify/api/common/lang/StackTraceElementsTest.java
// Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // }
import org.junit.Assert; import org.junit.Test; import com.stackify.api.TraceFrame;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.lang; /** * StackTraceElements JUnit Test * * @author Eric Martin */ public class StackTraceElementsTest { /** * testToStackFrame */ @Test public void testToStackFrame() { String declaringClass = StackTraceElementsTest.class.getCanonicalName(); String methodName = "methodName"; String fileName = "fileName"; int lineNumber = 14; StackTraceElement element = new StackTraceElement(declaringClass, methodName, fileName, lineNumber);
// Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // } // Path: src/test/java/com/stackify/api/common/lang/StackTraceElementsTest.java import org.junit.Assert; import org.junit.Test; import com.stackify.api.TraceFrame; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.lang; /** * StackTraceElements JUnit Test * * @author Eric Martin */ public class StackTraceElementsTest { /** * testToStackFrame */ @Test public void testToStackFrame() { String declaringClass = StackTraceElementsTest.class.getCanonicalName(); String methodName = "methodName"; String fileName = "fileName"; int lineNumber = 14; StackTraceElement element = new StackTraceElement(declaringClass, methodName, fileName, lineNumber);
TraceFrame frame = StackTraceElements.toTraceFrame(element);
stackify/stackify-api-java
src/test/java/com/stackify/api/common/lang/ThrowablesTest.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // }
import java.util.List; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame;
} /** * testGetCausalChainWithSelfCausation */ @Test public void testGetCausalChainWithSelfCausation() { Throwable c2 = new RuntimeException(); Throwable c1 = new RuntimeException(c2); c2.initCause(c1); Throwable t = new RuntimeException(c1); List<Throwable> throwables = Throwables.getCausalChain(t); Assert.assertNotNull(throwables); Assert.assertEquals(3, throwables.size()); Assert.assertEquals(t, throwables.get(0)); Assert.assertEquals(c1, throwables.get(1)); Assert.assertEquals(c2, throwables.get(2)); } /** * testToErrorDetail */ @Test public void testToErrorDetail() { String message = "message"; String causeMessage = "causeMessage"; Throwable cause = new NullPointerException(causeMessage); Throwable throwable = new RuntimeException(message, cause);
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // } // Path: src/test/java/com/stackify/api/common/lang/ThrowablesTest.java import java.util.List; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame; } /** * testGetCausalChainWithSelfCausation */ @Test public void testGetCausalChainWithSelfCausation() { Throwable c2 = new RuntimeException(); Throwable c1 = new RuntimeException(c2); c2.initCause(c1); Throwable t = new RuntimeException(c1); List<Throwable> throwables = Throwables.getCausalChain(t); Assert.assertNotNull(throwables); Assert.assertEquals(3, throwables.size()); Assert.assertEquals(t, throwables.get(0)); Assert.assertEquals(c1, throwables.get(1)); Assert.assertEquals(c2, throwables.get(2)); } /** * testToErrorDetail */ @Test public void testToErrorDetail() { String message = "message"; String causeMessage = "causeMessage"; Throwable cause = new NullPointerException(causeMessage); Throwable throwable = new RuntimeException(message, cause);
ErrorItem errorDetail = Throwables.toErrorItem(throwable);
stackify/stackify-api-java
src/test/java/com/stackify/api/common/lang/ThrowablesTest.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // }
import java.util.List; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame;
Throwable c2 = new RuntimeException(); Throwable c1 = new RuntimeException(c2); c2.initCause(c1); Throwable t = new RuntimeException(c1); List<Throwable> throwables = Throwables.getCausalChain(t); Assert.assertNotNull(throwables); Assert.assertEquals(3, throwables.size()); Assert.assertEquals(t, throwables.get(0)); Assert.assertEquals(c1, throwables.get(1)); Assert.assertEquals(c2, throwables.get(2)); } /** * testToErrorDetail */ @Test public void testToErrorDetail() { String message = "message"; String causeMessage = "causeMessage"; Throwable cause = new NullPointerException(causeMessage); Throwable throwable = new RuntimeException(message, cause); ErrorItem errorDetail = Throwables.toErrorItem(throwable); Assert.assertNotNull(errorDetail); Assert.assertEquals(message, errorDetail.getMessage()); Assert.assertEquals("java.lang.RuntimeException", errorDetail.getErrorType());
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/TraceFrame.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class TraceFrame { // // /** // * The file name // */ // @JsonProperty("CodeFileName") // private String codeFileName; // // /** // * The line number // */ // @JsonProperty("LineNum") // private Integer lineNum; // // /** // * The method name // */ // @JsonProperty("Method") // private String method; // // } // Path: src/test/java/com/stackify/api/common/lang/ThrowablesTest.java import java.util.List; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import com.stackify.api.ErrorItem; import com.stackify.api.TraceFrame; Throwable c2 = new RuntimeException(); Throwable c1 = new RuntimeException(c2); c2.initCause(c1); Throwable t = new RuntimeException(c1); List<Throwable> throwables = Throwables.getCausalChain(t); Assert.assertNotNull(throwables); Assert.assertEquals(3, throwables.size()); Assert.assertEquals(t, throwables.get(0)); Assert.assertEquals(c1, throwables.get(1)); Assert.assertEquals(c2, throwables.get(2)); } /** * testToErrorDetail */ @Test public void testToErrorDetail() { String message = "message"; String causeMessage = "causeMessage"; Throwable cause = new NullPointerException(causeMessage); Throwable throwable = new RuntimeException(message, cause); ErrorItem errorDetail = Throwables.toErrorItem(throwable); Assert.assertNotNull(errorDetail); Assert.assertEquals(message, errorDetail.getMessage()); Assert.assertEquals("java.lang.RuntimeException", errorDetail.getErrorType());
List<TraceFrame> stackTrace = errorDetail.getStackTrace();
stackify/stackify-api-java
src/main/java/com/stackify/api/common/error/ErrorGovernor.java
// Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // }
import com.stackify.api.StackifyError;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * Utility class for limiting transmission of duplicate errors * * @author Eric Martin */ public class ErrorGovernor { /** * Number of instances of a unique error that are allowed to be sent in one minute */ private static final int MAX_DUP_ERROR_PER_MINUTE = 100; /** * Elapsed time before the errorToCounter map is purged of expired entries */ private static final int CLEAN_UP_MINUTES = 15; /** * Map from * MD5(<type>-<typeCode>-<method>) * to * Unix epoch minute, error count for that minute */ private final ErrorCounter errorCounter = new ErrorCounter(); /** * The next time the errorToCounter dictionary needs to be purged of expired entries */ private long nextErrorToCounterCleanUp = getUnixEpochMinutes() + CLEAN_UP_MINUTES; /** * Determines if the error should be sent based on our throttling criteria * @param error The error * @return True if this error should be sent to Stackify, false otherwise */
// Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // Path: src/main/java/com/stackify/api/common/error/ErrorGovernor.java import com.stackify.api.StackifyError; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * Utility class for limiting transmission of duplicate errors * * @author Eric Martin */ public class ErrorGovernor { /** * Number of instances of a unique error that are allowed to be sent in one minute */ private static final int MAX_DUP_ERROR_PER_MINUTE = 100; /** * Elapsed time before the errorToCounter map is purged of expired entries */ private static final int CLEAN_UP_MINUTES = 15; /** * Map from * MD5(<type>-<typeCode>-<method>) * to * Unix epoch minute, error count for that minute */ private final ErrorCounter errorCounter = new ErrorCounter(); /** * The next time the errorToCounter dictionary needs to be purged of expired entries */ private long nextErrorToCounterCleanUp = getUnixEpochMinutes() + CLEAN_UP_MINUTES; /** * Determines if the error should be sent based on our throttling criteria * @param error The error * @return True if this error should be sent to Stackify, false otherwise */
public boolean errorShouldBeSent(final StackifyError error) {
stackify/stackify-api-java
src/test/java/com/stackify/api/common/log/LogBackgroundServiceSchedulerTest.java
// Path: src/main/java/com/stackify/api/common/http/HttpException.java // public class HttpException extends Exception { // // /** // * Serial version UID // */ // private static final long serialVersionUID = -6349485370575426368L; // // /** // * HTTP status code // */ // private final int statusCode; // // /** // * Constructor // * @param statusCode HTTP status code // */ // public HttpException(int statusCode) { // this.statusCode = statusCode; // } // // /** // * @return the statusCode // */ // public int getStatusCode() { // return statusCode; // } // // /** // * @return True if 4xx status code // */ // public boolean isClientError() { // return (HttpURLConnection.HTTP_BAD_REQUEST <= statusCode) && (statusCode < HttpURLConnection.HTTP_INTERNAL_ERROR); // } // }
import java.net.HttpURLConnection; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.stackify.api.common.http.HttpException;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * LogBackgroundServiceScheduler JUnit Test * * @author Eric Martin */ @RunWith(PowerMockRunner.class) @PrepareForTest({LogBackgroundServiceScheduler.class, System.class}) public class LogBackgroundServiceSchedulerTest { /** * testUpdateOk */ @Test public void testNoUpdate() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); Assert.assertEquals(0, scheduler.getLastHttpError()); Assert.assertEquals(1000, scheduler.getScheduleDelay()); } /** * testUpdateOk */ @Test public void testUpdateOk() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); scheduler.update(50); Assert.assertEquals(0, scheduler.getLastHttpError()); Assert.assertEquals(1000, scheduler.getScheduleDelay()); } /** * testUpdateOkButLow */ @Test public void testUpdateOkButLow() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); scheduler.update(5); Assert.assertEquals(0, scheduler.getLastHttpError()); Assert.assertEquals(1250, scheduler.getScheduleDelay()); } /** * testUpdateUnauthorized */ @Test public void testUpdateUnauthorized() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); long beforeUpdate = System.currentTimeMillis();
// Path: src/main/java/com/stackify/api/common/http/HttpException.java // public class HttpException extends Exception { // // /** // * Serial version UID // */ // private static final long serialVersionUID = -6349485370575426368L; // // /** // * HTTP status code // */ // private final int statusCode; // // /** // * Constructor // * @param statusCode HTTP status code // */ // public HttpException(int statusCode) { // this.statusCode = statusCode; // } // // /** // * @return the statusCode // */ // public int getStatusCode() { // return statusCode; // } // // /** // * @return True if 4xx status code // */ // public boolean isClientError() { // return (HttpURLConnection.HTTP_BAD_REQUEST <= statusCode) && (statusCode < HttpURLConnection.HTTP_INTERNAL_ERROR); // } // } // Path: src/test/java/com/stackify/api/common/log/LogBackgroundServiceSchedulerTest.java import java.net.HttpURLConnection; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.stackify.api.common.http.HttpException; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * LogBackgroundServiceScheduler JUnit Test * * @author Eric Martin */ @RunWith(PowerMockRunner.class) @PrepareForTest({LogBackgroundServiceScheduler.class, System.class}) public class LogBackgroundServiceSchedulerTest { /** * testUpdateOk */ @Test public void testNoUpdate() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); Assert.assertEquals(0, scheduler.getLastHttpError()); Assert.assertEquals(1000, scheduler.getScheduleDelay()); } /** * testUpdateOk */ @Test public void testUpdateOk() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); scheduler.update(50); Assert.assertEquals(0, scheduler.getLastHttpError()); Assert.assertEquals(1000, scheduler.getScheduleDelay()); } /** * testUpdateOkButLow */ @Test public void testUpdateOkButLow() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); scheduler.update(5); Assert.assertEquals(0, scheduler.getLastHttpError()); Assert.assertEquals(1250, scheduler.getScheduleDelay()); } /** * testUpdateUnauthorized */ @Test public void testUpdateUnauthorized() { LogBackgroundServiceScheduler scheduler = new LogBackgroundServiceScheduler(); long beforeUpdate = System.currentTimeMillis();
scheduler.update(new HttpException(HttpURLConnection.HTTP_UNAUTHORIZED));
stackify/stackify-api-java
src/test/java/com/stackify/api/common/EnvironmentDetailsTest.java
// Path: src/main/java/com/stackify/api/EnvironmentDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class EnvironmentDetail { // // /** // * Device name // */ // @JsonProperty("DeviceName") // private String deviceName; // // /** // * Application name // */ // @JsonProperty("AppName") // private String appName; // // /** // * Application location // */ // @JsonProperty("AppLocation") // private String appLocation; // // /** // * Custom application name // */ // @JsonProperty("ConfiguredAppName") // private String configuredAppName; // // /** // * Custom application environment // */ // @JsonProperty("ConfiguredEnvironmentName") // private String configuredEnvironmentName; // // }
import java.net.InetAddress; import java.net.UnknownHostException; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.stackify.api.EnvironmentDetail;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common; /** * EnvironmentDetails JUnit Test * * @author Eric Martin */ @RunWith(PowerMockRunner.class) @PrepareForTest({EnvironmentDetails.class, System.class, InetAddress.class}) public class EnvironmentDetailsTest { /** * testGetEnvironmentDetail * @throws UnknownHostException */ @Test public void testGetEnvironmentDetail() throws UnknownHostException { String application = "application"; String environment = "environment"; String hostName = "hostName"; PowerMockito.mockStatic(System.class); PowerMockito.when(System.getenv("HOSTNAME")).thenReturn(hostName); PowerMockito.when(System.getProperty("user.dir")).thenReturn("/some/dir/");
// Path: src/main/java/com/stackify/api/EnvironmentDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class EnvironmentDetail { // // /** // * Device name // */ // @JsonProperty("DeviceName") // private String deviceName; // // /** // * Application name // */ // @JsonProperty("AppName") // private String appName; // // /** // * Application location // */ // @JsonProperty("AppLocation") // private String appLocation; // // /** // * Custom application name // */ // @JsonProperty("ConfiguredAppName") // private String configuredAppName; // // /** // * Custom application environment // */ // @JsonProperty("ConfiguredEnvironmentName") // private String configuredEnvironmentName; // // } // Path: src/test/java/com/stackify/api/common/EnvironmentDetailsTest.java import java.net.InetAddress; import java.net.UnknownHostException; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.stackify.api.EnvironmentDetail; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common; /** * EnvironmentDetails JUnit Test * * @author Eric Martin */ @RunWith(PowerMockRunner.class) @PrepareForTest({EnvironmentDetails.class, System.class, InetAddress.class}) public class EnvironmentDetailsTest { /** * testGetEnvironmentDetail * @throws UnknownHostException */ @Test public void testGetEnvironmentDetail() throws UnknownHostException { String application = "application"; String environment = "environment"; String hostName = "hostName"; PowerMockito.mockStatic(System.class); PowerMockito.when(System.getenv("HOSTNAME")).thenReturn(hostName); PowerMockito.when(System.getProperty("user.dir")).thenReturn("/some/dir/");
EnvironmentDetail env = EnvironmentDetails.getEnvironmentDetail(application, environment);
stackify/stackify-api-java
src/main/java/com/stackify/api/common/collect/SynchronizedEvictingQueue.java
// Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // }
import java.util.ArrayDeque; import java.util.Collection; import java.util.Iterator; import java.util.Queue; import com.stackify.api.common.util.Preconditions;
/* * Copyright 2015 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.collect; /** * SynchronizedEvictingQueue * @author Eric Martin */ public class SynchronizedEvictingQueue<E> implements Queue<E> { /** * Maximum size of the queue */ private final int maxSize; /** * Deque for the evicting queue implementation */ private final Queue<E> deque; /** * Constructor * @param maxSize Maximum size of the queue */ public SynchronizedEvictingQueue(final int maxSize) {
// Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // } // Path: src/main/java/com/stackify/api/common/collect/SynchronizedEvictingQueue.java import java.util.ArrayDeque; import java.util.Collection; import java.util.Iterator; import java.util.Queue; import com.stackify.api.common.util.Preconditions; /* * Copyright 2015 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.collect; /** * SynchronizedEvictingQueue * @author Eric Martin */ public class SynchronizedEvictingQueue<E> implements Queue<E> { /** * Maximum size of the queue */ private final int maxSize; /** * Deque for the evicting queue implementation */ private final Queue<E> deque; /** * Constructor * @param maxSize Maximum size of the queue */ public SynchronizedEvictingQueue(final int maxSize) {
Preconditions.checkArgument(0 < maxSize);
stackify/stackify-api-java
src/main/java/com/stackify/api/common/http/HttpClient.java
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // } // // Path: src/main/java/com/stackify/api/common/util/CharStreams.java // public class CharStreams { // // /** // * Read char stream to a string // * @param r Readable // * @return String // * @throws IOException // */ // public static String toString(final Readable r) throws IOException { // Preconditions.checkNotNull(r); // // StringBuilder sb = new StringBuilder(); // // CharBuffer buf = CharBuffer.allocate(0x800); // // while (r.read(buf) != -1) { // buf.flip(); // sb.append(buf); // buf.clear(); // } // // return sb.toString(); // } // // /** // * Hidden to prevent construction // */ // private CharStreams() { // } // } // // Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // }
import com.stackify.api.common.ApiConfiguration; import com.stackify.api.common.util.CharStreams; import com.stackify.api.common.util.Preconditions; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import java.util.zip.GZIPOutputStream;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.http; /** * HttpClient * @author Eric Martin */ public class HttpClient { /** * CONNECT_TIMEOUT */ private static final int CONNECT_TIMEOUT = 5000; /** * READ_TIMEOUT */ private static final int READ_TIMEOUT = 15000; /** * API configuration */
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // } // // Path: src/main/java/com/stackify/api/common/util/CharStreams.java // public class CharStreams { // // /** // * Read char stream to a string // * @param r Readable // * @return String // * @throws IOException // */ // public static String toString(final Readable r) throws IOException { // Preconditions.checkNotNull(r); // // StringBuilder sb = new StringBuilder(); // // CharBuffer buf = CharBuffer.allocate(0x800); // // while (r.read(buf) != -1) { // buf.flip(); // sb.append(buf); // buf.clear(); // } // // return sb.toString(); // } // // /** // * Hidden to prevent construction // */ // private CharStreams() { // } // } // // Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // } // Path: src/main/java/com/stackify/api/common/http/HttpClient.java import com.stackify.api.common.ApiConfiguration; import com.stackify.api.common.util.CharStreams; import com.stackify.api.common.util.Preconditions; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import java.util.zip.GZIPOutputStream; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.http; /** * HttpClient * @author Eric Martin */ public class HttpClient { /** * CONNECT_TIMEOUT */ private static final int CONNECT_TIMEOUT = 5000; /** * READ_TIMEOUT */ private static final int READ_TIMEOUT = 15000; /** * API configuration */
private final ApiConfiguration apiConfig;
stackify/stackify-api-java
src/main/java/com/stackify/api/common/http/HttpClient.java
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // } // // Path: src/main/java/com/stackify/api/common/util/CharStreams.java // public class CharStreams { // // /** // * Read char stream to a string // * @param r Readable // * @return String // * @throws IOException // */ // public static String toString(final Readable r) throws IOException { // Preconditions.checkNotNull(r); // // StringBuilder sb = new StringBuilder(); // // CharBuffer buf = CharBuffer.allocate(0x800); // // while (r.read(buf) != -1) { // buf.flip(); // sb.append(buf); // buf.clear(); // } // // return sb.toString(); // } // // /** // * Hidden to prevent construction // */ // private CharStreams() { // } // } // // Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // }
import com.stackify.api.common.ApiConfiguration; import com.stackify.api.common.util.CharStreams; import com.stackify.api.common.util.Preconditions; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import java.util.zip.GZIPOutputStream;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.http; /** * HttpClient * @author Eric Martin */ public class HttpClient { /** * CONNECT_TIMEOUT */ private static final int CONNECT_TIMEOUT = 5000; /** * READ_TIMEOUT */ private static final int READ_TIMEOUT = 15000; /** * API configuration */ private final ApiConfiguration apiConfig; /** * HTTP proxy */ private final Proxy proxy; /** * Constructor * @param apiConfig API configuration */ public HttpClient(final ApiConfiguration apiConfig) {
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // } // // Path: src/main/java/com/stackify/api/common/util/CharStreams.java // public class CharStreams { // // /** // * Read char stream to a string // * @param r Readable // * @return String // * @throws IOException // */ // public static String toString(final Readable r) throws IOException { // Preconditions.checkNotNull(r); // // StringBuilder sb = new StringBuilder(); // // CharBuffer buf = CharBuffer.allocate(0x800); // // while (r.read(buf) != -1) { // buf.flip(); // sb.append(buf); // buf.clear(); // } // // return sb.toString(); // } // // /** // * Hidden to prevent construction // */ // private CharStreams() { // } // } // // Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // } // Path: src/main/java/com/stackify/api/common/http/HttpClient.java import com.stackify.api.common.ApiConfiguration; import com.stackify.api.common.util.CharStreams; import com.stackify.api.common.util.Preconditions; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import java.util.zip.GZIPOutputStream; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.http; /** * HttpClient * @author Eric Martin */ public class HttpClient { /** * CONNECT_TIMEOUT */ private static final int CONNECT_TIMEOUT = 5000; /** * READ_TIMEOUT */ private static final int READ_TIMEOUT = 15000; /** * API configuration */ private final ApiConfiguration apiConfig; /** * HTTP proxy */ private final Proxy proxy; /** * Constructor * @param apiConfig API configuration */ public HttpClient(final ApiConfiguration apiConfig) {
Preconditions.checkNotNull(apiConfig);
stackify/stackify-api-java
src/main/java/com/stackify/api/common/http/HttpClient.java
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // } // // Path: src/main/java/com/stackify/api/common/util/CharStreams.java // public class CharStreams { // // /** // * Read char stream to a string // * @param r Readable // * @return String // * @throws IOException // */ // public static String toString(final Readable r) throws IOException { // Preconditions.checkNotNull(r); // // StringBuilder sb = new StringBuilder(); // // CharBuffer buf = CharBuffer.allocate(0x800); // // while (r.read(buf) != -1) { // buf.flip(); // sb.append(buf); // buf.clear(); // } // // return sb.toString(); // } // // /** // * Hidden to prevent construction // */ // private CharStreams() { // } // } // // Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // }
import com.stackify.api.common.ApiConfiguration; import com.stackify.api.common.util.CharStreams; import com.stackify.api.common.util.Preconditions; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import java.util.zip.GZIPOutputStream;
// read and close the input stream try { readAndClose(connection.getInputStream()); } catch (Throwable t) { // do nothing } // read and close the error stream try { readAndClose(connection.getErrorStream()); } catch (Throwable t) { // do nothing } } } } /** * Reads all remaining contents from the stream and closes it * @param stream The stream * @return The contents of the stream * @throws IOException */ private String readAndClose(final InputStream stream) throws IOException { String contents = null; if (stream != null) {
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java // @ToString // @Getter // @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") // public class ApiConfiguration { // // public static final String TRANSPORT_DIRECT = "direct"; // public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; // // private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; // private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; // // /** // * Default API URL // */ // private static final String DEFAULT_API_URL = "https://api.stackify.com"; // // /** // * API URL // */ // private final String apiUrl; // // /** // * API Key // */ // private final String apiKey; // // /** // * Application name // */ // private final String application; // // /** // * Environment // */ // private final String environment; // // /** // * Environment details // */ // private final EnvironmentDetail envDetail; // // /** // * Add #SKIPJSON tag to messages containing Json // */ // private final Boolean skipJson; // // /** // * Allow logging from com.stackify.* // */ // private final Boolean allowComDotStackify; // // /** // * Http Proxy Host ie) 10.20.30.40 // */ // private final String httpProxyHost; // // /** // * Http Proxy Port ie) 8080 // */ // private final String httpProxyPort; // // private final String transport; // // /** // * @return the apiUrl // */ // public String getApiUrl() { // return apiUrl != null ? apiUrl : DEFAULT_API_URL; // } // // public String getTransport() { // return transport != null ? transport : DEFAULT_TRANSPORT; // } // // public String getAgentSocketPath() { // return DEFAULT_AGENT_SOCKET_PATH_UNIX; // } // } // // Path: src/main/java/com/stackify/api/common/util/CharStreams.java // public class CharStreams { // // /** // * Read char stream to a string // * @param r Readable // * @return String // * @throws IOException // */ // public static String toString(final Readable r) throws IOException { // Preconditions.checkNotNull(r); // // StringBuilder sb = new StringBuilder(); // // CharBuffer buf = CharBuffer.allocate(0x800); // // while (r.read(buf) != -1) { // buf.flip(); // sb.append(buf); // buf.clear(); // } // // return sb.toString(); // } // // /** // * Hidden to prevent construction // */ // private CharStreams() { // } // } // // Path: src/main/java/com/stackify/api/common/util/Preconditions.java // public class Preconditions { // // /** // * Throws NullPointerException if the argument is null // * @param o The object to check // * @throws NullPointerException // */ // public static void checkNotNull(final Object o) { // if (o == null) { // throw new NullPointerException(); // } // } // // /** // * Throws IllegalArgumentException if the expression is false // * @param expression The expression // * @throws IllegalArgumentException // */ // public static void checkArgument(final boolean expression) { // if (!expression) { // throw new IllegalArgumentException(); // } // } // // /** // * Hidden to prevent construction // */ // private Preconditions() { // } // } // Path: src/main/java/com/stackify/api/common/http/HttpClient.java import com.stackify.api.common.ApiConfiguration; import com.stackify.api.common.util.CharStreams; import com.stackify.api.common.util.Preconditions; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; import java.util.zip.GZIPOutputStream; // read and close the input stream try { readAndClose(connection.getInputStream()); } catch (Throwable t) { // do nothing } // read and close the error stream try { readAndClose(connection.getErrorStream()); } catch (Throwable t) { // do nothing } } } } /** * Reads all remaining contents from the stream and closes it * @param stream The stream * @return The contents of the stream * @throws IOException */ private String readAndClose(final InputStream stream) throws IOException { String contents = null; if (stream != null) {
contents = CharStreams.toString(new InputStreamReader(new BufferedInputStream(stream), "UTF-8"));
stackify/stackify-api-java
src/main/java/com/stackify/api/common/ApiConfigurations.java
// Path: src/main/java/com/stackify/api/common/util/PropertyUtil.java // @Slf4j // public class PropertyUtil { // // public static Map<String, String> readAndMerge(@NonNull final String... paths) { // // Map<String, String> mergedMap = new HashMap<String, String>(); // // for (String path : paths) { // Map<String, String> map = read(path); // for (Map.Entry<String, String> entry : map.entrySet()) { // if (!mergedMap.containsKey(entry.getKey())) { // mergedMap.put(entry.getKey(), entry.getValue()); // } // } // } // // return mergedMap; // } // // /** // * Loads properties with given path - will load as file is able or classpath resource // */ // public static Properties loadProperties(final String path) { // // if (path != null) { // // try as file // try { // File file = new File(path); // if (file.exists()) { // try { // Properties p = new Properties(); // p.load(new FileInputStream(file)); // return p; // } catch (Exception e) { // log.error("Error loading properties from file: " + path); // } // } // } catch (Throwable e) { // log.debug(e.getMessage(), e); // } // // // try as resource // InputStream inputStream = null; // try { // inputStream = PropertyUtil.class.getResourceAsStream(path); // if (inputStream != null) { // try { // Properties p = new Properties(); // p.load(inputStream); // return p; // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } // } // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } finally { // if (inputStream != null) { // try { // inputStream.close(); // } catch (Throwable t) { // log.debug("Error closing: " + path, t); // } // } // } // } // // // // return empty Properties by default // return new Properties(); // } // // /** // * Reads properties from file path or classpath // */ // public static Map<String, String> read(final String path) { // // Map<String, String> map = new HashMap<String, String>(); // // if (path != null) { // try { // Properties p = loadProperties(path); // // for (Object key : p.keySet()) { // // String value = p.getProperty(String.valueOf(key)); // // // remove single/double quotes // if ((value.startsWith("\"") && value.endsWith("\"")) || // (value.startsWith("\'") && value.endsWith("\'"))) { // value = value.substring(1, value.length() - 1); // } // // value = value.trim(); // // if (!value.equals("")) { // map.put(String.valueOf(key), value); // } // } // // } catch (Exception e) { // log.error(e.getMessage(), e); // } // } // // return map; // } // // }
import com.stackify.api.common.util.PropertyUtil; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; import java.util.Map;
final String transport, final String allowComDotStackify) { ApiConfiguration props = ApiConfigurations.fromProperties(); String mergedApiUrl = ((apiUrl != null) && (0 < apiUrl.length())) ? apiUrl : props.getApiUrl(); String mergedApiKey = ((apiKey != null) && (0 < apiKey.length())) ? apiKey : props.getApiKey(); String mergedApplication = ((application != null) && (0 < application.length())) ? application : props.getApplication(); String mergedEnvironment = ((environment != null) && (0 < environment.length())) ? environment : props.getEnvironment(); ApiConfiguration.Builder builder = ApiConfiguration.newBuilder(); builder.transport(transport); builder.apiUrl(mergedApiUrl); builder.apiKey(mergedApiKey); builder.application(mergedApplication); builder.environment(mergedEnvironment); builder.envDetail(EnvironmentDetails.getEnvironmentDetail(mergedApplication, mergedEnvironment)); builder.allowComDotStackify(Boolean.valueOf(allowComDotStackify)); return builder.build(); } /** * @return ApiConfiguration read from the stackify-api.properties file */ public static ApiConfiguration fromProperties() { ApiConfiguration.Builder builder = ApiConfiguration.newBuilder(); try {
// Path: src/main/java/com/stackify/api/common/util/PropertyUtil.java // @Slf4j // public class PropertyUtil { // // public static Map<String, String> readAndMerge(@NonNull final String... paths) { // // Map<String, String> mergedMap = new HashMap<String, String>(); // // for (String path : paths) { // Map<String, String> map = read(path); // for (Map.Entry<String, String> entry : map.entrySet()) { // if (!mergedMap.containsKey(entry.getKey())) { // mergedMap.put(entry.getKey(), entry.getValue()); // } // } // } // // return mergedMap; // } // // /** // * Loads properties with given path - will load as file is able or classpath resource // */ // public static Properties loadProperties(final String path) { // // if (path != null) { // // try as file // try { // File file = new File(path); // if (file.exists()) { // try { // Properties p = new Properties(); // p.load(new FileInputStream(file)); // return p; // } catch (Exception e) { // log.error("Error loading properties from file: " + path); // } // } // } catch (Throwable e) { // log.debug(e.getMessage(), e); // } // // // try as resource // InputStream inputStream = null; // try { // inputStream = PropertyUtil.class.getResourceAsStream(path); // if (inputStream != null) { // try { // Properties p = new Properties(); // p.load(inputStream); // return p; // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } // } // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } finally { // if (inputStream != null) { // try { // inputStream.close(); // } catch (Throwable t) { // log.debug("Error closing: " + path, t); // } // } // } // } // // // // return empty Properties by default // return new Properties(); // } // // /** // * Reads properties from file path or classpath // */ // public static Map<String, String> read(final String path) { // // Map<String, String> map = new HashMap<String, String>(); // // if (path != null) { // try { // Properties p = loadProperties(path); // // for (Object key : p.keySet()) { // // String value = p.getProperty(String.valueOf(key)); // // // remove single/double quotes // if ((value.startsWith("\"") && value.endsWith("\"")) || // (value.startsWith("\'") && value.endsWith("\'"))) { // value = value.substring(1, value.length() - 1); // } // // value = value.trim(); // // if (!value.equals("")) { // map.put(String.valueOf(key), value); // } // } // // } catch (Exception e) { // log.error(e.getMessage(), e); // } // } // // return map; // } // // } // Path: src/main/java/com/stackify/api/common/ApiConfigurations.java import com.stackify.api.common.util.PropertyUtil; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; import java.util.Map; final String transport, final String allowComDotStackify) { ApiConfiguration props = ApiConfigurations.fromProperties(); String mergedApiUrl = ((apiUrl != null) && (0 < apiUrl.length())) ? apiUrl : props.getApiUrl(); String mergedApiKey = ((apiKey != null) && (0 < apiKey.length())) ? apiKey : props.getApiKey(); String mergedApplication = ((application != null) && (0 < application.length())) ? application : props.getApplication(); String mergedEnvironment = ((environment != null) && (0 < environment.length())) ? environment : props.getEnvironment(); ApiConfiguration.Builder builder = ApiConfiguration.newBuilder(); builder.transport(transport); builder.apiUrl(mergedApiUrl); builder.apiKey(mergedApiKey); builder.application(mergedApplication); builder.environment(mergedEnvironment); builder.envDetail(EnvironmentDetails.getEnvironmentDetail(mergedApplication, mergedEnvironment)); builder.allowComDotStackify(Boolean.valueOf(allowComDotStackify)); return builder.build(); } /** * @return ApiConfiguration read from the stackify-api.properties file */ public static ApiConfiguration fromProperties() { ApiConfiguration.Builder builder = ApiConfiguration.newBuilder(); try {
Map<String, String> properties = PropertyUtil.read("/stackify-api.properties");
stackify/stackify-api-java
src/test/java/com/stackify/api/common/error/ErrorGovernorTest.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // }
import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorGovernorTest JUnit Test * * @author Eric Martin */ public class ErrorGovernorTest { /** * testErrorShouldBeSentWithNull */ @Test(expected = NullPointerException.class) public void testErrorShouldBeSentWithNull() { ErrorGovernor governor = new ErrorGovernor(); governor.errorShouldBeSent(null); } /** * testErrorShouldBeSent */ @Test public void testErrorShouldBeSent() {
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // Path: src/test/java/com/stackify/api/common/error/ErrorGovernorTest.java import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorGovernorTest JUnit Test * * @author Eric Martin */ public class ErrorGovernorTest { /** * testErrorShouldBeSentWithNull */ @Test(expected = NullPointerException.class) public void testErrorShouldBeSentWithNull() { ErrorGovernor governor = new ErrorGovernor(); governor.errorShouldBeSent(null); } /** * testErrorShouldBeSent */ @Test public void testErrorShouldBeSent() {
ErrorItem.Builder builder = ErrorItem.newBuilder();
stackify/stackify-api-java
src/test/java/com/stackify/api/common/error/ErrorGovernorTest.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // }
import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorGovernorTest JUnit Test * * @author Eric Martin */ public class ErrorGovernorTest { /** * testErrorShouldBeSentWithNull */ @Test(expected = NullPointerException.class) public void testErrorShouldBeSentWithNull() { ErrorGovernor governor = new ErrorGovernor(); governor.errorShouldBeSent(null); } /** * testErrorShouldBeSent */ @Test public void testErrorShouldBeSent() { ErrorItem.Builder builder = ErrorItem.newBuilder(); builder.errorType("errorType"); builder.errorTypeCode("errorTypeCode"); builder.sourceMethod("sourceMethod"); ErrorItem errorItem = builder.build();
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // Path: src/test/java/com/stackify/api/common/error/ErrorGovernorTest.java import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorGovernorTest JUnit Test * * @author Eric Martin */ public class ErrorGovernorTest { /** * testErrorShouldBeSentWithNull */ @Test(expected = NullPointerException.class) public void testErrorShouldBeSentWithNull() { ErrorGovernor governor = new ErrorGovernor(); governor.errorShouldBeSent(null); } /** * testErrorShouldBeSent */ @Test public void testErrorShouldBeSent() { ErrorItem.Builder builder = ErrorItem.newBuilder(); builder.errorType("errorType"); builder.errorTypeCode("errorTypeCode"); builder.sourceMethod("sourceMethod"); ErrorItem errorItem = builder.build();
StackifyError error = StackifyError.newBuilder().error(errorItem).build();
stackify/stackify-api-java
src/main/java/com/stackify/api/common/mask/MaskerConfiguration.java
// Path: src/main/java/com/stackify/api/common/util/PropertyUtil.java // @Slf4j // public class PropertyUtil { // // public static Map<String, String> readAndMerge(@NonNull final String... paths) { // // Map<String, String> mergedMap = new HashMap<String, String>(); // // for (String path : paths) { // Map<String, String> map = read(path); // for (Map.Entry<String, String> entry : map.entrySet()) { // if (!mergedMap.containsKey(entry.getKey())) { // mergedMap.put(entry.getKey(), entry.getValue()); // } // } // } // // return mergedMap; // } // // /** // * Loads properties with given path - will load as file is able or classpath resource // */ // public static Properties loadProperties(final String path) { // // if (path != null) { // // try as file // try { // File file = new File(path); // if (file.exists()) { // try { // Properties p = new Properties(); // p.load(new FileInputStream(file)); // return p; // } catch (Exception e) { // log.error("Error loading properties from file: " + path); // } // } // } catch (Throwable e) { // log.debug(e.getMessage(), e); // } // // // try as resource // InputStream inputStream = null; // try { // inputStream = PropertyUtil.class.getResourceAsStream(path); // if (inputStream != null) { // try { // Properties p = new Properties(); // p.load(inputStream); // return p; // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } // } // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } finally { // if (inputStream != null) { // try { // inputStream.close(); // } catch (Throwable t) { // log.debug("Error closing: " + path, t); // } // } // } // } // // // // return empty Properties by default // return new Properties(); // } // // /** // * Reads properties from file path or classpath // */ // public static Map<String, String> read(final String path) { // // Map<String, String> map = new HashMap<String, String>(); // // if (path != null) { // try { // Properties p = loadProperties(path); // // for (Object key : p.keySet()) { // // String value = p.getProperty(String.valueOf(key)); // // // remove single/double quotes // if ((value.startsWith("\"") && value.endsWith("\"")) || // (value.startsWith("\'") && value.endsWith("\'"))) { // value = value.substring(1, value.length() - 1); // } // // value = value.trim(); // // if (!value.equals("")) { // map.put(String.valueOf(key), value); // } // } // // } catch (Exception e) { // log.error(e.getMessage(), e); // } // } // // return map; // } // // }
import com.stackify.api.common.util.PropertyUtil; import lombok.extern.slf4j.Slf4j; import java.net.URISyntaxException; import java.net.URL; import java.util.Map;
package com.stackify.api.common.mask; /** * Handled properties: * <p> * stackify.log.mask.enabled=true|false * stackify.log.mask.[CREDITCARD|SSN|IP]=true|false * stackify.log.mask.custom.[CUSTOM_LABEL]=[regex] * * @author Darin Howard */ @Slf4j public class MaskerConfiguration { public static Masker fromProperties() { return fromProperties("/stackify-api.properties"); } public static Masker fromProperties(String path) { Masker masker = new Masker(); // set default enabled masks masker.addMask(Masker.MASK_CREDITCARD); masker.addMask(Masker.MASK_SSN); try { if (path != null) {
// Path: src/main/java/com/stackify/api/common/util/PropertyUtil.java // @Slf4j // public class PropertyUtil { // // public static Map<String, String> readAndMerge(@NonNull final String... paths) { // // Map<String, String> mergedMap = new HashMap<String, String>(); // // for (String path : paths) { // Map<String, String> map = read(path); // for (Map.Entry<String, String> entry : map.entrySet()) { // if (!mergedMap.containsKey(entry.getKey())) { // mergedMap.put(entry.getKey(), entry.getValue()); // } // } // } // // return mergedMap; // } // // /** // * Loads properties with given path - will load as file is able or classpath resource // */ // public static Properties loadProperties(final String path) { // // if (path != null) { // // try as file // try { // File file = new File(path); // if (file.exists()) { // try { // Properties p = new Properties(); // p.load(new FileInputStream(file)); // return p; // } catch (Exception e) { // log.error("Error loading properties from file: " + path); // } // } // } catch (Throwable e) { // log.debug(e.getMessage(), e); // } // // // try as resource // InputStream inputStream = null; // try { // inputStream = PropertyUtil.class.getResourceAsStream(path); // if (inputStream != null) { // try { // Properties p = new Properties(); // p.load(inputStream); // return p; // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } // } // } catch (Exception e) { // log.error("Error loading properties from resource: " + path); // } finally { // if (inputStream != null) { // try { // inputStream.close(); // } catch (Throwable t) { // log.debug("Error closing: " + path, t); // } // } // } // } // // // // return empty Properties by default // return new Properties(); // } // // /** // * Reads properties from file path or classpath // */ // public static Map<String, String> read(final String path) { // // Map<String, String> map = new HashMap<String, String>(); // // if (path != null) { // try { // Properties p = loadProperties(path); // // for (Object key : p.keySet()) { // // String value = p.getProperty(String.valueOf(key)); // // // remove single/double quotes // if ((value.startsWith("\"") && value.endsWith("\"")) || // (value.startsWith("\'") && value.endsWith("\'"))) { // value = value.substring(1, value.length() - 1); // } // // value = value.trim(); // // if (!value.equals("")) { // map.put(String.valueOf(key), value); // } // } // // } catch (Exception e) { // log.error(e.getMessage(), e); // } // } // // return map; // } // // } // Path: src/main/java/com/stackify/api/common/mask/MaskerConfiguration.java import com.stackify.api.common.util.PropertyUtil; import lombok.extern.slf4j.Slf4j; import java.net.URISyntaxException; import java.net.URL; import java.util.Map; package com.stackify.api.common.mask; /** * Handled properties: * <p> * stackify.log.mask.enabled=true|false * stackify.log.mask.[CREDITCARD|SSN|IP]=true|false * stackify.log.mask.custom.[CUSTOM_LABEL]=[regex] * * @author Darin Howard */ @Slf4j public class MaskerConfiguration { public static Masker fromProperties() { return fromProperties("/stackify-api.properties"); } public static Masker fromProperties(String path) { Masker masker = new Masker(); // set default enabled masks masker.addMask(Masker.MASK_CREDITCARD); masker.addMask(Masker.MASK_SSN); try { if (path != null) {
Map<String, String> map = PropertyUtil.read(path);
stackify/stackify-api-java
src/main/java/com/stackify/api/common/error/ErrorCounter.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // }
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests;
/* * ErrorCounter.java * Copyright 2014 Stackify */ package com.stackify.api.common.error; /** * ErrorCounter * @author Eric Martin */ public class ErrorCounter { /** * Map from * MD5(<type>-<typeCode>-<method>) * to * Unix epoch minute, error count for that minute */ private final Map<String, MinuteCounter> errorCounter = new HashMap<String, MinuteCounter>(); /** * Unix epoch minute and error count for that minute * * @author Eric Martin */ protected static class MinuteCounter { /** * Unix epoch minute */ private final long epochMinute; /** * Error count for that minute */ private final int errorCount; /** * Constructs a new minute counter for the specified minute * @param epochMinute Unix epoch minute * @return A new minute counter for the specified minute */ public static MinuteCounter newMinuteCounter(final long epochMinute) { return new MinuteCounter(epochMinute, 1); } /** * Constructs a new minute counter from the existing counter with the count incremented * @param counter Error count for that minute * @return A new minute counter from the existing counter with the count incremented */ public static MinuteCounter incrementCounter(final MinuteCounter counter) { return new MinuteCounter(counter.epochMinute, counter.errorCount + 1); } /** * Private constructor * @param epochMinute Unix epoch minute * @param errorCount Error count for that minute */ private MinuteCounter(final long epochMinute, final int errorCount) { this.epochMinute = epochMinute; this.errorCount = errorCount; } /** * @return the epochMinute */ public long getEpochMinute() { return epochMinute; } /** * @return the errorCount */ public int getErrorCount() { return errorCount; } } /** * Gets the base error (the last error in the causal chain) * @param error The error * @return The inner most error */
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // } // Path: src/main/java/com/stackify/api/common/error/ErrorCounter.java import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests; /* * ErrorCounter.java * Copyright 2014 Stackify */ package com.stackify.api.common.error; /** * ErrorCounter * @author Eric Martin */ public class ErrorCounter { /** * Map from * MD5(<type>-<typeCode>-<method>) * to * Unix epoch minute, error count for that minute */ private final Map<String, MinuteCounter> errorCounter = new HashMap<String, MinuteCounter>(); /** * Unix epoch minute and error count for that minute * * @author Eric Martin */ protected static class MinuteCounter { /** * Unix epoch minute */ private final long epochMinute; /** * Error count for that minute */ private final int errorCount; /** * Constructs a new minute counter for the specified minute * @param epochMinute Unix epoch minute * @return A new minute counter for the specified minute */ public static MinuteCounter newMinuteCounter(final long epochMinute) { return new MinuteCounter(epochMinute, 1); } /** * Constructs a new minute counter from the existing counter with the count incremented * @param counter Error count for that minute * @return A new minute counter from the existing counter with the count incremented */ public static MinuteCounter incrementCounter(final MinuteCounter counter) { return new MinuteCounter(counter.epochMinute, counter.errorCount + 1); } /** * Private constructor * @param epochMinute Unix epoch minute * @param errorCount Error count for that minute */ private MinuteCounter(final long epochMinute, final int errorCount) { this.epochMinute = epochMinute; this.errorCount = errorCount; } /** * @return the epochMinute */ public long getEpochMinute() { return epochMinute; } /** * @return the errorCount */ public int getErrorCount() { return errorCount; } } /** * Gets the base error (the last error in the causal chain) * @param error The error * @return The inner most error */
public static ErrorItem getBaseError(final StackifyError error) {
stackify/stackify-api-java
src/main/java/com/stackify/api/common/error/ErrorCounter.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // }
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests;
/* * ErrorCounter.java * Copyright 2014 Stackify */ package com.stackify.api.common.error; /** * ErrorCounter * @author Eric Martin */ public class ErrorCounter { /** * Map from * MD5(<type>-<typeCode>-<method>) * to * Unix epoch minute, error count for that minute */ private final Map<String, MinuteCounter> errorCounter = new HashMap<String, MinuteCounter>(); /** * Unix epoch minute and error count for that minute * * @author Eric Martin */ protected static class MinuteCounter { /** * Unix epoch minute */ private final long epochMinute; /** * Error count for that minute */ private final int errorCount; /** * Constructs a new minute counter for the specified minute * @param epochMinute Unix epoch minute * @return A new minute counter for the specified minute */ public static MinuteCounter newMinuteCounter(final long epochMinute) { return new MinuteCounter(epochMinute, 1); } /** * Constructs a new minute counter from the existing counter with the count incremented * @param counter Error count for that minute * @return A new minute counter from the existing counter with the count incremented */ public static MinuteCounter incrementCounter(final MinuteCounter counter) { return new MinuteCounter(counter.epochMinute, counter.errorCount + 1); } /** * Private constructor * @param epochMinute Unix epoch minute * @param errorCount Error count for that minute */ private MinuteCounter(final long epochMinute, final int errorCount) { this.epochMinute = epochMinute; this.errorCount = errorCount; } /** * @return the epochMinute */ public long getEpochMinute() { return epochMinute; } /** * @return the errorCount */ public int getErrorCount() { return errorCount; } } /** * Gets the base error (the last error in the causal chain) * @param error The error * @return The inner most error */
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // } // Path: src/main/java/com/stackify/api/common/error/ErrorCounter.java import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests; /* * ErrorCounter.java * Copyright 2014 Stackify */ package com.stackify.api.common.error; /** * ErrorCounter * @author Eric Martin */ public class ErrorCounter { /** * Map from * MD5(<type>-<typeCode>-<method>) * to * Unix epoch minute, error count for that minute */ private final Map<String, MinuteCounter> errorCounter = new HashMap<String, MinuteCounter>(); /** * Unix epoch minute and error count for that minute * * @author Eric Martin */ protected static class MinuteCounter { /** * Unix epoch minute */ private final long epochMinute; /** * Error count for that minute */ private final int errorCount; /** * Constructs a new minute counter for the specified minute * @param epochMinute Unix epoch minute * @return A new minute counter for the specified minute */ public static MinuteCounter newMinuteCounter(final long epochMinute) { return new MinuteCounter(epochMinute, 1); } /** * Constructs a new minute counter from the existing counter with the count incremented * @param counter Error count for that minute * @return A new minute counter from the existing counter with the count incremented */ public static MinuteCounter incrementCounter(final MinuteCounter counter) { return new MinuteCounter(counter.epochMinute, counter.errorCount + 1); } /** * Private constructor * @param epochMinute Unix epoch minute * @param errorCount Error count for that minute */ private MinuteCounter(final long epochMinute, final int errorCount) { this.epochMinute = epochMinute; this.errorCount = errorCount; } /** * @return the epochMinute */ public long getEpochMinute() { return epochMinute; } /** * @return the errorCount */ public int getErrorCount() { return errorCount; } } /** * Gets the base error (the last error in the causal chain) * @param error The error * @return The inner most error */
public static ErrorItem getBaseError(final StackifyError error) {
stackify/stackify-api-java
src/main/java/com/stackify/api/common/error/ErrorCounter.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // }
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests;
throw new NullPointerException("StackifyError is null"); } ErrorItem errorItem = error.getError(); if (errorItem != null) { while (errorItem.getInnerError() != null) { errorItem = errorItem.getInnerError(); } } return errorItem; } /** * Generates a unique key based on the error. The key will be an MD5 hash of the type, type code, and method. * @param errorItem The error item * @return The unique key for the error */ public static String getUniqueKey(final ErrorItem errorItem) { if (errorItem == null) { throw new NullPointerException("ErrorItem is null"); } String type = errorItem.getErrorType(); String typeCode = errorItem.getErrorTypeCode(); String method = errorItem.getSourceMethod(); String uniqueKey = String.format("%s-%s-%s", type, typeCode, method);
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // } // Path: src/main/java/com/stackify/api/common/error/ErrorCounter.java import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests; throw new NullPointerException("StackifyError is null"); } ErrorItem errorItem = error.getError(); if (errorItem != null) { while (errorItem.getInnerError() != null) { errorItem = errorItem.getInnerError(); } } return errorItem; } /** * Generates a unique key based on the error. The key will be an MD5 hash of the type, type code, and method. * @param errorItem The error item * @return The unique key for the error */ public static String getUniqueKey(final ErrorItem errorItem) { if (errorItem == null) { throw new NullPointerException("ErrorItem is null"); } String type = errorItem.getErrorType(); String typeCode = errorItem.getErrorTypeCode(); String method = errorItem.getSourceMethod(); String uniqueKey = String.format("%s-%s-%s", type, typeCode, method);
return MessageDigests.md5Hex(uniqueKey);
stackify/stackify-api-java
src/test/java/com/stackify/api/common/error/ErrorCounterTest.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // }
import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorCounter JUnit Test * * @author Eric Martin */ public class ErrorCounterTest { /** * testGetBaseErrorWithNull */ @Test(expected = NullPointerException.class) public void testGetBaseErrorWithNull() { ErrorCounter.getBaseError(null); } /** * testGetBaseError */ @Test public void testGetBaseError() {
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // } // Path: src/test/java/com/stackify/api/common/error/ErrorCounterTest.java import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorCounter JUnit Test * * @author Eric Martin */ public class ErrorCounterTest { /** * testGetBaseErrorWithNull */ @Test(expected = NullPointerException.class) public void testGetBaseErrorWithNull() { ErrorCounter.getBaseError(null); } /** * testGetBaseError */ @Test public void testGetBaseError() {
ErrorItem errorDetail = ErrorItem.newBuilder().build();
stackify/stackify-api-java
src/test/java/com/stackify/api/common/error/ErrorCounterTest.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // }
import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorCounter JUnit Test * * @author Eric Martin */ public class ErrorCounterTest { /** * testGetBaseErrorWithNull */ @Test(expected = NullPointerException.class) public void testGetBaseErrorWithNull() { ErrorCounter.getBaseError(null); } /** * testGetBaseError */ @Test public void testGetBaseError() { ErrorItem errorDetail = ErrorItem.newBuilder().build();
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // } // Path: src/test/java/com/stackify/api/common/error/ErrorCounterTest.java import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorCounter JUnit Test * * @author Eric Martin */ public class ErrorCounterTest { /** * testGetBaseErrorWithNull */ @Test(expected = NullPointerException.class) public void testGetBaseErrorWithNull() { ErrorCounter.getBaseError(null); } /** * testGetBaseError */ @Test public void testGetBaseError() { ErrorItem errorDetail = ErrorItem.newBuilder().build();
StackifyError.Builder builder = StackifyError.newBuilder();
stackify/stackify-api-java
src/test/java/com/stackify/api/common/error/ErrorCounterTest.java
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // }
import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests;
/* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorCounter JUnit Test * * @author Eric Martin */ public class ErrorCounterTest { /** * testGetBaseErrorWithNull */ @Test(expected = NullPointerException.class) public void testGetBaseErrorWithNull() { ErrorCounter.getBaseError(null); } /** * testGetBaseError */ @Test public void testGetBaseError() { ErrorItem errorDetail = ErrorItem.newBuilder().build(); StackifyError.Builder builder = StackifyError.newBuilder(); builder.error(errorDetail); StackifyError stackifyError = builder.build(); Assert.assertEquals(errorDetail, ErrorCounter.getBaseError(stackifyError)); } /** * testGetUniqueKeyWithNull */ @Test(expected = NullPointerException.class) public void testGetUniqueKeyWithNull() { ErrorCounter.getUniqueKey(null); } /** * testGetUniqueKey */ @Test public void testGetUniqueKey() { ErrorItem.Builder builder = ErrorItem.newBuilder(); builder.errorType("errorType"); builder.errorTypeCode("errorTypeCode"); builder.sourceMethod("sourceMethod");
// Path: src/main/java/com/stackify/api/ErrorItem.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class ErrorItem { // // /** // * The error message // */ // @Setter // @JsonProperty("Message") // private String message; // // /** // * The error's class name // */ // @JsonProperty("ErrorType") // private String errorType; // // /** // * The error type code // */ // @JsonProperty("ErrorTypeCode") // private String errorTypeCode; // // /** // * Custom data for the error // */ // @JsonProperty("Data") // private Map<String, String> data; // // /** // * The method name // */ // @JsonProperty("SourceMethod") // private String sourceMethod; // // /** // * The stack trace // */ // @JsonProperty("StackTrace") // private List<TraceFrame> stackTrace; // // /** // * The cause of this error // */ // @JsonProperty("InnerError") // private ErrorItem innerError; // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // // Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java // public class MessageDigests { // // /** // * Generates an MD5 hash hex string for the input string // * @param input The input string // * @return MD5 hash hex string // */ // public static String md5Hex(final String input) { // if (input == null) { // throw new NullPointerException("String is null"); // } // // MessageDigest digest = null; // // try { // digest = MessageDigest.getInstance("MD5"); // } catch (NoSuchAlgorithmException e) { // // this should never happen // throw new RuntimeException(e); // } // // byte[] hash = digest.digest(input.getBytes()); // // return DatatypeConverter.printHexBinary(hash); // } // // /** // * Hidden to prevent construction // */ // private MessageDigests() { // // do nothing // } // } // Path: src/test/java/com/stackify/api/common/error/ErrorCounterTest.java import org.junit.Assert; import org.junit.Test; import com.stackify.api.ErrorItem; import com.stackify.api.StackifyError; import com.stackify.api.common.codec.MessageDigests; /* * Copyright 2013 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.error; /** * ErrorCounter JUnit Test * * @author Eric Martin */ public class ErrorCounterTest { /** * testGetBaseErrorWithNull */ @Test(expected = NullPointerException.class) public void testGetBaseErrorWithNull() { ErrorCounter.getBaseError(null); } /** * testGetBaseError */ @Test public void testGetBaseError() { ErrorItem errorDetail = ErrorItem.newBuilder().build(); StackifyError.Builder builder = StackifyError.newBuilder(); builder.error(errorDetail); StackifyError stackifyError = builder.build(); Assert.assertEquals(errorDetail, ErrorCounter.getBaseError(stackifyError)); } /** * testGetUniqueKeyWithNull */ @Test(expected = NullPointerException.class) public void testGetUniqueKeyWithNull() { ErrorCounter.getUniqueKey(null); } /** * testGetUniqueKey */ @Test public void testGetUniqueKey() { ErrorItem.Builder builder = ErrorItem.newBuilder(); builder.errorType("errorType"); builder.errorTypeCode("errorTypeCode"); builder.sourceMethod("sourceMethod");
String expectedHash = MessageDigests.md5Hex("errorType-errorTypeCode-sourceMethod");
stackify/stackify-api-java
src/main/java/com/stackify/api/common/log/LogBackgroundServiceScheduler.java
// Path: src/main/java/com/stackify/api/common/http/HttpException.java // public class HttpException extends Exception { // // /** // * Serial version UID // */ // private static final long serialVersionUID = -6349485370575426368L; // // /** // * HTTP status code // */ // private final int statusCode; // // /** // * Constructor // * @param statusCode HTTP status code // */ // public HttpException(int statusCode) { // this.statusCode = statusCode; // } // // /** // * @return the statusCode // */ // public int getStatusCode() { // return statusCode; // } // // /** // * @return True if 4xx status code // */ // public boolean isClientError() { // return (HttpURLConnection.HTTP_BAD_REQUEST <= statusCode) && (statusCode < HttpURLConnection.HTTP_INTERNAL_ERROR); // } // }
import java.net.HttpURLConnection; import com.stackify.api.common.http.HttpException;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * LogBackgroundServiceScheduler * * @author Eric Martin */ public class LogBackgroundServiceScheduler { /** * One second (milliseconds) */ private static final long ONE_SECOND = 1000; /** * Five seconds (milliseconds) */ private static final long FIVE_SECONDS = 5000; /** * One minute (milliseconds) */ private static final long ONE_MINUTE = 60000; /** * Five minutes (milliseconds) */ private static final long FIVE_MINUTES = 300000; /** * Schedule delay (in milliseconds) */ private long scheduleDelay = ONE_SECOND; /** * UTC timestamp of the HTTP error */ private long lastHttpError = 0; /** * Sets the next scheduled delay based on the number of messages sent * @param numSent The number of log messages sent */ public void update(final int numSent) { // Reset the last HTTP error lastHttpError = 0; // adjust the schedule delay based on the number of messages sent in the last iteration if (100 <= numSent) { // messages are coming in quickly so decrease our delay // minimum delay is 1 second scheduleDelay = Math.max(Math.round(scheduleDelay / 2.0), ONE_SECOND); } else if (numSent < 10) { // messages are coming in rather slowly so increase our delay // maximum delay is 5 seconds scheduleDelay = Math.min(Math.round(1.25 * scheduleDelay), FIVE_SECONDS); } } /** * Sets the next scheduled delay based on the HTTP transmission status * @param t The exception */ public void update(final Throwable t) { // see if the exception indicates an authorization problem boolean isAuthorized = true;
// Path: src/main/java/com/stackify/api/common/http/HttpException.java // public class HttpException extends Exception { // // /** // * Serial version UID // */ // private static final long serialVersionUID = -6349485370575426368L; // // /** // * HTTP status code // */ // private final int statusCode; // // /** // * Constructor // * @param statusCode HTTP status code // */ // public HttpException(int statusCode) { // this.statusCode = statusCode; // } // // /** // * @return the statusCode // */ // public int getStatusCode() { // return statusCode; // } // // /** // * @return True if 4xx status code // */ // public boolean isClientError() { // return (HttpURLConnection.HTTP_BAD_REQUEST <= statusCode) && (statusCode < HttpURLConnection.HTTP_INTERNAL_ERROR); // } // } // Path: src/main/java/com/stackify/api/common/log/LogBackgroundServiceScheduler.java import java.net.HttpURLConnection; import com.stackify.api.common.http.HttpException; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * LogBackgroundServiceScheduler * * @author Eric Martin */ public class LogBackgroundServiceScheduler { /** * One second (milliseconds) */ private static final long ONE_SECOND = 1000; /** * Five seconds (milliseconds) */ private static final long FIVE_SECONDS = 5000; /** * One minute (milliseconds) */ private static final long ONE_MINUTE = 60000; /** * Five minutes (milliseconds) */ private static final long FIVE_MINUTES = 300000; /** * Schedule delay (in milliseconds) */ private long scheduleDelay = ONE_SECOND; /** * UTC timestamp of the HTTP error */ private long lastHttpError = 0; /** * Sets the next scheduled delay based on the number of messages sent * @param numSent The number of log messages sent */ public void update(final int numSent) { // Reset the last HTTP error lastHttpError = 0; // adjust the schedule delay based on the number of messages sent in the last iteration if (100 <= numSent) { // messages are coming in quickly so decrease our delay // minimum delay is 1 second scheduleDelay = Math.max(Math.round(scheduleDelay / 2.0), ONE_SECOND); } else if (numSent < 10) { // messages are coming in rather slowly so increase our delay // maximum delay is 5 seconds scheduleDelay = Math.min(Math.round(1.25 * scheduleDelay), FIVE_SECONDS); } } /** * Sets the next scheduled delay based on the HTTP transmission status * @param t The exception */ public void update(final Throwable t) { // see if the exception indicates an authorization problem boolean isAuthorized = true;
if (t instanceof HttpException) {
stackify/stackify-api-java
src/main/java/com/stackify/api/common/ApiConfiguration.java
// Path: src/main/java/com/stackify/api/EnvironmentDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class EnvironmentDetail { // // /** // * Device name // */ // @JsonProperty("DeviceName") // private String deviceName; // // /** // * Application name // */ // @JsonProperty("AppName") // private String appName; // // /** // * Application location // */ // @JsonProperty("AppLocation") // private String appLocation; // // /** // * Custom application name // */ // @JsonProperty("ConfiguredAppName") // private String configuredAppName; // // /** // * Custom application environment // */ // @JsonProperty("ConfiguredEnvironmentName") // private String configuredEnvironmentName; // // }
import com.stackify.api.EnvironmentDetail; import lombok.Builder; import lombok.Getter; import lombok.ToString;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common; /** * ApiConfiguration * * @author Eric Martin */ @ToString @Getter @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") public class ApiConfiguration { public static final String TRANSPORT_DIRECT = "direct"; public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; /** * Default API URL */ private static final String DEFAULT_API_URL = "https://api.stackify.com"; /** * API URL */ private final String apiUrl; /** * API Key */ private final String apiKey; /** * Application name */ private final String application; /** * Environment */ private final String environment; /** * Environment details */
// Path: src/main/java/com/stackify/api/EnvironmentDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class EnvironmentDetail { // // /** // * Device name // */ // @JsonProperty("DeviceName") // private String deviceName; // // /** // * Application name // */ // @JsonProperty("AppName") // private String appName; // // /** // * Application location // */ // @JsonProperty("AppLocation") // private String appLocation; // // /** // * Custom application name // */ // @JsonProperty("ConfiguredAppName") // private String configuredAppName; // // /** // * Custom application environment // */ // @JsonProperty("ConfiguredEnvironmentName") // private String configuredEnvironmentName; // // } // Path: src/main/java/com/stackify/api/common/ApiConfiguration.java import com.stackify.api.EnvironmentDetail; import lombok.Builder; import lombok.Getter; import lombok.ToString; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common; /** * ApiConfiguration * * @author Eric Martin */ @ToString @Getter @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder") public class ApiConfiguration { public static final String TRANSPORT_DIRECT = "direct"; public static final String TRANSPORT_AGENT_SOCKET = "agent_socket"; private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT; private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock"; /** * Default API URL */ private static final String DEFAULT_API_URL = "https://api.stackify.com"; /** * API URL */ private final String apiUrl; /** * API Key */ private final String apiKey; /** * Application name */ private final String application; /** * Environment */ private final String environment; /** * Environment details */
private final EnvironmentDetail envDetail;
stackify/stackify-api-java
src/main/java/com/stackify/api/common/log/EventAdapter.java
// Path: src/main/java/com/stackify/api/LogMsg.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class LogMsg { // // /** // * The log message // */ // @Setter // @JsonProperty("Msg") // private String msg; // // /** // * Extra contextual data from the log message // */ // @Setter // @JsonProperty("data") // private String data; // // /** // * The error/exception details // */ // @JsonProperty("Ex") // private StackifyError ex; // // /** // * The thread name // */ // @JsonProperty("Th") // private String th; // // /** // * Unix timestamp of the log message // */ // @JsonProperty("EpochMs") // private Long epochMs; // // /** // * Log level of the message // */ // @JsonProperty("Level") // private String level; // // /** // * Transaction id // */ // @JsonProperty("TransID") // private String transId; // // /** // * Source method name // */ // @JsonProperty("SrcMethod") // private String srcMethod; // // /** // * Source line number // */ // @JsonProperty("SrcLine") // private Integer srcLine; // // /** // * The log message id // */ // @lombok.Builder.Default // @JsonProperty("id") // private String id = UUID.randomUUID().toString(); // // /** // * List of Tags // */ // @JsonProperty("Tags") // private List<String> tags; // // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // }
import com.stackify.api.LogMsg; import com.stackify.api.StackifyError;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * EventAdapter * @author Eric Martin */ public interface EventAdapter<T> { /** * Gets the Throwable (optional) from the logging event * @param event The logging event * @return The Throwable (optional) */ Throwable getThrowable(final T event); /** * Builds a StackifyError from the logging event * @param event The logging event * @param exception The exception * @return The StackifyError */
// Path: src/main/java/com/stackify/api/LogMsg.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class LogMsg { // // /** // * The log message // */ // @Setter // @JsonProperty("Msg") // private String msg; // // /** // * Extra contextual data from the log message // */ // @Setter // @JsonProperty("data") // private String data; // // /** // * The error/exception details // */ // @JsonProperty("Ex") // private StackifyError ex; // // /** // * The thread name // */ // @JsonProperty("Th") // private String th; // // /** // * Unix timestamp of the log message // */ // @JsonProperty("EpochMs") // private Long epochMs; // // /** // * Log level of the message // */ // @JsonProperty("Level") // private String level; // // /** // * Transaction id // */ // @JsonProperty("TransID") // private String transId; // // /** // * Source method name // */ // @JsonProperty("SrcMethod") // private String srcMethod; // // /** // * Source line number // */ // @JsonProperty("SrcLine") // private Integer srcLine; // // /** // * The log message id // */ // @lombok.Builder.Default // @JsonProperty("id") // private String id = UUID.randomUUID().toString(); // // /** // * List of Tags // */ // @JsonProperty("Tags") // private List<String> tags; // // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // Path: src/main/java/com/stackify/api/common/log/EventAdapter.java import com.stackify.api.LogMsg; import com.stackify.api.StackifyError; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * EventAdapter * @author Eric Martin */ public interface EventAdapter<T> { /** * Gets the Throwable (optional) from the logging event * @param event The logging event * @return The Throwable (optional) */ Throwable getThrowable(final T event); /** * Builds a StackifyError from the logging event * @param event The logging event * @param exception The exception * @return The StackifyError */
StackifyError getStackifyError(final T event, final Throwable exception);
stackify/stackify-api-java
src/main/java/com/stackify/api/common/log/EventAdapter.java
// Path: src/main/java/com/stackify/api/LogMsg.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class LogMsg { // // /** // * The log message // */ // @Setter // @JsonProperty("Msg") // private String msg; // // /** // * Extra contextual data from the log message // */ // @Setter // @JsonProperty("data") // private String data; // // /** // * The error/exception details // */ // @JsonProperty("Ex") // private StackifyError ex; // // /** // * The thread name // */ // @JsonProperty("Th") // private String th; // // /** // * Unix timestamp of the log message // */ // @JsonProperty("EpochMs") // private Long epochMs; // // /** // * Log level of the message // */ // @JsonProperty("Level") // private String level; // // /** // * Transaction id // */ // @JsonProperty("TransID") // private String transId; // // /** // * Source method name // */ // @JsonProperty("SrcMethod") // private String srcMethod; // // /** // * Source line number // */ // @JsonProperty("SrcLine") // private Integer srcLine; // // /** // * The log message id // */ // @lombok.Builder.Default // @JsonProperty("id") // private String id = UUID.randomUUID().toString(); // // /** // * List of Tags // */ // @JsonProperty("Tags") // private List<String> tags; // // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // }
import com.stackify.api.LogMsg; import com.stackify.api.StackifyError;
/* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * EventAdapter * @author Eric Martin */ public interface EventAdapter<T> { /** * Gets the Throwable (optional) from the logging event * @param event The logging event * @return The Throwable (optional) */ Throwable getThrowable(final T event); /** * Builds a StackifyError from the logging event * @param event The logging event * @param exception The exception * @return The StackifyError */ StackifyError getStackifyError(final T event, final Throwable exception); /** * Builds a LogMsg from the logging event * @param event The logging event * @param error The exception (optional) * @return The LogMsg */
// Path: src/main/java/com/stackify/api/LogMsg.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class LogMsg { // // /** // * The log message // */ // @Setter // @JsonProperty("Msg") // private String msg; // // /** // * Extra contextual data from the log message // */ // @Setter // @JsonProperty("data") // private String data; // // /** // * The error/exception details // */ // @JsonProperty("Ex") // private StackifyError ex; // // /** // * The thread name // */ // @JsonProperty("Th") // private String th; // // /** // * Unix timestamp of the log message // */ // @JsonProperty("EpochMs") // private Long epochMs; // // /** // * Log level of the message // */ // @JsonProperty("Level") // private String level; // // /** // * Transaction id // */ // @JsonProperty("TransID") // private String transId; // // /** // * Source method name // */ // @JsonProperty("SrcMethod") // private String srcMethod; // // /** // * Source line number // */ // @JsonProperty("SrcLine") // private Integer srcLine; // // /** // * The log message id // */ // @lombok.Builder.Default // @JsonProperty("id") // private String id = UUID.randomUUID().toString(); // // /** // * List of Tags // */ // @JsonProperty("Tags") // private List<String> tags; // // // } // // Path: src/main/java/com/stackify/api/StackifyError.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class StackifyError { // // /** // * Environment // */ // @JsonProperty("EnvironmentDetail") // private EnvironmentDetail environmentDetail; // // /** // * Date/time of the error // */ // @JsonProperty("OccurredEpochMillis") // private Long occurredEpochMillis; // // /** // * Error details // */ // @JsonProperty("Error") // private ErrorItem error; // // /** // * Details of the web request // */ // @JsonProperty("WebRequestDetail") // private WebRequestDetail webRequestDetail; // // /** // * Server variables // */ // @JsonProperty("ServerVariables") // private Map<String, String> serverVariables; // // /** // * Customer name // */ // @JsonProperty("CustomerName") // private String customerName; // // /** // * User name // */ // @JsonProperty("UserName") // private String userName; // // } // Path: src/main/java/com/stackify/api/common/log/EventAdapter.java import com.stackify.api.LogMsg; import com.stackify.api.StackifyError; /* * Copyright 2014 Stackify * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.stackify.api.common.log; /** * EventAdapter * @author Eric Martin */ public interface EventAdapter<T> { /** * Gets the Throwable (optional) from the logging event * @param event The logging event * @return The Throwable (optional) */ Throwable getThrowable(final T event); /** * Builds a StackifyError from the logging event * @param event The logging event * @param exception The exception * @return The StackifyError */ StackifyError getStackifyError(final T event, final Throwable exception); /** * Builds a LogMsg from the logging event * @param event The logging event * @param error The exception (optional) * @return The LogMsg */
LogMsg getLogMsg(final T event, final StackifyError error);
stackify/stackify-api-java
src/main/java/com/stackify/api/common/log/APMLogData.java
// Path: src/main/java/com/stackify/api/WebRequestDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class WebRequestDetail { // // /** // * User IP address // */ // @JsonProperty("UserIPAddress") // private String userIpAddress; // // /** // * HTTP method // */ // @JsonProperty("HttpMethod") // private String httpMethod; // // /** // * Request protocol // */ // @JsonProperty("RequestProtocol") // private String requestProtocol; // // /** // * Request URL // */ // @JsonProperty("RequestUrl") // private String requestUrl; // // /** // * Request URL root // */ // @JsonProperty("RequestUrlRoot") // private String requestUrlRoot; // // /** // * Referral URL // */ // @JsonProperty("ReferralUrl") // private String referralUrl; // // /** // * Headers // */ // @JsonProperty("Headers") // private Map<String, String> headers; // // /** // * Cookies // */ // @JsonProperty("Cookies") // private Map<String, String> cookies; // // /** // * Query string parameters // */ // @JsonProperty("QueryString") // private Map<String, String> queryString; // // /** // * Form post data // */ // @JsonProperty("PostData") // private Map<String, String> postData; // // /** // * Session data // */ // @JsonProperty("SessionData") // private Map<String, String> sessionData; // // /** // * Raw post data // */ // @JsonProperty("PostDataRaw") // private String postDataRaw; // // /** // * MVC action // */ // @JsonProperty("MVCAction") // private String mvcAction; // // /** // * MVC controller // */ // @JsonProperty("MVCController") // private String mvcController; // // /** // * MVC area // */ // @JsonProperty("MVCArea") // private String mvcArea; // // }
import com.stackify.api.WebRequestDetail; import java.util.Map;
package com.stackify.api.common.log; /** * Provides means for APM to link and provide data elements from the current profiler trace. * * @author Darin Howard */ public class APMLogData { /** * Details if APM has established a link to this class. When false all methods return null. */ public static boolean isLinked() { return false; } public static String getTransactionId() { // empty implementation - value will be provided by apm return null; } public static String getUser() { // empty implementation - value will be provided by apm return null; }
// Path: src/main/java/com/stackify/api/WebRequestDetail.java // @AllArgsConstructor // @NoArgsConstructor // @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true) // @Data // @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonIgnoreProperties(ignoreUnknown = true) // public class WebRequestDetail { // // /** // * User IP address // */ // @JsonProperty("UserIPAddress") // private String userIpAddress; // // /** // * HTTP method // */ // @JsonProperty("HttpMethod") // private String httpMethod; // // /** // * Request protocol // */ // @JsonProperty("RequestProtocol") // private String requestProtocol; // // /** // * Request URL // */ // @JsonProperty("RequestUrl") // private String requestUrl; // // /** // * Request URL root // */ // @JsonProperty("RequestUrlRoot") // private String requestUrlRoot; // // /** // * Referral URL // */ // @JsonProperty("ReferralUrl") // private String referralUrl; // // /** // * Headers // */ // @JsonProperty("Headers") // private Map<String, String> headers; // // /** // * Cookies // */ // @JsonProperty("Cookies") // private Map<String, String> cookies; // // /** // * Query string parameters // */ // @JsonProperty("QueryString") // private Map<String, String> queryString; // // /** // * Form post data // */ // @JsonProperty("PostData") // private Map<String, String> postData; // // /** // * Session data // */ // @JsonProperty("SessionData") // private Map<String, String> sessionData; // // /** // * Raw post data // */ // @JsonProperty("PostDataRaw") // private String postDataRaw; // // /** // * MVC action // */ // @JsonProperty("MVCAction") // private String mvcAction; // // /** // * MVC controller // */ // @JsonProperty("MVCController") // private String mvcController; // // /** // * MVC area // */ // @JsonProperty("MVCArea") // private String mvcArea; // // } // Path: src/main/java/com/stackify/api/common/log/APMLogData.java import com.stackify.api.WebRequestDetail; import java.util.Map; package com.stackify.api.common.log; /** * Provides means for APM to link and provide data elements from the current profiler trace. * * @author Darin Howard */ public class APMLogData { /** * Details if APM has established a link to this class. When false all methods return null. */ public static boolean isLinked() { return false; } public static String getTransactionId() { // empty implementation - value will be provided by apm return null; } public static String getUser() { // empty implementation - value will be provided by apm return null; }
public static WebRequestDetail getWebRequest() {
taskrabbit/ReactNativeSampleApp
android/app/src/main/java/com/sample/EnvironmentManager.java
// Path: android/app/src/main/java/com/sample/utils/LocaleUtils.java // public class LocaleUtils { // // public static Locale getDefault() { // if (null == Locale.getDefault()) { return Locale.US; } // return Locale.getDefault(); // } // // public static String getServerLocale(Locale locale) { // if (null != locale) { // return locale.toString().replace("_", "-"); // } else { // return ""; // } // } // // public static String getDefaultLocaleForServer() { // Locale locale = getDefault(); // return getServerLocale(locale); // } // // // } // // Path: android/app/src/main/java/com/sample/utils/LocaleUtils.java // public class LocaleUtils { // // public static Locale getDefault() { // if (null == Locale.getDefault()) { return Locale.US; } // return Locale.getDefault(); // } // // public static String getServerLocale(Locale locale) { // if (null != locale) { // return locale.toString().replace("_", "-"); // } else { // return ""; // } // } // // public static String getDefaultLocaleForServer() { // Locale locale = getDefault(); // return getServerLocale(locale); // } // // // }
import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.provider.Settings; import com.facebook.react.bridge.*; import com.sample.utils.LocaleUtils; import com.sample.utils.LocaleUtils; import javax.annotation.Nullable; import java.util.UUID;
private Context mApplication; private Activity mActivity; public EnvironmentManager(ReactApplicationContext reactContext) { super(reactContext); mApplication = getReactApplicationContext().getApplicationContext(); } @Override public String getName() { return "EnvironmentManager"; } @ReactMethod public void get(Callback callback) { WritableMap environment = Arguments.createMap(); PackageInfo packageInfo = null; try { packageInfo = mApplication.getPackageManager().getPackageInfo(mApplication.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } environment.putString("name", "debug"); //environment.putString("name", BuildConfig.ENVIRONMENT); environment.putBoolean("simulator", Build.FINGERPRINT.startsWith("generic")); environment.putString("buildCode", String.valueOf(packageInfo.versionCode)); environment.putString("version", String.valueOf(packageInfo.versionName)); environment.putString("uuid", getUuid());
// Path: android/app/src/main/java/com/sample/utils/LocaleUtils.java // public class LocaleUtils { // // public static Locale getDefault() { // if (null == Locale.getDefault()) { return Locale.US; } // return Locale.getDefault(); // } // // public static String getServerLocale(Locale locale) { // if (null != locale) { // return locale.toString().replace("_", "-"); // } else { // return ""; // } // } // // public static String getDefaultLocaleForServer() { // Locale locale = getDefault(); // return getServerLocale(locale); // } // // // } // // Path: android/app/src/main/java/com/sample/utils/LocaleUtils.java // public class LocaleUtils { // // public static Locale getDefault() { // if (null == Locale.getDefault()) { return Locale.US; } // return Locale.getDefault(); // } // // public static String getServerLocale(Locale locale) { // if (null != locale) { // return locale.toString().replace("_", "-"); // } else { // return ""; // } // } // // public static String getDefaultLocaleForServer() { // Locale locale = getDefault(); // return getServerLocale(locale); // } // // // } // Path: android/app/src/main/java/com/sample/EnvironmentManager.java import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.provider.Settings; import com.facebook.react.bridge.*; import com.sample.utils.LocaleUtils; import com.sample.utils.LocaleUtils; import javax.annotation.Nullable; import java.util.UUID; private Context mApplication; private Activity mActivity; public EnvironmentManager(ReactApplicationContext reactContext) { super(reactContext); mApplication = getReactApplicationContext().getApplicationContext(); } @Override public String getName() { return "EnvironmentManager"; } @ReactMethod public void get(Callback callback) { WritableMap environment = Arguments.createMap(); PackageInfo packageInfo = null; try { packageInfo = mApplication.getPackageManager().getPackageInfo(mApplication.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } environment.putString("name", "debug"); //environment.putString("name", BuildConfig.ENVIRONMENT); environment.putBoolean("simulator", Build.FINGERPRINT.startsWith("generic")); environment.putString("buildCode", String.valueOf(packageInfo.versionCode)); environment.putString("version", String.valueOf(packageInfo.versionName)); environment.putString("uuid", getUuid());
environment.putString("locale", LocaleUtils.getDefaultLocaleForServer());
NLeSC/ahn-pointcloud-viewer-ws
src/main/java/nl/esciencecenter/ahn/pointcloud/db/PointCloudStore.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Size.java // public class Size { // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection", example = "10193813") // private long rawPoints = 0; // // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection which will be returned", example = "9234324") // private long returnedPoints = 0; // // @NotNull // @Range(min=0, max=24) // @ApiModelProperty(value=" Level in octree pyramid to fetch points from. Lower number means less points", example="8") // private int level; // // private Size() { // } // // public Size(long rawPoints, long returnedPoints, int level) { // this.rawPoints = rawPoints; // this.returnedPoints = returnedPoints; // this.level = level; // } // // /** // * @return Number of points of selection based on 100% of the available points. // */ // public long getRawPoints() { // return rawPoints; // } // // /** // * @return Number of points which can be returned when maximum of points is taken into account. // */ // public long getReturnedPoints() { // return returnedPoints; // } // // /** // * @return Level in octree at which the returned points will be taken from. // */ // public int getLevel() { // return level; // } // // /** // * @return Ratio of returned points vs all points // */ // @JsonProperty("coverage") // @ApiModelProperty(value="Ratio of points returned with given level", example="0.9058") // public float getCoverage() { // if (rawPoints == 0) { // return 1; // } // return (float) returnedPoints / (float) rawPoints; // } // // @JsonProperty("coverage") // public void setCoverage(float coverage) { // // dummy setter, as it is a computed property // } // // @Override // public boolean equals(Object o) { // if (this == o) { return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Size size = (Size) o; // return Objects.equals(rawPoints, size.rawPoints) && // Objects.equals(returnedPoints, size.returnedPoints) && // Objects.equals(level, size.level); // } // // @Override // public int hashCode() { // return Objects.hash(rawPoints, returnedPoints, level); // } // // // @Override // public String toString() { // return "Size{" + // "rawPoints=" + rawPoints + // ", returnedPoints=" + returnedPoints + // ", level=" + level + // '}'; // } // }
import nl.esciencecenter.ahn.pointcloud.core.Selection; import nl.esciencecenter.ahn.pointcloud.core.Size; import org.skife.jdbi.v2.DBI;
package nl.esciencecenter.ahn.pointcloud.db; public class PointCloudStore { private final DBI dbi; private final long pointsLimit; private final int srid; public PointCloudStore(DBI dbi, int srid, long pointsLimit) { this.dbi = dbi; this.srid = srid; this.pointsLimit = pointsLimit; } /** * Retrieve approximate number of points within selection. * * @param selection Selection in a pointcloud * @return number of points */
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Size.java // public class Size { // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection", example = "10193813") // private long rawPoints = 0; // // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection which will be returned", example = "9234324") // private long returnedPoints = 0; // // @NotNull // @Range(min=0, max=24) // @ApiModelProperty(value=" Level in octree pyramid to fetch points from. Lower number means less points", example="8") // private int level; // // private Size() { // } // // public Size(long rawPoints, long returnedPoints, int level) { // this.rawPoints = rawPoints; // this.returnedPoints = returnedPoints; // this.level = level; // } // // /** // * @return Number of points of selection based on 100% of the available points. // */ // public long getRawPoints() { // return rawPoints; // } // // /** // * @return Number of points which can be returned when maximum of points is taken into account. // */ // public long getReturnedPoints() { // return returnedPoints; // } // // /** // * @return Level in octree at which the returned points will be taken from. // */ // public int getLevel() { // return level; // } // // /** // * @return Ratio of returned points vs all points // */ // @JsonProperty("coverage") // @ApiModelProperty(value="Ratio of points returned with given level", example="0.9058") // public float getCoverage() { // if (rawPoints == 0) { // return 1; // } // return (float) returnedPoints / (float) rawPoints; // } // // @JsonProperty("coverage") // public void setCoverage(float coverage) { // // dummy setter, as it is a computed property // } // // @Override // public boolean equals(Object o) { // if (this == o) { return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Size size = (Size) o; // return Objects.equals(rawPoints, size.rawPoints) && // Objects.equals(returnedPoints, size.returnedPoints) && // Objects.equals(level, size.level); // } // // @Override // public int hashCode() { // return Objects.hash(rawPoints, returnedPoints, level); // } // // // @Override // public String toString() { // return "Size{" + // "rawPoints=" + rawPoints + // ", returnedPoints=" + returnedPoints + // ", level=" + level + // '}'; // } // } // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/db/PointCloudStore.java import nl.esciencecenter.ahn.pointcloud.core.Selection; import nl.esciencecenter.ahn.pointcloud.core.Size; import org.skife.jdbi.v2.DBI; package nl.esciencecenter.ahn.pointcloud.db; public class PointCloudStore { private final DBI dbi; private final long pointsLimit; private final int srid; public PointCloudStore(DBI dbi, int srid, long pointsLimit) { this.dbi = dbi; this.srid = srid; this.pointsLimit = pointsLimit; } /** * Retrieve approximate number of points within selection. * * @param selection Selection in a pointcloud * @return number of points */
public Size getApproximateNumberOfPoints(Selection selection) {
NLeSC/ahn-pointcloud-viewer-ws
src/main/java/nl/esciencecenter/ahn/pointcloud/db/PointCloudStore.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Size.java // public class Size { // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection", example = "10193813") // private long rawPoints = 0; // // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection which will be returned", example = "9234324") // private long returnedPoints = 0; // // @NotNull // @Range(min=0, max=24) // @ApiModelProperty(value=" Level in octree pyramid to fetch points from. Lower number means less points", example="8") // private int level; // // private Size() { // } // // public Size(long rawPoints, long returnedPoints, int level) { // this.rawPoints = rawPoints; // this.returnedPoints = returnedPoints; // this.level = level; // } // // /** // * @return Number of points of selection based on 100% of the available points. // */ // public long getRawPoints() { // return rawPoints; // } // // /** // * @return Number of points which can be returned when maximum of points is taken into account. // */ // public long getReturnedPoints() { // return returnedPoints; // } // // /** // * @return Level in octree at which the returned points will be taken from. // */ // public int getLevel() { // return level; // } // // /** // * @return Ratio of returned points vs all points // */ // @JsonProperty("coverage") // @ApiModelProperty(value="Ratio of points returned with given level", example="0.9058") // public float getCoverage() { // if (rawPoints == 0) { // return 1; // } // return (float) returnedPoints / (float) rawPoints; // } // // @JsonProperty("coverage") // public void setCoverage(float coverage) { // // dummy setter, as it is a computed property // } // // @Override // public boolean equals(Object o) { // if (this == o) { return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Size size = (Size) o; // return Objects.equals(rawPoints, size.rawPoints) && // Objects.equals(returnedPoints, size.returnedPoints) && // Objects.equals(level, size.level); // } // // @Override // public int hashCode() { // return Objects.hash(rawPoints, returnedPoints, level); // } // // // @Override // public String toString() { // return "Size{" + // "rawPoints=" + rawPoints + // ", returnedPoints=" + returnedPoints + // ", level=" + level + // '}'; // } // }
import nl.esciencecenter.ahn.pointcloud.core.Selection; import nl.esciencecenter.ahn.pointcloud.core.Size; import org.skife.jdbi.v2.DBI;
package nl.esciencecenter.ahn.pointcloud.db; public class PointCloudStore { private final DBI dbi; private final long pointsLimit; private final int srid; public PointCloudStore(DBI dbi, int srid, long pointsLimit) { this.dbi = dbi; this.srid = srid; this.pointsLimit = pointsLimit; } /** * Retrieve approximate number of points within selection. * * @param selection Selection in a pointcloud * @return number of points */
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Size.java // public class Size { // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection", example = "10193813") // private long rawPoints = 0; // // @NotNull // @Range(min=0) // @ApiModelProperty(value="Approximate number of points in selection which will be returned", example = "9234324") // private long returnedPoints = 0; // // @NotNull // @Range(min=0, max=24) // @ApiModelProperty(value=" Level in octree pyramid to fetch points from. Lower number means less points", example="8") // private int level; // // private Size() { // } // // public Size(long rawPoints, long returnedPoints, int level) { // this.rawPoints = rawPoints; // this.returnedPoints = returnedPoints; // this.level = level; // } // // /** // * @return Number of points of selection based on 100% of the available points. // */ // public long getRawPoints() { // return rawPoints; // } // // /** // * @return Number of points which can be returned when maximum of points is taken into account. // */ // public long getReturnedPoints() { // return returnedPoints; // } // // /** // * @return Level in octree at which the returned points will be taken from. // */ // public int getLevel() { // return level; // } // // /** // * @return Ratio of returned points vs all points // */ // @JsonProperty("coverage") // @ApiModelProperty(value="Ratio of points returned with given level", example="0.9058") // public float getCoverage() { // if (rawPoints == 0) { // return 1; // } // return (float) returnedPoints / (float) rawPoints; // } // // @JsonProperty("coverage") // public void setCoverage(float coverage) { // // dummy setter, as it is a computed property // } // // @Override // public boolean equals(Object o) { // if (this == o) { return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Size size = (Size) o; // return Objects.equals(rawPoints, size.rawPoints) && // Objects.equals(returnedPoints, size.returnedPoints) && // Objects.equals(level, size.level); // } // // @Override // public int hashCode() { // return Objects.hash(rawPoints, returnedPoints, level); // } // // // @Override // public String toString() { // return "Size{" + // "rawPoints=" + rawPoints + // ", returnedPoints=" + returnedPoints + // ", level=" + level + // '}'; // } // } // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/db/PointCloudStore.java import nl.esciencecenter.ahn.pointcloud.core.Selection; import nl.esciencecenter.ahn.pointcloud.core.Size; import org.skife.jdbi.v2.DBI; package nl.esciencecenter.ahn.pointcloud.db; public class PointCloudStore { private final DBI dbi; private final long pointsLimit; private final int srid; public PointCloudStore(DBI dbi, int srid, long pointsLimit) { this.dbi = dbi; this.srid = srid; this.pointsLimit = pointsLimit; } /** * Retrieve approximate number of points within selection. * * @param selection Selection in a pointcloud * @return number of points */
public Size getApproximateNumberOfPoints(Selection selection) {
NLeSC/ahn-pointcloud-viewer-ws
src/main/java/nl/esciencecenter/ahn/pointcloud/core/LazRequest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/ScriptConfiguration.java // public class ScriptConfiguration extends Configuration { // @Valid // @NotNull // @JsonProperty // private int srid; // // @NotEmpty // @JsonProperty // private String executable; // // @NotEmpty // @JsonProperty // private String dataset; // // @NotEmpty // @JsonProperty // private String basePath; // // @NotEmpty // @JsonProperty // private String baseUrl; // // public ScriptConfiguration() { // } // // public ScriptConfiguration(int srid, String executable, String dataset, String basePath, String baseUrl) { // this.srid = srid; // this.executable = executable; // this.dataset = dataset; // this.basePath = basePath; // this.baseUrl = baseUrl; // } // // public int getSrid() { // return srid; // } // // public String getExecutable() { // return executable; // } // // public String getDataset() { // return dataset; // } // // public String getBasePath() { // return basePath; // } // // public String getBaseUrl() { // return baseUrl; // } // }
import javax.validation.constraints.NotNull; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Joiner; import io.swagger.annotations.ApiModelProperty; import nl.esciencecenter.ahn.pointcloud.ScriptConfiguration; import nl.esciencecenter.xenon.jobs.JobDescription; import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotBlank;
package nl.esciencecenter.ahn.pointcloud.core; public class LazRequest extends Selection { @NotNull @NotBlank @Email @JsonProperty @ApiModelProperty(value="E-mail to send laz file url to", example = "[email protected]") private String email; private LazRequest() { } public LazRequest(Double left, Double bottom, Double right, Double top, String email) { super(left, bottom, right, top); this.email = email; } public String getEmail() { return email; }
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/ScriptConfiguration.java // public class ScriptConfiguration extends Configuration { // @Valid // @NotNull // @JsonProperty // private int srid; // // @NotEmpty // @JsonProperty // private String executable; // // @NotEmpty // @JsonProperty // private String dataset; // // @NotEmpty // @JsonProperty // private String basePath; // // @NotEmpty // @JsonProperty // private String baseUrl; // // public ScriptConfiguration() { // } // // public ScriptConfiguration(int srid, String executable, String dataset, String basePath, String baseUrl) { // this.srid = srid; // this.executable = executable; // this.dataset = dataset; // this.basePath = basePath; // this.baseUrl = baseUrl; // } // // public int getSrid() { // return srid; // } // // public String getExecutable() { // return executable; // } // // public String getDataset() { // return dataset; // } // // public String getBasePath() { // return basePath; // } // // public String getBaseUrl() { // return baseUrl; // } // } // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/LazRequest.java import javax.validation.constraints.NotNull; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Joiner; import io.swagger.annotations.ApiModelProperty; import nl.esciencecenter.ahn.pointcloud.ScriptConfiguration; import nl.esciencecenter.xenon.jobs.JobDescription; import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotBlank; package nl.esciencecenter.ahn.pointcloud.core; public class LazRequest extends Selection { @NotNull @NotBlank @Email @JsonProperty @ApiModelProperty(value="E-mail to send laz file url to", example = "[email protected]") private String email; private LazRequest() { } public LazRequest(Double left, Double bottom, Double right, Double top, String email) { super(left, bottom, right, top); this.email = email; } public String getEmail() { return email; }
public JobDescription toJobDescription(int level, ScriptConfiguration scriptConfig) {
NLeSC/ahn-pointcloud-viewer-ws
src/test/java/nl/esciencecenter/ahn/pointcloud/validation/ValidSelectionValidatorTest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // }
import nl.esciencecenter.ahn.pointcloud.core.Selection; import org.junit.BeforeClass; import org.junit.Test; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import java.util.Set; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.hamcrest.CoreMatchers.equalTo;
package nl.esciencecenter.ahn.pointcloud.validation; public class ValidSelectionValidatorTest { private static Validator validator; @BeforeClass public static void setUp() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); validator = factory.getValidator(); } @Test public void testIsValid_valid() throws Exception {
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // } // Path: src/test/java/nl/esciencecenter/ahn/pointcloud/validation/ValidSelectionValidatorTest.java import nl.esciencecenter.ahn.pointcloud.core.Selection; import org.junit.BeforeClass; import org.junit.Test; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import java.util.Set; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.hamcrest.CoreMatchers.equalTo; package nl.esciencecenter.ahn.pointcloud.validation; public class ValidSelectionValidatorTest { private static Validator validator; @BeforeClass public static void setUp() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); validator = factory.getValidator(); } @Test public void testIsValid_valid() throws Exception {
Selection selection = new Selection(1.0, 2.0, 3.0, 4.0);
NLeSC/ahn-pointcloud-viewer-ws
src/main/java/nl/esciencecenter/ahn/pointcloud/db/PotreeExtentsDOA.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // }
import nl.esciencecenter.ahn.pointcloud.core.Selection; import org.skife.jdbi.v2.sqlobject.Bind; import org.skife.jdbi.v2.sqlobject.BindBean; import org.skife.jdbi.v2.sqlobject.SqlQuery;
package nl.esciencecenter.ahn.pointcloud.db; public interface PotreeExtentsDOA { @SqlQuery("SELECT " + " FLOOR(SUM(numberpoints * (ST_Area(ST_Intersection(geom, qgeom)) /ST_Area(geom)))) AS numpoints " + "FROM " + " extent_potree, " + " (SELECT ST_SetSRID(ST_MakeBox2D(ST_Point(:b.left, :b.bottom),ST_Point(:b.right, :b.top)), :srid) AS qgeom) AS B " + "WHERE level = :level " + "AND geom && qgeom " + "AND ST_Area(geom) != 0") long getNumberOfPoints(@Bind("level") int level,
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // } // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/db/PotreeExtentsDOA.java import nl.esciencecenter.ahn.pointcloud.core.Selection; import org.skife.jdbi.v2.sqlobject.Bind; import org.skife.jdbi.v2.sqlobject.BindBean; import org.skife.jdbi.v2.sqlobject.SqlQuery; package nl.esciencecenter.ahn.pointcloud.db; public interface PotreeExtentsDOA { @SqlQuery("SELECT " + " FLOOR(SUM(numberpoints * (ST_Area(ST_Intersection(geom, qgeom)) /ST_Area(geom)))) AS numpoints " + "FROM " + " extent_potree, " + " (SELECT ST_SetSRID(ST_MakeBox2D(ST_Point(:b.left, :b.bottom),ST_Point(:b.right, :b.top)), :srid) AS qgeom) AS B " + "WHERE level = :level " + "AND geom && qgeom " + "AND ST_Area(geom) != 0") long getNumberOfPoints(@Bind("level") int level,
@BindBean("b") Selection bbox,
NLeSC/ahn-pointcloud-viewer-ws
src/test/java/nl/esciencecenter/ahn/pointcloud/core/LazRequestTest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/ScriptConfiguration.java // public class ScriptConfiguration extends Configuration { // @Valid // @NotNull // @JsonProperty // private int srid; // // @NotEmpty // @JsonProperty // private String executable; // // @NotEmpty // @JsonProperty // private String dataset; // // @NotEmpty // @JsonProperty // private String basePath; // // @NotEmpty // @JsonProperty // private String baseUrl; // // public ScriptConfiguration() { // } // // public ScriptConfiguration(int srid, String executable, String dataset, String basePath, String baseUrl) { // this.srid = srid; // this.executable = executable; // this.dataset = dataset; // this.basePath = basePath; // this.baseUrl = baseUrl; // } // // public int getSrid() { // return srid; // } // // public String getExecutable() { // return executable; // } // // public String getDataset() { // return dataset; // } // // public String getBasePath() { // return basePath; // } // // public String getBaseUrl() { // return baseUrl; // } // }
import com.fasterxml.jackson.databind.ObjectMapper; import io.dropwizard.jackson.Jackson; import nl.esciencecenter.ahn.pointcloud.ScriptConfiguration; import nl.esciencecenter.xenon.jobs.JobDescription; import org.junit.BeforeClass; import org.junit.Test; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import java.util.Set; import static io.dropwizard.testing.FixtureHelpers.fixture; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package nl.esciencecenter.ahn.pointcloud.core; public class LazRequestTest { private static final ObjectMapper MAPPER = Jackson.newObjectMapper(); private static Validator validator; @BeforeClass public static void setUp() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); validator = factory.getValidator(); } @Test public void testGetEmail() throws Exception { LazRequest request = new LazRequest(1.0, 2.0, 3.0, 4.0, "[email protected]"); assertThat(request.getEmail(), is("[email protected]")); } @Test public void testToJobDescription() throws Exception { LazRequest request = new LazRequest(1.0, 2.0, 3.0, 4.0, "[email protected]");
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/ScriptConfiguration.java // public class ScriptConfiguration extends Configuration { // @Valid // @NotNull // @JsonProperty // private int srid; // // @NotEmpty // @JsonProperty // private String executable; // // @NotEmpty // @JsonProperty // private String dataset; // // @NotEmpty // @JsonProperty // private String basePath; // // @NotEmpty // @JsonProperty // private String baseUrl; // // public ScriptConfiguration() { // } // // public ScriptConfiguration(int srid, String executable, String dataset, String basePath, String baseUrl) { // this.srid = srid; // this.executable = executable; // this.dataset = dataset; // this.basePath = basePath; // this.baseUrl = baseUrl; // } // // public int getSrid() { // return srid; // } // // public String getExecutable() { // return executable; // } // // public String getDataset() { // return dataset; // } // // public String getBasePath() { // return basePath; // } // // public String getBaseUrl() { // return baseUrl; // } // } // Path: src/test/java/nl/esciencecenter/ahn/pointcloud/core/LazRequestTest.java import com.fasterxml.jackson.databind.ObjectMapper; import io.dropwizard.jackson.Jackson; import nl.esciencecenter.ahn.pointcloud.ScriptConfiguration; import nl.esciencecenter.xenon.jobs.JobDescription; import org.junit.BeforeClass; import org.junit.Test; import javax.validation.ConstraintViolation; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import java.util.Set; import static io.dropwizard.testing.FixtureHelpers.fixture; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package nl.esciencecenter.ahn.pointcloud.core; public class LazRequestTest { private static final ObjectMapper MAPPER = Jackson.newObjectMapper(); private static Validator validator; @BeforeClass public static void setUp() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); validator = factory.getValidator(); } @Test public void testGetEmail() throws Exception { LazRequest request = new LazRequest(1.0, 2.0, 3.0, 4.0, "[email protected]"); assertThat(request.getEmail(), is("[email protected]")); } @Test public void testToJobDescription() throws Exception { LazRequest request = new LazRequest(1.0, 2.0, 3.0, 4.0, "[email protected]");
ScriptConfiguration scriptConfig = new ScriptConfiguration(28992, "/bin/echo", "ahn2", "/data/jobs", "http://localhost/jobs");
NLeSC/ahn-pointcloud-viewer-ws
src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerConfigurationTest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // }
import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import org.junit.Before; import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.esciencecenter.ahn.pointcloud; public class ViewerConfigurationTest { private ViewerConfiguration config;
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // Path: src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerConfigurationTest.java import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import org.junit.Before; import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.esciencecenter.ahn.pointcloud; public class ViewerConfigurationTest { private ViewerConfiguration config;
private XenonConfiguration xenon;
NLeSC/ahn-pointcloud-viewer-ws
src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerConfigurationTest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // }
import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import org.junit.Before; import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.esciencecenter.ahn.pointcloud; public class ViewerConfigurationTest { private ViewerConfiguration config; private XenonConfiguration xenon; private DataSourceFactory database; private ScriptConfiguration scriptConfig; @Before public void setUp() { ImmutableMap<String, String> props = ImmutableMap.of("somepropkey", "somepropvalue");
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // Path: src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerConfigurationTest.java import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import org.junit.Before; import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.esciencecenter.ahn.pointcloud; public class ViewerConfigurationTest { private ViewerConfiguration config; private XenonConfiguration xenon; private DataSourceFactory database; private ScriptConfiguration scriptConfig; @Before public void setUp() { ImmutableMap<String, String> props = ImmutableMap.of("somepropkey", "somepropvalue");
SchedulerConfiguration scheduler = new SchedulerConfiguration("ssh", "someone@somewhere:2222", "multi", props);
NLeSC/ahn-pointcloud-viewer-ws
src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerApplicationTest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/resources/AbstractResource.java // public class AbstractResource { // private final PointCloudStore store; // // public AbstractResource(PointCloudStore store) { // this.store = store; // } // // public PointCloudStore getStore() { // return store; // } // }
import com.codahale.metrics.health.HealthCheckRegistry; import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.jersey.setup.JerseyEnvironment; import io.dropwizard.lifecycle.setup.LifecycleEnvironment; import io.dropwizard.setup.Environment; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import nl.esciencecenter.ahn.pointcloud.resources.AbstractResource; import org.junit.Before; import org.junit.Test; import java.net.MalformedURLException; import java.net.URL; import static org.mockito.Mockito.*;
package nl.esciencecenter.ahn.pointcloud; public class ViewerApplicationTest { private Environment env; private ViewerApplication app; private ViewerConfiguration config; @Before public void setUp() throws MalformedURLException { config = getViewerConfiguration(); env = getEnvironment(); app = new ViewerApplication(); } private Environment getEnvironment() { Environment environment = mock(Environment.class); JerseyEnvironment jersey = mock(JerseyEnvironment.class); when(environment.jersey()).thenReturn(jersey); LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class); when(environment.lifecycle()).thenReturn(lifecycle); HealthCheckRegistry healthchecks = mock(HealthCheckRegistry.class); when(environment.healthChecks()).thenReturn(healthchecks); return environment; } private ViewerConfiguration getViewerConfiguration() throws MalformedURLException { ImmutableMap<String, String> props = ImmutableMap.of();
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/resources/AbstractResource.java // public class AbstractResource { // private final PointCloudStore store; // // public AbstractResource(PointCloudStore store) { // this.store = store; // } // // public PointCloudStore getStore() { // return store; // } // } // Path: src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerApplicationTest.java import com.codahale.metrics.health.HealthCheckRegistry; import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.jersey.setup.JerseyEnvironment; import io.dropwizard.lifecycle.setup.LifecycleEnvironment; import io.dropwizard.setup.Environment; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import nl.esciencecenter.ahn.pointcloud.resources.AbstractResource; import org.junit.Before; import org.junit.Test; import java.net.MalformedURLException; import java.net.URL; import static org.mockito.Mockito.*; package nl.esciencecenter.ahn.pointcloud; public class ViewerApplicationTest { private Environment env; private ViewerApplication app; private ViewerConfiguration config; @Before public void setUp() throws MalformedURLException { config = getViewerConfiguration(); env = getEnvironment(); app = new ViewerApplication(); } private Environment getEnvironment() { Environment environment = mock(Environment.class); JerseyEnvironment jersey = mock(JerseyEnvironment.class); when(environment.jersey()).thenReturn(jersey); LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class); when(environment.lifecycle()).thenReturn(lifecycle); HealthCheckRegistry healthchecks = mock(HealthCheckRegistry.class); when(environment.healthChecks()).thenReturn(healthchecks); return environment; } private ViewerConfiguration getViewerConfiguration() throws MalformedURLException { ImmutableMap<String, String> props = ImmutableMap.of();
SchedulerConfiguration scheduler = new SchedulerConfiguration("local", "/", "multi", props);
NLeSC/ahn-pointcloud-viewer-ws
src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerApplicationTest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/resources/AbstractResource.java // public class AbstractResource { // private final PointCloudStore store; // // public AbstractResource(PointCloudStore store) { // this.store = store; // } // // public PointCloudStore getStore() { // return store; // } // }
import com.codahale.metrics.health.HealthCheckRegistry; import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.jersey.setup.JerseyEnvironment; import io.dropwizard.lifecycle.setup.LifecycleEnvironment; import io.dropwizard.setup.Environment; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import nl.esciencecenter.ahn.pointcloud.resources.AbstractResource; import org.junit.Before; import org.junit.Test; import java.net.MalformedURLException; import java.net.URL; import static org.mockito.Mockito.*;
package nl.esciencecenter.ahn.pointcloud; public class ViewerApplicationTest { private Environment env; private ViewerApplication app; private ViewerConfiguration config; @Before public void setUp() throws MalformedURLException { config = getViewerConfiguration(); env = getEnvironment(); app = new ViewerApplication(); } private Environment getEnvironment() { Environment environment = mock(Environment.class); JerseyEnvironment jersey = mock(JerseyEnvironment.class); when(environment.jersey()).thenReturn(jersey); LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class); when(environment.lifecycle()).thenReturn(lifecycle); HealthCheckRegistry healthchecks = mock(HealthCheckRegistry.class); when(environment.healthChecks()).thenReturn(healthchecks); return environment; } private ViewerConfiguration getViewerConfiguration() throws MalformedURLException { ImmutableMap<String, String> props = ImmutableMap.of(); SchedulerConfiguration scheduler = new SchedulerConfiguration("local", "/", "multi", props);
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/resources/AbstractResource.java // public class AbstractResource { // private final PointCloudStore store; // // public AbstractResource(PointCloudStore store) { // this.store = store; // } // // public PointCloudStore getStore() { // return store; // } // } // Path: src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerApplicationTest.java import com.codahale.metrics.health.HealthCheckRegistry; import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.jersey.setup.JerseyEnvironment; import io.dropwizard.lifecycle.setup.LifecycleEnvironment; import io.dropwizard.setup.Environment; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import nl.esciencecenter.ahn.pointcloud.resources.AbstractResource; import org.junit.Before; import org.junit.Test; import java.net.MalformedURLException; import java.net.URL; import static org.mockito.Mockito.*; package nl.esciencecenter.ahn.pointcloud; public class ViewerApplicationTest { private Environment env; private ViewerApplication app; private ViewerConfiguration config; @Before public void setUp() throws MalformedURLException { config = getViewerConfiguration(); env = getEnvironment(); app = new ViewerApplication(); } private Environment getEnvironment() { Environment environment = mock(Environment.class); JerseyEnvironment jersey = mock(JerseyEnvironment.class); when(environment.jersey()).thenReturn(jersey); LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class); when(environment.lifecycle()).thenReturn(lifecycle); HealthCheckRegistry healthchecks = mock(HealthCheckRegistry.class); when(environment.healthChecks()).thenReturn(healthchecks); return environment; } private ViewerConfiguration getViewerConfiguration() throws MalformedURLException { ImmutableMap<String, String> props = ImmutableMap.of(); SchedulerConfiguration scheduler = new SchedulerConfiguration("local", "/", "multi", props);
XenonConfiguration xenon = new XenonConfiguration(scheduler, props);
NLeSC/ahn-pointcloud-viewer-ws
src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerApplicationTest.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/resources/AbstractResource.java // public class AbstractResource { // private final PointCloudStore store; // // public AbstractResource(PointCloudStore store) { // this.store = store; // } // // public PointCloudStore getStore() { // return store; // } // }
import com.codahale.metrics.health.HealthCheckRegistry; import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.jersey.setup.JerseyEnvironment; import io.dropwizard.lifecycle.setup.LifecycleEnvironment; import io.dropwizard.setup.Environment; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import nl.esciencecenter.ahn.pointcloud.resources.AbstractResource; import org.junit.Before; import org.junit.Test; import java.net.MalformedURLException; import java.net.URL; import static org.mockito.Mockito.*;
config = getViewerConfiguration(); env = getEnvironment(); app = new ViewerApplication(); } private Environment getEnvironment() { Environment environment = mock(Environment.class); JerseyEnvironment jersey = mock(JerseyEnvironment.class); when(environment.jersey()).thenReturn(jersey); LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class); when(environment.lifecycle()).thenReturn(lifecycle); HealthCheckRegistry healthchecks = mock(HealthCheckRegistry.class); when(environment.healthChecks()).thenReturn(healthchecks); return environment; } private ViewerConfiguration getViewerConfiguration() throws MalformedURLException { ImmutableMap<String, String> props = ImmutableMap.of(); SchedulerConfiguration scheduler = new SchedulerConfiguration("local", "/", "multi", props); XenonConfiguration xenon = new XenonConfiguration(scheduler, props); DataSourceFactory database = new DataSourceFactory(); ScriptConfiguration scriptConfig = new ScriptConfiguration(28992, "/bin/echo", "ahn2", "/data/jobs", "http://localhost/jobs"); return new ViewerConfiguration(5, database, xenon, scriptConfig); } @Test public void testRun() throws Exception { app.run(config, env);
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/SchedulerConfiguration.java // public class SchedulerConfiguration { // /** // * Scheme of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String scheme; // // /** // * Location of scheduler used to submit jobs. // * eg. For scheme=='ssh' use 'username@hostname:port'. // */ // @JsonProperty // private String location; // // /** // * Queue of scheduler used to submit jobs // */ // @NotEmpty // @JsonProperty // private String queue; // // /** // * Xenon scheduler properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private SchedulerConfiguration() { // } // // public SchedulerConfiguration(String scheme, String location, String queue, ImmutableMap<String, String> properties) { // this.scheme = scheme; // this.location = location; // this.queue = queue; // this.properties = properties; // } // // public String getScheme() { // return scheme; // } // // public String getLocation() { // return location; // } // // public String getQueue() { // return queue; // } // // public ImmutableMap<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/resources/AbstractResource.java // public class AbstractResource { // private final PointCloudStore store; // // public AbstractResource(PointCloudStore store) { // this.store = store; // } // // public PointCloudStore getStore() { // return store; // } // } // Path: src/test/java/nl/esciencecenter/ahn/pointcloud/ViewerApplicationTest.java import com.codahale.metrics.health.HealthCheckRegistry; import com.google.common.collect.ImmutableMap; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.jersey.setup.JerseyEnvironment; import io.dropwizard.lifecycle.setup.LifecycleEnvironment; import io.dropwizard.setup.Environment; import nl.esciencecenter.ahn.pointcloud.job.SchedulerConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import nl.esciencecenter.ahn.pointcloud.resources.AbstractResource; import org.junit.Before; import org.junit.Test; import java.net.MalformedURLException; import java.net.URL; import static org.mockito.Mockito.*; config = getViewerConfiguration(); env = getEnvironment(); app = new ViewerApplication(); } private Environment getEnvironment() { Environment environment = mock(Environment.class); JerseyEnvironment jersey = mock(JerseyEnvironment.class); when(environment.jersey()).thenReturn(jersey); LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class); when(environment.lifecycle()).thenReturn(lifecycle); HealthCheckRegistry healthchecks = mock(HealthCheckRegistry.class); when(environment.healthChecks()).thenReturn(healthchecks); return environment; } private ViewerConfiguration getViewerConfiguration() throws MalformedURLException { ImmutableMap<String, String> props = ImmutableMap.of(); SchedulerConfiguration scheduler = new SchedulerConfiguration("local", "/", "multi", props); XenonConfiguration xenon = new XenonConfiguration(scheduler, props); DataSourceFactory database = new DataSourceFactory(); ScriptConfiguration scriptConfig = new ScriptConfiguration(28992, "/bin/echo", "ahn2", "/data/jobs", "http://localhost/jobs"); return new ViewerConfiguration(5, database, xenon, scriptConfig); } @Test public void testRun() throws Exception { app.run(config, env);
verify(env.jersey(), times(2)).register(any(AbstractResource.class));
NLeSC/ahn-pointcloud-viewer-ws
src/main/java/nl/esciencecenter/ahn/pointcloud/db/RawExtentsDOA.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // }
import nl.esciencecenter.ahn.pointcloud.core.Selection; import org.skife.jdbi.v2.sqlobject.Bind; import org.skife.jdbi.v2.sqlobject.BindBean; import org.skife.jdbi.v2.sqlobject.SqlQuery;
package nl.esciencecenter.ahn.pointcloud.db; public interface RawExtentsDOA { @SqlQuery("SELECT " + " FLOOR(SUM(numberpoints * (ST_Area(ST_Intersection(geom, qgeom)) /ST_Area(geom)))) AS numpoints " + "FROM " + " extent_raw, " + " (SELECT ST_SetSRID(ST_MakeBox2D(ST_Point(:b.left, :b.bottom),ST_Point(:b.right, :b.top)), :srid) AS qgeom) AS B " + "WHERE geom && qgeom " + "AND ST_Area(geom) != 0")
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/core/Selection.java // @ValidSelection // public class Selection { // @NotNull // @JsonProperty // @ApiModelProperty(value="Most left or minimum x coordinate", example = "124931.360") // private Double left; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most bottom or minimum y coordinate", example = "484567.840") // private Double bottom; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most right or maximum x coordinate", example = "126241.760") // private Double right; // // @NotNull // @JsonProperty // @ApiModelProperty(value="Most top or maximum x coordinate", example = "485730.400") // private Double top; // // public Selection(Double left, Double bottom, Double right, Double top) { // this.left = left; // this.bottom = bottom; // this.right = right; // this.top = top; // } // // protected Selection() { // } // // public Double getLeft() { // return left; // } // // public Double getBottom() { // return bottom; // } // // public Double getRight() { // return right; // } // // public Double getTop() { // return top; // } // // public void setLeft(Double left) { // this.left = left; // } // // public void setBottom(Double bottom) { // this.bottom = bottom; // } // // public void setRight(Double right) { // this.right = right; // } // // public void setTop(Double top) { // this.top = top; // } // // @Override // public boolean equals(Object o) { // if (this == o) {return true;} // if (o == null || getClass() != o.getClass()) {return false;} // Selection selection = (Selection) o; // return Objects.equals(getLeft(), selection.getLeft()) && // Objects.equals(getBottom(), selection.getBottom()) && // Objects.equals(getRight(), selection.getRight()) && // Objects.equals(getTop(), selection.getTop()); // } // // @Override // public int hashCode() { // return Objects.hash(getLeft(), getBottom(), getRight(), getTop()); // } // } // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/db/RawExtentsDOA.java import nl.esciencecenter.ahn.pointcloud.core.Selection; import org.skife.jdbi.v2.sqlobject.Bind; import org.skife.jdbi.v2.sqlobject.BindBean; import org.skife.jdbi.v2.sqlobject.SqlQuery; package nl.esciencecenter.ahn.pointcloud.db; public interface RawExtentsDOA { @SqlQuery("SELECT " + " FLOOR(SUM(numberpoints * (ST_Area(ST_Intersection(geom, qgeom)) /ST_Area(geom)))) AS numpoints " + "FROM " + " extent_raw, " + " (SELECT ST_SetSRID(ST_MakeBox2D(ST_Point(:b.left, :b.bottom),ST_Point(:b.right, :b.top)), :srid) AS qgeom) AS B " + "WHERE geom && qgeom " + "AND ST_Area(geom) != 0")
long getNumberOfPoints(@BindBean("b") Selection bbox,
NLeSC/ahn-pointcloud-viewer-ws
src/main/java/nl/esciencecenter/ahn/pointcloud/ViewerConfiguration.java
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // }
import com.fasterxml.jackson.annotation.JsonProperty; import io.dropwizard.Configuration; import io.dropwizard.db.DataSourceFactory; import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import org.hibernate.validator.constraints.Range; import javax.validation.Valid; import javax.validation.constraints.NotNull;
package nl.esciencecenter.ahn.pointcloud; public class ViewerConfiguration extends Configuration { @Valid @Range(min=1) @JsonProperty private long pointsLimit; @Valid @NotNull @JsonProperty private DataSourceFactory database = new DataSourceFactory(); @Valid @NotNull @JsonProperty
// Path: src/main/java/nl/esciencecenter/ahn/pointcloud/job/XenonConfiguration.java // public class XenonConfiguration { // /** // * Scheduler configuration used to submit jobs // */ // @Valid // @JsonProperty // private SchedulerConfiguration scheduler; // // /** // * Xenon global properties // */ // @JsonProperty // private ImmutableMap<String, String> properties = ImmutableMap.of(); // // private XenonConfiguration() { // } // // public XenonConfiguration(SchedulerConfiguration scheduler, ImmutableMap<String, String> properties) { // this.scheduler = scheduler; // this.properties = properties; // } // // public SchedulerConfiguration getScheduler() { // return scheduler; // } // // public Map<String, String> getProperties() { // return properties; // } // } // Path: src/main/java/nl/esciencecenter/ahn/pointcloud/ViewerConfiguration.java import com.fasterxml.jackson.annotation.JsonProperty; import io.dropwizard.Configuration; import io.dropwizard.db.DataSourceFactory; import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import nl.esciencecenter.ahn.pointcloud.job.XenonConfiguration; import org.hibernate.validator.constraints.Range; import javax.validation.Valid; import javax.validation.constraints.NotNull; package nl.esciencecenter.ahn.pointcloud; public class ViewerConfiguration extends Configuration { @Valid @Range(min=1) @JsonProperty private long pointsLimit; @Valid @NotNull @JsonProperty private DataSourceFactory database = new DataSourceFactory(); @Valid @NotNull @JsonProperty
private XenonConfiguration xenon;