Package sg.edu.nus.iss.se07.common

Examples of sg.edu.nus.iss.se07.common.Tuple2


                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new DataAccessException("[StoreKeeperDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[StoreKeeperDA::readData]Record not found.");
                                        }

                                        dataObjectSet = new ArrayList<Tuple2<NameValue<String>, NameValue<String>>>();
                                        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) {
                                                        throw new DataAccessException("[StoreKeeperDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(StoreKeeperDA.class.getName()).log(Level.SEVERE, "[StoreKeeperDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                NameValue<String> storekeeperName = new NameValue<String>("StoreKeeperName", fields[0]);
                                                                NameValue<String> storekeeperPassword = new NameValue<String>("StoreKeeperPassword", fields[1]);
                                                                dataObjectSet.add(new Tuple2<NameValue<String>, NameValue<String>>(storekeeperName, storekeeperPassword));
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[StoreKeeperDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here


                                FileUtil.writeContents(bw, data);
                        } else {
                                throw new IOException("[MemberDA::writeData]Failed to create filename " + fileName);
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here

                                        Member member = new Member(memberID, memberName, memberPoint);
                                        String data = member.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new DataAccessException("[MemberDA::writeData]Failed to create filename " + fileName);
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here

                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new DataAccessException("[MemberDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[MemberDA::readData]Record not found.");
                                        }

                                        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(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 3) {
                                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                //get all member value
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }

                                                                //match
                                                                if (memberID.equalsIgnoreCase(code)) {
                                                                        dataObject = new Member();
                                                                        dataObject.setMemberID(code);
                                                                        dataObject.setMemberName(name);
                                                                        dataObject.setMemberPoint(point);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[MemberDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new DataAccessException("[MemberDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[MemberDA::readData]Record not found.");
                                        }

                                        dataObjectSet = new ArrayList<Tuple3<NameValue<String>, NameValue<String>, NameValue<Integer>>>();
                                        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) {
                                                        throw new DataAccessException("[MemberDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 3) {
                                                                Logger.getLogger(MemberDA.class.getName()).log(Level.SEVERE, "[MemberDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                int point = -1;
                                                                try {
                                                                        point = Integer.parseInt(fields[2]);
                                                                } catch (NumberFormatException nfx) {
                                                                        throw new DataAccessException(nfx.getMessage(), nfx);
                                                                }

                                                                NameValue<String> memberID = new NameValue<String>("MemberID", code);
                                                                NameValue<String> memberName = new NameValue<String>("MemberName", name);
                                                                NameValue<Integer> memberPoint = new NameValue<Integer>("MemberPoint", point);
                                                                dataObjectSet.add(new Tuple3<NameValue<String>, NameValue<String>, NameValue<Integer>>(memberID, memberName, memberPoint));
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[MemberDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

                                FileUtil.writeContents(bw, data);
                        } else {
                                throw new IOException("[CategoryDA::writeData]Failed to create filename " + fileName);
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here

                                        Category category = new Category(categoryCode, categoryName);
                                        String data = category.toCSVFormat(format);
                                        FileUtil.writeContents(bw, data);
                                }
                        } else {
                                throw new DataAccessException("[CategoryDA::writeData]Failed to create filename " + fileName);
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        try {
                                if (bw != null) {
                                        bw.close();
                                }
View Full Code Here

                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new DataAccessException("[CategoryDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[CategoryDA::readData]Record not found.");
                                        }

                                        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::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                        throw new DataAccessException("[CategoryDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                String code = fields[0];
                                                                String name = fields[1];
                                                                if (categoryCode.equalsIgnoreCase(code)) {
                                                                        dataObject = new Category();
                                                                        dataObject.setCategoryCode(code);
                                                                        dataObject.setCategoryName(name);
                                                                        i = lines.length;
                                                                }
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[CategoryDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

                                if (contents == null) {
                                        return null;
                                }
                                String[] lines = StringUtil.parse(contents, format.getEndOfLineSymbols());
                                if (lines == null) {
                                        throw new DataAccessException("[CategoryDA::readData]Record not found.");
                                } else {

                                        if (lines.length < 1) {
                                                throw new DataAccessException("[CategoryDA::readData]Record not found.");
                                        }

                                        dataObjectSet = new ArrayList<Tuple2<NameValue<String>, NameValue<String>>>();
                                        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) {
                                                        throw new DataAccessException("[CategoryDA::readData]Unable to read record no " + (String.valueOf(i + 1)));
                                                } else {
                                                        if (fields.length != 2) {
                                                                Logger.getLogger(CategoryDA.class.getName()).log(Level.SEVERE, "[CategoryDA::readData]Record no " + (String.valueOf(i + 1)) + " is corrupted");
                                                        } else {
                                                                NameValue<String> categoryCode = new NameValue<String>("CategoryCode", fields[0]);
                                                                NameValue<String> categoryName = new NameValue<String>("CategoryName", fields[1]);
                                                                dataObjectSet.add(new Tuple2<NameValue<String>, NameValue<String>>(categoryCode, categoryName));
                                                        }
                                                }
                                        }
                                }
                        } else {
                                throw new DataAccessException("[CategoryDA::readData]File not found.");
                        }
                } catch (IOException ex) {
                        throw new DataAccessException(ex.getMessage(), ex);
                } finally {
                        if (br != null) {
                                try {
                                        br.close();
                                } catch (IOException ex) {
View Full Code Here

                                        categoryName = newCategory.getCategoryName();
                                }

                                NameValue<String> nmCategoryCode = new NameValue<String>("CategoryCode", categoryCode);
                                NameValue<String> nmCategoryName = new NameValue<String>("CategoryName", categoryName);
                                Tuple2<NameValue<String>, NameValue<String>> dataObject = new Tuple2(nmCategoryCode, nmCategoryName);
                                newDataObjectSet.add(dataObject);
                        }


                        try {
View Full Code Here

TOP

Related Classes of sg.edu.nus.iss.se07.common.Tuple2

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.