Project update.
This commit is contained in:
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.clientstrings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Forsaiken, Zoey76
|
||||
*/
|
||||
public abstract class Builder
|
||||
{
|
||||
public abstract String toString(final Object param);
|
||||
|
||||
public abstract String toString(final Object... params);
|
||||
|
||||
public abstract int getIndex();
|
||||
|
||||
public static final Builder newBuilder(final String text)
|
||||
{
|
||||
final ArrayList<Builder> builders = new ArrayList<>();
|
||||
|
||||
int index1 = 0, index2 = 0, paramId, subTextLen;
|
||||
|
||||
final char[] array = text.toCharArray();
|
||||
final int arrayLength = array.length;
|
||||
|
||||
char c, c2, c3;
|
||||
LOOP: for (; index1 < arrayLength; index1++)
|
||||
{
|
||||
c = array[index1];
|
||||
if ((c == '$') && (index1 < (arrayLength - 2)))
|
||||
{
|
||||
c2 = array[index1 + 1];
|
||||
if ((c2 == 'c') || (c2 == 's') || (c2 == 'p') || (c2 == 'C') || (c2 == 'S') || (c2 == 'P'))
|
||||
{
|
||||
c3 = array[index1 + 2];
|
||||
if (Character.isDigit(c3))
|
||||
{
|
||||
paramId = Character.getNumericValue(c3);
|
||||
subTextLen = index1 - index2;
|
||||
if (subTextLen != 0)
|
||||
{
|
||||
builders.add(new BuilderText(new String(array, index2, subTextLen)));
|
||||
}
|
||||
|
||||
builders.add(new BuilderObject(paramId));
|
||||
index1 += 2;
|
||||
index2 = index1 + 1;
|
||||
continue LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (arrayLength >= index1)
|
||||
{
|
||||
subTextLen = index1 - index2;
|
||||
if (subTextLen != 0)
|
||||
{
|
||||
builders.add(new BuilderText(new String(array, index2, subTextLen)));
|
||||
}
|
||||
}
|
||||
|
||||
if (builders.size() == 1)
|
||||
{
|
||||
return builders.get(0);
|
||||
}
|
||||
return new BuilderContainer(builders.toArray(new Builder[builders.size()]));
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.clientstrings;
|
||||
|
||||
/**
|
||||
* @author Forsaiken
|
||||
*/
|
||||
final class BuilderContainer extends Builder
|
||||
{
|
||||
private final Builder[] _builders;
|
||||
|
||||
BuilderContainer(final Builder[] builders)
|
||||
{
|
||||
_builders = builders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString(final Object param)
|
||||
{
|
||||
return toString(new Object[]
|
||||
{
|
||||
param
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString(final Object... params)
|
||||
{
|
||||
final int buildersLength = _builders.length;
|
||||
final int paramsLength = params.length;
|
||||
final String[] builds = new String[buildersLength];
|
||||
|
||||
Builder builder;
|
||||
String build;
|
||||
int i, paramIndex, buildTextLen = 0;
|
||||
if (paramsLength != 0)
|
||||
{
|
||||
for (i = buildersLength; i-- > 0;)
|
||||
{
|
||||
builder = _builders[i];
|
||||
paramIndex = builder.getIndex();
|
||||
build = (paramIndex != -1) && (paramIndex < paramsLength) ? builder.toString(params[paramIndex]) : builder.toString();
|
||||
buildTextLen += build.length();
|
||||
builds[i] = build;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = buildersLength; i-- > 0;)
|
||||
{
|
||||
build = _builders[i].toString();
|
||||
buildTextLen += build.length();
|
||||
builds[i] = build;
|
||||
}
|
||||
}
|
||||
|
||||
final FastStringBuilder fsb = new FastStringBuilder(buildTextLen);
|
||||
for (i = 0; i < buildersLength; i++)
|
||||
{
|
||||
fsb.append(builds[i]);
|
||||
}
|
||||
return fsb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getIndex()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.clientstrings;
|
||||
|
||||
/**
|
||||
* @author Forsaiken
|
||||
*/
|
||||
final class BuilderObject extends Builder
|
||||
{
|
||||
private final int _index;
|
||||
|
||||
BuilderObject(final int id)
|
||||
{
|
||||
if ((id < 1) || (id > 9))
|
||||
{
|
||||
throw new RuntimeException("Illegal Id: " + id);
|
||||
}
|
||||
_index = id - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString(final Object param)
|
||||
{
|
||||
return param == null ? "null" : param.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString(final Object... params)
|
||||
{
|
||||
if ((params == null) || (params.length == 0))
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
return params[0].toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getIndex()
|
||||
{
|
||||
return _index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString()
|
||||
{
|
||||
return "[PARAM-" + (_index + 1) + "]";
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.clientstrings;
|
||||
|
||||
/**
|
||||
* @author Forsaiken
|
||||
*/
|
||||
final class BuilderText extends Builder
|
||||
{
|
||||
private final String _text;
|
||||
|
||||
BuilderText(final String text)
|
||||
{
|
||||
_text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString(final Object param)
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString(final Object... params)
|
||||
{
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getIndex()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString()
|
||||
{
|
||||
return _text;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.clientstrings;
|
||||
|
||||
/**
|
||||
* @author Forsaiken
|
||||
*/
|
||||
final class FastStringBuilder
|
||||
{
|
||||
private final char[] _array;
|
||||
private int _len;
|
||||
|
||||
public FastStringBuilder(final int capacity)
|
||||
{
|
||||
_array = new char[capacity];
|
||||
}
|
||||
|
||||
public final void append(final String text)
|
||||
{
|
||||
text.getChars(0, text.length(), _array, _len);
|
||||
_len += text.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString()
|
||||
{
|
||||
return new String(_array);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user