/webportal/src/main/java/au/org/emii/portal/util/LayerSelection.java

http://alageospatialportal.googlecode.com/ · Java · 117 lines · 91 code · 18 blank · 8 comment · 13 complexity · 8df813c7fbf1dc1fa655d0bf8f85a610 MD5 · raw file

  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package au.org.emii.portal.util;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. /**
  10. *
  11. * @author Adam
  12. */
  13. public class LayerSelection {
  14. String displayString;
  15. String layerName;
  16. String analysisType;
  17. long created;
  18. long lastUse;
  19. String layers;
  20. ArrayList<Long> analysisIds;
  21. public LayerSelection(String displayString, String layersString) {
  22. this.displayString = displayString;
  23. this.layers = layersString;
  24. }
  25. public LayerSelection(String analysisType, String layerName, long created, String layersString) {
  26. this.layerName = layerName;
  27. this.analysisType = analysisType;
  28. this.created = created;
  29. this.lastUse = created;
  30. this.layers = layersString;
  31. }
  32. public String getDisplayString() {
  33. return displayString;
  34. }
  35. public String getLayerName() {
  36. return layerName;
  37. }
  38. public String getAnalysisType() {
  39. return analysisType;
  40. }
  41. public long getCreated() {
  42. return created;
  43. }
  44. public void setLastUse(long lastUse) {
  45. this.lastUse = lastUse;
  46. }
  47. public long getLastUse() {
  48. return lastUse;
  49. }
  50. public boolean contains(String layerId) {
  51. String lookFor = "(" + layerId + ")";
  52. return layers.contains(lookFor);
  53. }
  54. public String getLayers() {
  55. return layers;
  56. }
  57. @Override
  58. public String toString() {
  59. if(displayString != null) {
  60. return displayString;
  61. }
  62. SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
  63. int len = layers.split(",").length;
  64. if (len != 1) {
  65. return layerName + " | " + sdf.format(new Date(created)) + " | " + len + " layers";
  66. } else {
  67. return layerName + " | " + sdf.format(new Date(created)) + " | " + len + " layer";
  68. }
  69. }
  70. public boolean equalsList(LayerSelection ls) {
  71. String [] thisList = layers.split(",");
  72. String [] thatList = ls.layers.split(",");
  73. for(int i=0;i<thisList.length;i++) {
  74. boolean found = false;
  75. for(int j=0;j<thatList.length;j++) {
  76. if(thisList[i].equals(thatList[j])) {
  77. found = true;
  78. break;
  79. }
  80. }
  81. if(!found) {
  82. return false;
  83. }
  84. }
  85. for(int j=0;j<thatList.length;j++) {
  86. boolean found = false;
  87. for(int i=0;i<thisList.length;i++) {
  88. if(thisList[i].equals(thatList[j])) {
  89. found = true;
  90. break;
  91. }
  92. }
  93. if(!found) {
  94. return false;
  95. }
  96. }
  97. return true;
  98. }
  99. }