org.agrona.Strings Java Examples

The following examples show how to use org.agrona.Strings. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DomainSerialiser.java    From swblocks-decisiontree with Apache License 2.0 6 votes vote down vote up
private static List<InputDriver> getGroupDrivers(final String currentToken,
                                                 final DriverCache cache) {
    final List<InputDriver> drivers = new ArrayList<>();

    if (Strings.isEmpty(currentToken)) {
        return Collections.emptyList();
    }

    final String[] tokens = currentToken.split(":", 0);

    // Position 0 contains a name
    for (int i = 1; i < tokens.length; i++) {
        final String tokenValue = tokens[i];
        final InputValueType tokenType = INPUT_VALUE_TYPE_FUNCTION.apply(tokenValue);
        final InputDriver driver = getSingleDriver(tokenValue, cache, tokenType);
        drivers.add(driver);
    }
    return drivers;
}
 
Example #2
Source File: DomainSerialiser.java    From swblocks-decisiontree with Apache License 2.0 5 votes vote down vote up
private static InputDriver getValueGroupDriver(final String currentDriver,
                                               final DriverCache cache,
                                               final InputValueType type) {
    final String[] tokensGroup = currentDriver.split(GroupDriver.VG_PREFIX);
    final String value = tokensGroup[1].split(":")[0];

    InputDriver inputDriver = cache.get(value, type);
    if (inputDriver == null) {
        final List<InputDriver> topLevelDriver = new ArrayList<>(16);
        for (int i = 2; i < tokensGroup.length; i++) {
            if (Strings.isEmpty(tokensGroup[i])) {
                continue;
            }
            final String name = tokensGroup[i].split(":")[0];

            InputDriver subGroup = cache.get(name, type);
            if (subGroup == null) {
                final List<InputDriver> subDrivers = getGroupDrivers(tokensGroup[i], cache);
                subGroup = new GroupDriver(name, subDrivers);
                topLevelDriver.add(subGroup);
                cache.put(subGroup);
            }
        }

        topLevelDriver.addAll(getGroupDrivers(tokensGroup[1], cache));
        inputDriver = new GroupDriver(value, topLevelDriver);
        cache.put(inputDriver);
    }
    return inputDriver;
}
 
Example #3
Source File: SocketAddressParser.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Parse socket addresses from a {@link String}. Supports
 * hostname:port, ipV4Address:port, [ipV6Address]:port, and name
 *
 * @param value          to be parsed for the socket address.
 * @param uriParamName   for the parse.
 * @param isReResolution for the parse.
 * @param nameResolver   to be used for resolving hostnames.
 * @return An {@link InetSocketAddress} for the parsed input.
 * @throws UnknownHostException if address cannot be resolved
 */
static InetSocketAddress parse(
    final String value, final String uriParamName, final boolean isReResolution, final NameResolver nameResolver)
    throws UnknownHostException
{
    if (Strings.isEmpty(value))
    {
        throw new NullPointerException("input string must not be null or empty");
    }

    final String nameAndPort = nameResolver.lookup(value, uriParamName, isReResolution);
    InetSocketAddress address = tryParseIpV4(nameAndPort, uriParamName, isReResolution, nameResolver);

    if (null == address)
    {
        address = tryParseIpV6(nameAndPort, uriParamName, isReResolution, nameResolver);
    }

    if (null == address)
    {
        throw new IllegalArgumentException("invalid format: " + value);
    }

    if (address.isUnresolved())
    {
        throw new UnknownHostException(
            "Unresolved - " + uriParamName + "=" + value + ", name-and-port=" + nameAndPort +
            ", name-resolver=" + nameResolver.getClass().getName());
    }

    return address;
}
 
