Frame.java
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2011, Sjoerd van den Dries
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  * 
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Technische Universiteit Eindhoven nor the
00014  *       names of its contributors may be used to endorse or promote products
00015  *       derived from this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 
00031 package tfjava;
00032 
00033 import java.util.HashMap;
00034 import java.util.Set;
00035 
00042 public class Frame {
00043     
00045     private String frameID;
00047     private HashMap<Frame, TimeCache> parentMap;
00049     private long maxStorageTime;
00050     
00054     public Frame(String frameID, long maxStorageTime) {
00055         this.frameID = frameID;
00056         this.maxStorageTime = maxStorageTime;
00057         parentMap = new HashMap<Frame, TimeCache>();
00058     }
00059     
00063     public boolean insertData(TransformStorage newData) {
00064         Frame childFrame = newData.getChildFrame();
00065         
00066         if (childFrame != this) {
00067             // new data is not inserted in the right frame. TODO: throw error
00068             return false;
00069         }
00070         
00071         Frame parentFrame = newData.getParentFrame();
00072         TimeCache cache = parentMap.get(parentFrame);
00073         
00074         if (cache == null) {
00075             cache = new TimeCache(maxStorageTime, parentFrame, childFrame);
00076             parentMap.put(parentFrame, cache);
00077         }
00078         
00079         return cache.insertData(newData);
00080     }
00081     
00089     public TransformStorage getData(long time, Frame sourceFrame) {
00090         TimeCache cache = parentMap.get(sourceFrame);
00091         
00092         if (cache == null) {
00093             // parent frame not found. TODO: throw error
00094             return null;
00095         }
00096         return cache.getData(time);
00097     }
00098     
00102     public String getFrameID() {
00103         return frameID;
00104     }
00105     
00109     public TimeCache getTimeCache(Frame sourceFrame) {
00110         return parentMap.get(sourceFrame);
00111     }
00112     
00116     public Set<Frame> getParentFrames() {
00117         return parentMap.keySet();
00118     }
00119     
00120 }


tfjava
Author(s): Sjoerd van den Dries
autogenerated on Sun Oct 5 2014 22:54:19