Java 类io.netty.util.internal.ObjectUtil 实例源码

项目:redant    文件:PathPattern.java   
public static String removeSlashesAtBothEnds(String path) {
    ObjectUtil.checkNotNull(path, "path");

    if (path.isEmpty()) {
        return path;
    }

    int beginIndex = 0;
    while (beginIndex < path.length() && path.charAt(beginIndex) == '/') {
        beginIndex++;
    }
    if (beginIndex == path.length()) {
        return "";
    }

    int endIndex = path.length() - 1;
    while (endIndex > beginIndex && path.charAt(endIndex) == '/') {
        endIndex--;
    }

    return path.substring(beginIndex, endIndex + 1);
}
项目:netty4.0.27Learn    文件:OpenSslEngine.java   
/**
 * Creates a new instance
 *
 * @param sslCtx an OpenSSL {@code SSL_CTX} object
 * @param alloc the {@link ByteBufAllocator} that will be used by this engine
 * @param clientMode {@code true} if this is used for clients, {@code false} otherwise
 * @param sessionContext the {@link OpenSslSessionContext} this {@link SSLEngine} belongs to.
 */
OpenSslEngine(long sslCtx, ByteBufAllocator alloc, String fallbackApplicationProtocol,
              boolean clientMode, OpenSslSessionContext sessionContext, OpenSslEngineMap engineMap) {
    OpenSsl.ensureAvailability();
    if (sslCtx == 0) {
        throw new NullPointerException("sslCtx");
    }

    this.alloc = ObjectUtil.checkNotNull(alloc, "alloc");
    ssl = SSL.newSSL(sslCtx, !clientMode);
    networkBIO = SSL.makeNetworkBIO(ssl);
    this.fallbackApplicationProtocol = fallbackApplicationProtocol;
    this.clientMode = clientMode;
    this.sessionContext = sessionContext;
    this.engineMap = engineMap;
}
项目:netty4.0.27Learn    文件:OpenSslEngine.java   
@Override
public void putValue(String name, Object value) {
    ObjectUtil.checkNotNull(name, "name");
    ObjectUtil.checkNotNull(value, "value");

    Map<String, Object> values = this.values;
    if (values == null) {
        // Use size of 2 to keep the memory overhead small
        values = this.values = new HashMap<String, Object>(2);
    }
    Object old = values.put(name, value);
    if (value instanceof SSLSessionBindingListener) {
        ((SSLSessionBindingListener) value).valueBound(new SSLSessionBindingEvent(this, name));
    }
    notifyUnbound(old, name);
}
项目:netty4.0.27Learn    文件:LengthFieldPrepender.java   
/**
 * Creates a new instance.
 *
 * @param byteOrder         the {@link ByteOrder} of the length field
 * @param lengthFieldLength the length of the prepended length field.
 *                          Only 1, 2, 3, 4, and 8 are allowed.
 * @param lengthAdjustment  the compensation value to add to the value
 *                          of the length field
 * @param lengthIncludesLengthFieldLength
 *                          if {@code true}, the length of the prepended
 *                          length field is added to the value of the
 *                          prepended length field.
 *
 * @throws IllegalArgumentException
 *         if {@code lengthFieldLength} is not 1, 2, 3, 4, or 8
 */
