/src/org/pentaho/di/ui/trans/steps/mongodbinput/models/MongoTag.java

https://gitlab.com/bytekast/pentaho-mongodb-plugin · Java · 107 lines · 66 code · 25 blank · 16 comment · 18 complexity · d12c4bff7431487bca9637c3ad74ae4c MD5 · raw file

  1. /*!
  2. * Copyright 2010 - 2013 Pentaho Corporation. All rights reserved.
  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 org.pentaho.di.ui.trans.steps.mongodbinput.models;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.pentaho.ui.xul.XulEventSourceAdapter;
  21. import org.pentaho.ui.xul.util.AbstractModelList;
  22. public class MongoTag extends XulEventSourceAdapter{
  23. private String m_tagName = "";
  24. public MongoTag(){
  25. }
  26. public MongoTag(String name){
  27. m_tagName = name;
  28. }
  29. public String getTagName(){
  30. return this.m_tagName;
  31. }
  32. public void setTagName(String name){
  33. this.m_tagName = name;
  34. }
  35. public static void convertList(List<String> tags, AbstractModelList<MongoTag> docTags){
  36. if ( tags == null || tags.isEmpty()){
  37. return;
  38. }
  39. for (String tag: tags){
  40. MongoTag docTag = new MongoTag();
  41. if (tag.startsWith("{")) {
  42. tag = tag.substring(1);
  43. }
  44. if (tag.endsWith("}")) {
  45. tag = tag.substring(0, tag.length() - 1);
  46. }
  47. docTag.setTagName(tag);
  48. docTags.add(docTag);
  49. }
  50. }
  51. public static void trimList(List<String> tags, AbstractModelList<MongoTag> docTags){
  52. if ( tags == null || tags.isEmpty()){
  53. return;
  54. }
  55. for (int i = tags.size() -1; i >= 0; i--){
  56. String tag = tags.get(i);
  57. for(MongoTag docTag: docTags.asList()){
  58. if (tag.equalsIgnoreCase(docTag.getTagName())){
  59. tags.remove(tag);
  60. break;
  61. }
  62. }
  63. }
  64. }
  65. public static List<String> convertFromList(AbstractModelList<MongoTag> docTags){
  66. List<String> tags = new ArrayList<String>();
  67. if ( docTags == null || docTags.isEmpty()){
  68. return tags;
  69. }
  70. for (MongoTag docTag: docTags){
  71. String tag = docTag.getTagName();
  72. if (!tag.startsWith("{")) {
  73. tag = "{" + tag;
  74. }
  75. if (!tag.endsWith("}")) {
  76. tag += "}";
  77. }
  78. tags.add(tag);
  79. }
  80. return tags;
  81. }
  82. }