Java Bit Value Set bit_marker_geohash(String attribute, int bit, boolean on)

Here you can find the source of bit_marker_geohash(String attribute, int bit, boolean on)

Description

bimarkegeohash

License

Open Source License

Declaration

public static String bit_marker_geohash(String attribute, int bit, boolean on) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final String GEOHASH_TYPE = "geohash";
    public static final int GEOHASH_MAXBITS = 64;

    public static String bit_marker_geohash(String attribute, int bit, boolean on) {
        return bit_marker(attribute, GEOHASH_TYPE, GEOHASH_MAXBITS, bit, on);
    }//  w ww  . j a va  2s  .  c  o m

    private static String bit_marker(String attribute, String type, int maxBits, int bit, boolean on) {
        StringBuilder result = new StringBuilder(attribute.length() + maxBits + type.length() + 2);
        StringBuilder bitmarks = new StringBuilder(maxBits + 1);
        result.append(attribute).append('_').append(type).append('_');
        for (int i = 0; i < maxBits; i++) {
            bitmarks.append('x');
        }
        bitmarks.insert(maxBits - bit, on ? '1' : '0');

        // delete leading x
        // decreasing the maxBits in the loop by one would also fix this, but that leads to
        // an out of bounds exception, when trying to insert with bit = 0.
        bitmarks.deleteCharAt(0);

        return result.append(bitmarks).toString();
    }
}

Related

  1. bit_marker(String attribute, String type, int maxBits, int bit, boolean on)
  2. bit_marker_flexint(String attribute, int bit, boolean on)
  3. bitIsSet(byte data, byte bit)
  4. bitIsSet(int i, int offset)
  5. bitIsSet(int x, int pos)
  6. bitIsSet(long value, long test)