|
| 1 | +package redis.clients.jedis.resps; |
| 2 | + |
| 3 | +import redis.clients.jedis.Builder; |
| 4 | +import redis.clients.jedis.util.KeyValue; |
| 5 | + |
| 6 | +import java.util.Collections; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import static redis.clients.jedis.BuilderFactory.*; |
| 10 | + |
| 11 | +public class TrackingInfo { |
| 12 | + |
| 13 | + private final List<String> flags; |
| 14 | + private final long redirect; |
| 15 | + private final List<String> prefixes; |
| 16 | + |
| 17 | + public TrackingInfo(List<String> flags, long redirect, List<String> prefixes) { |
| 18 | + this.flags = flags; |
| 19 | + this.redirect = redirect; |
| 20 | + this.prefixes = prefixes; |
| 21 | + } |
| 22 | + |
| 23 | + |
| 24 | + public List<String> getFlags() { |
| 25 | + return flags; |
| 26 | + } |
| 27 | + |
| 28 | + public long getRedirect() { |
| 29 | + return redirect; |
| 30 | + } |
| 31 | + |
| 32 | + public List<String> getPrefixes() { |
| 33 | + return prefixes; |
| 34 | + } |
| 35 | + |
| 36 | + public static final Builder<TrackingInfo> TRACKING_INFO_BUILDER = new Builder<TrackingInfo>() { |
| 37 | + @Override |
| 38 | + public TrackingInfo build(Object data) { |
| 39 | + List commandData = (List) data; |
| 40 | + |
| 41 | + if (commandData.get(0) instanceof KeyValue) { |
| 42 | + List<String> flags = Collections.emptyList(); |
| 43 | + long redirect = -1; |
| 44 | + List<String> prefixes = Collections.emptyList(); |
| 45 | + |
| 46 | + for (KeyValue kv : (List<KeyValue>) commandData) { |
| 47 | + switch (STRING.build(kv.getKey())) { |
| 48 | + case "flags": |
| 49 | + flags = STRING_LIST.build(kv.getValue()); |
| 50 | + break; |
| 51 | + case "redirect": |
| 52 | + redirect = LONG.build(kv.getValue()); |
| 53 | + break; |
| 54 | + case "prefixes": |
| 55 | + prefixes = STRING_LIST.build(kv.getValue()); |
| 56 | + break; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + return new TrackingInfo(flags, redirect, prefixes); |
| 61 | + } else { |
| 62 | + List<String> flags = STRING_LIST.build(commandData.get(1)); |
| 63 | + long redirect = LONG.build(commandData.get(3)); |
| 64 | + List<String> prefixes = STRING_LIST.build(commandData.get(5)); |
| 65 | + |
| 66 | + return new TrackingInfo(flags, redirect, prefixes); |
| 67 | + } |
| 68 | + } |
| 69 | + }; |
| 70 | +} |
0 commit comments