Examples of CategorySet


Examples of sg.edu.nus.iss.se07.bc.category.CategorySet

         *
         * @return
         * @throws sg.edu.nus.iss.se07.common.exceptions.AppException
         */
        public CategorySet readDataSet() throws AppException {
                CategorySet dataObjectSet = null;
                BufferedReader br = null;

                try {
                        br = FileUtil.getBufferedReader(fileName);
                        if (br != null) {
                                String contents = FileUtil.getContents(br);
                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Record not found.");
                                        throw new IOException("[CategoryDA::readDataSet]Record not found.");
                                } else {
                                        if (lines.length < 1) {
                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Record not found.");
                                                throw new IOException("[CategoryDA::readDataSet]Record not found.");
                                        }

                                        dataObjectSet = new CategorySet();
                                        for (int i = 0; i < lines.length; i++) {
                                                String record = lines[i];
                                                String[] fields = StringUtil.parse(record, String.valueOf((char) format.getDelimiterChar()));
                                                if (fields == null) {
                                                        Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new IOException("[CategoryDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        //throw new IOException("[CategoryDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                Category category = new Category();
                                                                category.setCategoryCode(fields[0]);
                                                                category.setCategoryName(fields[1]);
                                                                dataObjectSet.add(category);
                                                                category = null;
                                                        }
                                                }
                                        }
                                }
View Full Code Here

Examples of sg.edu.nus.iss.se07.bc.category.CategorySet

         * @param categoryCode
         * @return
         * @throws sg.edu.nus.iss.se07.common.exceptions.AppException
         */
        public CategorySet readDataSet(String categoryCode) throws AppException {
                CategorySet dataObjectSet = null;
                BufferedReader br = null;

                try {
                        br = FileUtil.getBufferedReader(fileName);
                        if (br != null) {
                                String contents = FileUtil.getContents(br);
                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Record not found.");
                                        throw new IOException("[CategoryDA::readDataSet]Record not found.");
                                } else {
                                        if (lines.length < 1) {
                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Record not found.");
                                                throw new IOException("[CategoryDA::readDataSet]Record not found.");
                                        }

                                        dataObjectSet = new CategorySet();
                                        for (int i = 0; i < lines.length; i++) {
                                                String record = lines[i];
                                                String[] fields = StringUtil.parse(record, String.valueOf((char) format.getDelimiterChar()));
                                                if (fields == null) {
                                                        Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new IOException("[CategoryDA::readDataSet]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        //throw new IOException("[CategoryDA::readDataSet]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                if (categoryCode.equalsIgnoreCase(code)) {
                                                                        Category category = new Category();
                                                                        category.setCategoryCode(code);
                                                                        category.setCategoryName(name);
                                                                        dataObjectSet.add(category);
                                                                        category = null;
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
View Full Code Here

Examples of sg.edu.nus.iss.se07.bc.category.CategorySet

        }

        public void generateReport() {
                String reportFormat = "%1$3d\t%2$3s\t%3$s\n";
                CategoryManager categoryManager = null;
                CategorySet categorySet = null;
                try {
                        categoryManager = new CategoryManager();
                        categorySet = categoryManager.list();
                        if (categorySet == null) {
                                return;
                        }
                        for (int i = 0; i < categorySet.length(); i++) {
                                System.out.format(reportFormat, (i + 1), categorySet.get(i).getCategoryCode(), categorySet.get(i).getCategoryName());
                        }
                } catch (AppException ex) {
                        Logger.getLogger(CategoryRpt.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                        categoryManager = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.