/** Check if <code>a</code> and <code>b</code> are not equal. Each of them may be null. */ public static boolean ne(Object a, Object b) { return !eq(a, b); }
@Override public Boolean apply(A x) { return EqualsUtil.eq(x, a); } };
private boolean eqFields(Incident that) { return eq(id, that.getId()) && eq(jobId, that.getJobId()) && eq(serviceType, that.getServiceType()) && eq(processingHost, that.getProcessingHost()) && eq(timestamp, that.getTimestamp()) && eq(severity, that.getSeverity()) && eq(code, that.getCode()) && eq(details, that.getDetails()) && eq(parameters, that.getDescriptionParameters()); } }
/** Cast from A to B with special treatment of the Number classes. */ public static <A, B> B cast(A v, Class<B> to) { if (Number.class.isAssignableFrom(v.getClass())) { if (eq(Integer.class, to)) { return (B) ((Object) (((Number) v).intValue())); } else if (eq(Long.class, to)) { return (B) ((Object) (((Number) v).longValue())); } else if (eq(Double.class, to)) { return (B) ((Object) (((Number) v).doubleValue())); } else if (eq(Float.class, to)) { return (B) ((Object) (((Number) v).floatValue())); } else if (eq(Short.class, to)) { return (B) ((Object) (((Number) v).shortValue())); } else if (eq(Byte.class, to)) { return (B) ((Object) (((Number) v).byteValue())); } else { return (B) v; } } else if (to.isAssignableFrom(v.getClass())) { return (B) v; } else { throw new ClassCastException(v.getClass().getName() + " is not of type " + to.getName()); } }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (!(obj instanceof User)) return false; User other = (User) obj; return username.equals(other.getUsername()) && organization.equals(other.getOrganization()) && EqualsUtil.eq(provider, other.getProvider()); }
final List<Incident> incidents = svc.getIncidentsOfJob(jobIds); final MediaType mt = getResponseType(type); if (eq(FMT_SYS, format)) { return ok(mt, new JaxbIncidentList(incidents)); } else if (eq(FMT_DIGEST, format)) { return ok(mt, new JaxbIncidentDigestList(svc, request.getLocale(), incidents)); } else if (eq(FMT_FULL, format)) { return ok(mt, new JaxbIncidentFullList(svc, request.getLocale(), incidents)); } else {
final IncidentTree tree = svc.getIncidentsOfJob(jobId, cascade); final MediaType mt = getResponseType(type); if (eq(FMT_SYS, format)) { return ok(mt, new JaxbIncidentTree(tree)); } else if (eq(FMT_DIGEST, format)) { return ok(mt, new JaxbIncidentFullTree(svc, request.getLocale(), tree)); } else if (eq(FMT_FULL, format)) { return ok(mt, new JaxbIncidentFullTree(svc, request.getLocale(), tree)); } else {
/** * Wait for a certain status of a resource. * * @return either an exception or the status code of the last http response */ public static Either<Exception, Integer> waitForResource(final TrustedHttpClient http, final URI resourceUri, final int expectedStatus, final long timeout, final long pollingInterval) { long now = 0L; while (true) { final HttpHead head = new HttpHead(resourceUri); final Either<Exception, Integer> result = http.<Integer> run(head).apply(getStatusCode); for (final Integer status : result.right()) { if (eq(status, expectedStatus) || now >= timeout) { return right(status); } else if (now < timeout) { if (!sleep(pollingInterval)) { return left(new Exception("Interrupted")); } else { now = now + pollingInterval; } } } for (Exception e : result.left()) { return left(e); } } } }