Want more features on Pastebin? Sign Up, it's FREE!
Guest

Sync Issue - Controller.java

By: lukejessee on Jun 13th, 2012  |  syntax: Java  |  size: 0.72 KB  |  views: 143  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. public class Controller{
  5.         Tuple3f defaultColor = new Tuple3f();
  6.         Map<Tuple3f, TestBuffer> colorToBufferMap = new HashMap<Tuple3f, TestBuffer>();
  7.         int i=0;
  8.        
  9.         public void addSome(Integer toAdd) {
  10.                 TestBuffer buffer = getBuffer();
  11.  
  12.                 for (int j=0;j<toAdd;j++) {
  13.                         buffer.add(i++);
  14.                 }
  15.         }
  16.  
  17.         public void remove() {
  18.                 TestBuffer oldBuffer = getBuffer();
  19.                 oldBuffer.remove(i++);
  20.         }
  21.  
  22.         public TestBuffer getBuffer() {
  23.                 TestBuffer buffer = null;
  24.                 if (colorToBufferMap.containsKey(defaultColor)) {
  25.                         buffer = colorToBufferMap.get(defaultColor);
  26.                 } else {
  27.                         buffer = new TestBuffer();
  28.                         colorToBufferMap.put(defaultColor, buffer);
  29.                 }
  30.                 return buffer;
  31.         }
  32. }
clone this paste RAW Paste Data