src/main/java/org/semgus/java/object/Identifier.java
public static Identifier deserialize(Object idDtoRaw) throws DeserializationException {
        if (idDtoRaw instanceof String name) { // just a string; it's non-indexed
            return new Identifier(name);
        } else if (idDtoRaw instanceof JSONArray idDto) { // it's an array; first elem is name, rest are indices
            // parse identifier name
            if (idDto.isEmpty()) {
                throw new DeserializationException("Identifier must include name!");
            }
            Object nameRaw = idDto.get(0);
            if (!(nameRaw instanceof String)) {
                throw new DeserializationException("Identifier name must be a string!", 0);
            }

            // parse indices
            Index[] indices = new Index[idDto.size() - 1];
            for (int i = 0; i < indices.length; i++) {
                try {
                    indices[i] = Index.deserialize(idDto.get(i + 1));
                } catch (DeserializationException e) {
                    throw e.prepend(i + 1);
                }
            }

            return new Identifier((String)nameRaw, indices);
        }
        throw new DeserializationException("Identifier must either be a string or an array!");
    }
/**
     * Deserializes an identifier which may or may not be indexed.
     *
     * @param idDtoRaw A JSON value representing an optionally-indexed identifier.
     * @return The deserialized identifier.
     * @throws DeserializationException If {@code idDtoRaw} is not a valid representation of an identifier.
     */
Deserializes an identifier which may or may not be indexed.
@param idDtoRaw A JSON value representing an optionally-indexed identifier.
@return The deserialized identifier.
@throws DeserializationException If  idDtoRaw is not a valid representation of an identifier.
Deserializes an identifier which may or may not be indexed . @param idDtoRaw A JSON value representing an optionally - indexed identifier . @return The deserialized identifier . @throws DeserializationException If idDtoRaw is not a valid representation of an identifier .
public static Identifier deserialize(Object idDtoRaw) throws DeserializationException {
        if (idDtoRaw instanceof String name) { 
            return new Identifier(name);
        } else if (idDtoRaw instanceof JSONArray idDto) { 
            if (idDto.isEmpty()) {
                throw new DeserializationException("Identifier must include name!");
            }
            Object nameRaw = idDto.get(0);
            if (!(nameRaw instanceof String)) {
                throw new DeserializationException("Identifier name must be a string!", 0);
            }
            Index[] indices = new Index[idDto.size() - 1];
            for (int i = 0; i < indices.length; i++) {
                try {
                    indices[i] = Index.deserialize(idDto.get(i + 1));
                } catch (DeserializationException e) {
                    throw e.prepend(i + 1);
                }
            }
            return new Identifier((String)nameRaw, indices);
        }
        throw new DeserializationException("Identifier must either be a string or an array!");
    }
public static Identifier deserialize ( Object idDtoRaw ) throws DeserializationException { if ( idDtoRaw instanceof String name ) { return new Identifier ( name ) ; } else if ( idDtoRaw instanceof JSONArray idDto ) { if ( idDto . isEmpty ( ) ) { throw new DeserializationException ( "Identifier must include name!" ) ; } Object nameRaw = idDto . get ( 0 ) ; if ( ! ( nameRaw instanceof String ) ) { throw new DeserializationException ( "Identifier name must be a string!" , 0 ) ; } Index [ ] indices = new Index [ idDto . size ( ) - 1 ] ; for ( int i = 0 ; i < indices . length ; i ++ ) { try { indices [ i ] = Index . deserialize ( idDto . get ( i + 1 ) ) ; } catch ( DeserializationException e ) { throw e . prepend ( i + 1 ) ; } } return new Identifier ( ( String ) nameRaw , indices ) ; } throw new DeserializationException ( "Identifier must either be a string or an array!" ) ; }
Deserializes an identifier which may or may not be indexed.
Deserializes an identifier which may or may not be indexed .
// just a string; it's non-indexed // it's an array; first elem is name, rest are indices // parse identifier name // parse indices