Java源码示例:org.mapdb.Fun.Tuple3

示例1
@Override
public void save(List<SpatialDataItem> objs) {

	List<SpatialDataItem> segments = new ArrayList<SpatialDataItem>();
	for(SpatialDataItem obj : objs) {

		Tuple3 segmentId = ((StreetSegment)obj).getSegmentId();
		if (segmentIndex.containsKey(segmentId))
			continue;

		segments.add(obj);

		segmentIndex.put(segmentId, obj.id);
	}

	super.save(segments);
}
 
示例2
@Override
public void delete(List<SpatialDataItem> objs) {
	List<SpatialDataItem> segments = new ArrayList<SpatialDataItem>();
	for(SpatialDataItem obj : objs) {

		Tuple3 segmentId = ((StreetSegment)obj).getSegmentId();
		if (!segmentIndex.containsKey(segmentId))
			continue;

		segments.add(obj);

		segmentIndex.remove(segmentId);
	}

	super.delete(segments);
}
 
示例3
@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);
}
 
示例4
@Override
public void delete(SpatialDataItem obj) {
	Tuple3 segmentId = ((StreetSegment)obj).getSegmentId();
	segmentIndex.remove(segmentId);

	super.delete(obj);
}
 
示例5
public void save(SpatialDataItem obj) {
	map.put(obj.id, obj);

	for(Tuple3<Integer, Integer, Long> tuple : obj.getTiles(Z_INDEX)) {
		tileIndex.add(tuple);
	}
	db.commit();
}
 
示例6
public void save(List<SpatialDataItem> objs) {
	for(SpatialDataItem obj : objs) {
		if (map.containsKey(obj.id))
			continue;

		map.put(obj.id, obj);

		for (Tuple3<Integer, Integer, Long> tuple : obj.getTiles(Z_INDEX)) {
			tileIndex.add(tuple);
		}
	}
	db.commit();
}
 
示例7
public void delete(List<SpatialDataItem> objs) {
	for (SpatialDataItem obj : objs) {
		if(!map.containsKey(obj.id))
			continue;

		map.remove(obj.id);
		for (Tuple3<Integer, Integer, Long> tuple : obj.getTiles(Z_INDEX)) {
			tileIndex.remove(tuple);
		}
	}
	db.commit();
}
 
示例8
public void delete(SpatialDataItem obj) {
	map.remove(obj.id);
	for(Tuple3<Integer, Integer, Long> tuple : obj.getTiles(Z_INDEX)) {
		tileIndex.remove(tuple);
	}
	db.commit();
}
 
示例9
/**
 * Insert the given way into the tile-based spatial index, based on its current node locations in the database.
 * If the way does not exist, this method does nothing (leaving any reference to the way in the index) because
 * it can't know anything about the location of a way that's already deleted. If the way object is not supplied
 * it will be looked up by its ID.
 */
public void indexWay(long wayId, Way way) {
    // We could also insert using ((float)lat, (float)lon) as a key
    // but depending on whether MapDB does tree path compression this might take more space
    WebMercatorTile tile = tileForWay(wayId, way);
    if (tile == null) {
        LOG.debug("Attempted insert way {} into the spatial index, but it is not currently in the database.", wayId);
    } else {
        this.index.add(new Tuple3(tile.xtile, tile.ytile, wayId));
    }
}
 
示例10
public void unIndexWay(long wayId) {
    Way way = ways.get(wayId);
    if (way == null) {
        LOG.debug("Attempted to remove way {} from the spatial index, but it is not currently in the database.", wayId);
    } else {
        WebMercatorTile tile = tileForWay(wayId, way);
        if (tile != null) {
            this.index.remove(new Tuple3(tile.xtile, tile.ytile, wayId));
        }
    }
}
 
示例11
@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;
}
 
示例12
@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);
}
 
示例13
public SpatialDataItem getBySegmentId(Tuple3<Long, Long, Long> segmentId) {
	if(!segmentIndex.containsKey(segmentId))
		return null;
	return map.get(segmentIndex.get(segmentId));
}
 
示例14
public boolean contains(Tuple3<Long, Long, Long> segmentId) {
	return segmentIndex.containsKey(segmentId);
}
 
示例15
public List<Long> getIdsByEnvelope(Envelope env) {

		int y1 = getTileY(env.getMinY(), Z_INDEX);
		int x1 = getTileX(env.getMinX(), Z_INDEX);
		int y2 = getTileY(env.getMaxY(), Z_INDEX);
		int x2 = getTileX(env.getMaxX(), Z_INDEX);

		int minY;
		int maxY;
		int minX;
		int maxX;

		if(x1 < x2) {
			minX = x1;
			maxX = x2;
		} else {
			minX = x2;
			maxX = x1;
		}

		if(y1 < y2) {
			minY = y1;
			maxY = y2;
		} else {
			minY = y2;
			maxY = y1;
		}

		minX--;
		maxX++;

		minY--;
		maxY++;

		List<Long> ids = new ArrayList();

		for(int tileX = minX; tileX <= maxX; tileX++) {
			NavigableSet<Tuple3<Integer, Integer, Long>> xSubset = tileIndex.subSet(
					new Tuple3(tileX, minY, null), true, // inclusive lower bound, null tests lower than anything
					new Tuple3(tileX, maxY, Fun.HI), true  // inclusive upper bound, HI tests higher than anything
			);

			for (Tuple3<Integer, Integer, Long> item : xSubset) {
				ids.add(item.c);
			}
		}

		return ids;
	}
 
示例16
public void save(SpatialDataItem obj) {
	Tuple3 segmentId = ((StreetSegment)obj).getSegmentId();
	if (segmentIndex.containsKey(segmentId))
		return;

	segmentIndex.put(segmentId, obj.id);

	super.save(obj);

}