All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tnakamot.jscdg.json.token.JSONTokenNumber Maven / Gradle / Ivy

There is a newer version: 0.2.1
Show newest version
/*
 *  Copyright (C) 2020 Takashi Nakamoto .
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see .
 */

package com.github.tnakamot.jscdg.json.token;

import com.github.tnakamot.jscdg.json.JSONText;
import com.github.tnakamot.jscdg.json.value.JSONValueNumber;

/**
 * Represents one "number" type token in JSON text.
 *
 * 

* The representation of a number in JSON is defined by * RFC 8259 - 6. Numbers. * This RFC specification does not set limits of the range and precision of numbers. * Although the specification allows software implementations to set limits, this * implementation does not practically set limits. An application program can get * the original text that represents this number without loosing precision by calling * {@link #text()} to maximize the interoperability. * *

* However, in reality, most of the Java application programs internally use * {@link Double} or {@link Long} (or their corresponding primitives) for data * storage and calculation. This class provides methods to convert the "number" * in JSON text into those types (e.g. {@link #toDouble()}, {@link #toLong()}). * *

* Instances of this class are immutable. */ public class JSONTokenNumber extends JSONToken { /** * Creates one "number" type token of a JSON text. * *

* It is the caller's responsibility to validate the token text as number * before creating this instance. * * @param text text of this token * @param begin beginning location of this token within the source JSON text * @param end end location of this token within the source JSON text * @param source source JSON text where this token was extracted from */ public JSONTokenNumber(String text, StringLocation begin, StringLocation end, JSONText source) { super(JSONTokenType.NUMBER, text, begin, end, source); // TODO: validate the text } /** * Text representation of this token as it appears in the source JSON text. * *

* The returned text always complies with * RFC 8259 - 6. Numbers. * * @return text representation of this token as it appears in the source JSON text. */ public String text() { return text; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy