Ignore:
Timestamp:
07/28/08 15:08:13 (16 years ago)
Author:
ra33
Message:

Added faster versions of search frameset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Simple.java

    r161 r162  
    162162                do {
    163163                        next = FrameIO.LoadNext(next);
    164                 } while (next != null && next.isTestFrame());
     164                } while (next != null && !next.isTestFrame());
    165165                FrameUtils.DisplayFrame(next, true);
    166166        }
     
    170170                do {
    171171                        prev = FrameIO.LoadPrevious(prev);
    172                 } while (prev != null && prev.isTestFrame());
     172                } while (prev != null && !prev.isTestFrame());
    173173
    174174                FrameUtils.DisplayFrame(prev, true);
     
    783783                        // Check for set statements
    784784                } else if (tokens[0].startsWith("calculatestring")) {
    785                         assertMinParametreCount(tokens, 2);
    786                         String toCalculate = context.getPrimitives().getStringValue(tokens[1]);
     785                        assertMinParametreCount(tokens, 1);
     786                        String toCalculate = context.getPrimitives().getStringValue(
     787                                        tokens[1]);
    787788                        boolean result = true;
     789                        String error = "";
    788790                        ExpediteeJEP myParser = new ExpediteeJEP();
    789                         //Add the variables in the system
     791                        // Add the variables in the system
    790792                        context.getPrimitives().addToParser(myParser);
    791793                        Node equation = myParser.parseExpression(toCalculate);
    792                         //TODO get the answer
    793                        
     794                        // TODO get the answer
     795                        if (equation == null) {
     796                                result = false;
     797                                error = myParser.getErrorInfo().replace("\n", "");
     798                        } else {
     799                                double value = myParser.getValue();
     800                                if (myParser.hasError()) {
     801                                        result = false;
     802                                        error = myParser.getErrorInfo().replace("\n", "");
     803                                } else {
     804                                        // Add a new variable if its an assignment statement
     805                                        String newVar = myParser.getNewVariable();
     806                                        if (newVar.length() > 0) {
     807                                                try {
     808                                                        context.getPrimitives().setValue(newVar,
     809                                                                        new SReal(value));
     810                                                } catch (IncorrectTypeException e) {
     811                                                        result = false;
     812                                                        error = e.getMessage();
     813                                                }
     814                                        }
     815                                        if (tokens.length > 2) {
     816                                                context.getPrimitives().setValue(tokens[2],
     817                                                                new SReal(value));
     818                                        }
     819                                }
     820                        }
     821                        // Set the result variable if there is one
     822                        if (tokens.length > 3) {
     823                                context.getPrimitives().setValue(tokens[3],
     824                                                new SBoolean(result));
     825                                // Set the result variable if there is one
     826                                if (tokens.length > 4 && !result) {
     827                                        context.getPrimitives().setValue(tokens[4], error);
     828                                }
     829                        }
    794830                } else if (tokens[0].startsWith("calculateitem")) {
    795831                        assertMinParametreCount(tokens, 1);
    796832                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    797                         Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue();
     833                        Item item = (Item) context.getPointers().getVariable(tokens[1])
     834                                        .getValue();
    798835                        Frame frame = null;
    799                         if(tokens.length > 2){
     836                        if (tokens.length > 2) {
    800837                                assertVariableType(tokens[2], 2, SPointer.framePrefix);
    801                                 frame = (Frame)context.getPointers().getVariable(tokens[2]).getValue();
     838                                frame = (Frame) context.getPointers().getVariable(tokens[2])
     839                                                .getValue();
    802840                        }
    803841                        Misc.calculate(frame, item);
    804                 }else if (tokens[0].startsWith("issearchpatternvalid")) {
     842                } else if (tokens[0].startsWith("issearchpatternvalid")) {
    805843                        assertExactParametreCount(tokens, 2);
    806844                        boolean result = true;
     
    885923                                String pattern = context.getPrimitives().getStringValue(
    886924                                                tokens[2]);
    887                                 SearchAgent searchAgent = new SearchFrameset();
     925                                long firstFrame = 1;
     926                                long maxFrame = Long.MAX_VALUE;
     927                                if(tokens.length > 7){
     928                                        firstFrame = context.getPrimitives().getIntegerValue(tokens[7]);
     929                                        if(tokens.length > 8){
     930                                                maxFrame = context.getPrimitives().getIntegerValue(tokens[8]);
     931                                        }
     932                                }
     933                               
     934                                SearchAgent searchAgent = new SearchFrameset(firstFrame, maxFrame);
    888935                                searchAgent.initialise(null, null, frameset, resultsFrameset,
    889936                                                replacementString, pattern);
     
    11871234                                                        .getStringValue(tokens[1]), context.getPrimitives()
    11881235                                                        .getStringValue(tokens[2]));
     1236                        } else if (tokens[0].equals("assertequalframes")) {
     1237                                assertExactParametreCount(tokens, 2);
     1238                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1239                                assertVariableType(tokens[2], 2, SPointer.framePrefix);
     1240                                Frame frame1 = (Frame) context.getPointers().getVariable(
     1241                                                tokens[1]).getValue();
     1242                                Frame frame2 = (Frame) context.getPointers().getVariable(
     1243                                                tokens[2]).getValue();
     1244                                // Check that all the items on the frame are the same
     1245                                List<Item> items1 = frame1.getVisibleItems();
     1246                                List<Item> items2 = frame2.getVisibleItems();
     1247                                if (items1.size() != items2.size()) {
     1248                                        throw new UnitTestFailedException(items1.size() + " items",
     1249                                                        items2.size() + " items");
     1250                                } else {
     1251                                        for (int i = 0; i < items1.size(); i++) {
     1252                                                Item i1 = items1.get(i);
     1253                                                Item i2 = items2.get(i);
     1254                                                String s1 = i1.getText();
     1255                                                String s2 = i2.getText();
     1256                                                if (!s1.equals(s2)) {
     1257                                                        throw new UnitTestFailedException(s1, s2);
     1258                                                }
     1259                                        }
     1260                                }
    11891261                        } else if (tokens[0].equals("assertdefined")) {
    11901262                                assertExactParametreCount(tokens, 1);
     
    11931265                                                        "not defined");
    11941266                                }
     1267                        } else {
     1268                                throw new RuntimeException("Invalid Assert statement");
    11951269                        }
    11961270                } else if (tokens[0].startsWith("goto")) {
     
    19572031                                freshCopy.setFrameset(destinationFrameset);
    19582032                        }// Otherwise add it to the end of this frameset
    1959                         freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy
    1960                                         .getFramesetName()) + 1);
    1961                         context.getPointers().setObject(tokens[2], freshCopy);
    1962                         String fileContents = FrameIO.ForceSaveFrame(freshCopy);
     2033                        int nextNumber = FrameIO.getLastNumber(freshCopy.getFramesetName()) + 1;
     2034                        // if the frameset doesnt already exist then create it
     2035                        if (nextNumber <= 0) {
     2036                                try {
     2037                                        FrameIO.CreateFrameset(freshCopy.getFramesetName(),
     2038                                                        frameToCopy.path);
     2039                                        nextNumber = 1;
     2040                                } catch (Exception e) {
     2041                                }
     2042                        }
     2043                        boolean success = false;
     2044                        if (nextNumber > 0) {
     2045                                freshCopy.setFrameNumber(nextNumber);
     2046                                context.getPointers().setObject(tokens[2], freshCopy);
     2047                                String fileContents = FrameIO.ForceSaveFrame(freshCopy);
     2048                                success = fileContents != null;
     2049                        }
    19632050                        FrameIO.ResumeCache();
    1964                         // Need to add the new copy to the cache in case it is edited by
    1965                         // other simple statements
    1966                         FrameIO.addToCache(freshCopy);
    1967                         boolean success = fileContents != null;
     2051                        if (success) {
     2052                                // Need to add the new copy to the cache in case it is edited by
     2053                                // other simple statements
     2054                                FrameIO.addToCache(freshCopy);
     2055                        }
    19682056                        if (!success && _verbose)
    19692057                                MessageBay.warningMessage("Error copying "
Note: See TracChangeset for help on using the changeset viewer.