`
mryangjw
  • 浏览: 20439 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

JSTOCKCHART中【Duplicates are not permitted. Try using the addOrUpdate() method.】

阅读更多

关于使用【JSTOCKCHART】插件开发过程中【You are attempting to add an observation for the time period  Thu Jun 24 10:34:26 CST 2010 but the series already contains an observation for that time period. Duplicates are not permitted.  Try using the addOrUpdate() method.】问题的解决办法

 

问题描述:

  更新坐标点上纵坐标的值时,出现此类异常。

 

原因分析:

  在【dataset】中添加新项目(调用【addDataItem】方法)时,程序最后会调用到【JFREECHART】插件中的【TimeSeries】类的【add(TimeSeriesDataItem item, boolean notify)】方法,在该【add】方法中会根据横坐标去判断该坐标是否已经存在,如果不存在,则添加,如果存在,就会抛出如上异常信息。【add】方法的详细内容如下:

    注:标【***********】的为重点

 

    /**
     * Adds a data item to the series and sends a {@link SeriesChangeEvent} to
     * all registered listeners.
     *
     * @param item  the (timeperiod, value) pair (<code>null</code> not
     *              permitted).
     * @param notify  notify listeners?
     */
    public void add(TimeSeriesDataItem item, boolean notify) {
        if (item == null) {
            throw new IllegalArgumentException("Null 'item' argument.");
        }
        Class c = item.getPeriod().getClass();
        if (this.timePeriodClass == null) {
            this.timePeriodClass = c;
        }
        else if (!this.timePeriodClass.equals(c)) {
            StringBuffer b = new StringBuffer();
            b.append("You are trying to add data where the time period class ");
            b.append("is ");
            b.append(item.getPeriod().getClass().getName());
            b.append(", but the TimeSeries is expecting an instance of ");
            b.append(this.timePeriodClass.getName());
            b.append(".");
            throw new SeriesException(b.toString());
        }

        // make the change (if it's not a duplicate time period)...
        boolean added = false;
        int count = getItemCount();
        if (count == 0) {
            this.data.add(item);
            added = true;
        }
        else {
            RegularTimePeriod last = getTimePeriod(getItemCount() - 1);
            if (item.getPeriod().compareTo(last) > 0) {
                this.data.add(item);
                added = true;
            }
            else {

                // ***************************************************

                // 查找数据集中是否已经包含要添加的记录(以横坐标作为key)
                int index = Collections.binarySearch(this.data, item);

                // 不存在添加
                if (index < 0) {
                    this.data.add(-index - 1, item);
                    added = true;
                }

                // 存在就抛出以下异常信息
                else {
                      StringBuffer b = new StringBuffer();
                      b.append("You are attempting to add an observation for ");
                      b.append("the time period ");
                      b.append(item.getPeriod().toString());
                      b.append(" but the series already contains an observation");
                      b.append(" for that time period. Duplicates are not ");
                      b.append("permitted.  Try using the addOrUpdate() method.");
                      throw new SeriesException(b.toString());
                }

                // ***************************************************
            }
        }
        if (added) {
            // check if this addition will exceed the maximum item count...
            if (getItemCount() > this.maximumItemCount) {
                this.data.remove(0);
            }

            removeAgedItems(false);  // remove old items if necessary, but
                                     // don't notify anyone, because that
                                     // happens next anyway...
            if (notify) {
                fireSeriesChanged();
            }
        }

    }

 

解决方法:

  把程序中的这一段内容注释掉,然后添加【this.data.set(index, item);】语句即可。

//                    StringBuffer b = new StringBuffer();
//                    b.append("You are attempting to add an observation for ");
//                    b.append("the time period ");
//                    b.append(item.getPeriod().toString());
//                    b.append(" but the series already contains an observation");
//                    b.append(" for that time period. Duplicates are not ");
//                    b.append("permitted.  Try using the addOrUpdate() method.");
//                    throw new SeriesException(b.toString());
                 this.data.set(index, item);

重新编译下工程,然后再运行,OK,问题解决!
如有不对之处,希望批评指正!

0
0
分享到:
评论

相关推荐

    数据库系统概念第六版答案(包括实践习题,习题)下载

    Since the except operator eliminates duplicates, there is no need to use a select distinct clause, although doing so would not affect correctness of the query. •SQL query: select dept, max...

    微软内部资料-SQL性能优化5

    On a qualified select, update, or delete, the correct leaf page will be the lowest page of the tree in which one or more rows with the specified key or keys reside. A qualified operation is one that ...

    squashfs1.3r3.tar.gz

    duplicates. 3. Using squashfs ----------------- Squashfs filesystems should be mounted with 'mount' with the filesystem type 'squashfs'. If the filesystem is on a block device, the filesystem can ...

    squashfs2.2-r2.tar.gz

    added to the filesystem for duplicates. This can result in quicker filesystem generation and appending although obviously compression will suffer badly if there is a lot of duplicate files. The -b ...

    EurekaLog_7.5.0.0_Enterprise

    Please, update your projects by renaming or recreating the component 2)....Important: File layout was changed for BDS 2006+. Delphi and C++ Builder files are now located in StudioNum folders instead ...

    Cody‘s_Data_Cleaning_Techniques_Using_SAS_(Second_Edtion)

    - **Detecting Duplicates by Using DATA Step Approaches**: Describes various DATA step methods for detecting duplicates. - **Using PROC FREQ to Detect Duplicate ID's**: Demonstrates using PROC FREQ to ...

    BobBuilder_app

    Even faster Key/Value store nosql embedded database engine utilizing the new MGIndex data structure with MurMur2 Hashing and WAH Bitmap indexes for duplicates. See Also More like this More by this...

    Python代码源码-实操案例-框架案例-重复数据处理(df.drop duplicates方法).zip

    在Python编程语言中,Pandas库是数据处理和分析的核心工具。这个压缩包文件"Python代码源码-实操案例-框架案例-重复数据处理(df.drop duplicates方法).zip"显然包含了一些示例代码,用于解释如何使用Pandas的`df....

    Python Cookbook, 2nd Edition

    Using the Code from This Book Audience Organization Further Reading Conventions Used in This Book How to Contact Us Safari® Enabled Acknowledgments Chapter 1. Text Introduction ...

    UE(官方下载)

    We are often asked if it is possible to run an UltraEdit macro or script on a file from the command line. The answer is yes - and it's not only possible, it's extremely simple! Using find/replace ...

    Build Report Tool 3.0.19.rar

    Instantiate actually merely duplicates/clones an existing game object (whether it is currently residing in the scene or exists as a prefab in the assets folder). (side note: you can actually use ...

    SAS_Programming_III英文

    6.2 Eliminating Duplicates.....................................................................................................6-5 6.3 Sorting Resources ..................................................

    Delete Duplicates for Outlook Express and Windows Mail v3.8.0.1注册版

    Delete Duplicates for Outlook Express and Windows Mail v3.8.0.1注册版程序

    LINQPad_Premium_5.36.03_Any_CPU 含破解

    LINQPad now identifies NuGet packages with duplicate extension attributes in Content_Types.xml, and automatically removes the duplicates so that the package loader will not throw an ...

    duplicates-0.3.jar

    jar包,官方版本,自测可用

    duplicates-0.2.6.jar

    jar包,官方版本,自测可用

    duplicates-0.2.4.jar

    jar包,官方版本,自测可用

    duplicates-0.2.2.jar

    jar包,官方版本,自测可用

    duplicates-0.2.1.jar

    jar包,官方版本,自测可用

    duplicates-0.2.jar

    jar包,官方版本,自测可用

Global site tag (gtag.js) - Google Analytics