forked from Datomic/datomic-java-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFns.java
More file actions
38 lines (32 loc) · 1016 Bytes
/
Fns.java
File metadata and controls
38 lines (32 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package datomic.samples;
import datomic.Peer;
import datomic.Connection;
import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;
public class Fns {
/**
* Returns single item in the collection, null if collection empty, throws if collection
* has more than one item.
*/
public static Object solo(Object c) {
if (c == null) return null;
Iterator it = ((Collection)c).iterator();
if (!it.hasNext()) return null;
Object result = it.next();
if (it.hasNext()) throw new RuntimeException("Expected one item, got more than one");
return result;
}
/**
* Connection to a fresh in-memory Datomic database.
* @return
*/
public static Connection scratchConnection() {
String uri = "datomic:mem://" + UUID.randomUUID();
Peer.createDatabase(uri);
return Peer.connect(uri);
}
public static void printQueryResult(Collection coll) {
System.out.println(coll);
}
}