1ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes/* 2ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * Copyright 2012 AndroidPlot.com 3ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * 4ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * you may not use this file except in compliance with the License. 6ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * You may obtain a copy of the License at 7ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * 8ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * 10ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * Unless required by applicable law or agreed to in writing, software 11ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * See the License for the specific language governing permissions and 14ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * limitations under the License. 15ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes */ 16ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes 170965ac3ceff49f3c090c417c0e30ea51c6f294a7Andreas Gampepackage com.androidplot.ui; 18ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes 191c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughesimport com.androidplot.Series; 20ddfdbb9d172fe9b72e08e8d7deab0aa3b8acf044Elliott Hughes 210ac77ac8e915bff1a863e371f9b363033f9cf759Elliott Hughesimport java.util.LinkedList; 2244177e6982a62506127a857070a2452956c3f0f1Enrico Granataimport java.util.List; 236d1649c5b37b21ef2b690bc0f86306e19a32db02Yi Kong 248f5b46d72e5c1b1b1dd4357580c4fb5a60e3f4deErik Kline/** 25b974666d79ebc392b37ec1ae83aae57ae6331c08Elliott Hughes * Associates a Series with a Formatter. 264f11ebea266eada830d507b8f011e811a8e5d7bcElliott Hughes * @param270a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes * @param 28a8b7587c5001db3489c64ac1d16c254a683f76bdLorenzo Colitti */ 2970c820401677ca251ad09ac64cc23c760764e75dElliott Hughespublic class SeriesAndFormatterList<SeriesType extends Series, FormatterType> { 30d4419fce71d11ec8494525eca65e54d1aab51de6Elliott Hughes private LinkedList<SeriesType> seriesList; 31a5fb706fe4a6dbeaaf4cb1f8bbc2c68b0a2a3f3cElliott Hughes private LinkedList<FormatterType> formatterList; 32ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes { 335744e4a762ca12243b47dd8aed24d87d963b4d3bAndreas Gampe seriesList = new LinkedList<SeriesType>(); 34461d0d860814c68154d8dd06d24f94118f33d28aElliott Hughes formatterList = new LinkedList<FormatterType>(); 357e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes } 365215e4c0db7530519981f1e505e6db82401802f2Nick Kralevich 37e873cd1285c04da110758df066b4bd40ad6eb93dNarayan Kamath public boolean contains(SeriesType series) { 3859e4744d27231f260271dbbca406e0cc39768116Elliott Hughes return seriesList.contains(series); 3947cb338d43f75dd998b29caaaa9446c5705217d1Elliott Hughes } 40069525a39125c203b658c805685b6045a7d4dfebElliott Hughes 410a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes public int size() { 420ac77ac8e915bff1a863e371f9b363033f9cf759Elliott Hughes return seriesList.size(); 43bbac92e691de7d570928ddfba639067978e55b06Elliott Hughes } 440ab1a26ca767ae36fbbe27b62893670b208fa494Neil Fuller 457341b9ed7157a1e37a3e69a0974676da358b735aElliott Hughes public List<SeriesType> getSeriesList() { 469e67ca71d3d4a489a157abadc5ba519ced7a0b50Elliott Hughes return seriesList; 4790246a0ae7117d780e077c9e84cdb73ff5b44af7Jeff Sharkey } 48bb5816aa1626eb2f6263bd21479600b114c8a1bdJohan Redestig 490ac77ac8e915bff1a863e371f9b363033f9cf759Elliott Hughes public List<FormatterType> getFormatterList() { 506d8d1ea910c1ad026b48c87424da92a250664dd2Mark Salyzyn return formatterList; 51b3aacde3d8af759ee4a7b395c636ea360547d92dIan Rogers } 52efae3837b3eb79dea3400735fdcdd5a39020e0b0Ian Rogers 532cb2851f4a528e3e6e3e59cf3e854c2abf9f1811Elliott Hughes public boolean add(SeriesType series, FormatterType formatter) { 542c549f1ba3fb683ab1c4ede75bdcb312e8769672Andreas Gampe if(series == null || formatter == null) { 5555dd377d62cf780df94d8e0198b66e99456b6f50Yi Kong throw new IllegalArgumentException("series and formatter must not be null."); 56d3a88f94be9fb4d0a6da32cf3a820e5b206ded4aMark Salyzyn } 57cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland if(seriesList.contains(series)) { 58cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland return false; 59cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland } 60cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland seriesList.add(series); 61cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland formatterList.add(formatter); 62cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland return true; 63cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland } 64cab01ac294bb8ded259851673baa4c6ca226f828Steven Moreland 652cb2851f4a528e3e6e3e59cf3e854c2abf9f1811Elliott Hughes public boolean remove(SeriesType series) { 666d8d1ea910c1ad026b48c87424da92a250664dd2Mark Salyzyn int index = seriesList.indexOf(series); 676d8d1ea910c1ad026b48c87424da92a250664dd2Mark Salyzyn if(index < 0) { 686d8d1ea910c1ad026b48c87424da92a250664dd2Mark Salyzyn return false; 696d8d1ea910c1ad026b48c87424da92a250664dd2Mark Salyzyn } 706d8d1ea910c1ad026b48c87424da92a250664dd2Mark Salyzyn seriesList.remove(index); 71efae3837b3eb79dea3400735fdcdd5a39020e0b0Ian Rogers formatterList.remove(index); 7237dd0ac5767197bf7e3e90f1a5d4e54c8f1fe93dIan Rogers return true; 73efae3837b3eb79dea3400735fdcdd5a39020e0b0Ian Rogers } 7437dd0ac5767197bf7e3e90f1a5d4e54c8f1fe93dIan Rogers 75d4419fce71d11ec8494525eca65e54d1aab51de6Elliott Hughes 76d4419fce71d11ec8494525eca65e54d1aab51de6Elliott Hughes public FormatterType getFormatter(SeriesType series) { 77a0b3a2c22454fad9026cff3b0173ada828bad280Chih-Hung Hsieh return formatterList.get(seriesList.indexOf(series)); 78d4419fce71d11ec8494525eca65e54d1aab51de6Elliott Hughes } 792c549f1ba3fb683ab1c4ede75bdcb312e8769672Andreas Gampe 802c549f1ba3fb683ab1c4ede75bdcb312e8769672Andreas Gampe public FormatterType getFormatter(int index) { 81e3a3a06a94a50d31b7033e496f23becb0f1329c7Tobias Thierer return formatterList.get(index); 82e3a3a06a94a50d31b7033e496f23becb0f1329c7Tobias Thierer } 832c549f1ba3fb683ab1c4ede75bdcb312e8769672Andreas Gampe 842c549f1ba3fb683ab1c4ede75bdcb312e8769672Andreas Gampe public SeriesType getSeries(int index) { 852c549f1ba3fb683ab1c4ede75bdcb312e8769672Andreas Gampe return seriesList.get(index); 861c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes } 871c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes 881c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes public FormatterType setFormatter(SeriesType series, FormatterType formatter) { 891c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes return formatterList.set(seriesList.indexOf(series), formatter); 901c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes } 911c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes} 921c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes