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

📄 samplexysymbolicdataset.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void setXSymbolicValues(String[] sValues) {
        xSymbolicValues = sValues;
    }

    /**
     * Sets the list of Y symbolic values.
     *
     * @param sValues the new list of symbolic value.
     */
    public void setYSymbolicValues(String[] sValues) {
        ySymbolicValues = sValues;
    }

    /**
     * Returns the X symbolic value of the data set specified by
     * <CODE>series</CODE> and <CODE>item</CODE> parameters.
     *
     * @param series value of the serie.
     * @param item value of the item.
     *
     * @return the symbolic value.
     */
    public String getXSymbolicValue(int series, int item) {
        Integer intValue = (Integer) getXValue(series, item);
        return getXSymbolicValue(intValue);
    }

    /**
     * Returns the Y symbolic value of the data set specified by
     * <CODE>series</CODE> and <CODE>item</CODE> parameters.
     *
     * @param series value of the serie.
     * @param item value of the item.
     * @return the symbolic value.
     */
    public String getYSymbolicValue(int series, int item) {
        Integer intValue = (Integer) getYValue(series, item);
        return getYSymbolicValue(intValue);
    }

    /**
     * Returns the X symbolic value linked with the specified
     * <CODE>Integer</CODE>.
     *
     * @param val value of the integer linked with the symbolic value.
     * @return the symbolic value.
     */
    public String getXSymbolicValue(Integer val) {
        return xSymbolicValues[val.intValue()];
    }

    /**
     * Returns the Y symbolic value linked with the specified
     * <CODE>Integer</CODE>.
     *
     * @param val value of the integer linked with the symbolic value.
     * @return the symbolic value.
     */
    public String getYSymbolicValue(Integer val) {
        return ySymbolicValues[val.intValue()];
    }

    /**
     * This function modify <CODE>dataset1</CODE> and <CODE>dataset1</CODE> in
     * order that they share the same Y symbolic value list.
     * <P>
     * The sharing Y symbolic value list is obtained adding the Y symbolic data
     * list of the fist data set to the Y symbolic data list of the second data
     * set.
     * <P>
     * This function is use with the <I>combined plot</I> functions of
     * JFreeChart.
     *
     * @param dataset1  the first data set to combine.
     * @param dataset2  the second data set to combine.
     *
     * @return  the shared Y symbolic array.
     */
    public static String[] combineYSymbolicDataset(YisSymbolic dataset1, YisSymbolic dataset2) {

        SampleXYSymbolicDataset sDataset1 = (SampleXYSymbolicDataset) dataset1;
        SampleXYSymbolicDataset sDataset2 = (SampleXYSymbolicDataset) dataset2;
        String[] sDatasetSymbolicValues1 = sDataset1.getYSymbolicValues();
        String[] sDatasetSymbolicValues2 = sDataset2.getYSymbolicValues();

        //Combine the two list of symbolic value of the two data set
        int s1length = sDatasetSymbolicValues1.length;
        int s2length = sDatasetSymbolicValues2.length;
        List ySymbolicValuesCombined = new Vector();
        for (int i = 0; i < s1length; i++) {
            ySymbolicValuesCombined.add(sDatasetSymbolicValues1[i]);
        }
        for (int i = 0; i < s2length; i++) {
            if (!ySymbolicValuesCombined.contains(sDatasetSymbolicValues2[i])) {
                ySymbolicValuesCombined.add(sDatasetSymbolicValues2[i]);
            }
        }

        //Change the Integer reference of the second data set
        int newIndex;
        for (int i = 0; i < sDataset2.getSeriesCount(); i++) {
            for (int j = 0; j < sDataset2.getItemCount(i); j++) {
                newIndex = ySymbolicValuesCombined.indexOf(sDataset2.getYSymbolicValue(i, j));
                sDataset2.setYValue(i, j, new Integer(newIndex));
            }
        }

        //Set the new list of symbolic value on the two data sets
        String[] ySymbolicValuesCombinedA = new String[ySymbolicValuesCombined.size()];
        ySymbolicValuesCombined.toArray(ySymbolicValuesCombinedA);
        sDataset1.setYSymbolicValues(ySymbolicValuesCombinedA);
        sDataset2.setYSymbolicValues(ySymbolicValuesCombinedA);

        return ySymbolicValuesCombinedA;
    }

    /**
     * This function modify <CODE>dataset1</CODE> and <CODE>dataset1</CODE> in
     * order that they share the same X symbolic value list.
     * <P>
     * The sharing X symbolic value list is obtained adding the X symbolic data
     * list of the fist data set to the X symbolic data list of the second data
     * set.
     * <P>
     * This function is use with the <I>combined plot</I> functions of
     * JFreeChart.
     *
     * @param dataset1 the first data set to combine.
     * @param dataset2 the second data set to combine.
     *
     * @return  the shared X symbolic array.
     */
    public static String[] combineXSymbolicDataset(XisSymbolic dataset1, XisSymbolic dataset2) {
        SampleXYSymbolicDataset sDataset1 = (SampleXYSymbolicDataset) dataset1;
        SampleXYSymbolicDataset sDataset2 = (SampleXYSymbolicDataset) dataset2;
        String[] sDatasetSymbolicValues1 = sDataset1.getXSymbolicValues();
        String[] sDatasetSymbolicValues2 = sDataset2.getXSymbolicValues();

        //Combine the two list of symbolic value of the two data set
        int s1length = sDatasetSymbolicValues1.length;
        int s2length = sDatasetSymbolicValues2.length;
        List xSymbolicValuesCombined = new Vector();
        for (int i = 0; i < s1length; i++) {
            xSymbolicValuesCombined.add(sDatasetSymbolicValues1[i]);
        }
        for (int i = 0; i < s2length; i++) {
            if (!xSymbolicValuesCombined.contains(sDatasetSymbolicValues2[i])) {
                xSymbolicValuesCombined.add(sDatasetSymbolicValues2[i]);
            }
        }

        //Change the Integer reference of the second data set
        int newIndex;
        for (int i = 0; i < sDataset2.getSeriesCount(); i++) {
            for (int j = 0; j < sDataset2.getItemCount(i); j++) {
                newIndex = xSymbolicValuesCombined.indexOf(sDataset2.getXSymbolicValue(i, j));
                sDataset2.setXValue(i, j, new Integer(newIndex));
            }
        }

        //Set the new list of symbolic value on the two data sets
        String[] xSymbolicValuesCombinedA = new String[xSymbolicValuesCombined.size()];
        xSymbolicValuesCombined.toArray(xSymbolicValuesCombinedA);
        sDataset1.setXSymbolicValues(xSymbolicValuesCombinedA);
        sDataset2.setXSymbolicValues(xSymbolicValuesCombinedA);

        return xSymbolicValuesCombinedA;
    }

    /**
     * Clone the SampleXYSymbolicDataset object
     *
     * @return the cloned object.
     */
    public Object clone() {
        String nDatasetName = new String(this.datasetName);
        Integer[][] nXValues = (Integer[][]) cloneArray(this.xValues);
        Integer[][] nYValues = (Integer[][]) cloneArray(this.yValues);
        String[] nXSymbolicValues = (String[]) cloneArray(this.xSymbolicValues);
        String[] nYSymbolicValues = (String[]) cloneArray(this.ySymbolicValues);
        String[] seriesName = (String[]) cloneArray(this.seriesName);
        return new SampleXYSymbolicDataset(nDatasetName, nXValues, nYValues,
                                           nXSymbolicValues, nYSymbolicValues, seriesName);
    }

    /**
     * Returns a clone of the array.
     *
     * @param arr the array.
     *
     * @return a clone.
     */
    private static Object cloneArray(Object arr) {

        if (arr == null) {
            return arr;
        }

        Class cls = arr.getClass();
        if (!cls.isArray()) {
            return arr;
        }

        int length = Array.getLength(arr);
        Object[] newarr = (Object[]) Array.newInstance(cls.getComponentType(), length);

        Object obj;

        for (int i = 0; i < length; i++) {
            obj = Array.get(arr, i);
            if (obj.getClass().isArray()) {
                newarr[i] = cloneArray(obj);
            }
            else {
                newarr[i] = obj;
            }
        }

        return newarr;
    }

}

⌨️ 快捷键说明

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