Guest User

ToTDrops

a guest
Jun 17th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.12 KB | None | 0 0
  1. package gw2.tot;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.util.Comparator;
  7. import java.util.Iterator;
  8. import java.util.Map;
  9. import java.util.Scanner;
  10. import java.util.TreeMap;
  11.  
  12. import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument;
  13.  
  14. public class ToTDrops
  15. {
  16.     private TreeMap<String,Integer> dropMappings ;
  17.     private int bagCount ;
  18.  
  19.     public ToTDrops()
  20.     {
  21.         dropMappings = new TreeMap<String,Integer>(new IgnoreCaseComparator()) ;
  22.         setUp() ;
  23.     }
  24.  
  25.     public void incrementTotal(String item, int increment) throws ItemNotFoundException
  26.     {
  27.         if(increment > 0) {
  28.             if(dropMappings.containsKey(item) == true) {
  29.                 dropMappings.put(item,dropMappings.get(item) + increment) ;
  30.             } else {
  31.                 throw new ItemNotFoundException("The item you entered is not a valid drop.") ;
  32.             }
  33.         } else {
  34.             throw new IllegalArgumentException("Increment must be greater than 0") ;
  35.         }
  36.     }
  37.  
  38.     public void decrementTotal(String item, int decrement) throws ItemNotFoundException
  39.     {
  40.         if(decrement > 0) {
  41.             if(dropMappings.containsKey(item) == true) {
  42.                 dropMappings.put(item,dropMappings.get(item) - decrement) ;
  43.             } else {
  44.                 throw new ItemNotFoundException("The item you entered is not a valid drop.") ;
  45.             }
  46.         } else {
  47.             throw new IllegalArgumentException("Decrement must be greater than 0") ;
  48.         }
  49.     }
  50.  
  51.     public void generateEntryList() throws Exception
  52.     {
  53.        OdfSpreadsheetDocument odt = OdfSpreadsheetDocument.loadDocument("ToTDrops.odt");
  54.        
  55.    
  56.        Iterator<Map.Entry<String,Integer>> it = dropMappings.entrySet().iterator();
  57.        int i = 1 ;
  58.            
  59.             while (it.hasNext() == true) {
  60.                 Map.Entry pairs = (Map.Entry)it.next();
  61.                
  62.                 odt.getTableList().get(0).getCellByPosition("A" + i).setDisplayText((String) pairs.getKey()) ;
  63.                 odt.getTableList().get(0).getCellByPosition("B" + i).setDisplayText((pairs.getValue().toString())) ;
  64.                 it.remove(); // avoids a ConcurrentModificationException
  65.                 i++ ;
  66.             }
  67.        try {
  68.            odt.save("ToTDrops.odt") ;
  69.        } catch (Exception e) {
  70.            // TODO Auto-generated catch block
  71.            e.printStackTrace();
  72.        }
  73.     }
  74.  
  75.     private void setUp()
  76.     {
  77.         dropMappings.put("Bowl of Candy Corn Custard",0) ;
  78.         dropMappings.put("Glazed Peach Tart",0) ;
  79.         dropMappings.put("Glazed Pear Tart",0) ;
  80.         dropMappings.put("Piece of Candy Corn x1",0) ;
  81.         dropMappings.put("Piece of Candy Corn Almond Brittle",0) ;
  82.         dropMappings.put("Rotten Egg",0) ;
  83.         dropMappings.put("Spicy Pumpkin Cookie",0) ;
  84.         dropMappings.put("Strawberry Ghost",0) ;
  85.         dropMappings.put("Toilet Paper",0) ;
  86.         dropMappings.put("Chattering Skull x1",0) ;
  87.         dropMappings.put("Nougat Center x1",0) ;
  88.         dropMappings.put("Plastic Fang x1",0) ;
  89.         dropMappings.put("Recipe: Candy Corn Custard",0) ;
  90.         dropMappings.put("Recipe: Major Rune of the Mad King",0) ;
  91.         dropMappings.put("Recipe: Major Sigil of the Night",0) ;
  92.         dropMappings.put("Recipe: Superior Rune of the Mad King",0) ;
  93.         dropMappings.put("Recipe: Superior Sigil of the Night",0) ;
  94.         dropMappings.put("Recipe: Strawberry Ghost",0) ;
  95.         dropMappings.put("Candy Corn Tonic",0) ;
  96.         dropMappings.put("Concentrated  Halloween Tonic",0) ;
  97.         dropMappings.put("Endless Halloween Tonic",0) ;
  98.         dropMappings.put("Halloween Tonic",0) ;
  99.         dropMappings.put("Plastic Spider Tonic",0) ;
  100.     }
  101. }
  102.  
  103.  
  104. class IgnoreCaseComparator implements Comparator<String>
  105. {
  106.     public int compare(String s1, String s2)
  107.     {
  108.         return s1.compareToIgnoreCase(s2) ;
  109.     }
  110. }
  111.  
  112. class ItemNotFoundException extends Exception
  113. {
  114.     public ItemNotFoundException()
  115.     {
  116.         super() ;
  117.     }
  118.  
  119.     public ItemNotFoundException(String message)
  120.     {
  121.         super(message) ;
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment