Get a {@code long} from a {@link JSONValue}.  Return 0 if the {@link JSONValue} is
{@code null}.

@param   value   the {@link JSONValue}
@return  the value as a {@code long}
@throws  JSONException if the value is not a number
176121
public static long getLong(JSONValue value) {
        if (value == null)
            return 0;
        if (!(value instanceof Number))
            throw new JSONException(NOT_A_NUMBER);
        return ((Number)value).longValue();
    }
390087
public static long parseDate(String value) {
        Date date = null;
        for (SimpleDateFormat format : FORMATS_TEMPLATE) {
            try {
                date = format.parse(value);
            } catch (ParseException e) {
                // Nothing.
            }
        }

        if (date == null) return -1L;
        return date.getTime();
    }
1055841
public static long longFromBase64(String value) {
        int pos = 0;
        long longVal = base64Values[value.charAt(pos++)];
        int len = value.length();
        while (pos < len) {
            longVal <<= 6;
            longVal |= base64Values[value.charAt(pos++)];
        }
        return longVal;
    }
1259381
public LongConstant getLongByValue(long value)
  {
    for (int i = 0; i < _entries.size(); i++) {
      ConstantPoolEntry entry = _entries.get(i);

      if (! (entry instanceof LongConstant))
        continue;

      LongConstant longEntry = (LongConstant) entry;

      if (longEntry.getValue() == value)
        return longEntry;
    }

    return null;
  }
193690
@Override
    public Long convert(Object value) {
        if (value instanceof Number) {
            double d = ((Number)value).doubleValue();
            if (Double.isNaN(d) || Math.round(d)!=d) throw new IllegalArgumentException("Not a valid long: " + value);
            return ((Number)value).longValue();
        } else if (value instanceof String) {
            return Long.parseLong((String)value);
        } else if (value instanceof Idfiable) {
            return ((Idfiable)value).longId();
        } else return null;
    }
536809
public long getLong( int index ) {
      Object o = get( index );
      if( o != null ){
         return o instanceof Number ? ((Number) o).longValue() : (long) getDouble( index );
      }
      throw new JSONException( "JSONArray[" + index + "] is not a number." );
   }
599430
public long getLong(int index) throws JSONException {
        Object object = this.get(index);
        try {
            return object instanceof Number ? ((Number) object).longValue()
                    : Long.parseLong((String) object);
        } catch (Exception e) {
            throw new JSONException("JSONArray[" + index + "] is not a number.");
        }
    }
848786
public Object nextValue() throws JSONException {
        char c = nextClean();
        String s;

        switch (c) {
            case '"':
            case '\'':
                return nextString(c);
            case '{':
                back();
                return new JSONObject(this);
            case '[':
                back();
                return new JSONArray(this);
        }

        /*
         * Handle unquoted text. This could be the values true, false, or
         * null, or it can be a number. An implementation (such as this one)
         * is allowed to also accept non-standard forms.
         *
         * Accumulate characters until we reach the end of the text or a
         * formatting character.
         */

        StringBuilder sb = new StringBuilder();
        char b = c;
        while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
            sb.append(c);
            c = next();
        }
        back();

        /*
         * If it is true, false, or null, return the proper value.
         */

        s = sb.toString().trim();
        if (s.equals("")) {
            throw syntaxError("Missing value.");
        }
        if (s.equalsIgnoreCase("true")) {
            return Boolean.TRUE;
        }
        if (s.equalsIgnoreCase("false")) {
            return Boolean.FALSE;
        }
        if (s.equalsIgnoreCase("null")) {
            return null;
        }

        if (s.startsWith("new Date(")) {
            try {
                Matcher matcher = Pattern.compile("^\\s*new\\s+Date\\(\\s*(\\d+)\\s*\\)\\s*$").matcher(s);
                if (matcher.find()) {
                    long time = Long.parseLong(matcher.group(1));
                    return new Date(time);
                }
            } catch (Exception e) {
                // ignored
            }
        }

        /*
         * If it might be a number, try converting it. We support the 0- and 0x-
         * conventions. If a number cannot be produced, then the value will just
         * be a string. Note that the 0-, 0x-, plus, and implied string
         * conventions are non-standard. A JSON parser is free to accept
         * non-JSON forms as long as it accepts all correct JSON forms.
         */

        if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
            if (b == '0') {
                if (s.length() > 2 &&
                        (s.charAt(1) == 'x' || s.charAt(1) == 'X')) {
                    try {
                        return Integer.parseInt(s.substring(2), 16);
                    } catch (Exception e) {
                        /* Ignore the error */
                    }
                } else {
                    try {
                        return Integer.parseInt(s, 8);
                    } catch (Exception e) {
                        /* Ignore the error */
                    }
                }
            }
            try {
                return Integer.valueOf(s);
            } catch (Exception e) {
                try {
                    return Long.valueOf(s);
                } catch (Exception f) {
                    try {
                        return Double.valueOf(s);
                    } catch (Exception g) {
                        return s;
                    }
                }
            }
        }
        return s;
    }
771263
private static Object toLong( BigDecimal value)
    {
    Object number;
        
    try
      {
      number =
        value.scale() == 0
        ? Long.valueOf( value.longValueExact())
        : null;
      }
    catch( Exception e)
      {
      number = null;
      }
        
    return number;
    }
1052958
public Long getLong(String key, Long defaultValue) {
        Object o = get(key);
        if (o != null) {
            if (o instanceof Long) {
                return (Long) o;
            } else if (o instanceof Integer) {
                return new Long((Integer)o);
            }
        }
        return defaultValue;
    }
845631
@Pure
	@Inline(value = "$2.valueOf($1.longValue())", imported = Long.class)
	public static Long toLong(AtomicLong number) {
		return number.longValue();
	}
888761
public static boolean getBoolean(JSONValue value) {
        if (value == null)
            return false;
        if (!(value instanceof JSONBoolean))
            throw new JSONException(NOT_A_BOOLEAN);
        return ((JSONBoolean)value).booleanValue();
    }
603919
public long getLong(String key, long defaultValue) {
    Object value = get(key);
    if (value instanceof Long) {
      return (long) value;
    }
    if (value instanceof Number) {
      return ((Number) value).longValue();
    } else if (value instanceof String) {
      try {
        return Long.valueOf((String) value);
      } catch (NumberFormatException ignored) {
      }
    }
    return defaultValue;
  }
465500
public static long getLong(JsonObject object, String field) {
        final JsonValue value = object.get(field);
        throwExceptionIfNull(value, field);
        return value.asLong();
    }
255030
@Override
  public long readLong() throws IOException {
    byte[] longBytes = new byte[8];
    int i = in.read(longBytes);
    if (i < 8) {
      throw new EOFException();
    }
    longBytes[0] = (byte) (longBytes[0] ^ 0x80);

    long value = 0;
    for (int j = 0; j < longBytes.length; ++j) {
      value = (value << 8) + (longBytes[j] & 0xff);
    }
    return value;
  }
12016
protected Long eval(final Object[] _value)
    {
        final Long ret;

        if (_value == null) {
            ret = null;
        } else if (_value[0] instanceof String && ((String) _value[0]).length() > 0) {
            ret = Long.parseLong((String) _value[0]);
        } else if (_value[0] instanceof Number) {
            ret = ((Number) _value[0]).longValue();
        } else  {
            ret = null;
        }

        return ret;
    }
190667
public static Long toLong(Object value, Long defaultValue) {
		return convert(Long.class, value, defaultValue);
	}