Example usage for org.apache.commons.lang ObjectUtils defaultIfNull

List of usage examples for org.apache.commons.lang ObjectUtils defaultIfNull

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils defaultIfNull.

Prototype

public static <T> T defaultIfNull(T object, T defaultValue) 

Source Link

Document

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 

Usage

From source file:org.apache.qpid.disttest.controller.config.ProducerConfig.java

public CreateProducerCommand createCommand(String sessionName) {
    CreateProducerCommand command = new CreateProducerCommand();

    setParticipantProperties(command);/*  w  w w. ja  v  a  2  s  .  co  m*/

    command.setSessionName(sessionName);
    command.setDeliveryMode(_deliveryMode);

    Integer messageSize = (Integer) ObjectUtils.defaultIfNull(getOverriddenMessageSize(), _messageSize);

    command.setMessageSize(messageSize);
    command.setPriority(_priority);
    command.setTimeToLive(_timeToLive);
    command.setInterval(_interval);
    command.setStartDelay(_startDelay);
    command.setMessageProviderName(_messageProviderName);

    return command;
}

From source file:org.apache.qpid.server.security.access.plugins.DefaultAccessControl.java

public Result authoriseFromAddress(Operation operation, ObjectType objectType, ObjectProperties properties,
        InetAddress addressOfClient) {
    final Subject subject = SecurityManager.getThreadSubject();
    // Abstain if there is no subject/principal associated with this thread
    if (subject == null || subject.getPrincipals().size() == 0) {
        return Result.ABSTAIN;
    }//  w  w w.  j a v  a  2  s  .  co  m

    if (_logger.isDebugEnabled()) {
        _logger.debug("Checking " + operation + " " + objectType + " "
                + ObjectUtils.defaultIfNull(addressOfClient, ""));
    }

    try {
        return _ruleSet.check(subject, operation, objectType, properties, addressOfClient);
    } catch (Exception e) {
        _logger.error("Unable to check " + operation + " " + objectType + " "
                + ObjectUtils.defaultIfNull(addressOfClient, ""), e);
        return Result.DENIED;
    }
}

From source file:org.beangle.struts2.convention.config.SmartActionConfigBuilder.java

protected ClassLoaderInterface getClassLoaderInterface() {
    if (isReloadEnabled())
        return new ClassLoaderInterfaceDelegate(reloadingClassLoader);
    else {/*from ww  w. j ava2  s  .c o  m*/
        ClassLoaderInterface classLoaderInterface = null;
        ActionContext ctx = ActionContext.getContext();
        if (ctx != null)
            classLoaderInterface = (ClassLoaderInterface) ctx.get(ClassLoaderInterface.CLASS_LOADER_INTERFACE);
        return (ClassLoaderInterface) ObjectUtils.defaultIfNull(classLoaderInterface,
                new ClassLoaderInterfaceDelegate(getClassLoader()));
    }
}

From source file:org.carrot2.util.attribute.AttributeInfo.java

