Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MkFrame |
|
| 1.3;1.3 | ||||
MkFrame$1 |
|
| 1.3;1.3 | ||||
MkFrame$AjcClosure1 |
|
| 1.3;1.3 | ||||
MkFrame$AjcClosure11 |
|
| 1.3;1.3 | ||||
MkFrame$AjcClosure13 |
|
| 1.3;1.3 | ||||
MkFrame$AjcClosure3 |
|
| 1.3;1.3 | ||||
MkFrame$AjcClosure5 |
|
| 1.3;1.3 | ||||
MkFrame$AjcClosure7 |
|
| 1.3;1.3 | ||||
MkFrame$AjcClosure9 |
|
| 1.3;1.3 |
1 | 0 | /** |
2 | * Copyright (c) 2012-2016, jcabi.com | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: 1) Redistributions of source code must retain the above | |
8 | * copyright notice, this list of conditions and the following | |
9 | * disclaimer. 2) Redistributions in binary form must reproduce the above | |
10 | * copyright notice, this list of conditions and the following | |
11 | * disclaimer in the documentation and/or other materials provided | |
12 | * with the distribution. 3) Neither the name of the jcabi.com nor | |
13 | * the names of its contributors may be used to endorse or promote | |
14 | * products derived from this software without specific prior written | |
15 | * permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
19 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
20 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
21 | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
28 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | package com.jcabi.dynamo.mock; | |
31 | ||
32 | import com.amazonaws.services.dynamodbv2.model.Condition; | |
33 | import com.google.common.base.Function; | |
34 | import com.google.common.collect.Iterators; | |
35 | import com.jcabi.aspects.Immutable; | |
36 | import com.jcabi.aspects.Loggable; | |
37 | import com.jcabi.dynamo.Attributes; | |
38 | import com.jcabi.dynamo.Conditions; | |
39 | import com.jcabi.dynamo.Frame; | |
40 | import com.jcabi.dynamo.Item; | |
41 | import com.jcabi.dynamo.Table; | |
42 | import com.jcabi.dynamo.Valve; | |
43 | import com.jcabi.immutable.ArrayMap; | |
44 | import java.io.IOException; | |
45 | import java.util.AbstractCollection; | |
46 | import java.util.Iterator; | |
47 | import java.util.Map; | |
48 | import lombok.EqualsAndHashCode; | |
49 | import lombok.ToString; | |
50 | ||
51 | /** | |
52 | * Mock version of {@link Frame}. | |
53 | * | |
54 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
55 | * @version $Id: 540262f2430d5149b51586befafd6f861009fbd6 $ | |
56 | * @since 0.10 | |
57 | */ | |
58 | @Immutable | |
59 | 2 | @ToString |
60 | @Loggable(Loggable.DEBUG) | |
61 | 0 | @EqualsAndHashCode(callSuper = false, of = { "tbl", "data", "conds" }) |
62 | 4 | final class MkFrame extends AbstractCollection<Item> implements Frame { |
63 | ||
64 | /** | |
65 | * Data. | |
66 | */ | |
67 | private final transient MkData data; | |
68 | ||
69 | /** | |
70 | * Table. | |
71 | */ | |
72 | private final transient String tbl; | |
73 | ||
74 | /** | |
75 | * Conditions. | |
76 | */ | |
77 | private final transient Conditions conds; | |
78 | ||
79 | /** | |
80 | * Public ctor. | |
81 | * @param dta Data | |
82 | * @param table Table | |
83 | */ | |
84 | MkFrame(final MkData dta, final String table) { | |
85 | 2 | this(dta, table, new Conditions()); |
86 | 2 | } |
87 | ||
88 | /** | |
89 | * Public ctor. | |
90 | * @param dta Data | |
91 | * @param table Table | |
92 | * @param conditions Map of conditions | |
93 | */ | |
94 | MkFrame(final MkData dta, final String table, final Conditions conditions) { | |
95 | 2 | super(); |
96 | 2 | this.data = dta; |
97 | 2 | this.tbl = table; |
98 | 2 | this.conds = conditions; |
99 | 2 | } |
100 | ||
101 | @Override | |
102 | public Iterator<Item> iterator() { | |
103 | try { | |
104 | 4 | return Iterators.transform( |
105 | this.data.iterate(this.tbl, this.conds).iterator(), | |
106 | 4 | new Function<Attributes, Item>() { |
107 | @Override | |
108 | public Item apply(final Attributes input) { | |
109 | 2 | return new MkItem( |
110 | MkFrame.this.data, | |
111 | MkFrame.this.tbl, | |
112 | input | |
113 | ); | |
114 | } | |
115 | } | |
116 | ); | |
117 | 0 | } catch (final IOException ex) { |
118 | 0 | throw new IllegalStateException(ex); |
119 | } | |
120 | } | |
121 | ||
122 | @Override | |
123 | public int size() { | |
124 | 0 | return Iterators.size(this.iterator()); |
125 | } | |
126 | ||
127 | @Override | |
128 | public Frame where(final String name, final String value) { | |
129 | 0 | return this.where(name, Conditions.equalTo(value)); |
130 | } | |
131 | ||
132 | @Override | |
133 | public Frame where(final String name, final Condition condition) { | |
134 | 0 | return this.where( |
135 | new ArrayMap<String, Condition>().with(name, condition) | |
136 | ); | |
137 | } | |
138 | ||
139 | @Override | |
140 | public Frame where(final Map<String, Condition> conditions) { | |
141 | 0 | return new MkFrame(this.data, this.tbl, this.conds.with(conditions)); |
142 | } | |
143 | ||
144 | @Override | |
145 | public Table table() { | |
146 | 0 | return new MkTable(this.data, this.tbl); |
147 | } | |
148 | ||
149 | @Override | |
150 | public Frame through(final Valve valve) { | |
151 | 0 | return this; |
152 | } | |
153 | } |