Java List Replace replaceNpcId(final List npcListSqlLines, final int lineIndex, final int newNpcId, final boolean markAsGuess)

Here you can find the source of replaceNpcId(final List npcListSqlLines, final int lineIndex, final int newNpcId, final boolean markAsGuess)

Description

Method to Replace the NPC ID on the Current Line w/ a New One

License

Open Source License

Parameter

Parameter Description
npcListSqlLines Line Array of the NPC List SQL
lineIndex Index of Current Line
newNpcId New Short NPC ID

Declaration

public static void replaceNpcId(final List<String> npcListSqlLines,
        final int lineIndex, final int newNpcId,
        final boolean markAsGuess) 

Method Source Code

//package com.java2s;
/** //www .  j av a  2  s.  com
 * 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 final String NPC_LIST_INSERT_START = "INSERT INTO `npc_list` VALUES (";

    /**
     * Method to Replace the NPC ID on the Current Line w/ a New One
     * @param npcListSqlLines Line Array of the NPC List SQL
     * @param lineIndex Index of Current Line
     * @param newNpcId New Short NPC ID
     */
    public static void replaceNpcId(final List<String> npcListSqlLines,
            final int lineIndex, final int newNpcId,
            final boolean markAsGuess) {
        final String npcIdLine = npcListSqlLines.get(lineIndex);
        final int endIndex = npcIdLine.indexOf(",");
        final String insertStringFragment = npcIdLine.substring(0,
                NPC_LIST_INSERT_START.length());
        final String postIdFragment = npcIdLine.substring(endIndex,
                npcIdLine.length());
        String newNpcIdLine = insertStringFragment + newNpcId
                + postIdFragment;

        if (markAsGuess) {
            newNpcIdLine = "FIXME: " + newNpcIdLine;
        }

        npcListSqlLines.set(lineIndex, newNpcIdLine);
    }
}

Related

  1. replaceFields(Map mapFields, String changeStr, List listString)
  2. replaceIgnoreList(String text)
  3. replaceInLines(List lines, String from, String to, int fromIndex, int toIndex)
  4. replaceInList(T a, T b, List list)
  5. replaceList(String v, String[] patterns, String[] values)
  6. replaceOrAdd(List list, T object)
  7. replacePolUtilsName( final List npcListSqlLines, final int lineIndex, final String name)
  8. replacePositions(StringBuffer c, int origLength, String string, List positions)