PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/storage/src/main/java/jahspotify/storage/statistics/MongoDBHistoryCursor.java

http://github.com/johanlindquist/jahspotify
Java | 63 lines | 33 code | 9 blank | 21 comment | 0 complexity | db6af415479258d5e91e1119ac174b39 MD5 | raw file
  1. package jahspotify.storage.statistics;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import com.google.gson.Gson;
  21. import com.mongodb.DBCursor;
  22. import com.mongodb.util.JSON;
  23. /**
  24. * @author Johan Lindquist
  25. */
  26. public class MongoDBHistoryCursor implements HistoryCursor
  27. {
  28. private DBCursor _dbObjects;
  29. private static Gson _gson = new Gson();
  30. MongoDBHistoryCursor(final DBCursor dbObjects)
  31. {
  32. _dbObjects = dbObjects;
  33. }
  34. @Override
  35. public int getCount()
  36. {
  37. return _dbObjects.count();
  38. }
  39. @Override
  40. public boolean hasNext()
  41. {
  42. return _dbObjects.hasNext();
  43. }
  44. @Override
  45. public TrackHistory next()
  46. {
  47. return _gson.fromJson(JSON.serialize(_dbObjects.next()), TrackHistory.class);
  48. }
  49. @Override
  50. public void remove()
  51. {
  52. throw new UnsupportedOperationException("Not supported");
  53. }
  54. }