public AttributeInfo(String key, String className, String fieldName, String javaDoc, String label, String title,
        String description, String group, AttributeLevel level, AttributeInfo inheritFrom) {
    this.fieldName = fieldName;
    this.className = className;

    this.key = key;
    if (inheritFrom == null) {
        this.javaDoc = javaDoc;
        this.label = label;
        this.title = title;
        this.description = description;

        this.group = group;
        this.level = level;
    } else {/*from www  .j av  a2 s  .c o  m*/
        this.javaDoc = StringUtils.defaultString(javaDoc, inheritFrom.javaDoc);
        this.label = StringUtils.defaultString(label, inheritFrom.label);
        this.title = StringUtils.defaultString(title, inheritFrom.title);
        this.description = StringUtils.defaultString(description, inheritFrom.description);

        this.group = StringUtils.defaultString(group, inheritFrom.group);
        this.level = (AttributeLevel) ObjectUtils.defaultIfNull(level, inheritFrom.level);
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpoint.java

private CswRecordCollection queryCsw(GetRecordsType request) throws CswException {
    if (LOGGER.isDebugEnabled()) {
        try {/*from  w ww  . ja  va2 s.  c  o m*/
            Writer writer = new StringWriter();
            try {
                Marshaller marshaller = CswQueryFactory.getJaxBContext().createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

                JAXBElement<GetRecordsType> jaxbElement = new ObjectFactory().createGetRecords(request);
                marshaller.marshal(jaxbElement, writer);
            } catch (JAXBException e) {
                LOGGER.debug("Unable to marshall {} to XML.  Exception {}", GetRecordsType.class, e);
            }
            LOGGER.debug(writer.toString());
        } catch (Exception e) {
            LOGGER.debug("Unable to create debug message for getRecordsType: {}", e);
        }
    }

    QueryType query = (QueryType) request.getAbstractQuery().getValue();

    CswRecordCollection response = new CswRecordCollection();
    response.setRequest(request);
    response.setOutputSchema(request.getOutputSchema());
    response.setMimeType(request.getOutputFormat());
    response.setElementName(query.getElementName());
    response.setElementSetType(
            (query.getElementSetName() != null) ? query.getElementSetName().getValue() : null);
    response.setResultType((ResultType) ObjectUtils.defaultIfNull(request.getResultType(), ResultType.HITS));

    if (ResultType.HITS.equals(request.getResultType()) || ResultType.RESULTS.equals(request.getResultType())) {
        QueryRequest queryRequest = queryFactory.getQuery(request);
        try {
            queryRequest = queryFactory.updateQueryRequestTags(queryRequest, request.getOutputSchema());
            LOGGER.debug("Attempting to execute query: {}", response.getRequest());
            QueryResponse queryResponse = framework.query(queryRequest);
            response.setSourceResponse(queryResponse);
        } catch (UnsupportedQueryException e) {
            LOGGER.warn("Unable to query", e);
            throw new CswException(e);
        } catch (SourceUnavailableException e) {
            LOGGER.warn("Unable to query", e);
            throw new CswException(e);
        } catch (FederationException e) {
            LOGGER.warn("Unable to query", e);
            throw new CswException(e);
        }
    }
    return response;
}

From source file:org.drools.planner.config.localsearch.decider.acceptor.AcceptorConfig.java

public Acceptor buildAcceptor(EnvironmentMode environmentMode, ScoreDefinition scoreDefinition) {
    List<Acceptor> acceptorList = new ArrayList<Acceptor>();
    if (acceptorClassList != null) {
        for (Class<? extends Acceptor> acceptorClass : acceptorClassList) {
            try {
                acceptorList.add(acceptorClass.newInstance());
            } catch (InstantiationException e) {
                throw new IllegalArgumentException("acceptorClass (" + acceptorClass.getName()
                        + ") does not have a public no-arg constructor", e);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException("acceptorClass (" + acceptorClass.getName()
                        + ") does not have a public no-arg constructor", e);
            }/*w  ww  .  j  a  va  2  s  .  co m*/
        }
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.MOVE_TABU)) || moveTabuSize != null
            || partialMoveTabuSize != null) {
        MoveTabuAcceptor moveTabuAcceptor = new MoveTabuAcceptor();
        moveTabuAcceptor.setUseUndoMoveAsTabuMove(false);
        if (moveTabuSize != null) {
            moveTabuAcceptor.setTabuSize(moveTabuSize);
        }
        if (partialMoveTabuSize != null) {
            moveTabuAcceptor.setPartialTabuSize(partialMoveTabuSize);
        }
        if (environmentMode == EnvironmentMode.TRACE) {
            moveTabuAcceptor.setAssertTabuHashCodeCorrectness(true);
        }
        acceptorList.add(moveTabuAcceptor);
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.UNDO_MOVE_TABU))
            || undoMoveTabuSize != null || partialUndoMoveTabuSize != null) {
        MoveTabuAcceptor undoMoveTabuAcceptor = new MoveTabuAcceptor();
        undoMoveTabuAcceptor.setUseUndoMoveAsTabuMove(true);
        if (undoMoveTabuSize != null) {
            undoMoveTabuAcceptor.setTabuSize(undoMoveTabuSize);
        }
        if (partialUndoMoveTabuSize != null) {
            undoMoveTabuAcceptor.setPartialTabuSize(partialUndoMoveTabuSize);
        }
        if (environmentMode == EnvironmentMode.TRACE) {
            undoMoveTabuAcceptor.setAssertTabuHashCodeCorrectness(true);
        }
        acceptorList.add(undoMoveTabuAcceptor);
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.PLANNING_ENTITY_TABU))
            || planningEntityTabuSize != null || partialPlanningEntityTabuSize != null) {
        PlanningEntityTabuAcceptor planningEntityTabuAcceptor = new PlanningEntityTabuAcceptor();
        if (planningEntityTabuSize != null) {
            planningEntityTabuAcceptor.setTabuSize(planningEntityTabuSize);
        }
        if (partialPlanningEntityTabuSize != null) {
            planningEntityTabuAcceptor.setPartialTabuSize(partialPlanningEntityTabuSize);
        }
        if (environmentMode == EnvironmentMode.TRACE) {
            planningEntityTabuAcceptor.setAssertTabuHashCodeCorrectness(true);
        }
        acceptorList.add(planningEntityTabuAcceptor);
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.PLANNING_VALUE_TABU))
            || planningValueTabuSize != null || partialPlanningValueTabuSize != null) {
        PlanningValueTabuAcceptor planningValueTabuAcceptor = new PlanningValueTabuAcceptor();
        if (planningValueTabuSize != null) {
            planningValueTabuAcceptor.setTabuSize(planningValueTabuSize);
        }
        if (partialPlanningValueTabuSize != null) {
            planningValueTabuAcceptor.setPartialTabuSize(partialPlanningValueTabuSize);
        }
        if (environmentMode == EnvironmentMode.TRACE) {
            planningValueTabuAcceptor.setAssertTabuHashCodeCorrectness(true);
        }
        acceptorList.add(planningValueTabuAcceptor);
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.SOLUTION_TABU))
            || solutionTabuSize != null || partialSolutionTabuSize != null) {
        SolutionTabuAcceptor solutionTabuAcceptor = new SolutionTabuAcceptor();
        if (solutionTabuSize != null) {
            solutionTabuAcceptor.setTabuSize(solutionTabuSize);
        }
        if (partialSolutionTabuSize != null) {
            solutionTabuAcceptor.setPartialTabuSize(partialSolutionTabuSize);
        }
        if (environmentMode == EnvironmentMode.TRACE) {
            solutionTabuAcceptor.setAssertTabuHashCodeCorrectness(true);
        }
        acceptorList.add(solutionTabuAcceptor);
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.SIMULATED_ANNEALING))
            || simulatedAnnealingStartingTemperature != null) {
        SimulatedAnnealingAcceptor simulatedAnnealingAcceptor = new SimulatedAnnealingAcceptor();
        simulatedAnnealingAcceptor
                .setStartingTemperature(scoreDefinition.parseScore(simulatedAnnealingStartingTemperature));
        acceptorList.add(simulatedAnnealingAcceptor);
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.GREAT_DELUGE))
            || greatDelugeWaterLevelUpperBoundRate != null || greatDelugeWaterRisingRate != null) {
        double waterLevelUpperBoundRate = (Double) ObjectUtils
                .defaultIfNull(greatDelugeWaterLevelUpperBoundRate, 1.20);
        double waterRisingRate = (Double) ObjectUtils.defaultIfNull(greatDelugeWaterRisingRate, 0.0000001);
        acceptorList.add(new GreatDelugeAcceptor(waterLevelUpperBoundRate, waterRisingRate));
    }
    if ((acceptorTypeList != null && acceptorTypeList.contains(AcceptorType.LATE_ACCEPTANCE))) {
        // TODO implement LATE_ACCEPTANCE
        throw new UnsupportedOperationException("LATE_ACCEPTANCE not yet supported.");
    }
    if (acceptorList.size() == 1) {
        return acceptorList.get(0);
    } else if (acceptorList.size() > 1) {
        CompositeAcceptor compositeAcceptor = new CompositeAcceptor();
        compositeAcceptor.setAcceptorList(acceptorList);
        return compositeAcceptor;
    } else {
        SolutionTabuAcceptor solutionTabuAcceptor = new SolutionTabuAcceptor();
        solutionTabuAcceptor.setTabuSize(1500); // TODO number pulled out of thin air
        if (environmentMode == EnvironmentMode.TRACE) {
            solutionTabuAcceptor.setAssertTabuHashCodeCorrectness(true);
        }
        return solutionTabuAcceptor;
    }
}

From source file:org.eclipse.wb.internal.core.model.description.ParameterDescription.java

/**
 * Joins this {@link ParameterDescription} with given one.
 *///from  w w w.  j  a v a 2s  . co  m
public void join(ParameterDescription description) {
    m_name = (String) ObjectUtils.defaultIfNull(m_name, description.m_name);
    // editor/converter
    if (description.m_editor != null) {
        m_converter = description.m_converter;
        m_editor = description.m_editor;
    }
    // tags
    putTags(description.getTags());
    // other
    m_property = description.m_property;
    m_defaultSource = description.m_defaultSource;
    {
        m_parent = description.m_parent;
        m_child = description.m_child;
    }
    {
        m_parent2 = description.m_parent2;
        m_child2 = description.m_child2;
    }
}

From source file:org.glite.security.voms.admin.integration.orgdb.DefaultSyncStrategy.java

private void synchronizeIdAndEmailAddress(VOMSUser u, VOMSOrgDBPerson orgDBPerson) {

    Validate.notNull(u, "User cannot be null");
    Validate.notNull(orgDBPerson, "OrgDBPerson cannot be null");

    Long oldOrgDbId = u.getOrgDbId();

    if (oldOrgDbId == null || !oldOrgDbId.equals(orgDBPerson.getId())) {
        log.info("Linking VOMS user {} to OrgDB membership id: {}", u.toString(), orgDBPerson.getId());

        u.setOrgDbId(orgDBPerson.getId());
    }//from ww w  . ja  v  a  2 s  . c o  m

    String orgdbEmailAdddress = (String) ObjectUtils.defaultIfNull(orgDBPerson.getPhysicalEmail(),
            orgDBPerson.getEmail());

    if (orgdbEmailAdddress == null) {
        log.warn("null email address for OrgDBPerson %s. Will not sync VOMS email address.",
                orgDBPerson.toString());
        return;
    }

    u.setEmailAddress(orgdbEmailAdddress.toLowerCase());
}

From source file:org.jboss.tools.openshift.internal.ui.OpenShiftImages.java

/**
 * Get an image to represent an application image (e.g. template details)
 * @param name//from  ww w .java 2  s  . c om
 * @return the image
 */
public static final Image getAppImage(String name) {
    if (name.startsWith(ICON_NAME_PREFIX)) {
        name = name.substring(ICON_NAME_PREFIX.length());
    }
    final String imagePath = NLS.bind("apps/{0}.png", name);
    if (!descriptorsByName.containsKey(name)) {
        descriptorsByName.put(name, repo.create(imagePath));
    }
    return (Image) ObjectUtils.defaultIfNull(repo.getImage(imagePath), BLOCKS_IMG);
}

From source file:org.kuali.rice.krad.maintenance.MaintenanceUtils.java

/**
 * Determines if there is another maintenance document that has a lock on the same key as the given document, and
 * therefore will block the maintenance document from being submitted
 *
 * @param document - maintenance document instance to check locking for
 * @param throwExceptionIfLocked - indicates if an exception should be thrown in the case of found locking document,
 * if false only an error will be added/*from   www. j av a 2  s  .  c  om*/
 */
public static void checkForLockingDocument(MaintenanceDocument document, final boolean throwExceptionIfLocked) {
    LOG.info("starting checkForLockingDocument (by MaintenanceDocument)");

    // get the docHeaderId of the blocking docs, if any are locked and blocking
    //String blockingDocId = getMaintenanceDocumentService().getLockingDocumentId(document);
    final String blockingDocId = document.getNewMaintainableObject().getLockingDocumentId();

    Maintainable maintainable = (Maintainable) ObjectUtils.defaultIfNull(document.getOldMaintainableObject(),
            document.getNewMaintainableObject());
    checkDocumentBlockingDocumentId(blockingDocId, throwExceptionIfLocked);
}