1 4 package com.openedit.store; 5 6 import java.util.ArrayList ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 10 import org.openedit.money.Money; 11 12 13 16 public class PriceSupport 17 { 18 protected List fieldTiers; 19 20 public Money getYourPriceByQuantity(int inQuantity) 21 { 22 Money price = Money.ZERO; 23 for (Iterator iter = getTiers().iterator(); iter.hasNext();) 25 { 26 PriceTier tier = (PriceTier)iter.next(); 27 if( inQuantity >= tier.getThresholdQuantity()) 28 { 29 price = tier.getValue(); 30 } 31 32 } 33 return price; 34 35 } 36 37 38 public List getTiers() 39 { 40 if (fieldTiers == null) 41 { 42 fieldTiers = new ArrayList (); 43 } 44 return fieldTiers; 45 } 46 47 public void addTierPrice( int inQuantity, Price inPrice ) 48 { 49 50 int finalPlace = -1; 51 for (int i = 0; i < getTiers().size(); i++) 52 { 53 PriceTier tier = (PriceTier) getTiers().get(i); 54 if( tier.getThresholdQuantity() == inQuantity ) 55 { 56 finalPlace = i; 57 getTiers().remove(tier); 58 break; 59 } 60 if( tier.getThresholdQuantity() > inQuantity ) 61 { 62 finalPlace = i-1; 63 break; 64 } 65 66 } 67 if ( finalPlace == -1) 69 { 70 finalPlace = getTiers().size(); 71 } 72 PriceTier tier = new PriceTier(); 73 tier.setPrice( inPrice ); 74 tier.setThresholdQuantity( inQuantity ); 75 getTiers().add( finalPlace, tier ); 76 } 77 78 81 public Money getRetailPrice() 82 { 83 Money price = Money.ZERO; 84 for (Iterator iter = getTiers().iterator(); iter.hasNext();) 86 { 87 PriceTier tier = (PriceTier)iter.next(); 88 if( 1 >= tier.getThresholdQuantity()) 89 { 90 price = tier.getPrice().getRetailPrice(); 91 } 92 93 } 94 return price; 95 } 96 97 public boolean isOnSale() 98 { 99 if ( getTiers().isEmpty() ) 100 { 101 return false; 102 } 103 PriceTier tier = (PriceTier)getTiers().get(0); 104 return tier.getPrice().isOnSale(); 105 } 106 107 108 111 public void clear() 112 { 113 getTiers().clear(); 114 } 115 } 116 | Popular Tags |