2
0

BuilderContainer.java 2.1 KB

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