-1

我有一个类“命题”。在这堂课中,我将用 for 循环多次调用另一类的 costrucor,即“命题”。“Proposition”类有一个“createProposition”方法。并且该方法必须将Proposition的数组列表返回给“Propositions”,同时保存在“Propositions Set”中。但我的方法返回null。我也必须使用 String 方法来更改 Proposition 的值。实际上,命题的数组列表,即“propositionsTempArray”应该从“Proposition”类返回到“Propositions”类中的“propList”;

    public class Proposition extends ArrayList<Proposition> {  
        private String productName;
        private Property     property;
        private Serializable value;
        private Type         type;
        private Rating       rating;

        public Proposition() {}


       public ArrayList<Proposition> createPropositions(UserModel userModel,Facts facts,Fact fact){ 
        ...

        assignPropositionVariablesInPreviousProductNoMatch(Fact newfact,String name, String previousProductValue)

       ....
        return propositionsTempArray ;
        }


        private  Proposition assignPropositionVariablesInPreviousProductNoMatch(Fact newfact,String name, String previousProductValue) {
             Proposition proposition=new Proposition();
             proposition.productName=name;
             proposition.type      = Type.PreviousProductNoMatch;
             proposition.value     = previousProductValue;
             proposition.property = (Property) Configuration.typeMapping.getData(("property " . concat((String) newfact.getData("property"))));
             proposition.rating    = (Rating) Configuration.typeMapping.getData(("rating " . concat((String) newfact.getData("rating"))));
             return proposition;
        }

        public String toString() {

             String valueString = "";
                        if (value == null) {
                            valueString = "null";
                        } else {
                            if (value instanceof String[]) {
                                valueString = Arrays.toString((String[]) getValue());
                            } else {
                                valueString = getValue().toString();
                             }

                        return MessageFormat.format(" {0}, {1}, {2}, (Rating:{3},Property:{4})", this.getProductName(), this.getType(),valueString,this.getRating(),this.getProperty());
       }


            public class Propositions extends HashSet<Proposition> implements Comparable<Propositions> {
                public Propositions() {
            }



            public Propositions(UserModel userModel,Facts facts) {



                for (Fact fact: facts) {
                        Proposition propList=new Proposition ();
                        propList.createPropositions(userModel,facts,fact);
                        this.addAll(propList);
                    }
                }

            }
4

1 回答 1

1
        assignPropositionVariablesInPreviousProductNoMatch(Fact newfact,String name, String previousProductValue)

此方法返回一个命题,但您没有捕捉到结果。

尝试:

Proposition proposition = assignPropositionVariablesInPreviousProductNoMatch(Fact newfact,String name, String previousProductValue);

...

propositionsTempArray.add(proposition);

...

希望这对您有所帮助。

编辑:我在你的代码中某处你有:

propositionsTempArray = new ArrayList<Proposition>();
于 2013-08-12T14:43:19.213 回答