Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. private void updateDisplay() {
  2.        
  3.         new Thread(
  4.                 () -> {
  5.                         if (catalogue == null)
  6.                             throw new Error("Internal error: catalogue not set");
  7.                         if (displayArea == null)
  8.                             throw new Error(
  9.                                     "Internal error: display area not set");
  10.                         // Then do the display
  11.                         value = 0;
  12.                         Document doc = displayArea.getDocument();
  13.                         // For each item in the stock, add it to the description
  14.                         // list and the total value
  15.                         List<String> list = new ArrayList<String>();
  16.                         try {
  17.                             doc.remove(0, doc.getLength());
  18.                             for (String name : catalogue.getEntryNames()) {
  19.                                 list.add(name);
  20.                             }
  21.                             list.parallelStream().forEach(n -> {
  22.                                 try {
  23.                                    
  24.                                     IEntry entry = catalogue.getEntry(n);
  25.                                     Product product = entry.getProduct();
  26.                                     int quantity = entry.getQuantity();
  27.                                     String text = product.getName() + "@"
  28.                                             + product.getPrice() + ": " + quantity
  29.                                             + "\n";
  30.                                     doc.insertString(doc.getLength(), text, null);
  31.                                     value += quantity * product.getPrice();
  32.                                 } catch (Exception e) {
  33.                                     // TODO Auto-generated catch block
  34.                                     e.printStackTrace();
  35.                                 }
  36.                             });
  37.                                
  38.                             doc.insertString(doc.getLength(), "Total value: "
  39.                                     + value, null);
  40.                         } catch (RemoteException exn) {
  41.                             throw new Error("Remote failure: " + exn);
  42.                         } catch (BadLocationException e) {
  43.                             throw new Error(
  44.                                     "Internal error: bad text location in GUI");
  45.                         }
  46.                    
  47.                 }).start();
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement