• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StringUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.threadly.util.StringUtils的典型用法代码示例。如果您正苦于以下问题:Java StringUtils类的具体用法?Java StringUtils怎么用?Java StringUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StringUtils类属于org.threadly.util包,在下文中一共展示了StringUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getAndSetGlobalParam

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void getAndSetGlobalParam() throws Exception {
  final String key = StringUtils.makeRandomString(5);
  final String value = StringUtils.makeRandomString(5);
  AbstractScriptStep setStep = new AbstractScriptStep(StringUtils.makeRandomString(5)) {
    @Override
    public void runStep() {
      setGlobalParam(key, value);
    }
  };
  AbstractScriptStep verifyStep = new AbstractScriptStep(StringUtils.makeRandomString(5)) {
    @Override
    public void runStep() {
      assertEquals(value, getGlobalParam(key));
    }
  };
  
  setStep.runStep();
  verifyStep.runStep();
}
 
开发者ID:threadly,项目名称:ambush,代码行数:21,代码来源:AbstractScriptStepTest.java


示例2: inParallelOnlyTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void inParallelOnlyTest() throws InterruptedException, ExecutionException {
  String identifier = StringUtils.makeRandomString(5);
  int runTime = 2;
  int runCount = 10;
  TestStep step = new TestStep(identifier, runTime);
  ParallelScriptBuilder builder = new ParallelScriptBuilder();
  builder.addStep(step, runCount);
  
  List<? extends ListenableFuture<StepResult>> futures = builder.build().startScript();
  assertEquals(runCount, futures.size());
  
  StepResult tr = futures.get(0).get();
  
  assertNull(tr.getError());
  assertEquals(identifier, tr.getDescription());
  assertTrue(tr.getRunTime(TimeUnit.MILLISECONDS) >= runTime);
}
 
开发者ID:threadly,项目名称:ambush,代码行数:19,代码来源:SimpleExecutionGraphTest.java


示例3: queryToString

import org.threadly.util.StringUtils; //导入依赖的package包/类
public static String queryToString(Map<String,String> map) {
  if(map.isEmpty()) {
    return "";
  }
  
  StringBuilder sb = new StringBuilder();
  sb.append('?');
  for(String k: map.keySet()) {
    if(sb.length() > 1) {
      sb.append('&');  
    }
    sb.append(k);
    String v = map.get(k);
    if(! StringUtils.isNullOrEmpty(v)) {
      sb.append('=');
      sb.append(v);
    }
  }
  return sb.toString();
}
 
开发者ID:threadly,项目名称:litesockets-http,代码行数:21,代码来源:HTTPUtils.java


示例4: queryToMap

import org.threadly.util.StringUtils; //导入依赖的package包/类
public static Map<String, String> queryToMap(String query) {
  if (StringUtils.isNullOrEmpty(query)) {
    return Collections.emptyMap();
  }
  Map<String, String> map = new HashMap<>();
  if(query.startsWith("?")) {
    query = query.substring(1);
  }
  String[] tmpQ = query.trim().split("&");
  for(String kv: tmpQ) {
    String[] tmpkv = kv.split("=");
    if (tmpkv.length == 0) {
      // case where either no `=` or empty key string
      continue;
    }
    if(tmpkv.length == 1) {
      map.put(tmpkv[0].trim(), "");
    } else {
      map.put(tmpkv[0].trim(), tmpkv[1].trim());
    }
  }
  return Collections.unmodifiableMap(map);
}
 
开发者ID:threadly,项目名称:litesockets-http,代码行数:24,代码来源:HTTPUtils.java


示例5: analyze

import org.threadly.util.StringUtils; //导入依赖的package包/类
public void analyze() throws IOException {
  System.out.println(StringUtils.NEW_LINE + "Done parsing file, now analyzing..." + StringUtils.NEW_LINE);
  
  analyzeInstances();
  
  List<Summary> summaryList = new ArrayList<>();
  summaryList.addAll(instanceSummary.values());
  summaryList.addAll(arraySummary.values());
  Collections.sort(summaryList, (s1, s2) -> {
    return s2.getTotalBytesUsed() - s1.getTotalBytesUsed();
  });
  
  Iterator<Summary> it = summaryList.iterator();
  while (it.hasNext()) {
    Summary summary = it.next();
    if (summary.getInstanceCount() == 0 || summary.getTotalBytesUsed() < 1024) {
      continue;
    }
    System.out.println(summary.toString());
  }
  pointerSize = -1;
}
 
