| 1 | 0 | |
| 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 | |
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 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 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 | |
|
| 66 | |
|
| 67 | |
private final transient MkData data; |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
private final transient String tbl; |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
private final transient Conditions conds; |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
MkFrame(final MkData dta, final String table) { |
| 85 | 2 | this(dta, table, new Conditions()); |
| 86 | 2 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 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 | |
} |