class VectorUtil {

	public static DenseVector parseDense(String str) {
		if (org.apache.flink.util.StringUtils.isNullOrWhitespaceOnly(str)) {
			return new DenseVector();
		}

		int len = str.length();

		int inDataBuffPos = 0;
		boolean isInBuff = false;

		for (int i = 0; i < len; ++i) {
			char c = str.charAt(i);

			if (c == ELEMENT_DELIMITER
				// to be compatible with previous delimiter
				|| c == ',') {
				if (isInBuff) {
					inDataBuffPos++;
				}

				isInBuff = false;
			} else {
				isInBuff = true;
			}
		}

		if (isInBuff) {
			inDataBuffPos++;
		}

		double[] data = new double[inDataBuffPos];
		int lastestInCharBuffPos = 0;

		inDataBuffPos = 0;
		isInBuff = false;

		for (int i = 0; i < len; ++i) {
			char c = str.charAt(i);

			if (c == ELEMENT_DELIMITER
				// to be compatible with previous delimiter
				|| c == ',') {
				if (isInBuff) {
					data[inDataBuffPos++] = Double.parseDouble(
						StringUtils.substring(str, lastestInCharBuffPos, i).trim()
					);

					lastestInCharBuffPos = i + 1;
				}

				isInBuff = false;
			} else {
				isInBuff = true;
			}
		}

		if (isInBuff) {
			data[inDataBuffPos] = Double.valueOf(
				StringUtils.substring(str, lastestInCharBuffPos).trim()
			);
		}

		return new DenseVector(data);
	}

}