Java Assert assertSplit(final String text, final int length)

Here you can find the source of assertSplit(final String text, final int length)

Description

assert Split

License

Open Source License

Declaration

public static String[] assertSplit(final String text, final int length) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Vienna University of Technology.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w  w w.  j  a  v  a2 s . co m
 * Martin Fleck (Vienna University of Technology) - initial API and implementation
 *
 * Initially developed in the context of ARTIST EU project www.artist-project.eu
 *******************************************************************************/

public class Main {
    public static final String JAVA_DELIMITER_ESCAPED = "\\.";
    public static final String UML_DELIMITER = "::";

    public static String[] assertSplit(final String text, final int length) {
        return assertSplit(text, length,
                "'" + text + "' must have at least " + length + " parts delimited by '.' or '::'.");
    }

    public static String[] assertSplit(final String text, final int length, final String message) {
        final String[] parts = split(text);
        if (parts.length != length) {
            throw new IllegalArgumentException(message);
        }
        return parts;
    }

    public static String[] split(final String text) {
        return text.split("(" + JAVA_DELIMITER_ESCAPED + "|" + UML_DELIMITER + ")");
    }
}

Related

  1. assertSame(Object targetObject0, Object targetObject1)
  2. assertSameClazz(Object object, Object defaults)
  3. assertSameObject(Object obj1, Object obj2)
  4. assertSameSize(double[][] newLogPhi, double[][] logPhi)
  5. assertSorted(final int[] values)
  6. assertSquare(double[]... d)
  7. assertState(boolean expression)
  8. assertStringMatch(String first, String second)
  9. assertStringNotEmpty(String str, String name)