com.hedera.node.app.hapi.utils.sysfiles.ParsingUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of app-hapi-utils Show documentation
Show all versions of app-hapi-utils Show documentation
Hedera Services API Utilities
/*
* Copyright (C) 2020-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hedera.node.app.hapi.utils.sysfiles;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
public class ParsingUtils {
public static T fromTwoPartDelimited(
final String literal,
final String delimiter,
final BiConsumer validator,
final Function aParser,
final Function bParser,
final BiFunction finisher) {
final var splitIndex = literal.indexOf(delimiter);
if (splitIndex == -1) {
throw new IllegalArgumentException("Missing '" + delimiter + "' in literal '" + literal + "'");
}
final var delimLen = delimiter.length();
final var a = aParser.apply(literal.substring(0, splitIndex));
final var b = bParser.apply(literal.substring(splitIndex + delimLen));
validator.accept(a, b);
return finisher.apply(a, b);
}
private ParsingUtils() {
throw new UnsupportedOperationException("Utility Class");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy