public String getName() {
        return name;
    }

/* TQuotAuthor.java - author of quotation,
 * SQL operations with the table 'quot_author' in Wiktionary parsed database.
 *
 */
package wikokit.base.wikt.sql.quote;

import wikokit.base.wikipedia.sql.Connect;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import wikokit.base.wikipedia.language.Encodings;
import wikokit.base.wikipedia.sql.PageTableBase;

/**
 * Author of quotation and
 * operations with the table 'quot_author' in MySQL Wiktionary parsed database.
 *
 * Remark: quot_author table has UNIQUE compound KEY (name, wikilink),
 * and wikilink field could be NULL.
 */
public class TQuotAuthor {

    /**
     * Inique identifier of the author.
     */
    private int id;

    /**
     * Author's name of the quote.
     */
    private String name;

    /**
     * A wikilink to author's name in Wikipedia (format: [[w:name|]]),
     * it could not be NULL, though it can be empty ("").
     */
    private String wikilink;

    private final static TQuotAuthor[] NULL_TQUOTAUTHOR_ARRAY = new TQuotAuthor[0];

    public TQuotAuthor(int _id, String _name, String _wikilink) {
        id = _id;
        name = _name;
        wikilink = _wikilink;
    }

    public TQuotAuthor(int _id, String _name) {
        id = _id;
        name = _name;
        wikilink = "";
    }

    /**
     * Gets unique ID from database
     */
    public int getID() {
        return id;
    }

    /**
     * Gets author's name from database.
     */

/**
     * Gets wikilink to Wikipedia (format: [[w:name|]]) for the author.
     */
    public String getWikilink() {
        return wikilink;
    }

    /**
     * Inserts record into the table 'quot_author'.

     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   _wikilink can be empty or NULL
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertName(Connect connect, String _name) {
        return insertNameWikilink(connect, _name, "");
    }

    /**
     * Inserts record into the table 'quot_author'.

     * INSERT INTO quot_author (name,wikilink) VALUES ("Isaac Asimov", "Isaac Asimov");
     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   it could be empty ("")
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertNameWikilink(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor.insertNameAndWikilink()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("INSERT INTO quot_author (name,wikilink) VALUES (\"");
        str_sql.append(safe_name);
        str_sql.append("\", \"");
        str_sql.append(safe_wikilink);
        str_sql.append("\")");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.executeUpdate(str_sql.toString());
                s = connect.conn.createStatement();
                ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID() as id");
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.insertName):: _name='" + _name + "'; _wikilink='" + _wikilink + "'; sql='" + str_sql.toString() + "' error=" + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's first record from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" LIMIT 1;
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor getFirst(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        result = new TQuotAuthor(_id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's array of records from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov";
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor[] get(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\";");
        List<TQuotAuthor> list_authors = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    while (rs.next()) {
                        if (null == list_authors)
                            list_authors = new ArrayList<TQuotAuthor>();
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        list_authors.add(new TQuotAuthor(_id, _name, _wikilink));
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        if (null == list_authors)
            return NULL_TQUOTAUTHOR_ARRAY;
        return (TQuotAuthor[]) list_authors.toArray(NULL_TQUOTAUTHOR_ARRAY);
    }

    /**
     * Get's first suitable row from the table 'quot_author' by the author's name and wikilink.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" AND wikilink="" LIMIT 1;
     *
     * @param _name author's name
     * @param _wikilink author's name, it could be NULL or empty ("")
     *
     * @return NULL if data is absent
     */
    public static TQuotAuthor get(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("SELECT id FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" AND wikilink=\"");
        str_sql.append(safe_wikilink);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Gets ID of a record or inserts record (if it is absent)
     * into the table 'quot_author'.
     *
     * @param _author author's name
     * @param _author_wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                          it could be empty ("")
     */
    public static TQuotAuthor getOrInsert(Connect connect, String _author, String _author_wikilink) {
        if (null == _author || 0 == _author.length())
            return null;
        TQuotAuthor a = TQuotAuthor.getFirst(connect, _author);
        if (null == a)
            a = TQuotAuthor.insertNameWikilink(connect, _author, _author_wikilink);
        return a;
    }

    /**
     * Selects row from the table 'quot_author' by ID.

     *
     * SELECT name,wikilink FROM quot_author WHERE id=1
     *
     * @return null if data is absent
     */
    public static TQuotAuthor getByID(Connect connect, int id) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("SELECT name,wikilink FROM quot_author WHERE id=");
        str_sql.append(id);
        TQuotAuthor quot_author = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        byte[] bb = rs.getBytes("name");
                        String _name = null == bb ? null : Encodings.bytesToUTF8(bb);
                        bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? null : Encodings.bytesToUTF8(bb);
                        quot_author = new TQuotAuthor(id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.getByID()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return quot_author;
    }

    /**
     * Deletes row from the table 'quot_author' by a value of ID.

     * DELETE FROM quot_author WHERE id=4;
     */
    public void delete(Connect connect) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("DELETE FROM quot_author WHERE id=");
        str_sql.append(id);
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.execute(str_sql.toString());
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.delete()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
    }
}


if (null == a)
            a = TQuotAuthor.insertNameWikilink(connect, _author, _author_wikilink);

/* TQuotAuthor.java - author of quotation,
 * SQL operations with the table 'quot_author' in Wiktionary parsed database.
 *
 */
package wikokit.base.wikt.sql.quote;

import wikokit.base.wikipedia.sql.Connect;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import wikokit.base.wikipedia.language.Encodings;
import wikokit.base.wikipedia.sql.PageTableBase;

/**
 * Author of quotation and
 * operations with the table 'quot_author' in MySQL Wiktionary parsed database.
 *
 * Remark: quot_author table has UNIQUE compound KEY (name, wikilink),
 * and wikilink field could be NULL.
 */
public class TQuotAuthor {

    /**
     * Inique identifier of the author.
     */
    private int id;

    /**
     * Author's name of the quote.
     */
    private String name;

    /**
     * A wikilink to author's name in Wikipedia (format: [[w:name|]]),
     * it could not be NULL, though it can be empty ("").
     */
    private String wikilink;

    private final static TQuotAuthor[] NULL_TQUOTAUTHOR_ARRAY = new TQuotAuthor[0];

    public TQuotAuthor(int _id, String _name, String _wikilink) {
        id = _id;
        name = _name;
        wikilink = _wikilink;
    }

    public TQuotAuthor(int _id, String _name) {
        id = _id;
        name = _name;
        wikilink = "";
    }

    /**
     * Gets unique ID from database
     */
    public int getID() {
        return id;
    }

    /**
     * Gets author's name from database.
     */
    public String getName() {
        return name;
    }

    /**
     * Gets wikilink to Wikipedia (format: [[w:name|]]) for the author.
     */
    public String getWikilink() {
        return wikilink;
    }

    /**
     * Inserts record into the table 'quot_author'.

     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   _wikilink can be empty or NULL
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertName(Connect connect, String _name) {
        return insertNameWikilink(connect, _name, "");
    }

    /**
     * Inserts record into the table 'quot_author'.

     * INSERT INTO quot_author (name,wikilink) VALUES ("Isaac Asimov", "Isaac Asimov");
     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   it could be empty ("")
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertNameWikilink(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor.insertNameAndWikilink()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("INSERT INTO quot_author (name,wikilink) VALUES (\"");
        str_sql.append(safe_name);
        str_sql.append("\", \"");
        str_sql.append(safe_wikilink);
        str_sql.append("\")");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.executeUpdate(str_sql.toString());
                s = connect.conn.createStatement();
                ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID() as id");
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.insertName):: _name='" + _name + "'; _wikilink='" + _wikilink + "'; sql='" + str_sql.toString() + "' error=" + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's first record from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" LIMIT 1;
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor getFirst(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        result = new TQuotAuthor(_id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's array of records from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov";
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor[] get(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\";");
        List<TQuotAuthor> list_authors = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    while (rs.next()) {
                        if (null == list_authors)
                            list_authors = new ArrayList<TQuotAuthor>();
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        list_authors.add(new TQuotAuthor(_id, _name, _wikilink));
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        if (null == list_authors)
            return NULL_TQUOTAUTHOR_ARRAY;
        return (TQuotAuthor[]) list_authors.toArray(NULL_TQUOTAUTHOR_ARRAY);
    }

    /**
     * Get's first suitable row from the table 'quot_author' by the author's name and wikilink.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" AND wikilink="" LIMIT 1;
     *
     * @param _name author's name
     * @param _wikilink author's name, it could be NULL or empty ("")
     *
     * @return NULL if data is absent
     */
    public static TQuotAuthor get(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("SELECT id FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" AND wikilink=\"");
        str_sql.append(safe_wikilink);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Gets ID of a record or inserts record (if it is absent)
     * into the table 'quot_author'.
     *
     * @param _author author's name
     * @param _author_wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                          it could be empty ("")
     */
    public static TQuotAuthor getOrInsert(Connect connect, String _author, String _author_wikilink) {
        if (null == _author || 0 == _author.length())
            return null;
        TQuotAuthor a = TQuotAuthor.getFirst(connect, _author);

return a;
    }

    /**
     * Selects row from the table 'quot_author' by ID.

     *
     * SELECT name,wikilink FROM quot_author WHERE id=1
     *
     * @return null if data is absent
     */
    public static TQuotAuthor getByID(Connect connect, int id) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("SELECT name,wikilink FROM quot_author WHERE id=");
        str_sql.append(id);
        TQuotAuthor quot_author = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        byte[] bb = rs.getBytes("name");
                        String _name = null == bb ? null : Encodings.bytesToUTF8(bb);
                        bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? null : Encodings.bytesToUTF8(bb);
                        quot_author = new TQuotAuthor(id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.getByID()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return quot_author;
    }

    /**
     * Deletes row from the table 'quot_author' by a value of ID.

     * DELETE FROM quot_author WHERE id=4;
     */
    public void delete(Connect connect) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("DELETE FROM quot_author WHERE id=");
        str_sql.append(id);
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.execute(str_sql.toString());
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.delete()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
    }
}


while (rs.next()) {
                        if (null == list_authors)
                            list_authors = new ArrayList<TQuotAuthor>();
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        list_authors.add(new TQuotAuthor(_id, _name, _wikilink));
                    }

/* TQuotAuthor.java - author of quotation,
 * SQL operations with the table 'quot_author' in Wiktionary parsed database.
 *
 */
package wikokit.base.wikt.sql.quote;

import wikokit.base.wikipedia.sql.Connect;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import wikokit.base.wikipedia.language.Encodings;
import wikokit.base.wikipedia.sql.PageTableBase;

/**
 * Author of quotation and
 * operations with the table 'quot_author' in MySQL Wiktionary parsed database.
 *
 * Remark: quot_author table has UNIQUE compound KEY (name, wikilink),
 * and wikilink field could be NULL.
 */
public class TQuotAuthor {

    /**
     * Inique identifier of the author.
     */
    private int id;

    /**
     * Author's name of the quote.
     */
    private String name;

    /**
     * A wikilink to author's name in Wikipedia (format: [[w:name|]]),
     * it could not be NULL, though it can be empty ("").
     */
    private String wikilink;

    private final static TQuotAuthor[] NULL_TQUOTAUTHOR_ARRAY = new TQuotAuthor[0];

    public TQuotAuthor(int _id, String _name, String _wikilink) {
        id = _id;
        name = _name;
        wikilink = _wikilink;
    }

    public TQuotAuthor(int _id, String _name) {
        id = _id;
        name = _name;
        wikilink = "";
    }

    /**
     * Gets unique ID from database
     */
    public int getID() {
        return id;
    }

    /**
     * Gets author's name from database.
     */
    public String getName() {
        return name;
    }

    /**
     * Gets wikilink to Wikipedia (format: [[w:name|]]) for the author.
     */
    public String getWikilink() {
        return wikilink;
    }

    /**
     * Inserts record into the table 'quot_author'.

     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   _wikilink can be empty or NULL
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertName(Connect connect, String _name) {
        return insertNameWikilink(connect, _name, "");
    }

    /**
     * Inserts record into the table 'quot_author'.

     * INSERT INTO quot_author (name,wikilink) VALUES ("Isaac Asimov", "Isaac Asimov");
     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   it could be empty ("")
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertNameWikilink(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor.insertNameAndWikilink()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("INSERT INTO quot_author (name,wikilink) VALUES (\"");
        str_sql.append(safe_name);
        str_sql.append("\", \"");
        str_sql.append(safe_wikilink);
        str_sql.append("\")");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.executeUpdate(str_sql.toString());
                s = connect.conn.createStatement();
                ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID() as id");
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.insertName):: _name='" + _name + "'; _wikilink='" + _wikilink + "'; sql='" + str_sql.toString() + "' error=" + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's first record from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" LIMIT 1;
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor getFirst(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        result = new TQuotAuthor(_id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's array of records from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov";
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor[] get(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\";");
        List<TQuotAuthor> list_authors = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {

} finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        if (null == list_authors)
            return NULL_TQUOTAUTHOR_ARRAY;
        return (TQuotAuthor[]) list_authors.toArray(NULL_TQUOTAUTHOR_ARRAY);
    }

    /**
     * Get's first suitable row from the table 'quot_author' by the author's name and wikilink.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" AND wikilink="" LIMIT 1;
     *
     * @param _name author's name
     * @param _wikilink author's name, it could be NULL or empty ("")
     *
     * @return NULL if data is absent
     */
    public static TQuotAuthor get(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("SELECT id FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" AND wikilink=\"");
        str_sql.append(safe_wikilink);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Gets ID of a record or inserts record (if it is absent)
     * into the table 'quot_author'.
     *
     * @param _author author's name
     * @param _author_wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                          it could be empty ("")
     */
    public static TQuotAuthor getOrInsert(Connect connect, String _author, String _author_wikilink) {
        if (null == _author || 0 == _author.length())
            return null;
        TQuotAuthor a = TQuotAuthor.getFirst(connect, _author);
        if (null == a)
            a = TQuotAuthor.insertNameWikilink(connect, _author, _author_wikilink);
        return a;
    }

    /**
     * Selects row from the table 'quot_author' by ID.

     *
     * SELECT name,wikilink FROM quot_author WHERE id=1
     *
     * @return null if data is absent
     */
    public static TQuotAuthor getByID(Connect connect, int id) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("SELECT name,wikilink FROM quot_author WHERE id=");
        str_sql.append(id);
        TQuotAuthor quot_author = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        byte[] bb = rs.getBytes("name");
                        String _name = null == bb ? null : Encodings.bytesToUTF8(bb);
                        bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? null : Encodings.bytesToUTF8(bb);
                        quot_author = new TQuotAuthor(id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.getByID()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return quot_author;
    }

    /**
     * Deletes row from the table 'quot_author' by a value of ID.

     * DELETE FROM quot_author WHERE id=4;
     */
    public void delete(Connect connect) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("DELETE FROM quot_author WHERE id=");
        str_sql.append(id);
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.execute(str_sql.toString());
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.delete()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
    }
}


try {
                s.executeUpdate(str_sql.toString());
                s = connect.conn.createStatement();
                ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID() as id");
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }

/* TQuotAuthor.java - author of quotation,
 * SQL operations with the table 'quot_author' in Wiktionary parsed database.
 *
 */
package wikokit.base.wikt.sql.quote;

import wikokit.base.wikipedia.sql.Connect;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import wikokit.base.wikipedia.language.Encodings;
import wikokit.base.wikipedia.sql.PageTableBase;

/**
 * Author of quotation and
 * operations with the table 'quot_author' in MySQL Wiktionary parsed database.
 *
 * Remark: quot_author table has UNIQUE compound KEY (name, wikilink),
 * and wikilink field could be NULL.
 */
public class TQuotAuthor {

    /**
     * Inique identifier of the author.
     */
    private int id;

    /**
     * Author's name of the quote.
     */
    private String name;

    /**
     * A wikilink to author's name in Wikipedia (format: [[w:name|]]),
     * it could not be NULL, though it can be empty ("").
     */
    private String wikilink;

    private final static TQuotAuthor[] NULL_TQUOTAUTHOR_ARRAY = new TQuotAuthor[0];

    public TQuotAuthor(int _id, String _name, String _wikilink) {
        id = _id;
        name = _name;
        wikilink = _wikilink;
    }

    public TQuotAuthor(int _id, String _name) {
        id = _id;
        name = _name;
        wikilink = "";
    }

    /**
     * Gets unique ID from database
     */
    public int getID() {
        return id;
    }

    /**
     * Gets author's name from database.
     */
    public String getName() {
        return name;
    }

    /**
     * Gets wikilink to Wikipedia (format: [[w:name|]]) for the author.
     */
    public String getWikilink() {
        return wikilink;
    }

    /**
     * Inserts record into the table 'quot_author'.

     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   _wikilink can be empty or NULL
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertName(Connect connect, String _name) {
        return insertNameWikilink(connect, _name, "");
    }

    /**
     * Inserts record into the table 'quot_author'.

     * INSERT INTO quot_author (name,wikilink) VALUES ("Isaac Asimov", "Isaac Asimov");
     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   it could be empty ("")
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertNameWikilink(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor.insertNameAndWikilink()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("INSERT INTO quot_author (name,wikilink) VALUES (\"");
        str_sql.append(safe_name);
        str_sql.append("\", \"");
        str_sql.append(safe_wikilink);
        str_sql.append("\")");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();

} catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.insertName):: _name='" + _name + "'; _wikilink='" + _wikilink + "'; sql='" + str_sql.toString() + "' error=" + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's first record from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" LIMIT 1;
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor getFirst(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        result = new TQuotAuthor(_id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's array of records from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov";
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor[] get(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\";");
        List<TQuotAuthor> list_authors = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    while (rs.next()) {
                        if (null == list_authors)
                            list_authors = new ArrayList<TQuotAuthor>();
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        list_authors.add(new TQuotAuthor(_id, _name, _wikilink));
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        if (null == list_authors)
            return NULL_TQUOTAUTHOR_ARRAY;
        return (TQuotAuthor[]) list_authors.toArray(NULL_TQUOTAUTHOR_ARRAY);
    }

    /**
     * Get's first suitable row from the table 'quot_author' by the author's name and wikilink.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" AND wikilink="" LIMIT 1;
     *
     * @param _name author's name
     * @param _wikilink author's name, it could be NULL or empty ("")
     *
     * @return NULL if data is absent
     */
    public static TQuotAuthor get(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("SELECT id FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" AND wikilink=\"");
        str_sql.append(safe_wikilink);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Gets ID of a record or inserts record (if it is absent)
     * into the table 'quot_author'.
     *
     * @param _author author's name
     * @param _author_wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                          it could be empty ("")
     */
    public static TQuotAuthor getOrInsert(Connect connect, String _author, String _author_wikilink) {
        if (null == _author || 0 == _author.length())
            return null;
        TQuotAuthor a = TQuotAuthor.getFirst(connect, _author);
        if (null == a)
            a = TQuotAuthor.insertNameWikilink(connect, _author, _author_wikilink);
        return a;
    }

    /**
     * Selects row from the table 'quot_author' by ID.

     *
     * SELECT name,wikilink FROM quot_author WHERE id=1
     *
     * @return null if data is absent
     */
    public static TQuotAuthor getByID(Connect connect, int id) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("SELECT name,wikilink FROM quot_author WHERE id=");
        str_sql.append(id);
        TQuotAuthor quot_author = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        byte[] bb = rs.getBytes("name");
                        String _name = null == bb ? null : Encodings.bytesToUTF8(bb);
                        bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? null : Encodings.bytesToUTF8(bb);
                        quot_author = new TQuotAuthor(id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.getByID()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return quot_author;
    }

    /**
     * Deletes row from the table 'quot_author' by a value of ID.

     * DELETE FROM quot_author WHERE id=4;
     */
    public void delete(Connect connect) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("DELETE FROM quot_author WHERE id=");
        str_sql.append(id);
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.execute(str_sql.toString());
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.delete()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
    }
}


/* TQuotAuthor.java - author of quotation,
 * SQL operations with the table 'quot_author' in Wiktionary parsed database.
 *
 */
package wikokit.base.wikt.sql.quote;

import wikokit.base.wikipedia.sql.Connect;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import wikokit.base.wikipedia.language.Encodings;
import wikokit.base.wikipedia.sql.PageTableBase;

/**
 * Author of quotation and
 * operations with the table 'quot_author' in MySQL Wiktionary parsed database.
 *
 * Remark: quot_author table has UNIQUE compound KEY (name, wikilink),
 * and wikilink field could be NULL.
 */
public class TQuotAuthor {

    /**
     * Inique identifier of the author.
     */
    private int id;

    /**
     * Author's name of the quote.
     */
    private String name;

    /**
     * A wikilink to author's name in Wikipedia (format: [[w:name|]]),
     * it could not be NULL, though it can be empty ("").
     */
    private String wikilink;

    private final static TQuotAuthor[] NULL_TQUOTAUTHOR_ARRAY = new TQuotAuthor[0];

    public TQuotAuthor(int _id, String _name, String _wikilink) {
        id = _id;
        name = _name;
        wikilink = _wikilink;
    }

    public TQuotAuthor(int _id, String _name) {
        id = _id;
        name = _name;
        wikilink = "";
    }

    /**
     * Gets unique ID from database
     */
    public int getID() {
        return id;
    }

    /**
     * Gets author's name from database.
     */
    public String getName() {
        return name;
    }

    /**
     * Gets wikilink to Wikipedia (format: [[w:name|]]) for the author.
     */
    public String getWikilink() {
        return wikilink;
    }

    /**
     * Inserts record into the table 'quot_author'.

     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   _wikilink can be empty or NULL
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertName(Connect connect, String _name) {
        return insertNameWikilink(connect, _name, "");
    }

    /**
     * Inserts record into the table 'quot_author'.

     * INSERT INTO quot_author (name,wikilink) VALUES ("Isaac Asimov", "Isaac Asimov");
     *
     * @param _name author's name, it is not empty or NULL
     * @param _wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                   it could be empty ("")
     * @return inserted record, or null if insertion failed
     */
    public static TQuotAuthor insertNameWikilink(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor.insertNameAndWikilink()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("INSERT INTO quot_author (name,wikilink) VALUES (\"");
        str_sql.append(safe_name);
        str_sql.append("\", \"");
        str_sql.append(safe_wikilink);
        str_sql.append("\")");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.executeUpdate(str_sql.toString());
                s = connect.conn.createStatement();
                ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID() as id");
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.insertName):: _name='" + _name + "'; _wikilink='" + _wikilink + "'; sql='" + str_sql.toString() + "' error=" + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's first record from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" LIMIT 1;
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor getFirst(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        result = new TQuotAuthor(_id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Get's array of records from the table 'quot_author' by the author's name.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov";
     *
     * @param _name author's name
     * @return NULL if data is absent
     */
    public static TQuotAuthor[] get(Connect connect, String _name) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor[] TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        str_sql.append("SELECT id,wikilink FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\";");
        List<TQuotAuthor> list_authors = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    while (rs.next()) {
                        if (null == list_authors)
                            list_authors = new ArrayList<TQuotAuthor>();
                        int _id = rs.getInt("id");
                        byte[] bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? "" : Encodings.bytesToUTF8(bb);
                        list_authors.add(new TQuotAuthor(_id, _name, _wikilink));
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        if (null == list_authors)
            return NULL_TQUOTAUTHOR_ARRAY;
        return (TQuotAuthor[]) list_authors.toArray(NULL_TQUOTAUTHOR_ARRAY);
    }

    /**
     * Get's first suitable row from the table 'quot_author' by the author's name and wikilink.

.
     * SELECT id,wikilink FROM quot_author WHERE name="Azimov" AND wikilink="" LIMIT 1;
     *
     * @param _name author's name
     * @param _wikilink author's name, it could be NULL or empty ("")
     *
     * @return NULL if data is absent
     */
    public static TQuotAuthor get(Connect connect, String _name, String _wikilink) {
        if (null == _name || 0 == _name.length()) {
            System.out.println("Error (TQuotAuthor TQuotAuthor.get()):: null argument: author's name.");
            return null;
        }
        if (null == _wikilink)
            _wikilink = "";
        StringBuilder str_sql = new StringBuilder();
        String safe_name = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _name);
        String safe_wikilink = PageTableBase.convertToSafeStringEncodeToDBWunderscore(connect, _wikilink);
        str_sql.append("SELECT id FROM quot_author WHERE name=\"");
        str_sql.append(safe_name);
        str_sql.append("\" AND wikilink=\"");
        str_sql.append(safe_wikilink);
        str_sql.append("\" LIMIT 1");
        TQuotAuthor result = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next())
                        result = new TQuotAuthor(rs.getInt("id"), _name, _wikilink);
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.get()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return result;
    }

    /**
     * Gets ID of a record or inserts record (if it is absent)
     * into the table 'quot_author'.
     *
     * @param _author author's name
     * @param _author_wikilink  link to author's name in Wikipedia (format: [[w:name|]]),
     *                          it could be empty ("")
     */
    public static TQuotAuthor getOrInsert(Connect connect, String _author, String _author_wikilink) {
        if (null == _author || 0 == _author.length())
            return null;
        TQuotAuthor a = TQuotAuthor.getFirst(connect, _author);
        if (null == a)
            a = TQuotAuthor.insertNameWikilink(connect, _author, _author_wikilink);
        return a;
    }

    /**
     * Selects row from the table 'quot_author' by ID.

     *
     * SELECT name,wikilink FROM quot_author WHERE id=1
     *
     * @return null if data is absent
     */
    public static TQuotAuthor getByID(Connect connect, int id) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("SELECT name,wikilink FROM quot_author WHERE id=");
        str_sql.append(id);
        TQuotAuthor quot_author = null;
        try {
            Statement s = connect.conn.createStatement();
            try {
                ResultSet rs = s.executeQuery(str_sql.toString());
                try {
                    if (rs.next()) {
                        byte[] bb = rs.getBytes("name");
                        String _name = null == bb ? null : Encodings.bytesToUTF8(bb);
                        bb = rs.getBytes("wikilink");
                        String _wikilink = null == bb ? null : Encodings.bytesToUTF8(bb);
                        quot_author = new TQuotAuthor(id, _name, _wikilink);
                    }
                } finally {
                    rs.close();
                }
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.getByID()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
        return quot_author;
    }

    /**
     * Deletes row from the table 'quot_author' by a value of

ID.

     * DELETE FROM quot_author WHERE id=4;
     */
    public void delete(Connect connect) {
        StringBuilder str_sql = new StringBuilder();
        str_sql.append("DELETE FROM quot_author WHERE id=");
        str_sql.append(id);
        try {
            Statement s = connect.conn.createStatement();
            try {
                s.execute(str_sql.toString());
            } finally {
                s.close();
            }
        } catch (SQLException ex) {
            System.out.println("SQLException (TQuotAuthor.delete()):: sql='" + str_sql.toString() + "' " + ex.getMessage());
        }
    }
}


package com.android.settings.deviceinfo.storage;

import android.annotation.NonNull;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.text.TextUtils;
import com.android.settings.R;
import java.io.File;

/**
 * This object contains a {@link VolumeInfo} for a mountable storage or a {@link DiskInfo} for an
 * unsupported disk which is not able to be mounted automatically.
 */
public class StorageEntry implements Comparable<StorageEntry>, Parcelable {

    private final VolumeInfo mVolumeInfo;

    private final DiskInfo mUnsupportedDiskInfo;

    private final VolumeRecord mMissingVolumeRecord;

    private final String mVolumeInfoDescription;

    public StorageEntry(@NonNull Context context, @NonNull VolumeInfo volumeInfo) {
        mVolumeInfo = volumeInfo;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = null;
        if (isDefaultInternalStorage()) {
            mVolumeInfoDescription = context.getResources().getString(R.string.storage_default_internal_storage);
        } else {
            mVolumeInfoDescription = context.getSystemService(StorageManager.class).getBestVolumeDescription(mVolumeInfo);
        }
    }

    public StorageEntry(@NonNull DiskInfo diskInfo) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = diskInfo;
        mMissingVolumeRecord = null;
        mVolumeInfoDescription = null;
    }

    public StorageEntry(@NonNull VolumeRecord volumeRecord) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = volumeRecord;
        mVolumeInfoDescription = null;
    }

    private StorageEntry(Parcel in) {
        mVolumeInfo = in.readParcelable(VolumeInfo.class.getClassLoader());
        mUnsupportedDiskInfo = in.readParcelable(DiskInfo.class.getClassLoader());
        mMissingVolumeRecord = in.readParcelable(VolumeRecord.class.getClassLoader());
        mVolumeInfoDescription = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(mVolumeInfo, 0);
        out.writeParcelable(mUnsupportedDiskInfo, 0);
        out.writeParcelable(mMissingVolumeRecord, 0);
        out.writeString(mVolumeInfoDescription);
    }

    public static final Parcelable.Creator<StorageEntry> CREATOR = new Parcelable.Creator<StorageEntry>() {

        public StorageEntry createFromParcel(Parcel in) {
            return new StorageEntry(in);
        }

        public StorageEntry[] newArray(int size) {
            return new StorageEntry[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof StorageEntry)) {
            return false;
        }
        final StorageEntry StorageEntry = (StorageEntry) o;
        if (isVolumeInfo()) {
            return mVolumeInfo.equals(StorageEntry.mVolumeInfo);
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.equals(StorageEntry.mUnsupportedDiskInfo);
        }
        return mMissingVolumeRecord.equals(StorageEntry.mMissingVolumeRecord);
    }

    @Override
    public int hashCode() {
        if (isVolumeInfo()) {
            return mVolumeInfo.hashCode();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.hashCode();
        }
        return mMissingVolumeRecord.hashCode();
    }

    @Override
    public String toString() {
        if (isVolumeInfo()) {
            return mVolumeInfo.toString();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.toString();
        }
        return mMissingVolumeRecord.toString();
    }

    @Override
    public int compareTo(StorageEntry other) {
        if (isDefaultInternalStorage() && !other.isDefaultInternalStorage()) {
            return -1;
        }
        if (!isDefaultInternalStorage() && other.isDefaultInternalStorage()) {
            return 1;
        }
        if (isVolumeInfo() && !other.isVolumeInfo()) {
            return -1;
        }
        if (!isVolumeInfo() && other.isVolumeInfo()) {
            return 1;
        }
        if (isPrivate() && !other.isPrivate()) {
            return -1;
        }
        if (!isPrivate() && other.isPrivate()) {
            return 1;
        }
        if (isMounted() && !other.isMounted()) {
            return -1;
        }
        if (!isMounted() && other.isMounted()) {
            return 1;
        }
        if (!isVolumeRecordMissed() && other.isVolumeRecordMissed()) {
            return -1;
        }
        if (isVolumeRecordMissed() && !other.isVolumeRecordMissed()) {
            return 1;
        }
        if (getDescription() == null) {
            return 1;
        }
        if (other.getDescription() == null) {
            return -1;
        }
        return getDescription().compareTo(other.getDescription());
    }

    public static StorageEntry getDefaultInternalStorageEntry(Context context) {
        return new StorageEntry(context, context.getSystemService(StorageManager.class).findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL));
    }

    /**
     * If it's a VolumeInfo.
     */
    public boolean isVolumeInfo() {
        return mVolumeInfo != null;
    }

    /**
     * If it's an unsupported DiskInfo.
     */
    public boolean isDiskInfoUnsupported() {
        return mUnsupportedDiskInfo != null;
    }

    /**
     * If it's a missing VolumeRecord.
     */
    public boolean isVolumeRecordMissed() {
        return mMissingVolumeRecord != null;
    }

    /**
     * If it's a default internal storage.
     */
    public boolean isDefaultInternalStorage() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE && TextUtils.equals(mVolumeInfo.getId(), VolumeInfo.ID_PRIVATE_INTERNAL);
        }
        return false;
    }

    /**
     * If it's a mounted storage.
     */

{
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED || mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED_READ_ONLY);
    }

    /**
     * If it's an unmounted storage.
     */
    public boolean isUnmounted() {
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTED);
    }

    /**
     * If it's an unmountable storage.
     */
    public boolean isUnmountable() {
        return mVolumeInfo == null ? false : mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTABLE;
    }

    /**
     * If it's a private storage.
     */
    public boolean isPrivate() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE;
    }

    /**
     * If it's a public storage.
     */
    public boolean isPublic() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PUBLIC;
    }

    /**
     * Returns description.
     */
    public String getDescription() {
        if (isVolumeInfo()) {
            return mVolumeInfoDescription;
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getDescription();
        }
        return mMissingVolumeRecord.getNickname();
    }

    /**
     * Returns ID.
     */
    public String getId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns disk ID.
     */
    public String getDiskId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getDiskId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return null;
    }

    /**
     * Returns fsUuid.
     */
    public String getFsUuid() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getFsUuid();
        }
        if (isDiskInfoUnsupported()) {
            return null;
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns root file if it's a VolumeInfo.
     */
    public File getPath() {
        return mVolumeInfo == null ? null : mVolumeInfo.getPath();
    }

    /**
     * Returns VolumeInfo of the StorageEntry.
     */
    public VolumeInfo getVolumeInfo() {
        return mVolumeInfo;
    }
}


{
        if (isVolumeInfo()) {
            return mVolumeInfo.hashCode();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.hashCode();
        }
        return mMissingVolumeRecord.hashCode();
    }

package com.android.settings.deviceinfo.storage;

import android.annotation.NonNull;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.text.TextUtils;
import com.android.settings.R;
import java.io.File;

/**
 * This object contains a {@link VolumeInfo} for a mountable storage or a {@link DiskInfo} for an
 * unsupported disk which is not able to be mounted automatically.
 */
public class StorageEntry implements Comparable<StorageEntry>, Parcelable {

    private final VolumeInfo mVolumeInfo;

    private final DiskInfo mUnsupportedDiskInfo;

    private final VolumeRecord mMissingVolumeRecord;

    private final String mVolumeInfoDescription;

    public StorageEntry(@NonNull Context context, @NonNull VolumeInfo volumeInfo) {
        mVolumeInfo = volumeInfo;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = null;
        if (isDefaultInternalStorage()) {
            mVolumeInfoDescription = context.getResources().getString(R.string.storage_default_internal_storage);
        } else {
            mVolumeInfoDescription = context.getSystemService(StorageManager.class).getBestVolumeDescription(mVolumeInfo);
        }
    }

    public StorageEntry(@NonNull DiskInfo diskInfo) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = diskInfo;
        mMissingVolumeRecord = null;
        mVolumeInfoDescription = null;
    }

    public StorageEntry(@NonNull VolumeRecord volumeRecord) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = volumeRecord;
        mVolumeInfoDescription = null;
    }

    private StorageEntry(Parcel in) {
        mVolumeInfo = in.readParcelable(VolumeInfo.class.getClassLoader());
        mUnsupportedDiskInfo = in.readParcelable(DiskInfo.class.getClassLoader());
        mMissingVolumeRecord = in.readParcelable(VolumeRecord.class.getClassLoader());
        mVolumeInfoDescription = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(mVolumeInfo, 0);
        out.writeParcelable(mUnsupportedDiskInfo, 0);
        out.writeParcelable(mMissingVolumeRecord, 0);
        out.writeString(mVolumeInfoDescription);
    }

    public static final Parcelable.Creator<StorageEntry> CREATOR = new Parcelable.Creator<StorageEntry>() {

        public StorageEntry createFromParcel(Parcel in) {
            return new StorageEntry(in);
        }

        public StorageEntry[] newArray(int size) {
            return new StorageEntry[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof StorageEntry)) {
            return false;
        }
        final StorageEntry StorageEntry = (StorageEntry) o;
        if (isVolumeInfo()) {
            return mVolumeInfo.equals(StorageEntry.mVolumeInfo);
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.equals(StorageEntry.mUnsupportedDiskInfo);
        }
        return mMissingVolumeRecord.equals(StorageEntry.mMissingVolumeRecord);
    }

    @Override
    public int hashCode()

    @Override
    public String toString() {
        if (isVolumeInfo()) {
            return mVolumeInfo.toString();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.toString();
        }
        return mMissingVolumeRecord.toString();
    }

    @Override
    public int compareTo(StorageEntry other) {
        if (isDefaultInternalStorage() && !other.isDefaultInternalStorage()) {
            return -1;
        }
        if (!isDefaultInternalStorage() && other.isDefaultInternalStorage()) {
            return 1;
        }
        if (isVolumeInfo() && !other.isVolumeInfo()) {
            return -1;
        }
        if (!isVolumeInfo() && other.isVolumeInfo()) {
            return 1;
        }
        if (isPrivate() && !other.isPrivate()) {
            return -1;
        }
        if (!isPrivate() && other.isPrivate()) {
            return 1;
        }
        if (isMounted() && !other.isMounted()) {
            return -1;
        }
        if (!isMounted() && other.isMounted()) {
            return 1;
        }
        if (!isVolumeRecordMissed() && other.isVolumeRecordMissed()) {
            return -1;
        }
        if (isVolumeRecordMissed() && !other.isVolumeRecordMissed()) {
            return 1;
        }
        if (getDescription() == null) {
            return 1;
        }
        if (other.getDescription() == null) {
            return -1;
        }
        return getDescription().compareTo(other.getDescription());
    }

    public static StorageEntry getDefaultInternalStorageEntry(Context context) {
        return new StorageEntry(context, context.getSystemService(StorageManager.class).findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL));
    }

    /**
     * If it's a VolumeInfo.
     */
    public boolean isVolumeInfo() {
        return mVolumeInfo != null;
    }

    /**
     * If it's an unsupported DiskInfo.
     */
    public boolean isDiskInfoUnsupported() {
        return mUnsupportedDiskInfo != null;
    }

    /**
     * If it's a missing VolumeRecord.
     */
    public boolean isVolumeRecordMissed() {
        return mMissingVolumeRecord != null;
    }

    /**
     * If it's a default internal storage.
     */
    public boolean isDefaultInternalStorage() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE && TextUtils.equals(mVolumeInfo.getId(), VolumeInfo.ID_PRIVATE_INTERNAL);
        }
        return false;
    }

    /**
     * If it's a mounted storage.
     */
    public boolean isMounted() {
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED || mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED_READ_ONLY);
    }

    /**
     * If it's an unmounted storage.
     */
    public boolean isUnmounted() {
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTED);
    }

    /**
     * If it's an unmountable storage.
     */
    public boolean isUnmountable() {
        return mVolumeInfo == null ? false : mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTABLE;
    }

    /**
     * If it's a private storage.
     */
    public boolean isPrivate() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE;
    }

    /**
     * If it's a public storage.
     */
    public boolean isPublic() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PUBLIC;
    }

    /**
     * Returns description.
     */
    public String getDescription() {
        if (isVolumeInfo()) {
            return mVolumeInfoDescription;
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getDescription();
        }
        return mMissingVolumeRecord.getNickname();
    }

    /**
     * Returns ID.
     */
    public String getId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns disk ID.
     */
    public String getDiskId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getDiskId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return null;
    }

    /**
     * Returns fsUuid.
     */
    public String getFsUuid() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getFsUuid();
        }
        if (isDiskInfoUnsupported()) {
            return null;
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns root file if it's a VolumeInfo.
     */
    public File getPath() {
        return mVolumeInfo == null ? null : mVolumeInfo.getPath();
    }

    /**
     * Returns VolumeInfo of the StorageEntry.
     */
    public VolumeInfo getVolumeInfo() {
        return mVolumeInfo;
    }
}


        if (isVolumeInfo()) {
            return mVolumeInfoDescription;
        }

package com.android.settings.deviceinfo.storage;

