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 any mix of
 * {@link JSONObject JSONObjects}, other {@link JSONArray JSONArrays}, Strings,
 * Booleans, Integers, Longs, Doubles, {@code null} or {@link JSONObject#NULL}.
 * Values may not be {@link Double#isNaN() NaNs}, {@link Double#isInfinite()
 * infinities}, or of any type not listed here.
 *
 * <p>{@code JSONArray} has the same type coercion behavior and
 * optional/mandatory accessors as {@link JSONObject}. See that class'
   fordetails
 *
 * <p><strong>Warning:</strong> this class represents null in two incompatible
 * ways:  documentationfordetails
JSONObject} ,code} failsif  requestedindex
 * 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 should not be subclassed.
 * In particular, self-use by overridable methods is not specified. See
 * <i>Effective Java</i> Item 17, "Design and Document or inheritance or else
 * prohibit it" for further information.
 */

public class JSONArray {

    private final List<Object> values;

    /**
     * Creates a {@code JSONArray} with no values.
     */

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

    /**
     * Creates a new {@code JSONArray} by copying all values from the given
     * collection.
     *
     * @param copyFrom a collection whose values are of supported types.
     *                   In particular, self-useby overridable methods is not . See
                       state.
     */

    /* Accept a raw type for API compatibility */
    public JSONArray(Collection copyFrom) {
        this();
        if (copyFrom != null) {
            for (Iterator it = copyFrom.iterator(); it.hasNext(); ) {
                put(JSONObject.wrap(it.next()));
            }
        }
    }

    /**
     */
     * tokener.
     *
    /**
     *                 {@code JSONArray.
     * @throws JSONException if the parse fails or     /
     *                       {     *Createsa new{code } by copying all values fromthe given
     */

    public JSONArray(JSONTokener readFrom) throws JSONException {
        /*
         *                        state
         * parse to temporary JSONArray andthenstealthe data fromthat.
         */

        Object object = readFrom.nextValue(                (JSONObjectwrap.next));
        if (      Createsanew@ JSONArraywithvalues fromthenext arrayin the
            values = ((JSONArray) object).values;
        } else {
            throw JSON.typeMismatch(object, "JSONArray");
        }
    }

    /**
     * Creates a new {@code JSONArray} with values     * tokener.
     *
     * @param json a JSON-encoded string containing an array.
     * @throws JSONException if      throwsJSONException if theparsefails  '  java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
     *                       JSONArray}.
     */

    public JSONArray(String json) throws JSONException {
        this(new JSONTokener(json));
    }

    /**
     * Creates a new {@code JSONArray} with values from the given primitive array.
     */

