//European countries use ";" as //CSV separator because "," is their digit separator private static final String CSV_SEPARATOR = ","; private static void writeToCSV(ArrayList<Product> productList) { try { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("products.csv"), "UTF-8")); for (Product product : productList) { StringBuffer oneLine = new StringBuffer(); oneLine.append(product.getId() <=0 ? "" : product.getId()); oneLine.append(CSV_SEPARATOR); oneLine.append(product.getName().trim().length() == 0? "" : product.getName()); oneLine.append(CSV_SEPARATOR); oneLine.append(product.getCostPrice() < 0 ? "" : product.getCostPrice()); oneLine.append(CSV_SEPARATOR); oneLine.append(product.isVatApplicable() ? "Yes" : "No"); bw.write(oneLine.toString()); bw.newLine(); } bw.flush(); bw.close(); } catch (UnsupportedEncodingException e) {} catch (FileNotFoundException e){} catch (IOException e){} }
public void updateProduct(Product product) throws ProductNotFoundException { for (Product existing : allProducts) { if (existing.getId() == product.getId()) { existing.setPrice(product.getPrice()); return; } } System.out.println("No such product " + product.getId()); throw new ProductNotFoundException(product.getName()); }
public void updateProduct(Product product) throws ProductNotFoundException { Iterator<Product> it = allProducts.iterator(); Product p = null; if (!allProducts.isEmpty()) { while (it.hasNext()) { p = it.next(); if (p.getId() == product.getId()) { p.setPrice(product.getPrice()); System.out.println("Successfully updated the product " + product.getId()); } } } if (p == null ) { System.out.println("No such product " + product.getId()); throw new ProductNotFoundException(product.getName()); } }
public void updateProduct(Product product) throws ProductNotFoundException { Iterator<Product> it = allProducts.iterator(); Product p = null; if (!allProducts.isEmpty()) { while (it.hasNext()) { p = it.next(); if (p.getId() == product.getId()) { p.setPrice(product.getPrice()); System.out.println("Successfully updated the product " + product.getId()); return; } } } throw new ProductNotFoundException(product.getName()); }
ApplicationContext context = new ClassPathXmlApplicationContext( "FileReaderConfig.xml"); ProductFieldSetMapper obj = (ProductFieldSetMapper) context.getBean("fieldSetMapper"); DelimitedLineTokenizer tokenizer = (DelimitedLineTokenizer) context .getBean("lineTokenizer"); FieldSet fieldSet = tokenizer.tokenize("1,Pepsi,Cold drinks,30"); Product product = (Product) obj.mapFieldSet(fieldSet); System.out.println(product.getDescription() + "-" + product.getId() + "-" + product.getName());
@Stateless public class ShoppingServiceLocal implements ShoppingService { @EJB private ProductDAO productDAO; @EJB private OrderDAO orderDAO; @Override public List<Product> searchProducts(String query) { return productDAO.find(query); } @Override public Order orderProduct(User user, Product product, int quantity) { product.setAvailable(product.getAvailable() - quantity); productDAO.update(product); Order order = new Order(user.getId(), product.getId(), quantity); orderDAO.create(order); return order; } }
layout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { layout.getViewTreeObserver().removeGlobalOnLayoutListener(this); RelativeLayout.LayoutParams layoutParams; int currentX = 20; int currentY = 20; for (Product product: controller.getProducts("pizza")){ layoutParams = new RelativeLayout.LayoutParams(BUTTON_WIDTH, BUTTON_HEIGHT); Button tempButton = new Button(getActivity().getApplicationContext()); tempButton.setId(product.getId()); tempButton.setText(product.getName()); layoutParams.setMargins(currentX, currentY, 0, 0); tempButton.setLayoutParams(layoutParams); layout.addView(tempButton); if (layout.getWidth() < currentX + MARGIN_LEFT + (2 * BUTTON_WIDTH)){ currentX = 20; currentY += BUTTON_HEIGHT + MARGIN_BOTTOM; } else{ currentX += MARGIN_LEFT + BUTTON_WIDTH; } } //layout.requestLayout(); } });
this.id = new SimpleIntegerProperty(product.getId()); this.name = new SimpleStringProperty(product.getName())