View Javadoc
1   package org.neo4j.driver.projection;
2   
3   import org.neo4j.driver.exception.Neo4jClientException;
4   import org.neo4j.driver.v1.Record;
5   
6   import java.util.function.Function;
7   
8   /**
9    * Abstract class for projection.
10   * A projection is just a function that can be passed to a map.
11   */
12  abstract class Projection<T> implements Function<Record, T> {
13  
14      /**
15       * Projection's type.
16       */
17      protected Class type;
18  
19      /**
20       * Default constructor.
21       *
22       * @param type
23       */
24      public Projection(Class type) {
25          this.type = type;
26      }
27  
28      /**
29       * Check if the given <code>record</code> has only one column.
30       * if not, a {@link Neo4jClientException} is throw.
31       *
32       * @param record
33       */
34      protected void checkIfRecordHaveSingleValue(Record record) {
35          if (record.size() > 1) {
36              throw new Neo4jClientException("Record doesn't have a single column -> can't cast it to primitive object type");
37          }
38      }
39  
40  }