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

📄 ddffield.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * subfield wasn't repeated, it will provide a list containing one     * object. Will return null if the subfield doesn't exist.     */    public List getSubfields(String subfieldName) {        Object obj = subfields.get(subfieldName);        if (obj instanceof List) {            return (List) obj;        } else if (obj != null) {            LinkedList ll = new LinkedList();            ll.add(obj);            return ll;        }        return null;    }    /**     * Will return a DDFSubfield object with the given name, or the     * first one off the list for a repeating subfield. Will return     * null if the subfield doesn't exist.     */    public DDFSubfield getSubfield(String subfieldName) {        Object obj = subfields.get(subfieldName);        if (obj instanceof List) {            List l = (List) obj;            if (!l.isEmpty()) {                return (DDFSubfield) (l.get(0));            }            obj = null;        }        // May be null if subfield list above is empty. Not sure if        // that's possible.        return (DDFSubfield) obj;    }    /**     * Fetch raw data pointer for a particular subfield of this field.     *      * The passed DDFSubfieldDefn (poSFDefn) should be acquired from     * the DDFFieldDefn corresponding with this field. This is     * normally done once before reading any records. This method     * involves a series of calls to DDFSubfield::GetDataLength() in     * order to track through the DDFField data to that belonging to     * the requested subfield. This can be relatively expensive.     * <p>     *      * @param poSFDefn The definition of the subfield for which the     *        raw data pointer is desired.     * @param pnMaxBytes The maximum number of bytes that can be     *        accessed from the returned data pointer is placed in     *        this int, unless it is null.     * @param iSubfieldIndex The instance of this subfield to fetch.     *        Use zero (the default) for the first instance.     *      * @return A pointer into the DDFField's data that belongs to the     *         subfield. This returned pointer is invalidated by the     *         next record read (DDFRecord::ReadRecord()) and the     *         returned pointer should not be freed by the     *         application.     */    public byte[] getSubfieldData(DDFSubfieldDefinition poSFDefn,                                  MutableInt pnMaxBytes, int iSubfieldIndex) {        int iOffset = 0;        if (poSFDefn == null)            return null;        if (iSubfieldIndex > 0 && poDefn.getFixedWidth() > 0) {            iOffset = poDefn.getFixedWidth() * iSubfieldIndex;            iSubfieldIndex = 0;        }        MutableInt nBytesConsumed = new MutableInt(0);        while (iSubfieldIndex >= 0) {            for (int iSF = 0; iSF < poDefn.getSubfieldCount(); iSF++) {                DDFSubfieldDefinition poThisSFDefn = poDefn.getSubfieldDefn(iSF);                byte[] subPachData = new byte[pachData.length - iOffset];                System.arraycopy(pachData,                        iOffset,                        subPachData,                        0,                        subPachData.length);                if (poThisSFDefn == poSFDefn && iSubfieldIndex == 0) {                    if (pnMaxBytes != null) {                        pnMaxBytes.value = pachData.length - iOffset;                    }                    return subPachData;                }                poThisSFDefn.getDataLength(subPachData,                        subPachData.length,                        nBytesConsumed);                iOffset += nBytesConsumed.value;            }            iSubfieldIndex--;        }        // We didn't find our target subfield or instance!        return null;    }    public void buildSubfields() {        byte[] pachFieldData = pachData;        int nBytesRemaining = pachData.length;        for (int iRepeat = 0; iRepeat < getRepeatCount(); iRepeat++) {            /* -------------------------------------------------------- */            /* Loop over all the subfields of this field, advancing */            /* the data pointer as we consume data. */            /* -------------------------------------------------------- */            for (int iSF = 0; iSF < poDefn.getSubfieldCount(); iSF++) {                DDFSubfield ddfs = new DDFSubfield(poDefn.getSubfieldDefn(iSF), pachFieldData, nBytesRemaining);                addSubfield(ddfs);                // Reset data for next subfield;                int nBytesConsumed = ddfs.getByteSize();                nBytesRemaining -= nBytesConsumed;                byte[] tempData = new byte[pachFieldData.length                        - nBytesConsumed];                System.arraycopy(pachFieldData,                        nBytesConsumed,                        tempData,                        0,                        tempData.length);                pachFieldData = tempData;            }        }    }    protected void addSubfield(DDFSubfield ddfs) {        if (Debug.debugging("iso8211")) {            Debug.output("DDFField(" + getFieldDefn().getName()                    + ").addSubfield(" + ddfs + ")");        }        String sfName = ddfs.getDefn().getName().trim().intern();        Object sf = subfields.get(sfName);        if (sf == null) {            subfields.put(sfName, ddfs);        } else {            if (sf instanceof List) {                ((List) sf).add(ddfs);            } else {                Vector subList = new Vector();                subList.add(sf);                subList.add(ddfs);                subfields.put(sfName, subList);            }        }    }    /**     * How many times do the subfields of this record repeat? This     * will always be one for non-repeating fields.     *      * @return The number of times that the subfields of this record     *         occur in this record. This will be one for     *         non-repeating fields.     */    public int getRepeatCount() {        if (!poDefn.isRepeating()) {            return 1;        }        /* -------------------------------------------------------------------- */        /* The occurance count depends on how many copies of this */        /* field's list of subfields can fit into the data space. */        /* -------------------------------------------------------------------- */        if (poDefn.getFixedWidth() != 0) {            return pachData.length / poDefn.getFixedWidth();        }        /* -------------------------------------------------------------------- */        /* Note that it may be legal to have repeating variable width */        /* subfields, but I don't have any samples, so I ignore it for */        /* now. */        /*                                                                      */        /*         * The file data/cape_royal_AZ_DEM/1183XREF.DDF has a         * repeating         */        /* variable length field, but the count is one, so it isn't */        /* much value for testing. */        /* -------------------------------------------------------------------- */        int iOffset = 0;        int iRepeatCount = 1;        MutableInt nBytesConsumed = new MutableInt(0);        while (true) {            for (int iSF = 0; iSF < poDefn.getSubfieldCount(); iSF++) {                DDFSubfieldDefinition poThisSFDefn = poDefn.getSubfieldDefn(iSF);                if (poThisSFDefn.getWidth() > pachData.length - iOffset) {                    nBytesConsumed.value = poThisSFDefn.getWidth();                } else {                    byte[] tempData = new byte[pachData.length - iOffset];                    System.arraycopy(pachData,                            iOffset,                            tempData,                            0,                            tempData.length);                    poThisSFDefn.getDataLength(tempData,                            tempData.length,                            nBytesConsumed);                }                iOffset += nBytesConsumed.value;                if (iOffset > pachData.length) {                    return iRepeatCount - 1;                }            }            if (iOffset > pachData.length - 2)                return iRepeatCount;            iRepeatCount++;        }    }}

⌨️ 快捷键说明

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