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

📄 section.java

📁 java 报表 to office文档: 本包由java语言开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                return 0;            else                return 1;        }    }    /**     * <p>Returns the value of the property with the specified ID. If     * the property is not available, <code>null</code> is returned     * and a subsequent call to {@link #wasNull} will return     * <code>true</code>.</p>     *     * @param id The property's ID     *     * @return The property's value     */    public Object getProperty(final long id)    {        wasNull = false;        for (int i = 0; i < properties.length; i++)            if (id == properties[i].getID())                return properties[i].getValue();        wasNull = true;        return null;    }    /**     * <p>Returns the value of the numeric property with the specified     * ID. If the property is not available, 0 is returned. A     * subsequent call to {@link #wasNull} will return     * <code>true</code> to let the caller distinguish that case from     * a real property value of 0.</p>     *     * @param id The property's ID     *     * @return The property's value     */    protected int getPropertyIntValue(final long id)    {        final Long i;        final Object o = getProperty(id);        if (o == null)            return 0;        if (!(o instanceof Long))            throw new HPSFRuntimeException                ("This property is not an integer type, but " +                 o.getClass().getName() + ".");        i = (Long) o;        return i.intValue();    }    /**     * <p>Returns the value of the boolean property with the specified     * ID. If the property is not available, <code>false</code> is     * returned. A subsequent call to {@link #wasNull} will return     * <code>true</code> to let the caller distinguish that case from     * a real property value of <code>false</code>.</p>     *     * @param id The property's ID     *     * @return The property's value     */    protected boolean getPropertyBooleanValue(final int id)    {        final Boolean b = (Boolean) getProperty(id);        if (b != null)            return b.booleanValue();        else            return false;        }    /**     * <p>This member is <code>true</code> if the last call to {@link     * #getPropertyIntValue} or {@link #getProperty} tried to access a     * property that was not available, else <code>false</code>.</p>     */    private boolean wasNull;    /**     * <p>Checks whether the property which the last call to {@link     * #getPropertyIntValue} or {@link #getProperty} tried to access     * was available or not. This information might be important for     * callers of {@link #getPropertyIntValue} since the latter     * returns 0 if the property does not exist. Using {@link     * #wasNull} the caller can distiguish this case from a property's     * real value of 0.</p>     *     * @return <code>true</code> if the last call to {@link     * #getPropertyIntValue} or {@link #getProperty} tried to access a     * property that was not available, else <code>false</code>.     */    public boolean wasNull()    {        return wasNull;    }    /**     * <p>Returns the PID string associated with a property ID. The ID     * is first looked up in the {@link Section}'s private     * dictionary. If it is not found there, the method calls {@link     * SectionIDMap#getPIDString}.</p>     *     * @param pid The property ID     *     * @return The property ID's string value     */    public String getPIDString(final long pid)    {        String s = null;        if (dictionary != null)            s = (String) dictionary.get(new Long(pid));        if (s == null)            s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid);        if (s == null)            s = SectionIDMap.UNDEFINED;        return s;    }    /**     * <p>Checks whether this section is equal to another object. The result is     * <code>false</code> if one of the the following conditions holds:</p>     *      * <ul>     *      * <li><p>The other object is not a {@link Section}.</p></li>     *      * <li><p>The format IDs of the two sections are not equal.</p></li>     *        * <li><p>The sections have a different number of properties. However,     * properties with ID 1 (codepage) are not counted.</p></li>     *      * <li><p>The other object is not a {@link Section}.</p></li>     *      * <li><p>The properties have different values. The order of the properties     * is irrelevant.</p></li>     *      * </ul>     *      * @param o The object to compare this section with     * @return <code>true</code> if the objects are equal, <code>false</code> if     * not     */    public boolean equals(final Object o)    {        if (o == null || !(o instanceof Section))            return false;        final Section s = (Section) o;        if (!s.getFormatID().equals(getFormatID()))            return false;        /* Compare all properties except 0 and 1 as they must be handled          * specially. */        Property[] pa1 = new Property[getProperties().length];        Property[] pa2 = new Property[s.getProperties().length];        System.arraycopy(getProperties(), 0, pa1, 0, pa1.length);        System.arraycopy(s.getProperties(), 0, pa2, 0, pa2.length);        /* Extract properties 0 and 1 and remove them from the copy of the         * arrays. */        Property p10 = null;        Property p20 = null;        for (int i = 0; i < pa1.length; i++)        {            final long id = pa1[i].getID();            if (id == 0)            {                p10 = pa1[i];                pa1 = remove(pa1, i);                i--;            }            if (id == 1)            {                // p11 = pa1[i];                pa1 = remove(pa1, i);                i--;            }        }        for (int i = 0; i < pa2.length; i++)        {            final long id = pa2[i].getID();            if (id == 0)            {                p20 = pa2[i];                pa2 = remove(pa2, i);                i--;            }            if (id == 1)            {                // p21 = pa2[i];                pa2 = remove(pa2, i);                i--;            }        }        /* If the number of properties (not counting property 1) is unequal the         * sections are unequal. */        if (pa1.length != pa2.length)            return false;        /* If the dictionaries are unequal the sections are unequal. */        boolean dictionaryEqual = true;        if (p10 != null && p20 != null)            dictionaryEqual = p10.getValue().equals(p20.getValue());        else if (p10 != null || p20 != null)            dictionaryEqual = false;        if (!dictionaryEqual)            return false;        else            return Util.equals(pa1, pa2);    }    /**     * <p>Removes a field from a property array. The resulting array is     * compactified and returned.</p>     */    private Property[] remove(final Property[] pa, final int i)    {        final Property[] h = new Property[pa.length - 1];        if (i > 0)            System.arraycopy(pa, 0, h, 0, i);        System.arraycopy(pa, i + 1, h, i, h.length - i);        return h;    }    /**     * @see Object#hashCode()     */    public int hashCode()    {        long hashCode = 0;        hashCode += getFormatID().hashCode();        final Property[] pa = getProperties();        for (int i = 0; i < pa.length; i++)            hashCode += pa[i].hashCode();        final int returnHashCode = (int) (hashCode & 0x0ffffffffL);        return returnHashCode;    }    /**     * @see Object#toString()     */    public String toString()    {        final StringBuffer b = new StringBuffer();        final Property[] pa = getProperties();        b.append(getClass().getName());        b.append('[');        b.append("formatID: ");        b.append(getFormatID());        b.append(", offset: ");        b.append(getOffset());        b.append(", propertyCount: ");        b.append(getPropertyCount());        b.append(", size: ");        b.append(getSize());        b.append(", properties: [\n");        for (int i = 0; i < pa.length; i++)        {            b.append(pa[i].toString());            b.append(",\n");        }        b.append(']');        b.append(']');        return b.toString();    }    /**     * <p>Gets the section's dictionary. A dictionary allows an application to     * use human-readable property names instead of numeric property IDs. It     * contains mappings from property IDs to their associated string     * values. The dictionary is stored as the property with ID 0. The codepage     * for the strings in the dictionary is defined by property with ID 1.</p>     *     * @return the dictionary or <code>null</code> if the section does not have     * a dictionary.     */    public Map getDictionary()    {        return dictionary;    }    /**     * <p>Gets the section's codepage, if any.</p>     *     * @return The section's codepage if one is defined, else -1.     */    public int getCodepage()    {        final Integer codepage =            (Integer) getProperty(PropertyIDMap.PID_CODEPAGE);        return codepage != null ? codepage.intValue() : -1;    }}

⌨️ 快捷键说明

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