import android.annotation.NonNull;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.text.TextUtils;
import com.android.settings.R;
import java.io.File;

/**
 * This object contains a {@link VolumeInfo} for a mountable storage or a {@link DiskInfo} for an
 * unsupported disk which is not able to be mounted automatically.
 */
public class StorageEntry implements Comparable<StorageEntry>, Parcelable {

    private final VolumeInfo mVolumeInfo;

    private final DiskInfo mUnsupportedDiskInfo;

    private final VolumeRecord mMissingVolumeRecord;

    private final String mVolumeInfoDescription;

    public StorageEntry(@NonNull Context context, @NonNull VolumeInfo volumeInfo) {
        mVolumeInfo = volumeInfo;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = null;
        if (isDefaultInternalStorage()) {
            mVolumeInfoDescription = context.getResources().getString(R.string.storage_default_internal_storage);
        } else {
            mVolumeInfoDescription = context.getSystemService(StorageManager.class).getBestVolumeDescription(mVolumeInfo);
        }
    }

    public StorageEntry(@NonNull DiskInfo diskInfo) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = diskInfo;
        mMissingVolumeRecord = null;
        mVolumeInfoDescription = null;
    }

    public StorageEntry(@NonNull VolumeRecord volumeRecord) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = volumeRecord;
        mVolumeInfoDescription = null;
    }

    private StorageEntry(Parcel in) {
        mVolumeInfo = in.readParcelable(VolumeInfo.class.getClassLoader());
        mUnsupportedDiskInfo = in.readParcelable(DiskInfo.class.getClassLoader());
        mMissingVolumeRecord = in.readParcelable(VolumeRecord.class.getClassLoader());
        mVolumeInfoDescription = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(mVolumeInfo, 0);
        out.writeParcelable(mUnsupportedDiskInfo, 0);
        out.writeParcelable(mMissingVolumeRecord, 0);
        out.writeString(mVolumeInfoDescription);
    }

    public static final Parcelable.Creator<StorageEntry> CREATOR = new Parcelable.Creator<StorageEntry>() {

        public StorageEntry createFromParcel(Parcel in) {
            return new StorageEntry(in);
        }

        public StorageEntry[] newArray(int size) {
            return new StorageEntry[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof StorageEntry)) {
            return false;
        }
        final StorageEntry StorageEntry = (StorageEntry) o;
        if (isVolumeInfo()) {
            return mVolumeInfo.equals(StorageEntry.mVolumeInfo);
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.equals(StorageEntry.mUnsupportedDiskInfo);
        }
        return mMissingVolumeRecord.equals(StorageEntry.mMissingVolumeRecord);
    }

    @Override
    public int hashCode() {
        if (isVolumeInfo()) {
            return mVolumeInfo.hashCode();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.hashCode();
        }
        return mMissingVolumeRecord.hashCode();
    }

    @Override
    public String toString() {
        if (isVolumeInfo()) {
            return mVolumeInfo.toString();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.toString();
        }
        return mMissingVolumeRecord.toString();
    }

    @Override
    public int compareTo(StorageEntry other) {
        if (isDefaultInternalStorage() && !other.isDefaultInternalStorage()) {
            return -1;
        }
        if (!isDefaultInternalStorage() && other.isDefaultInternalStorage()) {
            return 1;
        }
        if (isVolumeInfo() && !other.isVolumeInfo()) {
            return -1;
        }
        if (!isVolumeInfo() && other.isVolumeInfo()) {
            return 1;
        }
        if (isPrivate() && !other.isPrivate()) {
            return -1;
        }
        if (!isPrivate() && other.isPrivate()) {
            return 1;
        }
        if (isMounted() && !other.isMounted()) {
            return -1;
        }
        if (!isMounted() && other.isMounted()) {
            return 1;
        }
        if (!isVolumeRecordMissed() && other.isVolumeRecordMissed()) {
            return -1;
        }
        if (isVolumeRecordMissed() && !other.isVolumeRecordMissed()) {
            return 1;
        }
        if (getDescription() == null) {
            return 1;
        }
        if (other.getDescription() == null) {
            return -1;
        }
        return getDescription().compareTo(other.getDescription());
    }

    public static StorageEntry getDefaultInternalStorageEntry(Context context) {
        return new StorageEntry(context, context.getSystemService(StorageManager.class).findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL));
    }

    /**
     * If it's a VolumeInfo.
     */
    public boolean isVolumeInfo() {
        return mVolumeInfo != null;
    }

    /**
     * If it's an unsupported DiskInfo.
     */
    public boolean isDiskInfoUnsupported() {
        return mUnsupportedDiskInfo != null;
    }

    /**
     * If it's a missing VolumeRecord.
     */
    public boolean isVolumeRecordMissed() {
        return mMissingVolumeRecord != null;
    }

    /**
     * If it's a default internal storage.
     */
    public boolean isDefaultInternalStorage() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE && TextUtils.equals(mVolumeInfo.getId(), VolumeInfo.ID_PRIVATE_INTERNAL);
        }
        return false;
    }

    /**
     * If it's a mounted storage.
     */
    public boolean isMounted() {
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED || mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED_READ_ONLY);
    }

    /**
     * If it's an unmounted storage.
     */
    public boolean isUnmounted() {
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTED);
    }

    /**
     * If it's an unmountable storage.
     */
    public boolean isUnmountable() {
        return mVolumeInfo == null ? false : mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTABLE;
    }

    /**
     * If it's a private storage.
     */
    public boolean isPrivate() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE;
    }

    /**
     * If it's a public storage.
     */
    public boolean isPublic() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PUBLIC;
    }

    /**
     * Returns description.
     */
    public String getDescription() {

        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getDescription();
        }
        return mMissingVolumeRecord.getNickname();
    }

    /**
     * Returns ID.
     */
    public String getId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns disk ID.
     */
    public String getDiskId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getDiskId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return null;
    }

    /**
     * Returns fsUuid.
     */
    public String getFsUuid() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getFsUuid();
        }
        if (isDiskInfoUnsupported()) {
            return null;
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns root file if it's a VolumeInfo.
     */
    public File getPath() {
        return mVolumeInfo == null ? null : mVolumeInfo.getPath();
    }

    /**
     * Returns VolumeInfo of the StorageEntry.
     */
    public VolumeInfo getVolumeInfo() {
        return mVolumeInfo;
    }
}


if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getDescription();
        }

package com.android.settings.deviceinfo.storage;

import android.annotation.NonNull;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.storage.DiskInfo;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.text.TextUtils;
import com.android.settings.R;
import java.io.File;

/**
 * This object contains a {@link VolumeInfo} for a mountable storage or a {@link DiskInfo} for an
 * unsupported disk which is not able to be mounted automatically.
 */
public class StorageEntry implements Comparable<StorageEntry>, Parcelable {

    private final VolumeInfo mVolumeInfo;

    private final DiskInfo mUnsupportedDiskInfo;

    private final VolumeRecord mMissingVolumeRecord;

    private final String mVolumeInfoDescription;

    public StorageEntry(@NonNull Context context, @NonNull VolumeInfo volumeInfo) {
        mVolumeInfo = volumeInfo;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = null;
        if (isDefaultInternalStorage()) {
            mVolumeInfoDescription = context.getResources().getString(R.string.storage_default_internal_storage);
        } else {
            mVolumeInfoDescription = context.getSystemService(StorageManager.class).getBestVolumeDescription(mVolumeInfo);
        }
    }

    public StorageEntry(@NonNull DiskInfo diskInfo) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = diskInfo;
        mMissingVolumeRecord = null;
        mVolumeInfoDescription = null;
    }

    public StorageEntry(@NonNull VolumeRecord volumeRecord) {
        mVolumeInfo = null;
        mUnsupportedDiskInfo = null;
        mMissingVolumeRecord = volumeRecord;
        mVolumeInfoDescription = null;
    }

    private StorageEntry(Parcel in) {
        mVolumeInfo = in.readParcelable(VolumeInfo.class.getClassLoader());
        mUnsupportedDiskInfo = in.readParcelable(DiskInfo.class.getClassLoader());
        mMissingVolumeRecord = in.readParcelable(VolumeRecord.class.getClassLoader());
        mVolumeInfoDescription = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(mVolumeInfo, 0);
        out.writeParcelable(mUnsupportedDiskInfo, 0);
        out.writeParcelable(mMissingVolumeRecord, 0);
        out.writeString(mVolumeInfoDescription);
    }

    public static final Parcelable.Creator<StorageEntry> CREATOR = new Parcelable.Creator<StorageEntry>() {

        public StorageEntry createFromParcel(Parcel in) {
            return new StorageEntry(in);
        }

        public StorageEntry[] newArray(int size) {
            return new StorageEntry[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof StorageEntry)) {
            return false;
        }
        final StorageEntry StorageEntry = (StorageEntry) o;
        if (isVolumeInfo()) {
            return mVolumeInfo.equals(StorageEntry.mVolumeInfo);
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.equals(StorageEntry.mUnsupportedDiskInfo);
        }
        return mMissingVolumeRecord.equals(StorageEntry.mMissingVolumeRecord);
    }

    @Override
    public int hashCode() {
        if (isVolumeInfo()) {
            return mVolumeInfo.hashCode();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.hashCode();
        }
        return mMissingVolumeRecord.hashCode();
    }

    @Override
    public String toString() {
        if (isVolumeInfo()) {
            return mVolumeInfo.toString();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.toString();
        }
        return mMissingVolumeRecord.toString();
    }

    @Override
    public int compareTo(StorageEntry other) {
        if (isDefaultInternalStorage() && !other.isDefaultInternalStorage()) {
            return -1;
        }
        if (!isDefaultInternalStorage() && other.isDefaultInternalStorage()) {
            return 1;
        }
        if (isVolumeInfo() && !other.isVolumeInfo()) {
            return -1;
        }
        if (!isVolumeInfo() && other.isVolumeInfo()) {
            return 1;
        }
        if (isPrivate() && !other.isPrivate()) {
            return -1;
        }
        if (!isPrivate() && other.isPrivate()) {
            return 1;
        }
        if (isMounted() && !other.isMounted()) {
            return -1;
        }
        if (!isMounted() && other.isMounted()) {
            return 1;
        }
        if (!isVolumeRecordMissed() && other.isVolumeRecordMissed()) {
            return -1;
        }
        if (isVolumeRecordMissed() && !other.isVolumeRecordMissed()) {
            return 1;
        }
        if (getDescription() == null) {
            return 1;
        }
        if (other.getDescription() == null) {
            return -1;
        }
        return getDescription().compareTo(other.getDescription());
    }

    public static StorageEntry getDefaultInternalStorageEntry(Context context) {
        return new StorageEntry(context, context.getSystemService(StorageManager.class).findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL));
    }

    /**
     * If it's a VolumeInfo.
     */
    public boolean isVolumeInfo() {
        return mVolumeInfo != null;
    }

    /**
     * If it's an unsupported DiskInfo.
     */
    public boolean isDiskInfoUnsupported() {
        return mUnsupportedDiskInfo != null;
    }

    /**
     * If it's a missing VolumeRecord.
     */
    public boolean isVolumeRecordMissed() {
        return mMissingVolumeRecord != null;
    }

    /**
     * If it's a default internal storage.
     */
    public boolean isDefaultInternalStorage() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE && TextUtils.equals(mVolumeInfo.getId(), VolumeInfo.ID_PRIVATE_INTERNAL);
        }
        return false;
    }

    /**
     * If it's a mounted storage.
     */
    public boolean isMounted() {
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED || mVolumeInfo.getState() == VolumeInfo.STATE_MOUNTED_READ_ONLY);
    }

    /**
     * If it's an unmounted storage.
     */
    public boolean isUnmounted() {
        return mVolumeInfo == null ? false : (mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTED);
    }

    /**
     * If it's an unmountable storage.
     */
    public boolean isUnmountable() {
        return mVolumeInfo == null ? false : mVolumeInfo.getState() == VolumeInfo.STATE_UNMOUNTABLE;
    }

    /**
     * If it's a private storage.
     */
    public boolean isPrivate() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PRIVATE;
    }

    /**
     * If it's a public storage.
     */
    public boolean isPublic() {
        return mVolumeInfo == null ? false : mVolumeInfo.getType() == VolumeInfo.TYPE_PUBLIC;
    }

    /**
     * Returns description.
     */
    public String getDescription() {
        if (isVolumeInfo()) {
            return mVolumeInfoDescription;
        }

        return mMissingVolumeRecord.getNickname();
    }

    /**
     * Returns ID.
     */
    public String getId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns disk ID.
     */
    public String getDiskId() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getDiskId();
        }
        if (isDiskInfoUnsupported()) {
            return mUnsupportedDiskInfo.getId();
        }
        return null;
    }

    /**
     * Returns fsUuid.
     */
    public String getFsUuid() {
        if (isVolumeInfo()) {
            return mVolumeInfo.getFsUuid();
        }
        if (isDiskInfoUnsupported()) {
            return null;
        }
        return mMissingVolumeRecord.getFsUuid();
    }

    /**
     * Returns root file if it's a VolumeInfo.
     */
    public File getPath() {
        return mVolumeInfo == null ? null : mVolumeInfo.getPath();
    }

    /**
     * Returns VolumeInfo of the StorageEntry.
     */
    public VolumeInfo getVolumeInfo() {
        return mVolumeInfo;
    }
}