⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 record.java

📁 j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void setBooleanField(int fIndex, boolean value) {
        setDescriptor(fIndex, value ? 1 : 0);
    }

    /**
     * Sets specified column to <code>int</code> value
     * @param  fName the field name.
     * @param  value the field value.
     * @exception IndexOutOfBoundsException  if an invalid field name was given
     * @see FieldStructure#NULL
     **/
    public void setIntegerField(String fName, int value) {
        setIntegerField(struct.getFieldNum(fName), value);
    }

    /**
     * Sets specified column to <code>int</code> value
     * @param  fIndex the field index.
     * @param  value the field value.
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     * @see FieldStructure#NULL
     **/
    public void setIntegerField(int fIndex, int value) {
        setDescriptor(fIndex, value);
    }

    /**
     * Sets specified column to <code>NULL</code> value
     * @param  fName the field name.
     * @exception IndexOutOfBoundsException  if an invalid field name was given
     * @see FieldStructure#NULL
     **/
    public void setNull(String fName) {
        setNull(struct.getFieldNum(fName));
    }

    /**
     * Sets specified column to <code>NULL</code> value
     * @param  fIndex the field index.
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     * @see FieldStructure#NULL
     **/
    public void setNull(int fIndex) {
        setDescriptor(fIndex, FieldStructure.NULL);
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>String</code>
     * @param  fName the field name.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>null</code>;
     * if the field name is not valid, the value returned is <code>null</code>
     * @exception IndexOutOfBoundsException  if an invalid field name was given
     * @see FieldStructure#NULL
     */
    public String getStringField(String fName) {
        return getStringField(struct.getFieldNum(fName));
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>String</code>
     * @param  fIndex the field index, the first field is 0, second is 1.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>null</code>;
     * if the field index is not valid, the value returned is <code>null</code>
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     * @see FieldStructure#NULL
     */
    public String getStringField(int fIndex) {

        int desc = getDescriptor(fIndex);
        if (desc == FieldStructure.NULL) return null;
        int offset = desc >>> 16;
        int len = (desc & 0x0000ffff);
        if (len==0) return "";
        return new String(data, offset, len);
//        return new String(getBinaryField(fIndex));
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>boolean</code>
     * @param  fName the field name.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>true</code>
     * if the field name is not valid, the value returned is <code>false</code>
     * @exception IndexOutOfBoundsException  if an invalid field name was given
     * @see FieldStructure#NULL
     */
    public boolean getBooleanField(String fName) {
        return getBooleanField(struct.getFieldNum(fName));
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>boolean</code>
     * @param  fIndex the field index, the first field is 0, second is 1.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>true</code>
     * if the field index is not valid, the value returned is <code>false</code>
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     * @see FieldStructure#NULL
     */
    public boolean getBooleanField(int fIndex) {
        return getDescriptor(fIndex) != 0;
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>int</code>
     * @param  fName the field name.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>NULL</code>
     * if the field name is not valid, the value returned is <code>NULL</code>
     * @exception IndexOutOfBoundsException  if an invalid field name was given
     * @see FieldStructure#NULL
     */
    public int getIntegerField(String fName) {
        return getIntegerField(struct.getFieldNum(fName));
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>int</code>
     * @param  fIndex the field index, the first field is 0, second is 1.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>NULL</code>
     * if the field index is not valid, the value returned is <code>NULL</code>
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     * @see FieldStructure#NULL
     */
    public int getIntegerField(int fIndex) {
        return getDescriptor(fIndex);
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>byte[]</code>
     * @param  fName the field name.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>null</code>
     * if the field name is not valid, the value returned is <code>null</code>
     * @exception IndexOutOfBoundsException  if an invalid field name was given
     */
    public byte[] getBinaryField(String fName) {
        return getBinaryField(struct.getFieldNum(fName));
    }

    /**
     * Retrieves the value of the designated column in the current <code>Record</code> as a <code>byte[]</code>
     * @param  fIndex the field index, the first field is 0, second is 1.
     * @return the column value;
     * if the value is <code>NULL</code>, the value returned is <code>null</code>
     * if the field index is not valid, the value returned is <code>null</code>
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     */
    public byte[] getBinaryField(int fIndex) {

        int desc = getDescriptor(fIndex);
        if (desc == FieldStructure.NULL) return null;
        int offset = desc >>> 16;
        int len = (desc & 0x0000ffff);
        if (len < 0) return null;
        if (len==0) return new byte[0];
        byte[] rslt = new byte[len];
        System.arraycopy(data, offset, rslt, 0, len);
        return rslt;
    }

    /**
     * Set descriptor for the specified field
     * @param  fIndex the field index, the first field is 0, second is 1.
     * @param  desc the descriptor value.
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     */
    protected void setDescriptor(int fIndex, int desc) {
        int offset = fIndex * 4;
        data[offset + 0] = (byte) ((desc & 0xff000000) >> 24);
        data[offset + 1] = (byte) ((desc & 0x00ff0000) >> 16);
        data[offset + 2] = (byte) ((desc & 0x0000ff00) >> 8);
        data[offset + 3] = (byte) ((desc & 0x000000ff) >> 0);
    }

    /**
     * Get descriptor for the specified field
     * @param  fIndex the field index, the first field is 0, second is 1.
     * @return field descriptor
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     */
    protected int getDescriptor(int fIndex) {
        int offset = fIndex * 4;
        return ((((int) data[offset + 0]) << 24) & 0xff000000) |
               ((((int) data[offset + 1]) << 16) & 0x00ff0000) |
               ((((int) data[offset + 2]) <<  8) & 0x0000ff00) |
               ((((int) data[offset + 3]) <<  0) & 0x000000ff);
    }

    /**
     * Retrieves whether the field has <code>NULL</code> value.
     * @param  fName the field name.
     * @return <code>true</code> if the field has <code>NULL</code> value, <code>false</code> otherwise
     * @exception IndexOutOfBoundsException  if an invalid field name was given
     * @see FieldStructure#NULL
     */
    public boolean isNull(String fName) {
        return isNull(struct.getFieldNum(fName));
    }

    /**
     * Reports whether the field has <code>NULL</code> value.
     * @param  fIndex the field index, the first field is 0, second is 1.
     * @return <code>true</code> if the field has <code>NULL</code> value, <code>false</code> otherwise
     * @exception IndexOutOfBoundsException  if an invalid field index was given
     * @see FieldStructure#NULL
     */
    public boolean isNull(int fIndex) {
        return getDescriptor(fIndex) == FieldStructure.NULL;

    }

    /**
     * Reset data for current <code>Record</code>
     */
    public void reset() {
        for (int i = 0; i < data.length; i++) {
            data[i] = 0;
        }
        for (int i = 0; i < struct.fieldStructure.size(); i++) {
            setNull(i);
        }
        length = struct.fieldStructure.size()*4;
    }

} // class Record

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -