Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

XDDFDataSource.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.xddf.usermodel.chart;
  20. import org.apache.poi.util.Beta;
  21. import org.apache.poi.util.Internal;
  22. import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumData;
  23. import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumVal;
  24. import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrData;
  25. import org.openxmlformats.schemas.drawingml.x2006.chart.CTStrVal;
  26. @Beta
  27. public interface XDDFDataSource<T> {
  28. int getPointCount();
  29. T getPointAt(int index);
  30. /**
  31. * @since POI 4.0.2
  32. */
  33. boolean isLiteral();
  34. /**
  35. * @since POI 4.1.2
  36. */
  37. boolean isCellRange();
  38. boolean isReference();
  39. boolean isNumeric();
  40. int getColIndex();
  41. String getDataRangeReference();
  42. String getFormula();
  43. String getFormatCode();
  44. /**
  45. * @since POI 5.0.0
  46. */
  47. @Internal
  48. default void fillNumericalCache(CTNumData cache) {
  49. String formatCode = getFormatCode();
  50. if (formatCode == null) {
  51. if (cache.isSetFormatCode()) {
  52. cache.unsetFormatCode();
  53. }
  54. } else {
  55. cache.setFormatCode(formatCode);
  56. }
  57. cache.setPtArray(null); // unset old values
  58. final int numOfPoints = getPointCount();
  59. int effectiveNumOfPoints = 0;
  60. for (int i = 0; i < numOfPoints; ++i) {
  61. Object value = getPointAt(i);
  62. if (value != null) {
  63. CTNumVal ctNumVal = cache.addNewPt();
  64. ctNumVal.setIdx(i);
  65. ctNumVal.setV(value.toString());
  66. effectiveNumOfPoints++;
  67. }
  68. }
  69. if (effectiveNumOfPoints == 0) {
  70. if (cache.isSetPtCount()) {
  71. cache.unsetPtCount();
  72. }
  73. } else {
  74. if (cache.isSetPtCount()) {
  75. cache.getPtCount().setVal(numOfPoints);
  76. } else {
  77. cache.addNewPtCount().setVal(numOfPoints);
  78. }
  79. }
  80. }
  81. /**
  82. * @since POI 4.1.2
  83. */
  84. @Internal
  85. default void fillStringCache(CTStrData cache) {
  86. cache.setPtArray(null); // unset old values
  87. final int numOfPoints = getPointCount();
  88. int effectiveNumOfPoints = 0;
  89. for (int i = 0; i < numOfPoints; ++i) {
  90. Object value = getPointAt(i);
  91. if (value != null) {
  92. CTStrVal ctStrVal = cache.addNewPt();
  93. ctStrVal.setIdx(i);
  94. ctStrVal.setV(value.toString());
  95. effectiveNumOfPoints++;
  96. }
  97. }
  98. if (effectiveNumOfPoints == 0) {
  99. if (cache.isSetPtCount()) {
  100. cache.unsetPtCount();
  101. }
  102. } else {
  103. if (cache.isSetPtCount()) {
  104. cache.getPtCount().setVal(numOfPoints);
  105. } else {
  106. cache.addNewPtCount().setVal(numOfPoints);
  107. }
  108. }
  109. }
  110. }