List of usage examples for org.apache.commons.lang ObjectUtils defaultIfNull
public static <T> T defaultIfNull(T object, T defaultValue)
Returns a default value if the object passed is null
.
ObjectUtils.defaultIfNull(null, null) = null ObjectUtils.defaultIfNull(null, "") = "" ObjectUtils.defaultIfNull(null, "zz") = "zz" ObjectUtils.defaultIfNull("abc", *) = "abc" ObjectUtils.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
From source file:com.gst.infrastructure.campaigns.sms.domain.SmsCampaign.java
public LocalDate getLastTriggerDate() { return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.lastTriggerDate), null); }
From source file:com.gst.portfolio.client.domain.Client.java
public LocalDate getSubmittedOnDate() { return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.submittedOnDate), null); }
From source file:com.dycody.android.idealnote.ListFragment.java
void editNote2(Note note) { if (note.get_id() == null) { Log.d(Constants.TAG, "Adding new note"); // if navigation is a category it will be set into note try {/*w w w . j a va 2 s . co m*/ if (Navigation.checkNavigation(Navigation.CATEGORY) || !TextUtils.isEmpty(mainActivity.navigationTmp)) { String categoryId = (String) ObjectUtils.defaultIfNull(mainActivity.navigationTmp, Navigation.getCategory().toString()); note.setCategory(DbHelper.getInstance().getCategory(Long.parseLong(categoryId))); } } catch (NumberFormatException e) { Log.v(Constants.TAG, "Maybe was not a category!"); } } else { Log.d(Constants.TAG, "Editing note with id: " + note.get_id()); } // Current list scrolling position is saved to be restored later refreshListScrollPosition(); // Fragments replacing mainActivity.switchToDetail(note); }
From source file:com.gst.portfolio.client.domain.Client.java
public LocalDate getRejectedDate() { return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.rejectionDate), null); }
From source file:com.gst.portfolio.client.domain.Client.java
public LocalDate getWithdrawalDate() { return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.withdrawalDate), null); }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
public LocalDate getClosedOnDate() { return (LocalDate) ObjectUtils.defaultIfNull(new LocalDate(this.closedOnDate), null); }
From source file:nl.strohalm.cyclos.controls.accounts.transfertypes.PaymentCustomFieldsAjaxAction.java
@Override protected ActionForward executeAction(final ActionContext context) throws Exception { final HttpServletRequest request = context.getRequest(); final TransferType transferType = resolveTransferType(context); if (transferType == null) { // TT not found return null; }/*from w ww . jav a2 s . c o m*/ final Collection<PaymentCustomField> customFields = paymentCustomFieldService.list(transferType, false); if (CollectionUtils.isEmpty(customFields)) { // No custom fields return null; } // Set some specific use cases attributes final boolean isForLoan = CoercionHelper.coerce(boolean.class, request.getParameter("forLoan")); final String fieldName = isForLoan ? "loan(customValues).field" : "customValues.field"; final String valueName = isForLoan ? "loan(customValues).value" : "customValues.value"; request.setAttribute("isForLoan", isForLoan); request.setAttribute("fieldName", fieldName); request.setAttribute("valueName", valueName); request.setAttribute("columnWidth", ObjectUtils .defaultIfNull(StringHelper.removeMarkupTags(request.getParameter("columnWidth")), "25%")); // Delegate the rendering to a jsp request.setAttribute("customFields", customFields); context.getResponse().setContentType("text/html"); return new ActionForward("/pages/payments/paymentCustomFields.jsp", false); }
From source file:nl.strohalm.cyclos.dao.ads.AdDAOImpl.java
@Override public List<Ad> search(final AdQuery query) { final Map<String, Object> namedParameters = new HashMap<String, Object>(); final StringBuilder hql = new StringBuilder(); hql.append(" select ad"); hql.append(//ww w. j av a2 s .c o m " from Ad ad inner join ad.owner m left join ad.category c1 left join c1.parent c2 left join c2.parent c3 "); hibernateCustomFieldHandler.appendJoins(hql, "ad.customValues", query.getAdValues()); hibernateCustomFieldHandler.appendJoins(hql, "m.customValues", query.getMemberValues()); HibernateHelper.appendJoinFetch(hql, getEntityType(), "ad", query.getFetch()); hql.append(" where 1=1"); if (query.getCategory() != null) { hql.append(" and (c1 = :adCategory or c2 = :adCategory or c3 = :adCategory)"); namedParameters.put("adCategory", query.getCategory()); } if (!query.isIncludeDeleted()) { hql.append(" and ad.deleteDate is null "); } HibernateHelper.addParameterToQuery(hql, namedParameters, "ad.category.active", true); HibernateHelper.addParameterToQuery(hql, namedParameters, "ad.id", query.getId()); HibernateHelper.addParameterToQuery(hql, namedParameters, "ad.membersNotified", query.getMembersNotified()); HibernateHelper.addParameterToQuery(hql, namedParameters, "ad.externalPublication", query.getExternalPublication()); HibernateHelper.addParameterToQuery(hql, namedParameters, "m", query.getOwner()); // Group filters are handled at service level HibernateHelper.addInParameterToQuery(hql, namedParameters, "m.group", query.getGroups()); HibernateHelper.addParameterToQuery(hql, namedParameters, "ad.tradeType", query.getTradeType()); HibernateHelper.addParameterToQueryOperator(hql, namedParameters, "ad.price", ">=", query.getInitialPrice()); HibernateHelper.addParameterToQueryOperator(hql, namedParameters, "ad.price", "<=", query.getFinalPrice()); HibernateHelper.addParameterToQuery(hql, namedParameters, "ad.currency", query.getCurrency()); HibernateHelper.addPeriodParameterToQuery(hql, namedParameters, "ad.publicationPeriod.begin", Period.day(query.getBeginDate())); HibernateHelper.addPeriodParameterToQuery(hql, namedParameters, "ad.publicationPeriod.end", Period.day(query.getEndDate())); final Calendar now = Calendar.getInstance(); // Since if (query.getSince() != null && query.getSince().getNumber() > 0) { final Calendar since = DateHelper.truncate(query.getSince().remove(now)); HibernateHelper.addParameterToQueryOperator(hql, namedParameters, "ad.publicationPeriod.begin", ">=", since); } HibernateHelper.addPeriodParameterToQuery(hql, namedParameters, "ad.publicationPeriod.begin", query.getPeriod()); // With Images Only if (query.isWithImagesOnly()) { hql.append(" and exists (select img.id from AdImage img where img.ad = ad) "); } // Check the history date final Calendar historyDate = (Calendar) ObjectUtils.defaultIfNull(query.getHistoryDate(), Calendar.getInstance()); HibernateHelper.addParameterToQueryOperator(hql, namedParameters, "ad.creationDate", "<=", historyDate); hql.append(" and (ad.deleteDate is null or ad.deleteDate >= :historyDate)"); namedParameters.put("historyDate", historyDate); // Status if (query.getStatus() != null) { switch (query.getStatus()) { case PERMANENT: hql.append(" and ad.permanent = true "); break; case ACTIVE: hql.append( " and (ad.permanent = true or ((ad.publicationPeriod.end is null or ad.publicationPeriod.end >= :historyDate) and ad.publicationPeriod.begin <= :historyDate)) "); break; case SCHEDULED: hql.append( " and (ad.permanent is null or ad.permanent = false) and ad.publicationPeriod.begin > :historyDate "); break; case EXPIRED: hql.append( " and (ad.permanent is null or ad.permanent = false) and ad.publicationPeriod.end < :historyDate "); break; } } // Keywords if (StringUtils.isNotEmpty(query.getKeywords())) { hql.append(" and ((ad.title like :keywords) or (ad.description like :keywords))"); namedParameters.put("keywords", "%" + query.getKeywords() + "%"); } // Custom Values hibernateCustomFieldHandler.appendConditions(hql, namedParameters, query.getAdValues()); hibernateCustomFieldHandler.appendConditions(hql, namedParameters, query.getMemberValues()); // Handle order if (query.isRandomOrder()) { HibernateHelper.appendOrder(hql, "rand()"); } else { HibernateHelper.appendOrder(hql, "ad.publicationPeriod.begin desc, ad.id desc"); } return list(query, hql.toString(), namedParameters); }
From source file:nl.strohalm.cyclos.taglibs.MenuTag.java
private int index() { int index = (Integer) ObjectUtils.defaultIfNull(pageContext.getAttribute("menuIndex"), -1); index++;/*from w w w.java 2s .c om*/ pageContext.setAttribute("menuIndex", index); return index; }
From source file:org.apache.qpid.disttest.controller.config.ParticipantConfig.java
protected void setParticipantProperties(CreateParticpantCommand createParticipantCommand) { createParticipantCommand.setParticipantName(_name); createParticipantCommand.setDestinationName(_destinationName); createParticipantCommand.setTopic(_isTopic); createParticipantCommand.setNumberOfMessages(_numberOfMessages); createParticipantCommand.setBatchSize(_batchSize); Long maximumDuration = (Long) ObjectUtils.defaultIfNull(getOverriddenDuration(), _maximumDuration); createParticipantCommand.setMaximumDuration(maximumDuration); }