Package eu.flatworld.cstrader.data

Examples of eu.flatworld.cstrader.data.Pricelist


        java.lang.System.exit(0);
    }

    void clearPricelists() {
        for (int i = 0; i < pricelists.length; i++) {
            pricelists[i] = new Pricelist();
        }
    }
View Full Code Here


        File f = new File(PRICELISTS_FILE);
        try {
            if (!f.exists()) {
                LogX.log(Level.INFO, "Pricelists file not found, creating...");
                for (int i = 0; i < pricelists.length; i++) {
                    Pricelist p = new Pricelist();
                    p.setSystem(System.values()[i]);
                    pricelists[i] = p;
                }
                savePricelists();
            }
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
            pricelists = (Pricelist[]) ois.readObject();
            ois.close();
            if(pricelists.length != (System.stars() + System.expanses())) {
                pricelists = new Pricelist[System.stars() + System.expanses()];
            }
            for (int i = 0; i < pricelists.length; i++) {
                Pricelist p = pricelists[i];
                if (p == null || p.getForSale() == null || p.getWanted() == null
                        || p.getSystem() == null || p.getPricelistDate() == null) {
                    //something wrong with the loaded pricelist
                    LogX.log(Level.WARNING, "Recreating corrupted pricelist for system " + System.values()[i]);
                    Pricelist pn = new Pricelist();
                    pn.setSystem(System.values()[i]);
                    pricelists[i] = pn;
                    p = pn;
                }
                List<ItemLine> l = pricelists[i].getForSale();
                for (ItemLine itemLine : l) {
                    itemLine.setForSale(true);
                    itemLine.getItem().setWeight(PricelistsTools.loadWeight(itemLine.getItem().getName()));
                }
                l = p.getWanted();
                for (ItemLine itemLine : l) {
                    itemLine.setForSale(false);
                    itemLine.getItem().setWeight(PricelistsTools.loadWeight(itemLine.getItem().getName()));
                }
            }
        } catch (Exception ex) {
            LogX.log(Level.WARNING, "Error loading pricelists: " + f.getAbsolutePath(), ex, true);
            for (int i = 0; i < pricelists.length; i++) {
                Pricelist p = new Pricelist();
                p.setSystem(System.values()[i]);
                pricelists[i] = p;
            }
        }
    }
View Full Code Here

            fullUpdate();
            return;
        }
        if (evt.getPropertyName().equals(GalaxyPricelistPanel.P_PRICELISTSUPDATED)) {
            if (evt.getNewValue() == null) {
                Pricelist p;
                for (int i = 0; i < pricelists.length; i++) {
                    p = new Pricelist();
                    p.setSystem(System.values()[i]);
                    changeOnePricelist(p);
                }
            } else {
                Pricelist pp[] = (Pricelist[]) evt.getNewValue();
                for (int i = 0; i < pricelists.length; i++) {
                    changeOnePricelist(pp[i]);
                }
            }
            fullUpdate();
            return;
        }
        if (evt.getPropertyName().equals(PricelistPanel.P_PRICELISTUPDATED)) {
            Pricelist p = (Pricelist) evt.getNewValue();
            //java.lang.System.err.println("" + p);
            //java.lang.System.err.println("" + p.getSystem());
            changeOnePricelist(p);
            fullUpdate();
            return;
View Full Code Here

        ipd.setVisible(true);
        String text = ipd.getImportedText();
        if (text == null) {
            return;
        }
        Pricelist old[] = pricelists;
        Pricelist newpl[];
        try {
            if (text.toLowerCase().contains("<html>")) {
                newpl = PricelistsTools.importAllPricelistFromSource(text);
            } else {
                newpl = PricelistsTools.importAllPricelist(text);
View Full Code Here

        ipd.setVisible(true);
        String text = ipd.getImportedText();
        if (text == null) {
            return;
        }
        Pricelist old = pricelist;
        try {
            if (text.toLowerCase().contains("<html>")) {
                pricelist = PricelistsTools.importPricelistFromSource(text, pricelist.getSystem());
            } else {
                pricelist = PricelistsTools.importPricelist(text, pricelist.getSystem());
View Full Code Here

    private void jbClearListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbClearListActionPerformed
        int resp = JOptionPane.showConfirmDialog(this, "Do you want to clear the pricelist?", "Exit", JOptionPane.YES_NO_OPTION);
        if (resp != JOptionPane.YES_OPTION) {
            return;
        }
        Pricelist old = pricelist;
        pricelist = new Pricelist();
        pricelist.setSystem(old.getSystem());
        firePropertyChange(P_PRICELISTUPDATED, old, pricelist);
    }//GEN-LAST:event_jbClearListActionPerformed
View Full Code Here

    public static Pricelist importPricelistFromSource(String text, System galaxy) throws Exception {
        Map<String, LocationProperty> locationsProperties = (Map<String, LocationProperty>) Storage.getStorage().get(Main.STORAGE_LOCATIONSPROPERTIES);
        Map<String, Long> weightCache = (Map<String, Long>) Storage.getStorage().get(Main.STORAGE_WEIGHTCACHE);

        Pricelist pl = new Pricelist();
        pl.setSystem(galaxy);
        text = text.replace(",", "");
        String pattern = "<[^>]*item_id=([0-9]+)&[^>]*>([^<]*)(?:<[^>]*>\\s*)+X ([0-9,]+)(?: [(]([0-9,]+)[^<]*)?\\s*(?:<[^>]*>\\s*)+(?:for|at) [$]([0-9,]+)(?:<[^>]*>\\s*)+(?:For [0-9][^<]*)?(?:<[^>]*>\\s*)+<[^>]*system_id=([0-9]+)&sector_id=([0-9]+)&grid_id=([0-9]+)[^>]*>([^<]*)";
        Matcher m = Pattern.compile(pattern).matcher(text);

        while (m.find()) {
            // groups: 1-itemid, 2-item name, 3-quantity, 4-weight or null
            // 5-price 6,7,8-sys,sec,grid 9-place name
            ItemLine itemLine = new ItemLine();
            itemLine.setItem(new Item());
            itemLine.getItem().setName(m.group(2).replace('*', ' ').trim());
            itemLine.setQuantity(Long.parseLong(m.group(3)));
            if (m.group(4) == null) {
                itemLine.setForSale(false);
                itemLine.getItem().setWeight(PricelistsTools.loadWeight(itemLine.getItem().getName()));
            } else {
                itemLine.setForSale(true);
                long w = Long.parseLong(m.group(4));
                weightCache.put(itemLine.getItem().getName(), new Long(w));
                itemLine.getItem().setWeight(w);
            }
            itemLine.setPrice(Long.parseLong(m.group(5)));
            Location l = new Location();
            l.setName(m.group(9).trim());
            Long grd = Long.parseLong(m.group(8));
            if (grd == 190) {
                l.setPlanet(true);
            } else {
                l.setPlanet(false);
            }
            l.setGrid(grd);
            Long sector = Long.parseLong(m.group(7));
            l.setSector(sector);
            // get system id (6) and cross check
            l.setSystem(galaxy);
            // NEW: stash coords in file.
            LocationProperty lp = locationsProperties.get(itemLine.getItem().getName());
            if (lp == null) {
                lp = new LocationProperty();
            }
            lp.setLocation(galaxy, sector, grd);
            locationsProperties.put(itemLine.getItem().getName(), lp);

            itemLine.setLocation(l);
            if (itemLine.isForSale()) {
                pl.getForSale().add(itemLine);
            } else {
                pl.getWanted().add(itemLine);
            }
        }
        pl.setPricelistDate(new java.util.Date());
        return pl;
    }
View Full Code Here

    public static Pricelist importPricelist(String text, System galaxy) throws Exception {
        Map<String, LocationProperty> locationsProperties = (Map<String, LocationProperty>) Storage.getStorage().get(Main.STORAGE_LOCATIONSPROPERTIES);
        Map<String, Long> weightCache = (Map<String, Long>) Storage.getStorage().get(Main.STORAGE_WEIGHTCACHE);

        Pricelist pl = new Pricelist();
        pl.setSystem(galaxy);
        text = text.replace("\r", "");
        text = text.replace(",", "");
        text = text.replace("\t\t\t\t", "\t");
        text = text.replace("\t\t\t", "\t");
        text = text.replace("\t\t", "\t");
        text = text.replace("\t", " ");
        boolean forSale = false;
        boolean wanted = false;
        boolean planet = false;
        boolean starbase = false;
        java.lang.System.err.println(text);
        String rows[] = text.split("\n");
        boolean startOfListFound = false;
        for (String row : rows) {
            //this should avoid problems with stuff appearing at the begin of the list
            //and internet explorer
            //like recent greasemonkey planet buttons script from layze
            if (row.toLowerCase().contains("for sale at")) {
                startOfListFound = true;
            }
            if (!startOfListFound) {
                continue;
            }

            if (row.length() <= 1) {
                continue;
            }
            //end
            if (row.toLowerCase().contains("not looking to buy")) {
                forSale = false;
                wanted = false;
                continue;
            }
            if (row.toLowerCase().contains("have nothing to sell")) {
                forSale = false;
                wanted = false;
                continue;
            }
            if (row.toLowerCase().contains("for sale at")) {
                //if (!columns[0].toLowerCase().contains(galaxy.name().toLowerCase())) {
                //    throw new Exception("You have pasted a pricelist of a different galaxy.");
                //}
                forSale = true;
                wanted = false;
                if (row.toLowerCase().contains("planet")) {
                    planet = true;
                    starbase = false;
                }
                if (row.toLowerCase().contains("starbase")) {
                    planet = false;
                    starbase = true;
                }
                continue;
            }
            if (row.toLowerCase().contains("wanted at")) {
                //if (!columns[0].toLowerCase().contains(galaxy.name().toLowerCase())) {
                //    throw new Exception("You have pasted a pricelist from a different galaxy.");
                //}
                forSale = false;
                wanted = true;
                if (row.toLowerCase().contains("planet")) {
                    planet = true;
                    starbase = false;
                }
                if (row.toLowerCase().contains("starbase")) {
                    planet = false;
                    starbase = true;
                }
                continue;
            }
            if (row.indexOf("-------") != -1) {
                continue;
            }
            if (row.indexOf("_______") != -1) {
                continue;
            }


            if (forSale) {
                try {
                    int begin = 0;
                    int end = 0;
                    ItemLine itemLine = new ItemLine();
                    itemLine.setItem(new Item());
                    itemLine.setForSale(true);
                    begin = 0;
                    end = row.indexOf("X ", begin);
                    if (Character.isDigit(row.charAt(end + 2))) {
                        //the X of the price
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    } else {
                        //next X
                        end = row.indexOf("X ", end + 1);
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    }


                    begin = end + 2;
                    end = row.indexOf(" (", begin);
                    String qty = row.substring(begin, end).trim();
                    itemLine.setQuantity(Long.parseLong(qty));

                    begin = end + 2;
                    end = row.indexOf("Isaton");
                    String weight = row.substring(begin, end).trim();
                    long w = Long.parseLong(weight);
                    weightCache.put(itemLine.getItem().getName(), new Long(w));
                    itemLine.getItem().setWeight(w);

                    begin = row.indexOf("for $") + 5;
                    end = row.indexOf(" ", begin);
                    itemLine.setPrice(Long.parseLong(row.substring(begin, end).trim()));

                    Location l = new Location();
                    begin = end + 1;
                    l.setName(row.substring(begin).trim());
                    if (planet) {
                        l.setPlanet(true);
                        l.setSystem(galaxy);
                    }
                    if (starbase) {
                        l.setPlanet(false);
                        l.setSystem(galaxy);
                    }
                    // JUST a sec, lets check the coord cache.
                    LocationProperty lp = locationsProperties.get(itemLine.getItem().getName());
                    if (lp != null) {
                        l.setSector(lp.getSector());
                        l.setGrid(lp.getGrid());
                    }
                    itemLine.setLocation(l);
                    pl.getForSale().add(itemLine);
                } catch (Exception ex) {
                    throw new Exception("Impossible to import the pricelist. Offending line: " + row, ex);
                }
            }
            if (wanted) {
                try {
                    int begin = 0;
                    int end = 0;
                    ItemLine itemLine = new ItemLine();
                    itemLine.setItem(new Item());
                    itemLine.setForSale(false);
                    begin = 0;
                    end = row.indexOf("X ", begin);
                    if (Character.isDigit(row.charAt(end + 2))) {
                        //the X of the price
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    } else {
                        //next X
                        end = row.indexOf("X ", end + 1);
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    }

                    begin = end + 2;
                    end = row.indexOf(" ", begin);
                    String qty = row.substring(begin, end).trim();
                    itemLine.setQuantity(Long.parseLong(qty));

                    begin = row.indexOf("at $") + 4;
                    end = row.indexOf(" ", begin);
                    itemLine.setPrice(Long.parseLong(row.substring(begin, end).trim()));

                    itemLine.getItem().setWeight(PricelistsTools.loadWeight(itemLine.getItem().getName()));

                    Location l = new Location();
                    if (planet) {
                        begin = row.indexOf("CE") + 2;
                        l.setName(row.substring(begin).trim());
                        l.setPlanet(true);
                        l.setSystem(galaxy);
                    }
                    if (starbase) {
                        begin = end + 1;
                        l.setName(row.substring(begin).trim());
                        l.setPlanet(false);
                        l.setSystem(galaxy);
                    }
                    // JUST a sec, lets check the coord cache.
                    LocationProperty lp = locationsProperties.get(itemLine.getItem().getName());
                    if (lp != null) {
                        l.setSector(lp.getSector());
                        l.setGrid(lp.getGrid());
                    }
                    itemLine.setLocation(l);
                    pl.getWanted().add(itemLine);
                } catch (Exception ex) {
                    throw new Exception("Impossible to import the pricelist. Offending line: " + row, ex);
                }
            }
        }
        pl.setPricelistDate(new java.util.Date());
        return pl;
    }
View Full Code Here

    public static Pricelist[] importAllPricelistFromSource(String text) throws Exception {
        Map<String, LocationProperty> locationsProperties = (Map<String, LocationProperty>) Storage.getStorage().get(Main.STORAGE_LOCATIONSPROPERTIES);
        Map<String, Long> weightCache = (Map<String, Long>) Storage.getStorage().get(Main.STORAGE_WEIGHTCACHE);

        Pricelist newpls[] = new Pricelist[System.stars() + System.expanses()];
        for (int i = 0; i < newpls.length; i++) {
            newpls[i] = new Pricelist();
            newpls[i].setSystem(System.values()[i]);
            newpls[i].setPricelistDate(new java.util.Date());
        }

        text = text.replace(",", "");
View Full Code Here

    public static Pricelist[] importAllPricelist(String text) throws Exception {
        Map<String, LocationProperty> locationsProperties = (Map<String, LocationProperty>) Storage.getStorage().get(Main.STORAGE_LOCATIONSPROPERTIES);
        Map<String, Long> weightCache = (Map<String, Long>) Storage.getStorage().get(Main.STORAGE_WEIGHTCACHE);

        Pricelist newpls[] = new Pricelist[System.stars() + System.expanses()];
        for (int i = 0; i < newpls.length; i++) {
            newpls[i] = new Pricelist();
            newpls[i].setSystem(System.values()[i]);
            newpls[i].setPricelistDate(new java.util.Date());
        }
        Pricelist curpl = null;
        System cursys = null;
        String regex1 = "(for sale|wanted) at (\\w+) system (planets|starbases)";
        Pattern pat1 = Pattern.compile(regex1, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
        text = text.replace("\r", "");
        text = text.replace(",", "");
        text = text.replace("\t\t\t\t", "\t");
        text = text.replace("\t\t\t", "\t");
        text = text.replace("\t\t", "\t");
        text = text.replace("\t", " ");
        boolean forSale = false;
        boolean wanted = false;
        boolean planet = false;
        boolean starbase = false;
        java.lang.System.err.println(text);
        String rows[] = text.split("\n");
        for (String row : rows) {
            if (row.length() == 0) {
                continue;
            }
            //compatibility with internet explorer copy
            if (row.length() == 1) {
                continue;
            }
            if (row.toLowerCase().contains("item prices")) {
                continue;
            }
            if (row.toLowerCase().contains("adarian systemaltian systembasian")) {
                continue;
            }
            if (row.toLowerCase().contains("year")) {
                continue;
            }
            //end
            if (row.toLowerCase().contains("not looking to buy")) {
                forSale = false;
                wanted = false;
                continue;
            }
            if (row.toLowerCase().contains("have nothing to sell")) {
                forSale = false;
                wanted = false;
                continue;
            }
            Matcher m1 = pat1.matcher(row);
            if (m1.find()) {
                cursys = System.valueOf(m1.group(2));
                curpl = newpls[cursys.ordinal()];
            }
            if (row.toLowerCase().contains("for sale at")) {
                //if (!columns[0].toLowerCase().contains(galaxy.name().toLowerCase())) {
                //    throw new Exception("You have pasted a pricelist of a different galaxy.");
                //}
                forSale = true;
                wanted = false;
                if (row.toLowerCase().contains("planet")) {
                    planet = true;
                    starbase = false;
                }
                if (row.toLowerCase().contains("starbase")) {
                    planet = false;
                    starbase = true;
                }
                continue;
            }
            if (row.toLowerCase().contains("wanted at")) {
                //if (!columns[0].toLowerCase().contains(galaxy.name().toLowerCase())) {
                //    throw new Exception("You have pasted a pricelist from a different galaxy.");
                //}
                forSale = false;
                wanted = true;
                if (row.toLowerCase().contains("planet")) {
                    planet = true;
                    starbase = false;
                }
                if (row.toLowerCase().contains("starbase")) {
                    planet = false;
                    starbase = true;
                }
                continue;
            }
            if (row.indexOf("-------") != -1) {
                continue;
            }
            if (row.indexOf("_______") != -1) {
                continue;
            }


            if (forSale) {
                try {
                    int begin = 0;
                    int end = 0;
                    ItemLine itemLine = new ItemLine();
                    itemLine.setItem(new Item());
                    itemLine.setForSale(true);
                    begin = 0;
                    end = row.indexOf("X ", begin);
                    if (Character.isDigit(row.charAt(end + 2))) {
                        //the X of the price
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    } else {
                        //next X
                        end = row.indexOf("X ", end + 1);
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    }


                    begin = end + 2;
                    end = row.indexOf(" (", begin);
                    String qty = row.substring(begin, end).trim();
                    itemLine.setQuantity(Long.parseLong(qty));

                    begin = end + 2;
                    end = row.indexOf("Isaton");
                    String weight = row.substring(begin, end).trim();
                    long w = Long.parseLong(weight);
                    weightCache.put(itemLine.getItem().getName(), new Long(w));
                    itemLine.getItem().setWeight(w);

                    begin = row.indexOf("for $") + 5;
                    end = row.indexOf(" ", begin);
                    itemLine.setPrice(Long.parseLong(row.substring(begin, end).trim()));

                    Location l = new Location();
                    begin = end + 1;
                    l.setName(row.substring(begin).replace('*', ' ').trim());
                    if (planet) {
                        l.setPlanet(true);
                        l.setSystem(cursys);
                    }
                    if (starbase) {
                        l.setPlanet(false);
                        l.setSystem(cursys);
                    }
                    // JUST a sec, lets check the coord cache.
                    LocationProperty lp = locationsProperties.get(itemLine.getItem().getName());
                    if (lp != null) {
                        l.setSector(lp.getSector());
                        l.setGrid(lp.getGrid());
                    }
                    itemLine.setLocation(l);
                    curpl.getForSale().add(itemLine);
                } catch (Exception ex) {
                    throw new Exception("Impossible to import the pricelist. Offending line: " + row, ex);
                }
            }
            if (wanted) {
                try {
                    int begin = 0;
                    int end = 0;
                    ItemLine itemLine = new ItemLine();
                    itemLine.setItem(new Item());
                    itemLine.setForSale(false);
                    begin = 0;
                    end = row.indexOf("X ", begin);
                    if (Character.isDigit(row.charAt(end + 2))) {
                        //the X of the price
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    } else {
                        //next X
                        end = row.indexOf("X ", end + 1);
                        itemLine.getItem().setName(row.substring(begin, end).replace('*', ' ').trim());
                    }

                    begin = end + 2;
                    end = row.indexOf(" ", begin);
                    String qty = row.substring(begin, end).trim();
                    itemLine.setQuantity(Long.parseLong(qty));

                    begin = row.indexOf("at $") + 4;
                    end = row.indexOf(" ", begin);
                    itemLine.setPrice(Long.parseLong(row.substring(begin, end).trim()));

                    itemLine.getItem().setWeight(PricelistsTools.loadWeight(itemLine.getItem().getName()));

                    Location l = new Location();
                    if (planet) {
                        begin = row.indexOf("CE") + 2;
                        l.setName(row.substring(begin).trim());
                        l.setPlanet(true);
                        l.setSystem(cursys);
                    }
                    if (starbase) {
                        begin = end + 1;
                        l.setName(row.substring(begin).trim());
                        l.setPlanet(false);
                        l.setSystem(cursys);
                    }
                    // JUST a sec, lets check the coord cache.
                    LocationProperty lp = locationsProperties.get(itemLine.getItem().getName());
                    if (lp != null) {
                        l.setSector(lp.getSector());
                        l.setGrid(lp.getGrid());
                    }
                    itemLine.setLocation(l);
                    curpl.getWanted().add(itemLine);
                } catch (Exception ex) {
                    throw new Exception("Impossible to import the pricelist. Offending line: " + row, ex);
                }
            }
        }
View Full Code Here

TOP

Related Classes of eu.flatworld.cstrader.data.Pricelist

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.