function Product(name,price) { this.name = name; this.price = price; //this.discount = 0; // <- remove this line and refactor with the code below var _discount; // private member Object.defineProperty(this,"discount",{ get: function() { return _discount; }, set: function(value) { _discount = value; if(_discount>80) _discount = 80; } }); } // the client code var sneakers = new Product("Sneakers",20); sneakers.discount = 50; // 50, setter is called sneakers.discount+= 20; // 70, setter is called sneakers.discount+= 20; // 80, not 90! alert(sneakers.discount); // getter is called
public class PriceSorter implements Comparator<Product>{ public int compare(Product one, Product another){ int returnVal = 0; if(one.getPrice() < another.getPrice()){ returnVal = -1; }else if(one.getPrice() > another.getPrice()){ returnVal = 1; }else if(one.getPrice() == another.getPrice()){ returnVal = 0; } return returnVal; } }
assertEquals(1, products.size()); Product product = products.iterator().next(); assertEquals(productName, product.getProductName()); assertEquals(price, product.getPrice());
public Optional<BigDecimal> getActualUnitPrice() { if (this.price != null) { return Optional.of(price); } else if (this.getParent().isPresent() && this.getParent().get().isLoaded()) { Purchasable parent = this.getParent().get().get(); if (!Product.class.isAssignableFrom(parent.getClass())) { throw new RuntimeException("Cannot handle a parent purchasable that is not a product"); } Product parentProduct = (Product) parent; return Optional.fromNullable(parentProduct.getPrice()); } return Optional.absent(); }
if (purchasable.getParent().isPresent() && purchasable.getParent().get().isLoaded()) { rootPurchasable = purchasable.getParent().get().get(); title = rootPurchasable.getTitle() + " - " + purchasable.getTitle(); } else { if (product.getVatRateId().isPresent() && getRateDefinition(product.getVatRateId().get()).isPresent()) { vatRate = getRateDefinition(product.getVatRateId().get()).get().getValue(); } else { vatRate = taxesSettings.getVat().getValue().getDefaultRate(); orderItem.setPurchasableId(product.getId()); orderItem.setType("product"); orderItem.setTitle(title); addOrderAddons(rootPurchasable, data); if (product.isVirtual()) { data.put("variant", new HashMap<String, Object>() put("id", purchasedProduct.getId()); put("slug", purchasedProduct.getSlug()); put("title", purchasedProduct.getTitle());
Product product = (Product) p; if (product.getAddons().isLoaded()) { Map<String, Object> itemAddons = Maps.newHashMap(); Map<String, AddonGroup> addons = product.getAddons().get(); for (String groupName : addons.keySet()) { AddonGroup addonGroup = addons.get(groupName); (Map<String, AddonGroupDefinition>[]) sources); if (definition.isPresent() && definition.get().getProperties().containsKey("checkout.includeInOrder"))
public void update(Product product) throws EntityDoesNotExistException, InvalidEntityException { this.dao.begin(); Product originalProduct = this.findBySlug(product.getSlug(), product.getParentId()); if (originalProduct == null) { this.dao.commit(); throw new EntityDoesNotExistException(); } if (!product.getAddons().isLoaded()) { product.setAddons(originalProduct.getAddons().get()); } getObservationManager().notify(new EntityUpdatingEvent(), product); product.setId(originalProduct.getId()); Integer updatedRows = this.dao.updateProduct(product); this.dao.createOrUpdateAddons(product); if (product.getLocalizedVersions() != null && !product.getLocalizedVersions().isEmpty()) { Map<Locale, Map<String, Object>> localizedVersions = product.getLocalizedVersions(); for (Locale locale : localizedVersions.keySet()) { this.dao.createOrUpdateTranslation(product.getId(), locale, localizedVersions.get(locale)); } } this.dao.commit(); if (updatedRows <= 0) { throw new StoreException("No rows was updated when updating product"); } getObservationManager().notify(new EntityUpdatedEvent(), product); }
public Product create(Product product) throws EntityAlreadyExistsException, InvalidEntityException if (this.dao.findBySlug(product.getSlug(), getTenant(), product.getParentId()) != null) { throw new EntityAlreadyExistsException(); if (!product.getAddons().isLoaded()) { product.setAddons(new HashMap<String, AddonGroup>()); product.setId(entityId); product.setCreationDate(new Date()); if (product.getParentId() != null) { this.dao.createChildEntity(product, PRODUCT_TABLE_NAME, getTenant()); } else { this.dao.createEntity(product, PRODUCT_TABLE_NAME, getTenant()); product.setId(entityId); Integer lastIndex; if (product.getParentId() == null) { lastIndex = this.dao.lastPosition(getTenant()); } else {
String price = productItem.getPrice().toString(); holder.productTitle.setText(productItem.getTitle().toString()); holder.productSubTitle.setText(productItem.getSubtitle().toString()); holder.productQuantity.setText(productItem.getVolume().toString()); holder.priceDollar.setText(pricearray[0]+"."); holder.priceCent.setText(pricearray[1]); if(productItem.getInCart()) { holder.productCount.setVisibility(View.VISIBLE); holder.productCount.setText(productItem.getVolume()); .load(productItem.getImageUrl()) .placeholder(R.drawable.favourites) .error(R.drawable.favourites) .into(holder.productImage); urlSlug = productItem.getUrlSlug();
Product product = productStore.findById(idAndType.getId()); if (product != null) { if (product.getParentId() != null) { Product parent = productStore.findById(product.getParentId()); if (parent == null) { product.setParent(parent); } catch (Exception e) { logger.warn("Failed to add back product [{}] from session", product.getId());
public Product createProduct(Product entity) throws InvalidEntityException, EntityAlreadyExistsException { if (Strings.isNullOrEmpty(entity.getSlug())) { entity.setSlug(this.slugifier.slugify(entity.getTitle())); } productStore.get().create(entity); return this.findProductBySlug(entity.getSlug()); }
public class ProductMapper implements RowMapper<Product> { public Product mapRow(ResultSet rs, int rowNum) throws SQLException { Product product = new Product(); product.setProduct_id(rs.getInt("product_id")); //was id. was causing BadSqlGrammarException product.setProduct_name(rs.getString("product_name")); //was name. was causing BadSqlGrammarException product.setPrice(rs.getDouble("price")); product.setQuantity(rs.getInt("quantity")); return product; } }
@RequestMapping(value = "allproduct", method = RequestMethod.GET, headers = "Accept=*/*") public @ResponseBody String productList() { List<Product> products = ProductDAO.INSTANCE.listProduct(); String json = "["; for (int i = 0; i < products.size(); i++) { Product o = products.get(i); if (i > 0) { json += ","; } json += "{\"value\":\"" + o.getCode() + "\",\"label\":\"" + o.getCode() + " - " + o.getProvider() + " - " + o.getNominal() + "\",\"price\":\"" + o.getPrice() + "\",\"cost\":\"" + o.getCost() + "\"}"; } json += "]"; System.out.println(json); return json; }
switch (columnIndex) { case 0: value = product.getIdProduct(); break; case 1: value = product.getNomProduct(); break; case 2: value = product.getPrice(); break; case 3: value = product.getQuantity(); break;
ListMultimap<String, MyProduct> result = Multimaps.index(productList, new Function<String, Product>() { @Override public String apply(Product input) { return input.getTitle(); } });
public boolean apply(@Nullable Product input) { return input.getParentId() == null || input.isVirtual(); } };
ImmutableList<Product> results = FluentIterable.from(products).filter(new Predicate<Product>() { @Override public boolean apply(Product input) { return input.getType() == ProductType.BANANA; } }).toSortedList(new Comparator<Product>() { @Override public int compare(Product o1, Product o2) { return o1.getPrice().compareTo(o2.getPrice()); } });
Criteria crt=session.createCriteria(Product.class); List<Product> l=crt.list(); for(Product p:l) { System.out.println(p.getPrice()); System.out.println(p.getProductId()); System.out.println(p.getProName()); }