public class

CLElement

extends java.lang.Object

 java.lang.Object

↳androidx.constraintlayout.core.parser.CLElement

Subclasses:

CLContainer, CLObject, CLString, CLKey, CLArray, CLToken, CLNumber

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout-core', version: '1.1.0-alpha01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout-core
  • version: 1.1.0-alpha01

Artifact androidx.constraintlayout:constraintlayout-core:1.1.0-alpha01 it located at Google repository (https://maven.google.com/)

Summary

Fields
protected CLContainermContainer

protected longmEnd

protected longmStart

protected static intsBaseIndent

protected static intsMaxLine

Constructors
publicCLElement(char[] content[])

Methods
protected voidaddIndent(java.lang.StringBuilder builder, int indent)

public java.lang.Stringcontent()

public CLElementgetContainer()

protected java.lang.StringgetDebugName()

public longgetEnd()

The character index this element was ended on

public floatgetFloat()

public intgetInt()

public intgetLine()

get the line Number

public longgetStart()

The character index this element was started on

protected java.lang.StringgetStrClass()

public booleanisDone()

public booleanisStarted()

public booleannotStarted()

public voidsetContainer(CLContainer element)

public voidsetEnd(long end)

public voidsetLine(int line)

public voidsetStart(long start)

protected java.lang.StringtoFormattedJSON(int indent, int forceIndent)

protected java.lang.StringtoJSON()

public java.lang.StringtoString()

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Fields

protected long mStart

protected long mEnd

protected CLContainer mContainer

protected static int sMaxLine

protected static int sBaseIndent

Constructors

public CLElement(char[] content[])

Methods

public boolean notStarted()

public void setLine(int line)

public int getLine()

get the line Number

Returns:

return the line number this element was on

public void setStart(long start)

public long getStart()

The character index this element was started on

public long getEnd()

The character index this element was ended on

public void setEnd(long end)

protected void addIndent(java.lang.StringBuilder builder, int indent)

public java.lang.String toString()

protected java.lang.String getStrClass()

protected java.lang.String getDebugName()

public java.lang.String content()

public boolean isDone()

public void setContainer(CLContainer element)

public CLElement getContainer()

public boolean isStarted()

protected java.lang.String toJSON()

protected java.lang.String toFormattedJSON(int indent, int forceIndent)

public int getInt()

public float getFloat()

Source

/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.constraintlayout.core.parser;

public class CLElement {

    private final char[] mContent;
    protected long mStart = -1;
    protected long mEnd = Long.MAX_VALUE;
    protected CLContainer mContainer;
    private int mLine;

    protected static int sMaxLine = 80; // Max number of characters before the formatter indents
    protected static int sBaseIndent = 2; // default indentation value

    public CLElement(char[] content) {
        mContent = content;
    }

    /**
     * @TODO: add description
     */
    public boolean notStarted() {
        return mStart == -1;
    }

    public void setLine(int line) {
        this.mLine = line;
    }

    /**
     * get the line Number
     *
     * @return return the line number this element was on
     */
    public int getLine() {
        return mLine;
    }

    public void setStart(long start) {
        this.mStart = start;
    }

    /**
     * The character index this element was started on
     */
    public long getStart() {
        return this.mStart;
    }

    /**
     * The character index this element was ended on
     */
    public long getEnd() {
        return this.mEnd;
    }

    /**
     * @TODO: add description
     */
    public void setEnd(long end) {
        if (this.mEnd != Long.MAX_VALUE) {
            return;
        }
        this.mEnd = end;
        if (CLParser.sDebug) {
            System.out.println("closing " + this.hashCode() + " -> " + this);
        }
        if (mContainer != null) {
            mContainer.add(this);
        }
    }

    protected void addIndent(StringBuilder builder, int indent) {
        for (int i = 0; i < indent; i++) {
            builder.append(' ');
        }
    }

    @Override
    public String toString() {
        if (mStart > mEnd || mEnd == Long.MAX_VALUE) {
            return this.getClass() + " (INVALID, " + mStart + "-" + mEnd + ")";
        }
        String content = new String(mContent);
        content = content.substring((int) mStart, (int) mEnd + 1);

        return getStrClass() + " (" + mStart + " : " + mEnd + ") <<" + content + ">>";
    }

    protected String getStrClass() {
        String myClass = this.getClass().toString();
        return myClass.substring(myClass.lastIndexOf('.') + 1);
    }

    protected String getDebugName() {
        if (CLParser.sDebug) {
            return getStrClass() + " -> ";
        }
        return "";
    }

    /**
     * @TODO: add description
     */
    public String content() {
        String content = new String(mContent);
        if (mEnd == Long.MAX_VALUE || mEnd < mStart) {
            return content.substring((int) mStart, (int) mStart + 1);
        }
        return content.substring((int) mStart, (int) mEnd + 1);
    }

    public boolean isDone() {
        return mEnd != Long.MAX_VALUE;
    }

    public void setContainer(CLContainer element) {
        mContainer = element;
    }

    public CLElement getContainer() {
        return mContainer;
    }

    public boolean isStarted() {
        return mStart > -1;
    }

    protected String toJSON() {
        return "";
    }

    protected String toFormattedJSON(int indent, int forceIndent) {
        return "";
    }

    /**
     * @TODO: add description
     */
    public int getInt() {
        if (this instanceof CLNumber) {
            return ((CLNumber) this).getInt();
        }
        return 0;
    }

    /**
     * @TODO: add description
     */
    public float getFloat() {
        if (this instanceof CLNumber) {
            return ((CLNumber) this).getFloat();
        }
        return Float.NaN;
    }
}