forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckedTest.java
More file actions
124 lines (105 loc) · 2.95 KB
/
Copy pathCheckedTest.java
File metadata and controls
124 lines (105 loc) · 2.95 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (c) 2020 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
* which accompanies this distribution, and is available at
* http://opensource.org/licenses/BSD-3-Clause
*
* Contributors:
* Chapman Flack
*/
package org.postgresql.pljava.internal;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.stream.Stream;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import static org.postgresql.pljava.internal.Checked.closing;
import static org.postgresql.pljava.internal.Checked.OptionalBase.ofNullable;
public class CheckedTest
{
public void compilability()
{
try
{
Checked.Consumer
.use((String n) -> { Class.forName(n); })
.in(l -> { Stream.of("Foo").forEach(l); });
}
catch ( ClassNotFoundException e )
{
}
try
{
Checked.DoubleConsumer
.use(v -> {throw new IllegalAccessException();})
.in(l -> { DoubleStream.of(4.2).forEach(l); });
Checked.IntConsumer
.use(v -> {throw new IllegalAccessException();})
.in(l -> { IntStream.of(42).forEach(l); });
Checked.LongConsumer
.use(v -> {throw new IllegalAccessException();})
.in(l -> { LongStream.of(4).forEach(l); });
Checked.Runnable
.use(() -> {throw new IllegalAccessException();})
.in(r -> { Stream.of("").forEach(o -> {r.run();}); });
}
catch ( IllegalAccessException e )
{
}
Boolean zl =
Checked.Supplier
.use(() -> Boolean.TRUE)
.inReturning(s -> s.get());
boolean z =
Checked.BooleanSupplier
.use(() -> true)
.inBooleanReturning(zs -> zs.getAsBoolean());
double d =
Checked.DoubleSupplier
.use(() -> 4.2)
.inDoubleReturning(ds -> ds.getAsDouble());
int i =
Checked.IntSupplier
.use(() -> 4)
.inIntReturning(is -> is.getAsInt());
long j =
Checked.LongSupplier
.use(() -> 4)
.inLongReturning(ls -> ls.getAsLong());
byte b =
Checked.ByteSupplier
.use(() -> 4)
.inByteReturning(bs -> bs.getAsByte());
short s =
Checked.ShortSupplier
.use(() -> 4)
.inShortReturning(ss -> ss.getAsShort());
char c =
Checked.CharSupplier
.use(() -> 4)
.inCharReturning(cs -> cs.getAsChar());
float f =
Checked.FloatSupplier
.use(() -> 2.4f)
.inFloatReturning(fs -> fs.getAsFloat());
try (Checked.AutoCloseable<IllegalAccessException> ac = // Java 10: var
closing(() -> {throw new IllegalAccessException();}))
{
}
catch ( IllegalAccessException e )
{
}
OptionalDouble opd = ofNullable(4.2);
OptionalInt opi = ofNullable(4);
OptionalLong opj = ofNullable(4L);
Checked.OptionalBoolean opz = ofNullable(true);
Checked.OptionalByte opb = ofNullable((byte)2);
Checked.OptionalShort ops = ofNullable((short)2);
Checked.OptionalChar opc = ofNullable('2');
Checked.OptionalFloat opf = ofNullable(2f);
}
}