org.mapdb.BTreeMap Java Examples
The following examples show how to use
org.mapdb.BTreeMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: _TempMap.java From scava with Eclipse Public License 2.0 | 6 votes |
public static void main(String[] args) { // open new empty map // DBMaker will create files in temporary folder and opens it Map<String, String> map = DBMaker.newTempTreeMap(); //put some stuff into map //all data are stored in file in temp folder map.put("aa", "bb"); map.put("cc", "dd"); // Close map to release resources. // It is optional, there is JVM shutdown hook which deletes files on JVM exit. ((BTreeMap)map).close(); // After JVM exits files are deleted. // This map was temporary, there is no way to recover its data ! }
Example #2
Source File: StatisticDataRepositoryMapDB.java From AisAbnormal with GNU Lesser General Public License v3.0 | 6 votes |
@Override public StatisticData getStatisticData(String statisticName, long cellId) { BTreeMap<Object, Object> allCellDataForStatistic; if (readOnly) { allCellDataForStatistic = (BTreeMap<Object, Object>) db.getAll().get(statisticName); } else { allCellDataForStatistic = db.createTreeMap(statisticName).makeOrGet(); } StatisticData statistics = null; if (allCellDataForStatistic == null) { LOG.error("No data exists for statistic " + statisticName); } else { statistics = (StatisticData) allCellDataForStatistic.get(cellId); } return statistics; }
Example #3
Source File: MapDBTestSuite.java From eagle with Apache License 2.0 | 6 votes |
@Test public void testOnHeapDB() { DB db = DBMaker.heapDB().make(); BTreeMap<Long, String> map = db.treeMap("btree").keySerializer(Serializer.LONG).valueSerializer(Serializer.STRING).create(); Assert.assertFalse(map.putIfAbsentBoolean(1L, "val_1")); Assert.assertTrue(map.putIfAbsentBoolean(1L, "val_2")); Assert.assertTrue(map.putIfAbsentBoolean(1L, "val_3")); Assert.assertFalse(map.putIfAbsentBoolean(2L, "val_4")); Assert.assertEquals("val_1", map.get(1L)); Assert.assertEquals("val_4", map.get(2L)); Assert.assertTrue(map.replace(2L, "val_4", "val_5")); Assert.assertEquals("val_5", map.get(2L)); map.close(); db.close(); }
Example #4
Source File: TradeMap.java From Qora with MIT License | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public SortableList<Tuple2<BigInteger, BigInteger>, Trade> getTradesSortableList(long have, long want) { String pairKey; if(have > want) { pairKey = have + "/" + want; } else { pairKey = want + "/" + have; } //FILTER ALL KEYS Collection<Tuple2<BigInteger, BigInteger>> keys = ((BTreeMap<Tuple3, Tuple2<BigInteger, BigInteger>>) this.pairKeyMap).subMap( Fun.t3(pairKey, null, null), Fun.t3(pairKey, Fun.HI(), Fun.HI())).values(); //RETURN return new SortableList<Tuple2<BigInteger, BigInteger>, Trade>(this, keys); }
Example #5
Source File: OrderMap.java From Qora with MIT License | 6 votes |
@SuppressWarnings("unchecked") private Map<BigInteger, Order> openMap(DB database) { //OPEN MAP BTreeMap<BigInteger, Order> map = database.createTreeMap("orders") .valueSerializer(new OrderSerializer()) .makeOrGet(); //HAVE/WANT KEY this.haveWantKeyMap = database.createTreeMap("orders_key_have_want") .comparator(Fun.COMPARATOR) .makeOrGet(); //BIND HAVE/WANT KEY Bind.secondaryKey(map, this.haveWantKeyMap, new Fun.Function2<Tuple4<Long, Long, BigDecimal, BigInteger>, BigInteger, Order>() { @Override public Tuple4<Long, Long, BigDecimal, BigInteger> run(BigInteger key, Order value) { return new Tuple4<Long, Long, BigDecimal, BigInteger>(value.getHave(), value.getWant(), value.getPrice(), key); } }); //RETURN return map; }
Example #6
Source File: NameSaleMap.java From Qora with MIT License | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<NameSale> get(Account account) { List<NameSale> nameSales = new ArrayList<NameSale>(); try { Map<Tuple2<String, String>, BigDecimal> accountNames = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); for(Entry<Tuple2<String, String>, BigDecimal> entry: accountNames.entrySet()) { NameSale nameSale = new NameSale(entry.getKey().b, entry.getValue()); nameSales.add(nameSale); } } catch(Exception e) { //ERROR e.printStackTrace(); } return nameSales; }
Example #7
Source File: TradeMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private Collection<Tuple2> getKeys(Order order) { Map uncastedMap = this.map; //FILTER ALL KEYS Collection<Tuple2> keys = ((BTreeMap<Tuple2, Order>) uncastedMap).subMap( Fun.t2(order.getId(), null), Fun.t2(order.getId(), Fun.HI())).keySet(); //IF THIS IS A FORK if(this.parent != null) { //GET ALL KEYS FOR FORK Collection<Tuple2> forkKeys = ((TradeMap) this.parent).getKeys(order); //COMBINE LISTS Set<Tuple2> combinedKeys = new TreeSet<Tuple2>(keys); combinedKeys.addAll(forkKeys); //DELETE DELETED for(Tuple2 deleted: this.deleted) { combinedKeys.remove(deleted); } //CONVERT SET BACK TO COLLECTION keys = combinedKeys; } return keys; }
Example #8
Source File: OrderMap.java From Qora with MIT License | 5 votes |
private Map<Tuple2<String, BigInteger>, Order> openMap(DB database) { //OPEN MAP BTreeMap<Tuple2<String, BigInteger>, Order> map = database.createTreeMap("orders") //.keySerializer(BTreeKeySerializer.TUPLE2) .valueSerializer(new OrderSerializer()) .makeOrGet(); //RETURN return map; }
Example #9
Source File: OrderMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public void delete(Account account) { //GET ALL ORDERS THAT BELONG TO THAT ADDRESS Map<Tuple2<String, BigInteger>, Order> accountOrders = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //DELETE NAMES for(Tuple2<String, BigInteger> key: accountOrders.keySet()) { this.delete(key); } }
Example #10
Source File: TransactionMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<Transaction> get(Account account, int limit) { List<Transaction> transactions = new ArrayList<Transaction>(); try { //GET ALL TRANSACTIONS THAT BELONG TO THAT ADDRESS /*Map<Tuple2<String, String>, Transaction> accountTransactions = ((BTreeMap) this.map).subMap( Fun.t2(null, account.getAddress()), Fun.t2(Fun.HI(), account.getAddress()));*/ Map<Tuple2<String, String>, Transaction> accountTransactions = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //GET ITERATOR Iterator<Transaction> iterator = accountTransactions.values().iterator(); //RETURN {LIMIT} TRANSACTIONS int counter = 0; while(iterator.hasNext() && counter < limit) { transactions.add(iterator.next()); counter++; } } catch(Exception e) { //ERROR e.printStackTrace(); } return transactions; }
Example #11
Source File: TransactionMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public void delete(Account account) { //GET ALL TRANSACTIONS THAT BELONG TO THAT ADDRESS Map<Tuple2<String, String>, Transaction> accountTransactions = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //DELETE TRANSACTIONS for(Tuple2<String, String> key: accountTransactions.keySet()) { this.delete(key); } }
Example #12
Source File: NameSaleMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public void delete(Account account) { //GET ALL NAMES THAT BELONG TO THAT ADDRESS Map<Tuple2<String, String>, BigDecimal> accountNameSales = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //DELETE NAMES for(Tuple2<String, String> key: accountNameSales.keySet()) { this.delete(key); } }
Example #13
Source File: NameMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<Name> get(Account account) { List<Name> names = new ArrayList<Name>(); try { Map<Tuple2<String, String>, Name> accountNames = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //GET ITERATOR Iterator<Name> iterator = accountNames.values().iterator(); while(iterator.hasNext()) { names.add(iterator.next()); } } catch(Exception e) { //ERROR e.printStackTrace(); } return names; }
Example #14
Source File: NameMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public void delete(Account account) { //GET ALL NAMES THAT BELONG TO THAT ADDRESS Map<Tuple2<String, String>, Name> accountNames = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //DELETE NAMES for(Tuple2<String, String> key: accountNames.keySet()) { this.delete(key); } }
Example #15
Source File: BlockMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public void delete(Account account) { //GET ALL TRANSACTIONS THAT BELONG TO THAT ADDRESS Map<Tuple2<String, String>, Block> accountBlocks = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //DELETE TRANSACTIONS for(Tuple2<String, String> key: accountBlocks.keySet()) { this.delete(key); } }
Example #16
Source File: TradeMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public SortableList<Tuple2<BigInteger, BigInteger>, Trade> getTrades(Order order) { //ADD REVERSE KEYS Collection<Tuple2<BigInteger, BigInteger>> keys = ((BTreeMap<Tuple2, Tuple2<BigInteger, BigInteger>>) this.reverseKeyMap).subMap( Fun.t2(order.getId(), null), Fun.t2(order.getId(), Fun.HI())).values(); //RETURN return new SortableList<Tuple2<BigInteger, BigInteger>, Trade>(this, keys); }
Example #17
Source File: StatisticDataRepositoryMapDB.java From AisAbnormal with GNU Lesser General Public License v3.0 | 5 votes |
@Override public DatasetMetaData getMetaData() { BTreeMap<String, DatasetMetaData> allMetadata; if (readOnly) { allMetadata = (BTreeMap<String, DatasetMetaData>) db.getAll().get(COLLECTION_METADATA); } else { allMetadata = db.createTreeMap(COLLECTION_METADATA).makeOrGet(); } return allMetadata.get(KEY_METADATA); }
Example #18
Source File: StatisticDataRepositoryMapDB.java From AisAbnormal with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Set<Long> getCellsWithData(String statisticName) { BTreeMap<Long, StatisticData> allCellDataForStatistic; if (readOnly) { allCellDataForStatistic = (BTreeMap<Long, StatisticData>) db.getAll().get(statisticName); } else { allCellDataForStatistic = db.createTreeMap(statisticName).makeOrGet(); } return allCellDataForStatistic.keySet(); }
Example #19
Source File: StatisticDataRepositoryMapDB.java From AisAbnormal with GNU Lesser General Public License v3.0 | 5 votes |
@Override public StatisticData getStatisticDataForRandomCell(String statisticName) { BTreeMap<Long, StatisticData> allCellDataForStatistic; if (readOnly) { allCellDataForStatistic = (BTreeMap<Long, StatisticData>) db.getAll().get(statisticName); } else { allCellDataForStatistic = db.createTreeMap(statisticName).makeOrGet(); } return allCellDataForStatistic.get(allCellDataForStatistic.firstKey()); }
Example #20
Source File: PollMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public void delete(Account account) { //GET ALL POLLS THAT BELONG TO THAT ADDRESS Map<Tuple2<String, String>, Poll> accountPolls = ((BTreeMap) this.map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())); //DELETE NAMES for(Tuple2<String, String> key: accountPolls.keySet()) { this.delete(key); } }
Example #21
Source File: HistoDataServiceImpl.java From ipst with Mozilla Public License 2.0 | 5 votes |
@Override public DataSet getData(HistoDataSource datasource, QueryParams query) { Objects.requireNonNull(datasource); Objects.requireNonNull(query); log.info("getData " + query); DataSet result = new DataSet(); BTreeMap<HistoKey, Map<String, Object>> netMap = datasource.getMap(); List<Attribute> columns = query.getCols() != null ? query.getCols() : findAttributes(datasource.getReferenceNetwork(), query, true); long start = query.getStart() >= 0 ? query.getStart() : 0; long maxSize = query.getCount() >= 0 ? query.getCount() : Long.MAX_VALUE; result.addHeaders( query.getColumnStart() >= 0 && query.getColumnEnd() >= 0 ? columns.subList(query.getColumnStart(), query.getColumnEnd() < columns.size() ? query.getColumnEnd() + 1 : columns.size()) : columns); ConcurrentNavigableMap<HistoKey, Map<String, Object>> filtered = netMap.subMap( new HistoKey(query.getHorizon() != null ? query.getHorizon() : "", query.getTimeFrom(), query.getForecastTime() >= 0 ? query.getForecastTime() : Integer.MIN_VALUE), new HistoKey(query.getHorizon(), query.getTimeTo(), query.getForecastTime() >= 0 ? query.getForecastTime() : Integer.MAX_VALUE)); result.addAll(filtered.keySet().stream().filter(k -> matches(k, filtered.get(k), query)) .skip(start) .map(k -> filterColumns(filtered.get(k), query, columns)) .limit(maxSize) .collect(Collectors.toList())); return result; }
Example #22
Source File: HistoDataServiceImpl.java From ipst with Mozilla Public License 2.0 | 5 votes |
@Override public DataSet getForecastDiff(HistoDataSource datasource, QueryParams query) { Objects.requireNonNull(datasource); Objects.requireNonNull(query); log.info("getForecastDiff " + query); DataSet result = new DataSet(); BTreeMap<HistoKey, Map<String, Object>> netMap = datasource.getMap(); List<Attribute> columns = query.getCols() != null ? query.getCols() : findAttributes(datasource.getReferenceNetwork(), query, false); long start = query.getStart() >= 0 ? query.getStart() : 0; long maxSize = query.getCount() >= 0 ? query.getCount() : Long.MAX_VALUE; result.addHeaders( query.getColumnStart() >= 0 && query.getColumnEnd() >= 0 ? columns.subList(query.getColumnStart(), query.getColumnEnd() < columns.size() ? query.getColumnEnd() + 1 : columns.size()) : columns); ConcurrentNavigableMap<HistoKey, Map<String, Object>> filtered = netMap.subMap( new HistoKey(HistoDbHorizon.DACF.toString(), query.getTimeFrom(), query.getForecastTime() >= 0 ? query.getForecastTime() : Integer.MIN_VALUE), new HistoKey(HistoDbHorizon.DACF.toString(), query.getTimeTo(), query.getForecastTime() >= 0 ? query.getForecastTime() : Integer.MAX_VALUE)); filtered.keySet().stream().filter(k -> matches(k, filtered.get(k), query)).skip(start).limit(maxSize) .forEach(fk -> { HistoKey sk = new HistoKey(HistoDbHorizon.SN.toString(), fk.getDateTime(), 0); Map sm = netMap.get(sk); if (sm != null) { result.add(filterColumns(filtered.get(fk), query, columns)); result.add(filterColumns(sm, query, columns)); } }); return result; }
Example #23
Source File: DBMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings("unchecked") protected <V> void createIndex(int index, NavigableSet<?> indexSet, NavigableSet<?> descendingIndexSet, Function2<V, T, U> function) { Bind.secondaryKey((BTreeMap<T, U>) this.map, (NavigableSet<Tuple2<V, T>>) indexSet, function); this.indexes.put(index, (NavigableSet<Tuple2<?, T>>) indexSet); Bind.secondaryKey((BTreeMap<T, U>) this.map, (NavigableSet<Tuple2<V, T>>) descendingIndexSet, function); this.indexes.put(index + 10000, (NavigableSet<Tuple2<?, T>>) descendingIndexSet); }
Example #24
Source File: DBMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings("unchecked") protected <V> void createIndexes(int index, NavigableSet<?> indexSet, NavigableSet<?> descendingIndexSet, Function2<V[], T, U> function) { Bind.secondaryKeys((BTreeMap<T, U>) this.map, (NavigableSet<Tuple2<V, T>>) indexSet, function); this.indexes.put(index, (NavigableSet<Tuple2<?, T>>) indexSet); Bind.secondaryKeys((BTreeMap<T, U>) this.map, (NavigableSet<Tuple2<V, T>>) descendingIndexSet, function); this.indexes.put(index + 10000, (NavigableSet<Tuple2<?, T>>) descendingIndexSet); }
Example #25
Source File: CompletedOrderMap.java From Qora with MIT License | 5 votes |
private Map<BigInteger, Order> openMap(DB database) { //OPEN MAP BTreeMap<BigInteger, Order> map = database.createTreeMap("completedorders") .valueSerializer(new OrderSerializer()) .makeOrGet(); //RETURN return map; }
Example #26
Source File: OrderMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private Collection<BigInteger> getKeys(long have, long want) { //FILTER ALL KEYS Collection<BigInteger> keys = ((BTreeMap<Tuple4, BigInteger>) this.haveWantKeyMap).subMap( Fun.t4(have, want, null, null), Fun.t4(have, want, Fun.HI(), Fun.HI())).values(); //IF THIS IS A FORK if(this.parent != null) { //GET ALL KEYS FOR FORK Collection<BigInteger> forkKeys = ((OrderMap) this.parent).getKeys(have, want); //COMBINE LISTS Set<BigInteger> combinedKeys = new TreeSet<BigInteger>(keys); combinedKeys.addAll(forkKeys); //DELETE DELETED for(BigInteger deleted: this.deleted) { combinedKeys.remove(deleted); } //CONVERT SET BACK TO COLLECTION keys = combinedKeys; } return keys; }
Example #27
Source File: OrderMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public SortableList<BigInteger, Order> getOrdersSortableList(long have, long want) { //FILTER ALL KEYS Collection<BigInteger> keys = ((BTreeMap<Tuple4, BigInteger>) this.haveWantKeyMap).subMap( Fun.t4(have, want, null, null), Fun.t4(have, want, Fun.HI(), Fun.HI())).values(); //RETURN return new SortableList<BigInteger, Order>(this, keys); }
Example #28
Source File: BalanceMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked"}) @Override protected Map<Tuple2<String, Long>, BigDecimal> getMap(DB database) { //OPEN MAP BTreeMap<Tuple2<String, Long>, BigDecimal> map = database.createTreeMap("balances") .keySerializer(BTreeKeySerializer.TUPLE2) .counterEnable() .makeOrGet(); //HAVE/WANT KEY this.assetKeyMap = database.createTreeMap("balances_key_asset") .comparator(Fun.COMPARATOR) .counterEnable() .makeOrGet(); //BIND ASSET KEY Bind.secondaryKey(map, this.assetKeyMap, new Fun.Function2<Tuple3<Long, BigDecimal, String>, Tuple2<String, Long>, BigDecimal>() { @Override public Tuple3<Long, BigDecimal, String> run(Tuple2<String, Long> key, BigDecimal value) { return new Tuple3<Long, BigDecimal, String>(key.b, value.negate(), key.a); } }); //RETURN return map; }
Example #29
Source File: BalanceMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public SortableList<Tuple2<String, Long>, BigDecimal> getBalancesSortableList(long key) { //FILTER ALL KEYS Collection<Tuple2<String, Long>> keys = ((BTreeMap<Tuple3, Tuple2<String, Long>>) this.assetKeyMap).subMap( Fun.t3(key, null, null), Fun.t3(key, Fun.HI(), Fun.HI())).values(); //RETURN return new SortableList<Tuple2<String, Long>, BigDecimal>(this, keys); }
Example #30
Source File: BalanceMap.java From Qora with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public SortableList<Tuple2<String, Long>, BigDecimal> getBalancesSortableList(Account account) { BTreeMap map = (BTreeMap) this.map; //FILTER ALL KEYS Collection keys = ((BTreeMap<Tuple2, BigDecimal>) map).subMap( Fun.t2(account.getAddress(), null), Fun.t2(account.getAddress(), Fun.HI())).keySet(); //RETURN return new SortableList<Tuple2<String, Long>, BigDecimal>(this, keys); }