BuilderContainer.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.clientstrings;
  16. /**
  17. * @author Forsaiken
  18. */
  19. final class BuilderContainer extends Builder
  20. {
  21. private final Builder[] _builders;
  22. BuilderContainer(final Builder[] builders)
  23. {
  24. _builders = builders;
  25. }
  26. @Override
  27. public final String toString(final Object param)
  28. {
  29. return toString(new Object[]
  30. {
  31. param
  32. });
  33. }
  34. @Override
  35. public final String toString(final Object... params)
  36. {
  37. final int buildersLength = _builders.length;
  38. final int paramsLength = params.length;
  39. final String[] builds = new String[buildersLength];
  40. Builder builder;
  41. String build;
  42. int i, paramIndex, buildTextLen = 0;
  43. if (paramsLength != 0)
  44. {
  45. for (i = buildersLength; i-- > 0;)
  46. {
  47. builder = _builders[i];
  48. paramIndex = builder.getIndex();
  49. build = (paramIndex != -1) && (paramIndex < paramsLength) ? builder.toString(params[paramIndex]) : builder.toString();
  50. buildTextLen += build.length();
  51. builds[i] = build;
  52. }
  53. }
  54. else
  55. {
  56. for (i = buildersLength; i-- > 0;)
  57. {
  58. build = _builders[i].toString();
  59. buildTextLen += build.length();
  60. builds[i] = build;
  61. }
  62. }
  63. final FastStringBuilder fsb = new FastStringBuilder(buildTextLen);
  64. for (i = 0; i < buildersLength; i++)
  65. {
  66. fsb.append(builds[i]);
  67. }
  68. return fsb.toString();
  69. }
  70. @Override
  71. public final int getIndex()
  72. {
  73. return -1;
  74. }
  75. }