@Override public int defineRelationBits(int index, int shift) { relationCodeEncoder = new EncodedValue("RelationCode", shift, 3, 1, 0, 7); return shift + relationCodeEncoder.getBits(); }
/** * Swap the contents controlled by this value encoder with the given value. * <p> * * @return the new flags */ public long swap(long flags, EncodedValue otherEncoder) { long otherValue = otherEncoder.getValue(flags); flags = otherEncoder.setValue(flags, getValue(flags)); return setValue(flags, otherValue); } }
public long setValue(long flags, long value) { // scale value value = Math.round(value / factor); checkValue((long) (value * factor)); value <<= shift; // clear value bits flags &= ~mask; // set value return flags | value; }
@Test public void testSwap() { EncodedValue instance1 = new EncodedValue("test1", 0, 10, 1, 5, 1000); EncodedValue instance2 = new EncodedValue("test2", 10, 10, 1, 5, 1000); long flags = instance2.setValue(instance1.setValue(0, 13), 874); long swappedFlags = instance1.setValue(instance2.setValue(0, 13), 874); assertEquals(swappedFlags, instance1.swap(flags, instance2)); } }
/** * This method returns the spatialId stored in the specified flags or -1 if not enabled for this encoder. */ public int getSpatialId(long flags) { if (spatialEncoder == null) return -1; return (int) spatialEncoder.getValue(flags); }
/** * This method set the spatial ID (e.g. country ID) of the specified flags to the specified id. Fetch the unique * spatial ID via spatialRuleLookup.lookup().getSpatialId */ public long setSpatialId(long flags, int id) { return spatialEncoder.setValue(flags, id); }
@Test public void testSetValue() { EncodedValue instance = new EncodedValue("test", 6, 4, 1, 5, 10); assertEquals(10, instance.getValue(instance.setValue(0, 10))); instance = new EncodedValue("test", 0, 4, 1, 5, 10); assertEquals(10, instance.getValue(instance.setValue(0, 10))); instance = new EncodedValue("test", 0, 4, 1, 5, 10); assertEquals(5, instance.getValue(instance.setDefaultValue(0))); }
@Override public int defineRelationBits(int index, int shift) { relationCodeEncoder = new EncodedValue("RelationCode2", shift, 2, 1, 0, 3); return shift + 2; }
@Override public boolean isTurnRestricted(long flags) { if (maxTurnCosts == 0) return false; else if (maxTurnCosts == 1) return (flags & turnRestrictionBit) != 0; return turnCostEncoder.getValue(flags) == maxTurnCosts; }
long setValidityId(long flags, int validityId) { return this.validityId.setValue(flags, validityId); }
@Override public int defineRelationBits(int index, int shift) { relationCodeEncoder = new EncodedValue("RelationCode", shift, 3, 1, 0, 7); return shift + relationCodeEncoder.getBits(); }
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { oldRelationFlags = super.handleRelationTags(relation, oldRelationFlags); int code = 0; if (relation.hasTag("route", "mtb")) code = PREFER.getValue(); int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
long getTime(long flags) { return time.getValue(flags); }
public long setDefaultValue(long flags) { return setValue(flags, defaultValue); }
public long setValue( long flags, long value ) { checkValue(value); // scale value value /= factor; value <<= shift; // clear value bits flags &= ~mask; // set value return flags | value; }
@Override public int defineWayBits(int index, int shift) { // first two bits are reserved for route handling in superclass shift = super.defineWayBits(index, shift); speedEncoder = new EncodedDoubleValue("Speed", shift, speedBits, speedFactor, highwaySpeeds.get("cycleway"), maxPossibleSpeed); shift += speedEncoder.getBits(); unpavedBit = 1L << shift++; // 2 bits wayTypeEncoder = new EncodedValue("WayType", shift, 2, 1, 0, 3, true); shift += wayTypeEncoder.getBits(); priorityWayEncoder = new EncodedValue("PreferWay", shift, 3, 1, 0, 7); shift += priorityWayEncoder.getBits(); return shift; }
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { int code = 0; if (relation.hasTag("route", "hiking") || relation.hasTag("route", "foot")) { Integer val = hikingNetworkToCode.get(relation.getTag("network")); if (val != null) code = val; else code = hikingNetworkToCode.get("lwn"); } else if (relation.hasTag("route", "ferry")) { code = PriorityCode.AVOID_IF_POSSIBLE.getValue(); } int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
@Override public double getTurnCost(long flags) { if (maxTurnCosts == 0) return 0; else if (maxTurnCosts == 1) return ((flags & turnRestrictionBit) == 0) ? 0 : Double.POSITIVE_INFINITY; long cost = turnCostEncoder.getValue(flags); if (cost == maxTurnCosts) return Double.POSITIVE_INFINITY; return cost; }
long setTransfers(long flags, int transfers) { return this.transfers.setValue(flags, transfers); }
public long setValue(long flags, long value) { // scale value value = Math.round(value / factor); checkValue((long) (value * factor)); value <<= shift; // clear value bits flags &= ~mask; // set value return flags | value; }