@Override public List<String> apply(String a) { if (a != null) { final String trimmed = a.trim(); return trimmed.length() > 0 ? list(trimmed) : NIL; } else { return NIL; } } };
@Override public List<A> apply(MediaPackageElement mpe) { return type.isAssignableFrom(mpe.getClass()) ? list((A) mpe) : (List<A>) NIL; } };
/** Pattern matching on the wrapped list. */ public final <B> B match(Matcher<A, B>... ms) { return match(list(ms)); }
/** Return nil if <code>a</code> is null or a list containing <code>a</code> otherwise. */ @SuppressWarnings("unchecked") public static <A> List<A> toList(A a) { return a != null ? list(a) : Collections.<A> nil(); }
@Override public List<A> apply(A[] as) { if (as != null) { return Collections.list(as); } else { return Collections.nil(); } } };
@Override public ListMonadic<A> sort(Comparator<A> c) { final List<A> target = list(as); java.util.Collections.sort(target, c); return mlist(target); }
@Override public List<Integer> apply(String s) { try { return list(Integer.parseInt(s)); } catch (NumberFormatException e) { return nil(); } } };
@Override public ListMonadic<A> reverse() { final List<A> target = list(as); java.util.Collections.reverse(target); return mlist(target); }
private static void setFormParams(HttpEntityEnclosingRequest r, NameValuePair[] formParams) { final List<NameValuePair> params = list(formParams); try { r.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); } catch (UnsupportedEncodingException e) { chuck(e); } }
public static MimeType mimeType(String type, String subtype, String suffix) { return new MimeType(type, subtype, list(suffix), Collections.<MimeType>nil(), none(""), none(""), none("")); }
private List<IncidentTree> getChildIncidents(long jobId) throws NotFoundException, ServiceRegistryException, IncidentServiceException { List<Job> childJobs = getServiceRegistry().getChildJobs(jobId); List<IncidentTree> incidentResults = new ArrayList<IncidentTree>(); for (Job childJob : childJobs) { if (childJob.getParentJobId() != jobId) continue; List<Incident> incidentsForJob = getIncidentsOfJob(childJob.getId()); IncidentTree incidentTree = new IncidentTreeImpl(incidentsForJob, getChildIncidents(childJob.getId())); if (hasIncidents(Collections.list(incidentTree))) incidentResults.add(incidentTree); } return incidentResults; }
/** * Basic sanity checking for media packages. * * <pre> * // media package is ok * sanityCheck(mp).isNone() * </pre> * * @return none if the media package is a healthy condition, some([error_msgs]) otherwise */ public static Option<List<String>> sanityCheck(MediaPackage mp) { final Option<List<String>> errors = sequenceOpt(list(toOption(mp.getIdentifier() != null, "no ID"), toOption(mp.getIdentifier() != null && isNotBlank(mp.getIdentifier().toString()), "blank ID"))); return errors.getOrElse(NIL).size() == 0 ? Option.<List<String>> none() : errors; }
@Override public IncidentTree getIncidentsOfJob(long jobId, boolean cascade) throws NotFoundException, IncidentServiceException { List<Incident> incidents = getIncidentsOfJob(jobId); List<IncidentTree> childIncidents = new ArrayList<IncidentTree>(); try { Job job = getServiceRegistry().getJob(jobId); if (cascade && !"START_WORKFLOW".equals(job.getOperation())) { childIncidents = getChildIncidents(jobId); } else if (cascade && "START_WORKFLOW".equals(job.getOperation())) { for (WorkflowOperationInstance operation : getWorkflowService().getWorkflowById(jobId).getOperations()) { if (operation.getState().equals(OperationState.INSTANTIATED)) continue; IncidentTree operationResult = getIncidentsOfJob(operation.getId(), true); if (hasIncidents(Collections.list(operationResult))) childIncidents.add(operationResult); } } return new IncidentTreeImpl(incidents, childIncidents); } catch (NotFoundException ignore) { // Workflow deleted return new IncidentTreeImpl(incidents, childIncidents); } catch (Exception e) { logger.error("Error loading child jobs of {}: {}", jobId); throw new IncidentServiceException(e); } }
/** * {@inheritDoc} * * @see org.opencastproject.metadata.api.MetadataService#getMetadata(org.opencastproject.mediapackage.MediaPackage) */ @Override public StaticMetadata getMetadata(final MediaPackage mp) { return mlist(list(mp.getCatalogs(DublinCoreCatalog.ANY_DUBLINCORE))) .find(flavorPredicate(MediaPackageElements.EPISODE)) .flatMap(loader) .map(new Function<DublinCoreCatalog, StaticMetadata>() { @Override public StaticMetadata apply(DublinCoreCatalog episode) { return newStaticMetadataFromEpisode(episode); } }) .getOrElse((StaticMetadata) null); }