Java List Replace replacePolUtilsName( final List npcListSqlLines, final int lineIndex, final String name)

Here you can find the source of replacePolUtilsName( final List npcListSqlLines, final int lineIndex, final String name)

Description

replace Pol Utils Name

License

Open Source License

Declaration

public static void replacePolUtilsName(
            final List<String> npcListSqlLines, final int lineIndex,
            final String name) 

Method Source Code

//package com.java2s;
/** /*w  w w  .  j a  v a 2  s.co m*/
 * Copyright (c) 2010-2014 Darkstar Dev Teams
 * 
 * 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/
 * 
 * This file is part of DarkStar-server source code.
 */

import java.util.List;

public class Main {
    public static void replacePolUtilsName(
            final List<String> npcListSqlLines, final int lineIndex,
            final String name) {
        final String npcIdLine = npcListSqlLines.get(lineIndex);

        int startIndex = npcIdLine.indexOf(",");
        startIndex = npcIdLine.indexOf(",", startIndex + 1);
        int nextQuote = npcIdLine.indexOf("'", startIndex + 2);
        int endIndex = npcIdLine.indexOf(",", startIndex + 1);

        if (endIndex < nextQuote) {
            endIndex = npcIdLine.indexOf(",", endIndex + 1);
        }

        final String newLine;

        if (name == null) {
            newLine = npcIdLine.substring(0, startIndex + 1) + "\'\'"
                    + npcIdLine.substring(endIndex, npcIdLine.length());
        } else {
            newLine = npcIdLine.substring(0, startIndex + 1) + '\''
                    + name.replaceAll("'", "\\\\'") + '\''
                    + npcIdLine.substring(endIndex, npcIdLine.length());
        }

        npcListSqlLines.set(lineIndex, newLine);
    }
}

Related

  1. replaceInLines(List lines, String from, String to, int fromIndex, int toIndex)
  2. replaceInList(T a, T b, List list)
  3. replaceList(String v, String[] patterns, String[] values)
  4. replaceNpcId(final List npcListSqlLines, final int lineIndex, final int newNpcId, final boolean markAsGuess)
  5. replaceOrAdd(List list, T object)
  6. replacePositions(StringBuffer c, int origLength, String string, List positions)