public LengthFieldPrepender(
        ByteOrder byteOrder, int lengthFieldLength,
        int lengthAdjustment, boolean lengthIncludesLengthFieldLength) {
    if (lengthFieldLength != 1 && lengthFieldLength != 2 &&
        lengthFieldLength != 3 && lengthFieldLength != 4 &&
        lengthFieldLength != 8) {
        throw new IllegalArgumentException(
                "lengthFieldLength must be either 1, 2, 3, 4, or 8: " +
                lengthFieldLength);
    }
    ObjectUtil.checkNotNull(byteOrder, "byteOrder");

    this.byteOrder = byteOrder;
    this.lengthFieldLength = lengthFieldLength;
    this.lengthIncludesLengthFieldLength = lengthIncludesLengthFieldLength;
    this.lengthAdjustment = lengthAdjustment;
}
项目:netty4.0.27Learn    文件:AbstractScheduledEventExecutor.java   
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
    ObjectUtil.checkNotNull(command, "command");
    ObjectUtil.checkNotNull(unit, "unit");
    if (initialDelay < 0) {
        throw new IllegalArgumentException(
                String.format("initialDelay: %d (expected: >= 0)", initialDelay));
    }
    if (period <= 0) {
        throw new IllegalArgumentException(
                String.format("period: %d (expected: > 0)", period));
    }

    return schedule(new ScheduledFutureTask<Void>(
            this, Executors.<Void>callable(command, null),
            ScheduledFutureTask.deadlineNanos(unit.toNanos(initialDelay)), unit.toNanos(period)));
}
项目:netty4.0.27Learn    文件:AbstractScheduledEventExecutor.java   
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
    ObjectUtil.checkNotNull(command, "command");
    ObjectUtil.checkNotNull(unit, "unit");
    if (initialDelay < 0) {
        throw new IllegalArgumentException(
                String.format("initialDelay: %d (expected: >= 0)", initialDelay));
    }
    if (delay <= 0) {
        throw new IllegalArgumentException(
                String.format("delay: %d (expected: > 0)", delay));
    }

    return schedule(new ScheduledFutureTask<Void>(
            this, Executors.<Void>callable(command, null),
            ScheduledFutureTask.deadlineNanos(unit.toNanos(initialDelay)), -unit.toNanos(delay)));
}
项目:netty-router    文件:PathPattern.java   
public static String removeSlashesAtBothEnds(String path) {
    ObjectUtil.checkNotNull(path, "path");

    if (path.isEmpty()) {
        return path;
    }

    int beginIndex = 0;
    while (beginIndex < path.length() && path.charAt(beginIndex) == '/') {
        beginIndex++;
    }
    if (beginIndex == path.length()) {
        return "";
    }

    int endIndex = path.length() - 1;
    while (endIndex > beginIndex && path.charAt(endIndex) == '/') {
        endIndex--;
    }

    return path.substring(beginIndex, endIndex + 1);
}
项目:redant    文件:RouteResult.java   
/**
 * The maps will be wrapped in Collections.unmodifiableMap.
 */
public RouteResult(
        String uri, String decodedPath,
        Map<String, String> pathParams, Map<String, List<String>> queryParams,
        T target
) {
    this.uri = ObjectUtil.checkNotNull(uri, "uri");
    this.decodedPath = ObjectUtil.checkNotNull(decodedPath, "decodedPath");
    this.pathParams = Collections.unmodifiableMap(ObjectUtil.checkNotNull(pathParams, "pathParams"));
    this.queryParams = Collections.unmodifiableMap(ObjectUtil.checkNotNull(queryParams, "queryParams"));
    this.target = ObjectUtil.checkNotNull(target, "target");
}
项目:redant    文件:PathPattern.java   
/**
 * The pattern must not contain query, example:
 * {@code constant1/constant2?foo=bar}.
 *
 * <p>The pattern will be stored without slashes at both ends.
 */
public PathPattern(String pattern) {
    if (pattern.contains("?")) {
        throw new IllegalArgumentException("Path pattern must not contain query");
    }

    this.pattern = removeSlashesAtBothEnds(ObjectUtil.checkNotNull(pattern, "pattern"));
    this.tokens = this.pattern.split("/");
}
项目:redant    文件:OrderlessRouter.java   
/**
 * Removes all routes leading to the target.
 */
