Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright 2012 AndroidPlot.com
      3  *
      4  *    Licensed under the Apache License, Version 2.0 (the "License");
      5  *    you may not use this file except in compliance with the License.
      6  *    You may obtain a copy of the License at
      7  *
      8  *        http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  *    Unless required by applicable law or agreed to in writing, software
     11  *    distributed under the License is distributed on an "AS IS" BASIS,
     12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  *    See the License for the specific language governing permissions and
     14  *    limitations under the License.
     15  */
     16 
     17 package com.androidplot.ui;
     18 
     19 import com.androidplot.Series;
     20 
     21 import java.util.LinkedList;
     22 import java.util.List;
     23 
     24 /**
     25  * Associates a Series with a Formatter.
     26  * @param 
     27  * @param 
     28  */
     29 public class SeriesAndFormatterList<SeriesType extends Series, FormatterType> {
     30     private LinkedList<SeriesType> seriesList;
     31     private LinkedList<FormatterType> formatterList;
     32     {
     33         seriesList = new LinkedList<SeriesType>();
     34         formatterList = new LinkedList<FormatterType>();
     35     }
     36 
     37     public boolean contains(SeriesType series) {
     38         return seriesList.contains(series);
     39     }
     40 
     41     public int size() {
     42         return seriesList.size();
     43     }
     44 
     45     public List<SeriesType> getSeriesList() {
     46         return seriesList;
     47     }
     48 
     49     public List<FormatterType> getFormatterList() {
     50         return formatterList;
     51     }
     52 
     53     public boolean add(SeriesType series, FormatterType formatter) {
     54         if(series == null || formatter == null) {
     55             throw new IllegalArgumentException("series and formatter must not be null.");
     56         }
     57         if(seriesList.contains(series)) {
     58             return false;
     59         }
     60         seriesList.add(series);
     61         formatterList.add(formatter);
     62         return true;
     63     }
     64 
     65     public boolean remove(SeriesType series) {
     66         int index = seriesList.indexOf(series);
     67         if(index < 0) {
     68             return false;
     69         }
     70         seriesList.remove(index);
     71         formatterList.remove(index);
     72         return true;
     73     }
     74 
     75 
     76     public FormatterType getFormatter(SeriesType series) {
     77         return formatterList.get(seriesList.indexOf(series));
     78     }
     79 
     80     public FormatterType getFormatter(int index) {
     81         return formatterList.get(index);
     82     }
     83 
     84     public SeriesType getSeries(int index) {
     85         return seriesList.get(index);
     86     }
     87 
     88     public FormatterType setFormatter(SeriesType series, FormatterType formatter) {
     89         return formatterList.set(seriesList.indexOf(series), formatter);
     90     }
     91 }
     92