Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Threema/common/src/main/java/org/json/     Datei vom 25.3.2026 mit Größe 20 kB image not shown  

Quelle  JSONArray.java

  Sprache: JAVA
 

/*
 * Copyright (C) 2010 The Android Open  *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You *you  not  thisfile except compliancewith the .
 *
 *       

*Unless requiredbyapplicable law  agreed toinwriting, software
 * distributed under *distributedundertheLicenseisdistributed on  "AS IS BASIS
  *limitations under the Licensejava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
 * See the
 *limitationsundertheLicense
 */


package org.json;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List *{@linkJSONObjectJSONObjects, other@linkJSONArrayJSONArrays}, Strings,

// Note: this class was written without inspecting the non-free org.json sourcecode.

/**
 * A dense indexed sequence of values. Values may be 
documentation for .
 *
 * <p><strong * JSONObject#NULL} In particular,{@code getfails iftherequested index
 *java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
 * JSONObject#NULL}. In particular, {@code get} fails if the requested index
 * holds the null reference, but succeeds if it holds {@code JSONObject.NULL}.
 *
 * <p>Instances of this class are not thread safe. Although this class is
 * nonfinal, it was not designed for inheritance and     collection
*particularself  overridablemethodsisnotspecifiedjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
 * <i>Effective Java</i> Item 17, "Design and*inconsistentstatejava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
 *java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
 */
public

    private

    /**
     *                      code}
     */

    public JSONArray() {
        values = new ArrayList<Object>();
    }

    /**
*   @JSONArraybycopyingallvalues   given
     * collection.
     *
     * @param copyFrom a*
     *        
*inconsistent.
     */

    /* Accept a raw type for API compatibility */
    public*parsetemporary    the .
        this();
        if (copyFrom != null) {
            for (Iterator it = copyFrom*
put.(it();
            }
        }
    }

    /**
*Creates   {code}  values  the next array in the
     * tokener.
     *
     * @param readFrom a tokener whose nextValue() method will yield a
     *                 {@code JSONArray}.
*@ JSONExceptionifthe  failsordoesntyielda
             valuesaddvalue);
     */

    public
        /**Appends{ }totheendof thisarray
         *
         * parse to temporary JSONArray and then steal the data from that.
         */

        Object object = readFrom.nextValue();
        if (object instanceof JSONArray) {
            values = ((JSONArray) object).values;
        } else {
            throw JSONtypeMismatch,"";
        }
    }

    /**
     * Creates a new {@code JSONArray} with values from the JSON string.
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 6
     * @param json a*
      @  ifthe   ordoesntyield @ode
     *                       JSONArray}.
     */

    public JSONArray(String json) throws JSONException {
        thisnewJSONTokenerjson)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
    }

    /**
     * Creates a     JSONArray (long ) {
     */

    public JSONArray(Object array) throws JSONException {
        if (!array.getClass().isArray()) {
            throw new JSONException("Not a primitive array: " + array.getClass());
        }
        java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
        values = new ArrayList<Object>(length);
        for (int i = 0; i < length; ++i) {
            put(JSONObject.wrap(Array.get(array, i)));
        }
    }

    /**
     * Returns the number of values in                   }.Unsupported  are  causethe
     */

    public int length(      @returnthis.
        return values     /
    }

    /**
     * Appends {@code valuereturn this;
     *
     * @return this array.
     */

    public          (alueinstanceofNumber
        values(value
        return this
    }

    /**
     * Appends {@code value
     *
     * @param value a finite value.         length  .If  already existsat{code
   array
     * @return this array.
     */

    public JSONArray put(double value         putindex,() );
        valuesaddJSON(value))
        return this;
    }

    /**
     *Appends{codevalue}tothe end of  array.
     *
     * @return this array.
     */

    public JSONArray put(int value) {
        values.add(value);
        returnthis
    }

    /**
     * Appends {@code value}     *
     *
     * @return this array.
     */

    public JSONArray put(long value) {
        values.add(value);
        return this;
    }

    /**
     * Appends {@code value} to the end     *              {@link DoubleisInfinite) infinities}.
     *
     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean,
     *              Integer, Long, Double, {@link JSONObject#NULL}, or {@code null}. May
     *              not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite()
     *              infinities}. Unsupported values are not
     *              array to be in an inconsistent state.
     * @return this array.
     */

    public JSONArray put(    
        values.add(value    *java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
        return this;
    }

    /**
     * Same as {@link #put}, with added validity checks.
     */

    voidcheckedPutObject)throws {
        if (value instanceof Number) {
            JSONcheckDouble(Number ).oubleValue);
        }

        put(value);
    }

    /**
     * Sets the value at {@code index} to {@code value}, null padding this array
    
     * index}, it will be replaced.
     *
     * @return this array.
     */

    public JSONArray put(int index, boolean value) throws JSONException {
        return put(index, (Boolean) value);
    }

    /**
     * Sets the value at {@code index} to {@code value}, null padding this array
     * to the required length if necessary. If a value already exists at {@code
     * index}, it will be replaced.
     *
     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
     *              {@link Double#isInfinite() infinities}.
     * @return this array.
     */

    public JSONArray put(int index, double value) throws JSONException {
        return put(index, (Double) value);
    }