public void removeTarget(T target) {
    Set<PathPattern> patterns = reverseRoutes.remove(ObjectUtil.checkNotNull(target, "target"));
    if (patterns == null) {
        return;
    }

    // A pattern can only point to one target.
    // A target can have multiple patterns.
    // Remove all patterns leading to this target.
    for (PathPattern pattern : patterns) {
        routes.remove(pattern);
    }
}
项目:DovakinMQ    文件:MqttFixedHeader.java   
public MqttFixedHeader(
        MqttMessageType messageType,
        boolean isDup,
        MqttQoS qosLevel,
        boolean isRetain,
        int remainingLength) {
    this.messageType = ObjectUtil.checkNotNull(messageType, "messageType");
    this.isDup = isDup;
    this.qosLevel = ObjectUtil.checkNotNull(qosLevel, "qosLevel");
    this.isRetain = isRetain;
    this.remainingLength = remainingLength;
}
项目:netty4.0.27Learn    文件:OpenSslEngine.java   
@Override
public void setEnabledCipherSuites(String[] cipherSuites) {
    ObjectUtil.checkNotNull(cipherSuites, "cipherSuites");

    final StringBuilder buf = new StringBuilder();
    for (String c: cipherSuites) {
        if (c == null) {
            break;
        }

        String converted = CipherSuiteConverter.toOpenSsl(c);
        if (converted == null) {
            converted = c;
        }

        if (!OpenSsl.isCipherSuiteAvailable(converted)) {
            throw new IllegalArgumentException("unsupported cipher suite: " + c + '(' + converted + ')');
        }

        buf.append(converted);
        buf.append(':');
    }

    if (buf.length() == 0) {
        throw new IllegalArgumentException("empty cipher suites");
    }
    buf.setLength(buf.length() - 1);

    final String cipherSuiteSpec = buf.toString();
    try {
        SSL.setCipherSuites(ssl, cipherSuiteSpec);
    } catch (Exception e) {
        throw new IllegalStateException("failed to enable cipher suites: " + cipherSuiteSpec, e);
    }
}
项目:netty4.0.27Learn    文件:OpenSslEngine.java   
@Override
public Object getValue(String name) {
    ObjectUtil.checkNotNull(name, "name");

    if (values == null) {
        return null;
    }
    return values.get(name);
}
项目:netty4.0.27Learn    文件:OpenSslEngine.java   
@Override
public void removeValue(String name) {
    ObjectUtil.checkNotNull(name, "name");

    Map<String, Object> values = this.values;
    if (values == null) {
        return;
    }
    Object old = values.remove(name);
    notifyUnbound(old, name);
}
项目:netty4.0.27Learn    文件:AbstractScheduledEventExecutor.java   
@Override
public  ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
    ObjectUtil.checkNotNull(command, "command");
    ObjectUtil.checkNotNull(unit, "unit");
    if (delay < 0) {
        throw new IllegalArgumentException(
                String.format("delay: %d (expected: >= 0)", delay));
    }
    return schedule(new ScheduledFutureTask<Void>(
            this, command, null, ScheduledFutureTask.deadlineNanos(unit.toNanos(delay))));
}
项目:netty4.0.27Learn    文件:AbstractScheduledEventExecutor.java   
@Override
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
    ObjectUtil.checkNotNull(callable, "callable");
    ObjectUtil.checkNotNull(unit, "unit");
    if (delay < 0) {
        throw new IllegalArgumentException(
                String.format("delay: %d (expected: >= 0)", delay));
    }
    return schedule(new ScheduledFutureTask<V>(
            this, callable, ScheduledFutureTask.deadlineNanos(unit.toNanos(delay))));
}
项目:netty-router    文件:RouteResult.java   
/**
 * The maps will be wrapped in Collections.unmodifiableMap.
 */
public RouteResult(
        String uri, String decodedPath,
        Map<String, String> pathParams, Map<String, List<String>> queryParams,
        T target
) {
    this.uri = ObjectUtil.checkNotNull(uri, "uri");
    this.decodedPath = ObjectUtil.checkNotNull(decodedPath, "decodedPath");
    this.pathParams = Collections.unmodifiableMap(ObjectUtil.checkNotNull(pathParams, "pathParams"));
    this.queryParams = Collections.unmodifiableMap(ObjectUtil.checkNotNull(queryParams, "queryParams"));
    this.target = ObjectUtil.checkNotNull(target, "target");
}
项目:netty-router    文件:PathPattern.java   
/**
 * The pattern must not contain query, example:
 * {@code constant1/constant2?foo=bar}.
 *
 * <p>The pattern will be stored without slashes at both ends.
 */
public PathPattern(String pattern) {
    if (pattern.contains("?")) {
        throw new IllegalArgumentException("Path pattern must not contain query");
    }

    this.pattern = removeSlashesAtBothEnds(ObjectUtil.checkNotNull(pattern, "pattern"));
    this.tokens = this.pattern.split("/");
}
项目:netty-router    文件:OrderlessRouter.java   
/**
 * Removes all routes leading to the target.
 */
public void removeTarget(T target) {
    Set<PathPattern> patterns = reverseRoutes.remove(ObjectUtil.checkNotNull(target, "target"));
    if (patterns == null) {
        return;
    }

    // A pattern can only point to one target.
    // A target can have multiple patterns.
    // Remove all patterns leading to this target.
    for (PathPattern pattern : patterns) {
        routes.remove(pattern);
    }
}
项目:kraken    文件:ShutdownHookManager.java   
public static void addHook(final int priority, final Runnable shutdownHook) {
    ObjectUtil.checkNotNull(shutdownHook, "Shutdown hook should not be null");
    synchronized (shutdownHooks) {
        shutdownHooks.add(new ShutdownHookEntry(priority, shutdownHook));
    }
}