Java String Index Of getIndexOrConstraintName(String command)

Here you can find the source of getIndexOrConstraintName(String command)

Description

get Index Or Constraint Name

License

Apache License

Declaration

public static String getIndexOrConstraintName(String command) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static String getIndexOrConstraintName(String command) {
        String[] lines = command.split("\n");

        String indexOrConstraintName = "";

        if (lines.length < 1) {
            return indexOrConstraintName;
        }/* w  w  w . j a v a  2 s .  c  o  m*/

        String line1 = lines[0];
        List<Integer> indices = getQuotePositions(line1);

        if ((line1.contains("CREATE INDEX") || line1.contains("CREATE UNIQUE INDEX")) && indices.size() >= 4) {
            return line1.substring(indices.get(0), indices.get(3) + 1);
        }

        if (line1.contains("ALTER TABLE") && line1.contains("ADD CONSTRAINT") && indices.size() >= 6) {
            return line1.substring(indices.get(4), indices.get(5) + 1);
        }
        return indexOrConstraintName;
    }

    protected static List<Integer> getQuotePositions(String line) {
        List<Integer> indices = new ArrayList<>();

        char[] chars = line.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '"') {
                indices.add(i);
            }
        }

        return indices;
    }
}

Related

  1. getAllIndex(String source, String rex)
  2. getIndexesOf(String word, String value)
  3. getIndexOfChar(String str, String start, String end)
  4. getIndexString(T array, String indexPrefix, String separatorPrefix)
  5. getLowerBoundsOfAllStrings(int length, int seedIndex, int routeLength)
  6. getMatchingIndexes(final String source, final String match)
  7. getMergedLine(String lineOne, String lineTwo, int insertingIndex)