org.rapidoid.commons.Arr类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.rapidoid.commons.Arr类的一些代码示例,展示了Arr类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Arr类的具体详情如下:
包路径:org.rapidoid.commons.Arr
类名称:Arr

Arr介绍

暂无

代码示例

代码示例来源:origin: rapidoid/rapidoid

@SuppressWarnings("unchecked")
public static Object include(Object arrOrColl, Object item) {
  if (arrOrColl instanceof Object[]) {
    Object[] arr = (Object[]) arrOrColl;
    return Arr.indexOf(arr, item) < 0 ? Arr.expand(arr, item) : arr;
  } else if (arrOrColl instanceof Collection<?>) {
    Collection<Object> coll = (Collection<Object>) arrOrColl;
    if (!coll.contains(item)) {
      coll.add(item);
    }
    return coll;
  } else {
    throw Err.illegalArg("Expected array or collection!");
  }
}

代码示例来源:origin: rapidoid/rapidoid

public static <T> boolean containsAny(T[] arr, Iterable<? extends T> values) {
  for (T value : values) {
    if (contains(arr, value)) return true;
  }
  return false;
}

代码示例来源:origin: rapidoid/rapidoid

@SuppressWarnings("unchecked")
public static Object exclude(Object arrOrColl, Object item) {
  if (arrOrColl instanceof Object[]) {
    Object[] arr = (Object[]) arrOrColl;
    int ind = Arr.indexOf(arr, item);
    return ind >= 0 ? Arr.deleteAt(arr, ind) : arr;
  } else if (arrOrColl instanceof Collection<?>) {
    Collection<Object> coll = (Collection<Object>) arrOrColl;
    if (coll.contains(item)) {
      coll.remove(item);
    }
    return coll;
  } else {
    throw Err.illegalArg("Expected array or collection!");
  }
}

代码示例来源:origin: rapidoid/rapidoid

private String fullKey(String key, String separator) {
  return U.join(separator, Arr.concat(U.array(baseKeys), key));
}

代码示例来源:origin: rapidoid/rapidoid

public static String[] getLambdaParameterNames(Serializable lambda) {
  Method lambdaMethod = getLambdaMethod(lambda);
  Class<?>[] lambdaTypes = lambdaMethod.getParameterTypes();
  String[] names = getMethodParameterNames(lambdaMethod);
  List<Method> methods = U.list();
  for (Class<?> interf : lambda.getClass().getInterfaces()) {
    for (Method m : interf.getMethods()) {
      Class<?>[] types = m.getParameterTypes();
      if (types.length <= names.length) {
        int diff = names.length - types.length;
        boolean matching = true;
        for (int i = 0; i < types.length; i++) {
          if (!types[i].isAssignableFrom(lambdaTypes[i + diff])) {
            matching = false;
          }
        }
        if (matching) {
          methods.add(m);
        }
      }
    }
  }
  U.must(methods.size() > 0, "Cannot find the lambda target method of the functional interface!");
  U.must(methods.size() == 1, "Found more than one lambda target method of the functional interface: " + methods);
  return Arr.sub(names, names.length - methods.get(0).getParameterTypes().length, names.length);
}

代码示例来源:origin: rapidoid/rapidoid

public static boolean contains(float[] arr, float value) {
  return indexOf(arr, value) >= 0;
}

代码示例来源:origin: rapidoid/rapidoid

private void expandUnit() {
  if (bufN == bufs.length) {
    bufs = Arr.expand(bufs, 2);
  }
  bufs[bufN] = bufPool.get();
  bufs[bufN].clear();
  bufN++;
}

代码示例来源:origin: rapidoid/rapidoid

public static Layout values(Object... values) {
  List<Object> list = U.list();
  for (Object value : values) {
    if (Arr.isArray(value) && !hasGUIElements(value)) {
      value = U.str(value);
    }
    if (value == null || value instanceof Iterable<?>) {
      value = U.str(value);
    }
    list.add(row(value));
  }
  return layout(list);
}

代码示例来源:origin: rapidoid/rapidoid

public static String[] withDefaultPath(String[] templatesPath) {
  if (U.isEmpty(templatesPath) || U.neq(U.last(templatesPath), Templates.DEFAULT_TEMPLATES)) {
    return Arr.concat(templatesPath, Templates.DEFAULT_TEMPLATES);
  } else {
    return templatesPath;
  }
}

代码示例来源:origin: rapidoid/rapidoid

public NParamMethodHandler(FastHttp http, HttpRoutes routes, RouteOptions options, Method method, NParamLambda lambda) {
  super(http, options);
  this.method = method;
  Class<?>[] paramTypes = method.getParameterTypes();
  String[] paramNames;
  if (lambda != null) {
    paramNames = Cls.getLambdaParameterNames(lambda);
    paramTypes = Arr.sub(paramTypes, paramTypes.length - paramNames.length, paramTypes.length);
  } else {
    paramNames = Cls.getMethodParameterNames(method);
  }
  Annotation[][] annotations = method.getParameterAnnotations();
  this.paramRetrievers = new ParamRetriever[paramTypes.length];
  String par = "";
  for (int i = 0; i < paramRetrievers.length; i++) {
    paramRetrievers[i] = ParamRetrievers.createParamRetriever(routes.custom(), paramTypes[i], paramNames[i], annotations[i]);
    if (i > 0) {
      par += ", ";
    }
    par += paramTypes[i].getSimpleName() + " " + paramNames[i];
  }
  paramsAsStr = "(" + par + ")";
}

代码示例来源:origin: rapidoid/rapidoid

public static boolean contains(int[] arr, int value) {
  return indexOf(arr, value) >= 0;
}

代码示例来源:origin: rapidoid/rapidoid

@Override
public void release(T obj) {
  assert obj != null;
  if (freeN >= free.length) {
    int expandFactor = free.length < 1000000 ? 10 : 2;
    int newSize = free.length * expandFactor;
    Log.info("The pool wasn't big enough, expanding...", "name", getName(), "old size", free.length,
      "new size", newSize);
    free = Arr.expand(free, expandFactor);
  }
  free[freeN++] = obj;
}

代码示例来源:origin: rapidoid/rapidoid

static synchronized void startUp(String[] args, String... extraArgs) {
  U.must(!started, "The application was already started!");
  started = true;
  args = Arr.concat(extraArgs, args);
  ConfigHelp.processHelp(args);
  Env.setArgs(args);
  U.must(!Conf.isInitialized(), "The configuration shouldn't be initialized yet!");
}

代码示例来源:origin: rapidoid/rapidoid

@Override
public synchronized void set(String key, Object value, boolean overridenByEnv) {
  makeSureIsInitialized();
  String[] keys = key.split("\\.");
  if (keys.length > 1) {
    Config cfg = sub(Arr.sub(keys, 0, -1));
    cfg.set(U.last(keys), value, overridenByEnv);
    return;
  }
  if (overridenByEnv) {
    value = U.or(globalOrArgConfigByRelativeKey(key), value);
  }
  synchronized (base.properties) {
    asMap().put(key, value);
  }
}

代码示例来源:origin: rapidoid/rapidoid

public static boolean contains(long[] arr, long value) {
  return indexOf(arr, value) >= 0;
}

代码示例来源:origin: org.rapidoid/rapidoid-aop

public static synchronized void intercept(AOPInterceptor interceptor, Class<? extends Annotation>... annotated) {
  InterceptorConfig config = new InterceptorConfig(interceptor, annotated);
  INTERCEPTORS = Arr.expand(INTERCEPTORS, config);
}

代码示例来源:origin: rapidoid/rapidoid

public void waitForStatus(LoopStatus... requiredStatuses) {
  while (!Arr.contains(requiredStatuses, status)) {
    U.sleep(5);
  }
}

代码示例来源:origin: org.rapidoid/rapidoid-render

public static String[] withDefaultPath(String[] templatesPath) {
  if (U.isEmpty(templatesPath) || U.neq(U.last(templatesPath), Templates.DEFAULT_TEMPLATES)) {
    return Arr.concat(templatesPath, Templates.DEFAULT_TEMPLATES);
  } else {
    return templatesPath;
  }
}

代码示例来源:origin: rapidoid/rapidoid

@SuppressWarnings("unchecked")
@Override
public Object call(Method m, Object[] args) {
  U.must(!config.isEmpty(), "Cannot find configuration for the REST client interface: %s", clientInterface.getSimpleName());
  Config cfg = config.sub(m.getName());
  String verb = verbOf(cfg);
  String url = cfg.entry(verb).str().get();
  U.must(!U.isEmpty(verb), "The [verb: url] entry is not configured for the method: %s", m);
  U.must(!U.isEmpty(url), "Cannot find 'url' configuration for the method: %s", m);
  Class<Object> retType = (Class<Object>) m.getReturnType();
  Class<?>[] paramTypes = m.getParameterTypes();
  Class<?> lastParamType = U.last(paramTypes);
  if (lastParamType != null && Callback.class.isAssignableFrom(lastParamType)) {
    // async result with callback
    U.must(retType.equals(void.class) || Future.class.isAssignableFrom(retType)
      || org.rapidoid.concurrent.Future.class.isAssignableFrom(retType));
    Callback<Object> callback = (Callback<Object>) U.last(args);
    U.notNull(callback, "callback");
    args = Arr.sub(args, 0, -1);
    String realUrl = String.format(url, args);
    OfType ofType = Metadata.get(U.last(m.getParameterAnnotations()), OfType.class);
    Class<Object> resultType = (Class<Object>) (ofType != null ? ofType.value() : Object.class);
    return REST.call(verb, realUrl, resultType, callback);
  } else {
    String realUrl = String.format(url, args);
    return REST.call(verb, realUrl, retType);
  }
}

代码示例来源:origin: rapidoid/rapidoid

public static boolean contains(boolean[] arr, boolean value) {
  return indexOf(arr, value) >= 0;
}

相关文章