Example #4
Source File: InterfaceSearchAddress.java    From aeron with Apache License 2.0 5 votes vote down vote up
static InterfaceSearchAddress parse(final String s) throws UnknownHostException
{
    if (Strings.isEmpty(s))
    {
        throw new IllegalArgumentException("search address string is null or empty");
    }

    int slashIndex = -1;
    int colonIndex = -1;
    int rightAngleBraceIndex = -1;

    for (int i = 0, length = s.length(); i < length; i++)
    {
        switch (s.charAt(i))
        {
            case '/':
                slashIndex = i;
                break;

            case ':':
                colonIndex = i;
                break;

            case ']':
                rightAngleBraceIndex = i;
                break;
        }
    }

    final String addressString = getAddress(s, slashIndex, colonIndex, rightAngleBraceIndex);
    final InetAddress hostAddress = InetAddress.getByName(addressString);
    final int port = getPort(s, slashIndex, colonIndex, rightAngleBraceIndex);
    final int defaultSubnetPrefix = hostAddress.getAddress().length * 8;
    final int subnetPrefix = getSubnet(s, slashIndex, defaultSubnetPrefix);

    return new InterfaceSearchAddress(new InetSocketAddress(hostAddress, port), subnetPrefix);
}
 
Example #5
Source File: EventConfiguration.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Get the {@link Set} of {@link ArchiveEventCode}s that are enabled for the logger.
 *
 * @param enabledEventCodes that can be "all" or a comma separated list of Event Code ids or names.
 * @return the {@link Set} of {@link ArchiveEventCode}s that are enabled for the logger.
 */
static EnumSet<ArchiveEventCode> getEnabledArchiveEventCodes(final String enabledEventCodes)
{
    if (Strings.isEmpty(enabledEventCodes))
    {
        return EnumSet.noneOf(ArchiveEventCode.class);
    }

    final Function<Integer, ArchiveEventCode> eventCodeById = ArchiveEventCode::get;
    final Function<String, ArchiveEventCode> eventCodeByName = ArchiveEventCode::valueOf;

    return parseEventCodes(ArchiveEventCode.class, enabledEventCodes, eventCodeById, eventCodeByName);
}
 
Example #6
Source File: EventConfiguration.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Get the {@link Set} of {@link ClusterEventCode}s that are enabled for the logger.
 *
 * @param enabledEventCodes that can be "all" or a comma separated list of Event Code ids or names.
 * @return the {@link Set} of {@link ClusterEventCode}s that are enabled for the logger.
 */
static Set<ClusterEventCode> getEnabledClusterEventCodes(final String enabledEventCodes)
{
    if (Strings.isEmpty(enabledEventCodes))
    {
        return EnumSet.noneOf(ClusterEventCode.class);
    }

    final Function<Integer, ClusterEventCode> eventCodeById = ClusterEventCode::get;
    final Function<String, ClusterEventCode> eventCodeByName = ClusterEventCode::valueOf;

    return parseEventCodes(ClusterEventCode.class, enabledEventCodes, eventCodeById, eventCodeByName);
}
 
Example #7
Source File: CppGenerator.java    From simple-binary-encoding with Apache License 2.0 4 votes vote down vote up
private static void generateFieldMetaAttributeMethod(
    final StringBuilder sb, final Token token, final String indent)
{
    final Encoding encoding = token.encoding();
    final String epoch = encoding.epoch() == null ? "" : encoding.epoch();
    final String timeUnit = encoding.timeUnit() == null ? "" : encoding.timeUnit();
    final String semanticType = encoding.semanticType() == null ? "" : encoding.semanticType();

    sb.append("\n")
        .append(indent).append("    SBE_NODISCARD static const char *")
        .append(token.name()).append("MetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT\n")
        .append(indent).append("    {\n")
        .append(indent).append("        switch (metaAttribute)\n")
        .append(indent).append("        {\n");

    if (!Strings.isEmpty(epoch))
    {
        sb.append(indent)
            .append("            case MetaAttribute::EPOCH: return \"").append(epoch).append("\";\n");
    }

    if (!Strings.isEmpty(timeUnit))
    {
        sb.append(indent)
            .append("            case MetaAttribute::TIME_UNIT: return \"").append(timeUnit).append("\";\n");
    }

    if (!Strings.isEmpty(semanticType))
    {
        sb.append(indent)
            .append("            case MetaAttribute::SEMANTIC_TYPE: return \"").append(semanticType)
            .append("\";\n");
    }

    sb
        .append(indent).append("            case MetaAttribute::PRESENCE: return \"")
        .append(encoding.presence().toString().toLowerCase()).append("\";\n")
        .append(indent).append("            default: return \"\";\n")
        .append(indent).append("        }\n")
        .append(indent).append("    }\n");
}