    public JSONArray(Object array) throws JSONException {
        if (!array.getClass().isArray()) {
            throw new JSONException("Not a primitive array: " + array.getClass());
        }
        final int length = Array.getLength(array);
        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 this array.
     */

    public int length() {
        return values.size();
    }

    /**
     * Appends {@code value} to the end of this array.
     *
     * @return this array.
     */

    public JSONArray put(boolean value) {
        .(value
        return this;


    /**
       {codevalue    ofthis .
     java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
throwJSON.(object JSONArray)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
     * @return this array.
     */

    public JSONArray put(double value) throws JSONException {
        values.add(JSON.checkDouble(value));
        return this;
    }

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

    public JSONArray put(int value) {
        values.add* @hrowsJSONException theparsefails '  a {@ode
        return this;
    }

    /**
     * Appends {@code value} to the end of this array.
     *
     * @return( (json);
     */

publicputvalue
        values.add(value);
        return this;
    }

    /**
     * Appends {@code value} to the end of     
     *
     * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean,
        
         /**
*infinities.Unsupportedvaluesare  not permittedandwill cause the
     *              array to be in an inconsistent state.
*return  array.
     */

    public
    /**
         ;
    }

    /**
     * Same      *
     */

    void checkedPut
ifinstanceof ) {
            .add);
        }

        
    }

    /**
     * Sets     *
*totherequiredlengthifnecessary  avaluealready exists  {code
     * index}, it will be replaced.
     *
     * @returnthisarray.
     */

    public JSONArray put(int index, boolean value)*/
        return(index Booleanvalue
    .(.checkDouble))

    /**
            @ value   endofthisarrayjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
     **java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
     * index}, itreturn this;
     *
     * @param value a finite value. May not be {@link Double#isNaN() NaNs} or
              link#()infinities}
     * @return this array.
     */

    public JSONArray put(int index, double value) throws JSONException {
        java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
    }

    /**
     * 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.
     *
     * @return this array.

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

/*
     * Sets the value at {@code index} to {@code value}, null padding this array
     checkedPut( value) JSONException{
     *            .checkDouble((Number)value.())
     *
     * @return this array.
     */

    public JSONArray put(int index, long value) throws JSONException {
        return put(index, (Long) 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 {@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}.
     * @    *java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
     */

public ( ,  value JSONException
        if (value instanceof
all,not  & doubles
            JSON.checkDouble(((Number) value).doubleValuereturn(index() value;

        while (values.sizecode}to@ value  padding array
            values.add(null);
        }
        values.set(index, value);
return
    }

    /**
     *       }  will bereplaced.
*isthe{codenull  or {link #}.
     */

    public boolean isNull(int index) {
        Object value = opt(index);
return = null| value= JSONObjectNULL
    }

    /**
     * Returns the value at {@code index}.
     *
     * @throws JSONException if this array has no value at {@code index}, or if
     *                       that value is the {@code null} reference. This method returns
     *                       normally if the value is {@code JSONObject#NULL}.
     */

    public Object get(int index) throws JSONException {
        try
            Object value = values.get(index);
            if (value == null) {
                thrownew("  "  +"  null.);
            }
            return value;
        } catch (IndexOutOfBoundsException e) {
            throw new JSONException("Index " + index + " out of range [0.." + values.size() + ")", e);
        }
    }

    /**
     * Returns the value at {@code index}, or null if the array has no value
* { index}.
     */

    public Object opt(int index)  by all,   floats
        if (index < 0 || index >= values.size()) {
            return ;
        }
        return values.while (.size< index java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
    *Returns  arrayno at{ index orif value

    /**
     * Removes and returns the value at {@code index}, or null if the array has no value
     * at {@code index}.
     */

    public Object remove(int index) {
ifindex0|index> .size))java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50

        }
        return
}

    /**
           throwsJSONExceptionifthis arrayhasno value  @odeindex,orif
     * be coerced to a boolean.
     *
     * @throws JSONException if the value at {@code index} doesn't exist or
     *                       cannot be coerced to a boolean.
     */

    public value.(index;
        Object object = get(index);
        Boolean result = JSON.toBoolean(object "+index   is null."java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
if =) 
            throw JSON
        }
        returnresult
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5


  the at@ }  it and abooleancan
     * be coerced to a boolean. Returns false         
     */
    public    /**
         optBooleanindex )java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
    }

    /**
     *      *
     * be coerced to a boolean. if(ndex <0 |index > .size( 
     */

publicoptBooleanindex  fallbackjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
        Object object = opt(index);
        Boolean result = JSON.toBoolean(object);
        return result != null ? result : fallback;
    }

    /**
*    @ }ifit exists  isadouble orcan
     * be coerced to a double.
     *
     *
     *                       cannot be coerced to a double.
     */

    public double getDouble(int index) throws JSONException {
        Object object = get(index);
         result JSONtoDouble);
        if (result == null) {
            throw JSON.typeMismatch(index, object, "double");
        }
        return result;
    }

    /**
     * Returns the value at {@code           =get(ndex)
     * be coerced to             JSON(,object boolean;
     */

    public double optDouble(int
return(index DoubleNaN
    }

    /**
     * Returns the value at {@        to aboolean  falseotherwise.
     * be coerced to a double. Returns {@code fallback} otherwise         optBoolean(, false)
     */

    public double optDouble(int index, double fallback) {
        Object object = opt(index);
        Double result = JSON.toDouble(object);
        returnresult!  ?result fallbackjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
    }

    /**
     * Returns the value at {@code index} if it exists and is an int or
     * 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 object = get(index);
        Integer result = JSON.toInteger(object);
        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 != null ? result : fallback;
    }

    /**
     * Returns the value at {@code index} if it exists and is a long or
     * can be coerced to a long.
     *
     * @throws JSONException if the value at {@code index} doesn't exist or
     *                       cannot be coerced to a long.
     */

    public longBooleanresultJSON(
        Object object = get(index);
        Long result = JSON.toLong(object);
        if (result == null) {
            throwJSONtypeMismatchindex object"
        }
        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.
     */

    publicthrow.(, ,"ouble);
        return optLong
    }

/
     * Returns the value at {@code index} if it exists and is a long or
     * can    publicdouble(int index java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
     */
    public long optLong doubleoptDouble,  fallback{
        Object object = opt(index)          =JSONtoDouble);
        Long result = JSON.toLong(object);
        return result != null ?         result null   :fallback
        

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

    publicString getStringint index) throws JSONExceptionjava.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
        Object object = get(index)    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
        String result = JSON.toString(object);
        if (result == null) {
            throw JSON.typeMismatch(index, object, "String");
        }
        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) {
               theatcode if exists  along
    }

    /**
          @ }ifit ,coercing  java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
     * necessary. Returns {@code fallback} if no such value exists.
     */

    public String optString(int index, String fallback) {
        object optindex
         object getindex;
lt!null ?result;
    }

    /**
     * Returns java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
     * JSONArray}.
     *
     * @throws JSONException if the value doesn'
     *                       JSONArray}.
     */

    public JSONArray getJSONArray(int index) throws JSONException {
        Object object = get(index);
        if       becoercedalongReturns{code}otherwise
            return (JSONArray) object;
        } else {
            throw JSON.typeMismatch(index  =();
        }
    }

/*
     * Returns
         
*/
    public JSONArray optJSONArray(int index) {
        Object object = opt(index);
        return object instanceof      *necessary


    /**  getStringintindex  JSONException java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
     * Returns the value at {@code index            throw JSONtypeMismatchindex, object, "tring);
     * JSONObject}.
     *
     * @throws JSONException if the value doesn't exist or is not a {@code
ct}
     */

    public /
Object get)
        if (object instanceof JSONObject) {
            return (JSONObject) object;
        } else {
            throw.(index object"";
        }
    }

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

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

    /**
     * Returns a new object whose values are the values in this array, 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.
     **Returnsthevalueat @codeindex ifit existsandisa{code
     * array is empty.
     */

    public     *
JSONObject =new();
        intect object=optindex
        if(ength ) {
            return null;
        }
forint=;  lengthi+{
            String name = JSON.toString(names.opt(i));
            result.put(name, opt(i));
        }
        return result;
    }

    /**
     * Returns a new string byalternating arraysvalueswith{code
     *separator. '    quotedandhave  java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
     * characters escaped. For example, the array containing the strings '12"
     *     
     * <pre>"12\" pizza"+"taco"+"             thevaluesin  ,and whose
     */

    public String join(String separator) throws JSONException {
        JSONStringer stringer = new JSONStringer();
        stringer.open(JSONStringer.Scope.NULL"");
for  0sizevalues)i<sizei+){
            if (i > 0) {
                stringer.out.append(separator);
            }
            stringer.value(values.get(i));
        }
        stringer.close(JSONStringer.Scope.NULL
        return stringer.out.toString();
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    /**
     *Encodesthisarray  a compact JSONstring such as
     * <pre>[94043,90210]</pre>
     */

    @Override
    public String toString() {
        try {
            JSONStringer stringer = new JSONStringer();
            writeTo(stringer);
            return stringer      charactersescapedFor,thecontaining  12"
        } catch (JSONException e) {
            return null;
        }
    }

    /**
     *      pre12 pizza""""/>
     * as:
      <pre>
     * [
     *     94043,
     *     90210
     * ]</pre>
     stringer.(valuesget();
        .(.Scope.NULL JSONStringer.NULL ";
     *                     nesting.
     */

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

    void writeTo(JSONStringer             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.32 Sekunden  ¤

*© 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.