Java Collection Join getNeoString(String columnName, String delimiter, Collection input, String join)

Here you can find the source of getNeoString(String columnName, String delimiter, Collection input, String join)

Description

get Neo String

License

Open Source License

Declaration

private static String getNeoString(String columnName, String delimiter, Collection<String> input, String join) 

Method Source Code


//package com.java2s;
/*/*from ww  w . jav a  2  s  . c o m*/
 *
 *  Copyright (c) 2012-2016 "FlockData LLC"
 *
 *  This file is part of FlockData.
 *
 *  FlockData 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.
 *
 *  FlockData 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 FlockData.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;

public class Main {
    private static String getNeoString(String columnName, String delimiter, Collection<String> input, String join) {
        String result = "";//(delimiter.equals(":")? ":": "");
        for (String field : input) {
            if (field != null) {
                // ToDo: Fix this hack
                if (field.equals("User"))
                    field = "_FortressUser";
                if (requiresQuoting(field))
                    field = "`" + field + "`";

                if (result.equals(delimiter) || result.equals(""))
                    result = result + (columnName != null ? columnName + delimiter : "") + field + "";
                else
                    result = result + join + (columnName != null ? columnName : "") + delimiter + field;
            }
        }
        if (result.equals(delimiter))
            result = "";
        return result;
    }

    /**
     *
     * @param string to analyze
     * @return true if the string requires quoting in the world of Cypher
     */
    public static boolean requiresQuoting(String string) {
        return string.contains(" ") || string.contains("-") || string.contains(".")
                || string.matches("^[\\d\\-\\.]+$");
    }
}

Related

  1. implode(Collection items, String join)
  2. internalJoin(String sep, Collection pieces)
  3. isDisjoint(Collection a, Collection b)
  4. join(AbstractCollection s, String delimiter)

  5. HOME | Copyright © www.java2s.com 2016