Java String Split splitLargeStringIfNecessary(String s)

Here you can find the source of splitLargeStringIfNecessary(String s)

Description

Utility for splitting strings into lists of strings to pass as arguments to VistA Remote Procedure Calls (RPCs) to work around LITERAL parameter length limitations in the RPC Broker protocol.

License

Open Source License

Parameter

Parameter Description
s The string to split (if necessary)

Declaration

public static Object splitLargeStringIfNecessary(String s) 

Method Source Code

//package com.java2s;
/**// w  w  w . ja v a 2  s  .c  om
 * Function that attempts to fix capitalization of proper names.
 * <p/>
 * Example usage:
 * <pre>{@code
 *      VistaStringUtils.nameCase("RON BURGUNDY");  // => "Ron Burgundy"
 *      VistaStringUtils.nameCase("MCDONALDS");     // => "McDonalds"
 * }</pre>
 * <p/>
 * This is a port of the <pre>NameCase</pre> library, which is a Ruby implementation of Perl's
 * <pre>Lingua::EN::NameCase</pre> and owes most of its functionality to the Perl version by Mark Summerfield.
 * <p/>
 * Original Version:
 * Copyright (c) Mark Summerfield 1998-2002.  <summer@perlpress.com>  All Rights Reserved.
 * <p/>
 * Ruby Version:
 * Copyright (c) Aaron Patterson 2006
 * <p/>
 * <pre>NameCase</pre> is distributed under the GPL license.
 * <p/>
 * 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.
 * <p/>
 * 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.
 * <p/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @param s the String to properly namecase.
 * @return Returns a new String properly namecased.
 * @see "http://namecase.rubyforge.org/"
 * @see "http://www.gnu.org/licenses/"
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * Utility for splitting strings into lists of strings to pass as arguments to VistA Remote Procedure Calls (RPCs) to
     * work around LITERAL parameter length limitations in the RPC Broker protocol.  This will work for a particular RPC
     * parameter if and only if the parameter is defined in VistA as being of <code>WORD PROCESSING</code> type.
     *
     * @param s The string to split (if necessary)
     * @see #splitLargeStringIfNecessary(String, int)
     * @see "VistA FileMan REMOTE PROCEDURE,PARAMETER TYPE(8994.02,.02)"
     */
    public static Object splitLargeStringIfNecessary(String s) {
        return splitLargeStringIfNecessary(s, 245);
    }

    /**
     * Splits strings greater than the specified length into lists of strings of the specified length.  Strings less than
     * than the desired length are returned unmodified.
     *
     * @param s      The string to split (if necessary).
     * @param length The desired length of each string in the
     * @return <code>s</code> if
     */
    public static Object splitLargeStringIfNecessary(String s, int length) {
        if (s == null) {
            return "";
        } else if (s.length() <= length) {
            return s;
        } else {
            List<String> ret = new ArrayList<String>();
            while (s.length() > length) {
                ret.add(s.substring(0, length));
                s = s.substring(length);
            }
            if (s.length() > 0) {
                ret.add(s);
            }
            return ret;
        }
    }
}

Related

  1. splitIntoPackages(String stmt)
  2. splitIntoPairs(String subDirName)
  3. splitInts(String str)
  4. splitJsonObjects(String string)
  5. splitJsonObjects(String value)
  6. splitList(String list)
  7. splitList(String string)
  8. splitLists(String s)
  9. splitListToParts(final List list, final int times)