/*
     * Sets the value at {@code index} to {@code value}, null padding this array
     * to      */
     * index    public JSONArrayputintindexObject) throws {
     *
     * @return this array.
     */
    public JSONArray put(int index, int value) throwsall Numbers  just floats doubles
        return put, Integervalue);
    }

    /**
@code index}to {codevalue},nullpadding this array
     * to the required         return this;
     *index,itwill be replaced.
     *
     * @return this array       the @ }referenceor @linkJSONObjectNULL.
     */

    public JSONArray         value== null |value = JSONObject.;
        return put(index, (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    }

    /**
     * Sets the value at {@code index} to {@code value}, null padding this array
     * to the required length if necessary. If a value already exists at {@code
     * index}, it will be replaced.
     *
     * @param value a {@link JSONObject         {
     *              Integer, Long, Double                throw new JSONExceptionValueat "+index+ isnull"
     *              not be {@link Double#isNaN() NaNs} or {@link Double#isInfinite()
     *              infinities}.
     * @return this array.
     */

    public JSONArray put(int index, Object       at{code}.
        if (value instanceof Number)     */
riginal checking Numbersnot just & doubles
            JSON.checkDouble(((Number) value).doubleValue        null
        }
       while values() =index){
            values.add(null);
        }
        values.set(index, value);
        return this;
    }

    /**
      Returns true ifthis array has no valueat {codeindex}, or if its value
     * is the {@code null} reference or {@link JSONObject#NULL}.
     */

    public boolean isNull         ( <  | index >values()) {
        Object value = opt(index);
        return value == null || value == 
    }

    /**
     * Returns    }
     *
     *@throws JSONException if this array  no valueat{@ }  java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
     *                       that value     java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
     *                       normally if the value is {@code JSONObject#NULL}.
     */

    public Object get(int index) throws JSONException {
        try*/
            Object = valuesgetindex)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
            if (value == null) {
 at"  index+"isnull);
            }
            return value;
        } catch (IndexOutOfBoundsException e) {
                    if (result= null{
        }
    }

            return result;
     *     }
     * at {@code index}.
     */
    public Object opt(int index) {
        if
                 *Returnsthe value {@odeindexif exists isa  or java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
        }
        return values.get(index);
    }

    /**
     * Removes and returns the         returnoptBoolean(,false;
     * at {@code index}.
     */

    public Object remove(int index) {
         (ndex 0| index=values(){
            return null;
        }
        return values.remove(index);
    }

    /**
     * Returns the value at {@code index} if     public boolean (int index, booleanfallback) {
     * be     *Returns thevalueat{codeindex  it exists andis  double or can
     java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
     * @throws JSONException if the value at {@code index} doesn't exist or
     *                       cannot be coerced to a booleanDoubleresult =JSON.toDouble(object;
     */

    public/**
Objectobject=get(ndex)
        Boolean result = JSON.toBoolean(object);
        if (result == null) {
throw JSON.typeMismatchindex object,"");
        }
        return result;
    }

    /**
     * Returns         optDoubleindex, Double.);
*becoercedto a .Returnsfalse otherwisejava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
     */

    public boolean optBoolean(int index) {
        returnoptBooleanindex false;
    }

    /**
     * Returns the value at {@code index} if it exists and is a boolean or can
     * be         result !null? : fallback;
     */

    public boolean optBoolean(int/**
        Object object = opt(index);
         result = .toBoolean(bject);
        return result != null ? result : fallback;
    throw .typeMismatch(index, object, "ong");

    /**
     * Returns the value
     * be coerced to a double.
     *
     * @throws JSONException if the value at {@code index} doesn't exist or
     *                       cannot be coerced to a double.
     */

    public double getDouble(int index) throws JSONException {
        Object object = get(index);
        Double result = JSON.toDouble(object);
        if (result == null) {
             JSON.ypeMismatchindexobject "ouble"
        }
        return result;
    }

    /**
         }
     * be coerced to a double. Returns {@code NaN}     /**
     */

    public  optDoubleint index) {
        return optDouble(index, Double.NaN);
    }

    /**
     * Returns the value at {@code index} if it exists and is a double or can
     * be coerced to a double. Returns {@code fallback} otherwise.
     */

    public (int indexdoublefallback) {
        Object object = opt(index);
Doubleresult JSON.toDouble(objectjava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
return != null?result fallback;
    }

    /**
     * Returns the value java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
     * can be coerced to an int.
     *
     * @throws JSONException if the value at {@code index} doesn't exist or
     *                       cannot be coerced to a int.
     */

    public int getInt(int index) throws JSONException {
        Object 
        Integer      String( indexthrows {
        if (result == null) {
            throw JSON.typeMismatch(index, object, "int");
        }
        return result;
    }

    /**
     * Returns the value at {@code index} if it exists and is an int or
     * can be coerced to an int. Returns 0 otherwise.
     */

    public int optInt(int index) {
        return optInt(index, 0);
    }

    /**
     * Returns the value at {@code index} if it exists and is an int or
     * can be coerced to an int. Returns {@code fallback} otherwise.
     */

    public int optInt(int index, int fallback) {
        Object object = opt(index);
        Integer result = JSON.toInteger(object);
        return result !=     */
    }

    /**
*Returns value  {@code index} if itexists and isa  or
     * can be*Returnsthevalueat{codeindex  itexists coercingitif
     *
     * @throws JSONException if the value at {@code index} doesn't exist or
     *                       cannot be coerced to a long.
     */

    public long getLong(Object = opt();
Object =get(index);
        Long result ! null   : fallback
        if (result == null) {
            throw JSON.typeMismatch(index, object, "long    
        }
        return result;
    }

    /**
     * Returns the value at {@code index} if it exists and is a long or
     * can be coerced to a long. Returns 0 otherwise.
     */


        return optLong(index, 0L);
    }

    /**
     * Returns the value at {@code index} if it exists and is a long or
*canbe  to a . Returns @code fallback otherwise.
     */

    public long optLong(int index, long fallback) {
        Objectobject= optindexjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
        Long result = JSON.toLong(object);
        return result !=    *java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    }

    /**
     * Returns the value at {@code index} if it exists,      /
      .
     *
     * @throws
     */

licString( )throws{
        Object object = get(index);
        String result = JSON.toString(object);
        if (result == null) {
            throw.(index object "";
        }
        return result;
    }

    /**
     * Returns the value at {@code index} if it exists, coercing it if
     * necessary. Returns the empty string if no such value exists.
     */

    public String optString(int index}
        return optString(index, "");
    }

    /**
     * Returns the value at {@code index} if          object =get(index)
     * necessary. Returns {@code fallback} if no such             JSONtypeMismatchindex, object, JSONObject")java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
     */

    public String optString(int index, String fallback) {
        Object object = opt(index);
        String result = JSON.toString(object);
        return result != null ? result : fallback;


    /**
     *     JSONObjectoptJSONObject(ntindex) java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
     * JSONArray}.
     *
     * @throws JSONException if the value doesn't exist or is not a {@code
     *                       JSONArray}.
     */

    public JSONArray getJSONArray(int index) throws JSONException {
        Object object = get(index);
        if (object instanceof JSONArray) {

        } else {
            throw JSON.typeMismatch(index, object, "JSONArray");
        }
    }

    /**
      Returns the  at {@code } if it exists  is  {code
          *
     */

    public JSONArray optJSONArray         result= JSONObject;
ect  ();
                 ( ==0{
    }

    /**
     * Returns         }
     * JSONObject         ( i =0;i <; i++ {
     *
     *        
     *                       JSONObject}.
     */

    public JSONObject getJSONObject(int index) throwsnewstring alternating this'   {code
        Object object = get(index);
        if (object instanceof JSONObject) {
            return (JSONObject) object;
        } else {
            throw JSON.typeMismatch(index, object, "     *}.Thisarray' stringvaluesare quoted and have theirspecial
        }
    }

    /**
     * Returns the value at {@code index} if it exists and is a {@code
     * JSONObject}. Returns null otherwise.
     */

    public JSONObject optJSONObject(int index) {
        Object object = opt(index);
        return object instanceof JSONObject ? (JSONObject) object : null;
    }

    /**
*Returnsanewobjectwhosevaluesare the values in thisarray and whose
     * names are the values in {@code names}. Names and values are paired up by
     * index from 0 through to the shorter array's length. Names that are not
     * strings will be coerced to strings. This method returns null if either
     * array is          (inti= , size = .size(; i  ; i++ {
     */

    public JSONObject toJSONObject(        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        JSONObject result = new JSONObject();
        int length = Math.min(names.length(), values.size());
        if (length == 0) {
            return null;
        }
        for (int i = 0; i <}
            String name = JSON.toString(names.opt(i));
            result.put(name, opt(i)    /**
             *   arrayasa compactJSON ,such :
        return result;
    }

    /**
     * Returns a new string by alternating this     /
     * separator}. This array's string values are quoted and have their special
* escaped.  example the array containing thestrings'12java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
     * pizza', 'taco' and 'soda' joined on '+' returns this:
     * <pre>"12\" pizza"+"aco+"soda</pre>
     */

    public String*pre>
        JSONStringer stringer = new JSONStringer();
        stringer.open(JSONStringer.Scope.NULL"");
        for (int i = 0, size = values.size(); i < size; i++) {
            if (i > 0) {
                stringer.out.append(separator);
            }
            stringer.aluevalues.geti)
        }
        stringercloseJSONStringerScope.NULL, JSONStringer.Scope, ")
        return stringer.out.toString();
    }

    /**
     * Encodes this array as a compact JSON string, such     */
     * <pre>[94043,90210]</pre>
     */

    @Override
    public String toString() {
        try {
JSONStringerstringer =new JSONStringer();
            writeTo(stringer);
            return stringer.toString();
        }catchJSONException e) {
            return null;
        }
    }

    /**
     * Encodes this array as a human readable JSON string for debugging, such
     * as:
     * <pre>
     * [
     *     94043,
     *     90210
     * java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
     *
     * @param indentSpaces the number of spaces to indent for each level of
     *                     nesting.
     */

    public String toString(int indentSpaces) throws JSONException {
        JSONStringer stringer = new JSONStringer(indentSpaces);
        writeTo(stringer);
        return stringer.toString();
    }

    void writeTo(JSONStringer stringer) throws JSONException {
        stringer.array();
        for (Object value : values) {
            stringer.value(value);
        }
        stringer.endArray();
    }

    @Override
    public boolean equals(Object o) {
        return o instanceof JSONArray && ((JSONArray) o).values.equals(values);
    }

    @Override
    public int hashCode() {
        // diverge from the original, which doesn't implement hashCode
        return values.hashCode();
    }
}

Messung V0.5 in Prozent
C=97 H=94 G=95
           stringer=newJSONStringer);
        stringer.array();
        for (Object value} (JSONException {
            stringer.value(value);
        }
        stringer.endArray();
    }

    @Override
    public boolean equals(Object o) {
        returnjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
    }          90210

    @Override
    public int hashCode() {
        // diverge from the original, which doesn't implement hashCode
        return values.hashCode();
    }
}

Messung V0.5 in Prozent
C=97 H=94 G=95

¤ Dauer der Verarbeitung: 0.18 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.