开发者ID:threadly,项目名称:heapDumpAnalyzer,代码行数:23,代码来源:HprofParser.java


示例6: runBenchmark

import org.threadly.util.StringUtils; //导入依赖的package包/类
private static BenchmarkResult runBenchmark(String classpath, 
                                            Class<? extends AbstractBenchmark> benchmarkClass, 
                                            String executionArgs) {
  String[] command = {SHELL, "-c", 
                      JAVA_EXECUTE_CMD + "-cp " + classpath + ' ' + 
                        benchmarkClass.getName() + ' ' + executionArgs};
  System.gc();
  try {
    ExecResult runResult = runCommand(command);
    if (StringUtils.isNullOrEmpty(runResult.stdErr)) {
      int delimIndex = runResult.stdOut.indexOf(AbstractBenchmark.OUTPUT_DELIM);
      if (delimIndex > 0) {
        delimIndex += AbstractBenchmark.OUTPUT_DELIM.length();
        long runVal = Long.parseLong(runResult.stdOut.substring(delimIndex));
        return new BenchmarkResult(runVal);
      } else {
        return new BenchmarkResult("Invalid benchmark output: " + runResult.stdOut);
      }
    } else {
      return new BenchmarkResult(runResult.stdErr);
    }
  } catch (Exception e) {
    return new BenchmarkResult(ExceptionUtils.stackToString(e));
  }
}
 
开发者ID:threadly,项目名称:threadly_benchmarks,代码行数:26,代码来源:BenchmarkCollectionRunner.java


示例7: masterScheduler

import org.threadly.util.StringUtils; //导入依赖的package包/类
/**
 * Returns the master scheduler with a default priority requested.
 * @param defaultPriority Default priority for tasks submitted to scheduler
 * @param threadName if name should be set during execution
 * 
 * @return Master scheduler with the provided default priority
 */
