/** * Extracts a bucket containing key/value pairs with the {@code prefix}. * * @param prefix * @return */ public Bucket extract(String prefix) { Bucket partial = new Bucket(); for (Map.Entry<String, byte[]> entry : data.entrySet()) { if (entry.getKey().startsWith(prefix)) { partial.put(entry.getKey(), entry.getValue()); } } return partial; }
/** * Creates a new Bucket from a given raw map. * * @param source can be {@literal null}. * @return never {@literal null}. */ public static Bucket newBucketFromRawMap(Map<byte[], byte[]> source) { Bucket bucket = new Bucket(); if (source == null) { return bucket; } for (Map.Entry<byte[], byte[]> entry : source.entrySet()) { bucket.put(new String(entry.getKey(), CHARSET), entry.getValue()); } return bucket; }
/** * Creates a new Bucket from a given {@link String} map. * * @param source can be {@literal null}. * @return never {@literal null}. */ public static Bucket newBucketFromStringMap(Map<String, String> source) { Bucket bucket = new Bucket(); if (source == null) { return bucket; } for (Map.Entry<String, String> entry : source.entrySet()) { bucket.put( entry.getKey(), StringUtils.hasText(entry.getValue()) ? entry.getValue().getBytes(CHARSET) : new byte[] {}); } return bucket; }