org.opencastproject.util.data.Option.some()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(102)

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

Option.some介绍

[英]Create a new some.
[中]创建一个新的。

代码示例

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

/** Return the head of list <code>as</code> or <code>none</code>. */
public static <A> Option<A> head(List<A> as) {
 if (!as.isEmpty()) {
  return some(as.get(0));
 } else {
  return Option.none();
 }
}

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

/** Create a new entity manager or return none, if the factory has already been closed. */
public static Option<EntityManager> createEntityManager(EntityManagerFactory emf) {
 try {
  return some(emf.createEntityManager());
 } catch (IllegalStateException ex) {
  // factory is already closed
  return none();
 }
}

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

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getUsedSpace()
 */
@Override
public Option<Long> getUsedSpace() {
 return Option.some((Long) (getStorageReport().get("used")));
}

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

/**
 * Trim a string and return either <code>some</code> or <code>none</code> if it's empty. The string may be null.
 */
public static Option<String> trimToNone(String a) {
 if (a != null) {
  final String trimmed = a.trim();
  return trimmed.length() > 0 ? some(trimmed) : NONE;
 } else {
  return none();
 }
}

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

@Override
 public Option<Integer> apply(String s) {
  try {
   return some(Integer.parseInt(s));
  } catch (NumberFormatException e) {
   return none();
  }
 }
};

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

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getTotalSpace()
 */
@Override
public Option<Long> getTotalSpace() {
 return Option.some((Long) (getStorageReport().get("size")));
}

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

@Override
public Option<Long> getUsableSpace() {
 return some(new File(wsRoot).getUsableSpace());
}

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

@Override
public Option<A> option() {
 return as.length == 1 ? some(as[0]) : Option.<A> none();
}

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

/** Wrap an arbitrary object into an option with <code>null</code> being mapped to none. */
public static <A> Option<A> option(A a) {
 if (a != null)
  return some(a);
 else
  return none();
}

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

/** Convert an <code>Opt</code> into an <code>Option</code>. */
public static <A> Option<A> fromOpt(Opt<A> a) {
 for (A x : a) {
  return some(x);
 }
 return none();
}

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

@Override
 public Option<List<MediaPackageElement>> apply(HttpResponse response) {
  try {
   final String xml = IOUtils.toString(response.getEntity().getContent(), Charset.forName("utf-8"));
   List<MediaPackageElement> result = new ArrayList<>(MediaPackageElementParser.getArrayFromXml(xml));
   return some(result);
  } catch (Exception e) {
   logger.error("Error parsing Job from HTTP response", e);
   return none();
  }
 }
};

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

/** Get a classpath resource as a file using the class loader of {@link IoSupport}. */
public static Option<File> classPathResourceAsFile(String resource) {
 try {
  final URL res = IoSupport.class.getResource(resource);
  if (res != null) {
   return Option.some(new File(res.toURI()));
  } else {
   return Option.none();
  }
 } catch (URISyntaxException e) {
  return Option.none();
 }
}

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

@Override
public Option<A> lastOpt() {
 return !as.isEmpty() ? some(last()) : Option.<A> none();
}

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

/** Get the organization <code>orgId</code>. */
public static Option<Organization> getOrganization(OrganizationDirectoryService orgDir, String orgId) {
 try {
  return some(orgDir.getOrganization(orgId));
 } catch (NotFoundException e) {
  return none();
 }
}

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

@Override
 public Option<AclScope> apply(String s) {
  try {
   return some(AclScope.valueOf(s));
  } catch (IllegalArgumentException e) {
   return none();
  }
 }
};

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

@Override
public Option<A> find(Function<? super A, Boolean> p) {
 for (A a : as) {
  if (p.apply(a))
   return some(a);
 }
 return none();
}

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

@Override
public Option<A> find(Function<? super A, Boolean> p) {
 for (A a : forc(as)) {
  if (p.apply(a))
   return some(a);
 }
 return none();
}

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

/** Lazy version of {@link #andThenV(Object)}. */
public <B> Option<B> andThenV(Function0<B> some) {
 return isSome() ? some(some.apply()) : Option.<B> none();
}

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

protected <A> Option<A> runRequest(HttpRequestBase req, Function<HttpResponse, A> f) {
 HttpResponse res = null;
 try {
  res = getResponse(req);
  return res != null ? some(f.apply(res)) : Option.<A> none();
 } finally {
  closeConnection(res);
 }
}

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

public <B> Option<Tuple<A, B>> and(Option<B> b) {
 if (isSome() && b.isSome()) {
  return some(tuple(get(), b.get()));
 } else {
  return none();
 }
}

相关文章