private static PrioritySchedulerService masterScheduler(TaskPriority defaultPriority, 
                                                        String threadName) {
  PrioritySchedulerService result;
  if (defaultPriority == TaskPriority.High) {
    result = MASTER_SCHEDULER;
  } else if (defaultPriority ==  TaskPriority.Low) {
    result = LOW_PRIORITY_MASTER_SCHEDULER;
  } else {
    result = STARVABLE_PRIORITY_MASTER_SCHEDULER;
  }
  if (StringUtils.isNullOrEmpty(threadName)) {
    return result;
  } else {
    return new ThreadRenamingPriorityScheduler(result, threadName, false);
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:24,代码来源:CentralThreadlyPool.java


示例8: doExecute

import org.threadly.util.StringUtils; //导入依赖的package包/类
/**
 * Internal call to actually execute prepared runnable.
 * 
 * @param permits resource permits for this task
 * @param taskKey object key where {@code equals()} will be used to determine execution thread
 * @param task Runnable to execute when ready
 * @return Time in milliseconds task was delayed to maintain rate, or {@code -1} if rejected but handler did not throw
 */
protected long doExecute(double permits, Object taskKey, Runnable task) {
  RateLimiterExecutor rle;
  Object lock = sLock.getLock(taskKey);
  synchronized (lock) {
    rle = currentLimiters.get(taskKey);
    if (rle == null) {
      String keyedPoolName = subPoolName + (addKeyToThreadName ? taskKey.toString() : "");
      SubmitterScheduler threadNamedScheduler;
      if (StringUtils.isNullOrEmpty(keyedPoolName)) {
        threadNamedScheduler = scheduler;
      } else {
        threadNamedScheduler = new ThreadRenamingSubmitterScheduler(scheduler, keyedPoolName, false);
      }
      rle = new RateLimiterExecutor(threadNamedScheduler, permitsPerSecond, 
                                    maxScheduleDelayMillis, rejectedExecutionHandler);

      currentLimiters.put(taskKey, rle);
      // schedule task to check for removal later, should only be one task per limiter
      limiterCheckerScheduler.schedule(new LimiterChecker(taskKey, rle), 1000);
    }
    
    // must execute while in lock to prevent early removal
    return rle.execute(permits, task);
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:34,代码来源:KeyedRateLimiterExecutor.java


示例9: makeCompleteFutureWithResultNotCompleteTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void makeCompleteFutureWithResultNotCompleteTest() throws InterruptedException, TimeoutException, ExecutionException {
  String result = StringUtils.makeRandomString(5);
  List<SettableListenableFuture<?>> futures = new ArrayList<>(TEST_QTY);
  for (int i = 0; i < TEST_QTY; i++) {
    SettableListenableFuture<?> future = new SettableListenableFuture<>();
    if (i != 0) {
      future.setResult(null);
    }
    futures.add(future);
  }
  
  ListenableFuture<String> f = FutureUtils.makeCompleteFuture(futures, result);
  futures.get(0).setResult(null); // complete now
  
  verifyCompleteFuture(f, futures);
  assertEquals(result, f.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:FutureUtilsTest.java


示例10: makeFailurePropagatingCompleteFutureWithResultNotCompleteTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void makeFailurePropagatingCompleteFutureWithResultNotCompleteTest() throws InterruptedException, TimeoutException, ExecutionException {
  String result = StringUtils.makeRandomString(5);
  List<SettableListenableFuture<?>> futures = new ArrayList<>(TEST_QTY);
  for (int i = 0; i < TEST_QTY; i++) {
    SettableListenableFuture<?> future = new SettableListenableFuture<>();
    if (i != 0) {
      future.setResult(null);
    }
    futures.add(future);
  }
  
  ListenableFuture<String> f = FutureUtils.makeFailurePropagatingCompleteFuture(futures, result);
  futures.get(0).setResult(null);
  
  verifyCompleteFuture(f, futures);
  assertEquals(result, f.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:FutureUtilsTest.java


示例11: getResultTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void getResultTest() throws InterruptedException, ExecutionException {
  final String testResult = StringUtils.makeRandomString(5);
  
  PriorityScheduler scheduler = new StrictPriorityScheduler(1);
  try {
    scheduler.schedule(new Runnable() {
      @Override
      public void run() {
        slf.setResult(testResult);
      }
    }, DELAY_TIME);
    
    assertTrue(slf.get() == testResult);
  } finally {
    scheduler.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:SettableListenableFutureTest.java


示例12: getWithTimeoutResultTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void getWithTimeoutResultTest() throws InterruptedException, 
                                              ExecutionException, 
                                              TimeoutException {
  final String testResult = StringUtils.makeRandomString(5);
  
  PriorityScheduler scheduler = new StrictPriorityScheduler(1);
  try {
    scheduler.prestartAllThreads();
    scheduler.schedule(new Runnable() {
      @Override
      public void run() {
        slf.setResult(testResult);
      }
    }, DELAY_TIME);
    
    assertTrue(slf.get(DELAY_TIME + (SLOW_MACHINE ? 2000 : 1000), TimeUnit.MILLISECONDS) == testResult);
  } finally {
    scheduler.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:22,代码来源:SettableListenableFutureTest.java


示例13: mapAlreadyDoneTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void mapAlreadyDoneTest() throws InterruptedException, ExecutionException {
  String sourceObject = StringUtils.makeRandomString(5);
  ListenableFuture<String> lf = makeListenableFutureFactory().makeWithResult(sourceObject);
  String translatedObject = StringUtils.makeRandomString(10);
  ListenableFuture<String> mappedLF = lf.map((s) -> {
    if (s == sourceObject) {
      return translatedObject;
    } else {
      // test failure
      return null;
    }
  });
  
  assertTrue(mappedLF.isDone());
  assertTrue(translatedObject == mappedLF.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:18,代码来源:ListenableFutureInterfaceTest.java


示例14: mapWithExecutorAlreadyDoneTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void mapWithExecutorAlreadyDoneTest() throws InterruptedException, ExecutionException {
  TestableScheduler scheduler = new TestableScheduler();
  String sourceObject = StringUtils.makeRandomString(5);
  ListenableFuture<String> lf = makeListenableFutureFactory().makeWithResult(sourceObject);
  String translatedObject = StringUtils.makeRandomString(10);
  ListenableFuture<String> mappedLF = lf.map((s) -> {
    if (s == sourceObject) {
      return translatedObject;
    } else {
      // test failure
      return null;
    }
  }, scheduler);
  
  assertEquals(1, scheduler.tick());
  
  assertTrue(mappedLF.isDone());
  assertTrue(translatedObject == mappedLF.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:21,代码来源:ListenableFutureInterfaceTest.java


示例15: throwMapAlreadyDoneTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void throwMapAlreadyDoneTest() throws InterruptedException, ExecutionException {
  String sourceObject = StringUtils.makeRandomString(5);
  ListenableFuture<String> lf = makeListenableFutureFactory().makeWithResult(sourceObject);
  String translatedObject = StringUtils.makeRandomString(10);
  ListenableFuture<String> mappedLF = lf.throwMap((s) -> {
    if (s == sourceObject) {
      return translatedObject;
    } else {
      // test failure
      return null;
    }
  });
  
  assertTrue(mappedLF.isDone());
  assertTrue(translatedObject == mappedLF.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:18,代码来源:ListenableFutureInterfaceTest.java


示例16: throwMapWithExecutorAlreadyDoneTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void throwMapWithExecutorAlreadyDoneTest() throws InterruptedException, ExecutionException {
  TestableScheduler scheduler = new TestableScheduler();
  String sourceObject = StringUtils.makeRandomString(5);
  ListenableFuture<String> lf = makeListenableFutureFactory().makeWithResult(sourceObject);
  String translatedObject = StringUtils.makeRandomString(10);
  ListenableFuture<String> mappedLF = lf.throwMap((s) -> {
    if (s == sourceObject) {
      return translatedObject;
    } else {
      // test failure
      return null;
    }
  }, scheduler);
  
  assertEquals(1, scheduler.tick());
  
  assertTrue(mappedLF.isDone());
  assertTrue(translatedObject == mappedLF.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:21,代码来源:ListenableFutureInterfaceTest.java


示例17: flatMapAlreadyDoneTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void flatMapAlreadyDoneTest() throws InterruptedException, ExecutionException {
  String sourceObject = StringUtils.makeRandomString(5);
  ListenableFuture<String> lf = makeListenableFutureFactory().makeWithResult(sourceObject);
  String translatedObject = StringUtils.makeRandomString(10);
  ListenableFuture<String> mappedLF = lf.flatMap((s) -> {
    if (s == sourceObject) {
      return FutureUtils.immediateResultFuture(translatedObject);
    } else {
      // test failure
      return FutureUtils.immediateResultFuture(null);
    }
  });
  
  assertTrue(mappedLF.isDone());
  assertTrue(translatedObject == mappedLF.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:18,代码来源:ListenableFutureInterfaceTest.java


示例18: flatMapWithExecutorAlreadyDoneTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void flatMapWithExecutorAlreadyDoneTest() throws InterruptedException, ExecutionException {
  TestableScheduler scheduler = new TestableScheduler();
  String sourceObject = StringUtils.makeRandomString(5);
  ListenableFuture<String> lf = makeListenableFutureFactory().makeWithResult(sourceObject);
  String translatedObject = StringUtils.makeRandomString(10);
  ListenableFuture<String> mappedLF = lf.flatMap((s) -> {
    if (s == sourceObject) {
      return FutureUtils.immediateResultFuture(translatedObject);
    } else {
      // test failure
      return FutureUtils.immediateResultFuture(null);
    }
  }, scheduler);
  
  assertEquals(1, scheduler.tick());
  
  assertTrue(mappedLF.isDone());
  assertTrue(translatedObject == mappedLF.get());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:21,代码来源:ListenableFutureInterfaceTest.java


示例19: renameReplaceAndResetTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void renameReplaceAndResetTest() {
  final String originalName = Thread.currentThread().getName();
  final String newName = StringUtils.makeRandomString(5);
  
  TestRunnable tr = new TestRunnable() {
    @Override
    public void handleRunStart() {
      assertEquals(newName, Thread.currentThread().getName());
    }
  };

  assertEquals(originalName, Thread.currentThread().getName());
  
  new ThreadRenamingRunnable(tr, newName, true).run();
  
  assertTrue(tr.ranOnce());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:19,代码来源:ThreadRenamingRunnableTest.java


示例20: renamePrependAndResetTest

import org.threadly.util.StringUtils; //导入依赖的package包/类
@Test
public void renamePrependAndResetTest() {
  final String originalName = Thread.currentThread().getName();
  final String newName = StringUtils.makeRandomString(5);
  
  TestRunnable tr = new TestRunnable() {
    @Override
    public void handleRunStart() {
      assertTrue(Thread.currentThread().getName().startsWith(newName));
      assertTrue(Thread.currentThread().getName().contains(originalName));
    }
  };

  assertEquals(originalName, Thread.currentThread().getName());
  
  new ThreadRenamingRunnable(tr, newName, false).run();
  
  assertTrue(tr.ranOnce());
}
 
开发者ID:threadly,项目名称:threadly,代码行数:20,代码来源:ThreadRenamingRunnableTest.java



注:本文中的org.threadly.util.StringUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PdfArray类代码示例发布时间:2022-05-23
下一篇:
Java PagedRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap