Example usage for org.apache.commons.lang ArrayUtils isEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isEmpty.

Prototype

public static boolean isEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is empty or null.

Usage

From source file:edu.mayo.cts2.framework.webapp.rest.controller.MethodTimingAspect.java

/**
 * Execute./*  w w  w .j ava2 s.  co  m*/
 *
 * @param pjp the pjp
 * @return the object
 * @throws Throwable the throwable
 */
@Around("execution(public *"
        + " edu.mayo.cts2.framework.webapp.rest.controller.*.*(..,edu.mayo.cts2.framework.webapp.rest.command.QueryControl,..))")
public Object execute(final ProceedingJoinPoint pjp) throws Throwable {

    QueryControl queryControl = null;

    //this should never happen
    if (ArrayUtils.isEmpty(pjp.getArgs())) {
        throw new IllegalStateException("Pointcut failure!");
    }

    for (Object arg : pjp.getArgs()) {
        if (arg.getClass() == QueryControl.class) {
            queryControl = (QueryControl) arg;
            break;
        }
    }

    //this also should never happen
    if (queryControl == null) {
        throw new IllegalStateException("Pointcut failure!");
    }

    final AtomicLong threadId = new AtomicLong(-1);

    Future<Object> future = this.executorService.submit(new Callable<Object>() {

        @Override
        public Object call() {
            try {
                threadId.set(Thread.currentThread().getId());

                /*
                 * The model here is that we clear any previous timeout before we launch the job. A design flaw is that we
                 * can't tell if we are clearing a previous timeout that simply hadn't been cleaned up yet, or if we are
                 * clearing a timeout meant for this thread that happened before this thread even launched. The second scenario 
                 * seems unlikely as the minimum timeout is 1 second - hard to believe it would take more than 1 second to 
                 * launch this thread. Plus, this thread would have to launch in the exact window in between the timeout and 
                 * the future.cancel()
                 * 
                 * If the above scenario did defy all odds and happen , it shouldn't cause much harm, as the end result would
                 * be that this thread wouldn't see the cancelled flag - and would churn away for no reason, wasting some cpu
                 * cycles, but doing no other harm.
                 */

                Timeout.clearThreadFlag(threadId.get());
                return pjp.proceed();
            } catch (Throwable e) {

                if (e instanceof Error) {
                    throw (Error) e;
                }

                if (e instanceof RuntimeException) {
                    throw (RuntimeException) e;
                }

                throw new RuntimeException(e);
            }
        }
    });

    long time = queryControl.getTimelimit();

    try {
        if (time < 0) {
            return future.get();
        } else {
            return future.get(time, TimeUnit.SECONDS);
        }
    } catch (ExecutionException e) {
        throw e.getCause();
    } catch (TimeoutException e) {
        try {
            //Set the flag for the processing thread to read
            Timeout.setTimeLimitExceeded(threadId.get());

            //Schedule another future to make sure we don't cause a memory leak if the thread IDs aren't being reused (though, they should be)
            //and therefore don't get cleared up by the next run.  Give the running thread 30 seconds to see the cancelled flag before this 
            //cleanup takes place.
            this.scheduledExecutorService.schedule(new Runnable() {
                @Override
                public void run() {
                    Timeout.clearThreadFlag(threadId.get());
                }
            }, 30, TimeUnit.SECONDS);

            //Interrupt the processing thread so it has an opportunity to check the flag and stop.
            future.cancel(true);
        } catch (Exception e1) {
            // don't think this is possible, but just in case...
        }
        throw ExceptionFactory.createTimeoutException(e.getMessage());
    }
}

From source file:com.vmware.bdd.cli.config.CliProperties.java

public String[] getSupportedProtocols() {
    String[] values = properties.getStringArray(SUPPORTED_PROTOCOLS);
    return ArrayUtils.isEmpty(values) ? PspConfiguration.SSL_PROTOCOLS : values;
}

From source file:lodsve.springfox.config.SpringFoxDocket.java

private String getHost() {
    String serverUrl = serverProperties.getServerUrl();
    if (StringUtils.isBlank(serverUrl)) {
        return "localhost";
    }/* ww  w  .  j  ava 2s  . c  om*/
    String[] schemaAndHostAndPath = serverUrl.split("://");
    if (ArrayUtils.isEmpty(schemaAndHostAndPath) || 2 != ArrayUtils.getLength(schemaAndHostAndPath)) {
        return "localhost";
    }

    String[] hostAndPath = schemaAndHostAndPath[1].split("/");
    if (ArrayUtils.isEmpty(hostAndPath)) {
        return "localhost";
    }

    return hostAndPath[0];
}

From source file:com.activecq.samples.clientcontext.impl.ClientContextBuilderImpl.java

@Override
public JSONObject xssProtect(JSONObject json, String... whitelist) throws JSONException {
    final List<String> keys = IteratorUtils.toList(json.keys());
    final boolean useWhiteList = !ArrayUtils.isEmpty(whitelist);
    log.debug("Use Whitelist: " + !ArrayUtils.isEmpty(whitelist));

    for (final String key : keys) {
        log.debug("XSS Key: " + key);
        if (!useWhiteList || (useWhiteList && !ArrayUtils.contains(whitelist, key))) {
            log.debug("XSS -> " + key + XSS_SUFFIX + ": "
                    + xss.filter(ProtectionContext.PLAIN_HTML_CONTENT, json.optString(key)));
            json.put(key + XSS_SUFFIX, xss.filter(ProtectionContext.PLAIN_HTML_CONTENT, json.optString(key)));
        }/*from   w w  w  .  j a v  a2  s  . c o  m*/
    }

    log.debug("XSS JSON: " + json.toString(4));

    return json;
}

From source file:eu.europeana.api2.v2.model.json.view.RichView.java

public String getAttributionSnippet(boolean firstOnly, boolean htmlOut) {
    String rightsPage = "rel=\"xhv:license http://www.europeana.eu/schemas/edm/rights\"";
    String rightsLabel = "rightslabel";
    String aHref = "<a href=\"";
    String zHref = "\">";
    String hRefa = "</a>";
    String retval = "", landingPage, title = "", creator = "", dataProvider = "", shownAt, rights = "";
    int i, j;//  w w  w .  j a  v  a  2  s .  com

    landingPage = (!ArrayUtils.isEmpty(getEdmLandingPage()) ? getEdmLandingPage()[0]
            : (!"".equals(getGuid()) ? getGuid() : ""));

    if (!ArrayUtils.isEmpty(getTitle())) {
        j = getTitle().length;
        for (i = 0; i < j; i++) {
            title += getTitle()[i];
            if (firstOnly) {
                i = j;
            } else if (i < (j - 1)) {
                title += "; ";
            }
        }
    }

    if (!ArrayUtils.isEmpty(getDcCreator())) {
        j = getDcCreator().length;
        for (i = 0; i < j; i++) {
            creator += getDcCreator()[i];
            if (firstOnly) {
                i = j;
            } else if (i < (j - 1)) {
                creator += "; ";
            }
        }
        creator += ". ";
    }

    shownAt = !ArrayUtils.isEmpty(getEdmIsShownAt()) ? getEdmIsShownAt()[0] : "";
    if (!ArrayUtils.isEmpty(getDataProvider())) {
        j = getDataProvider().length;
        for (i = 0; i < j; i++) {
            dataProvider += getDataProvider()[i];
            if (firstOnly) {
                i = j;
            } else if (i < (j - 1)) {
                dataProvider += "; ";
            }
        }
    }

    if (!ArrayUtils.isEmpty(getRights())) {
        rights = getRights()[0];
    }

    if (htmlOut) {
        if (!"".equals(title)) {
            if (!"".equals(landingPage)) {
                retval += aHref + landingPage + zHref;
            }
            retval += title;
            if (!"".equals(landingPage)) {
                retval += hRefa;
            }
            retval += ". ";
        }
        retval += !"".equals(creator) ? creator + ". " : "";

        if (!"".equals(dataProvider)) {
            if (!"".equals(shownAt)) {
                retval += aHref + shownAt + zHref;
            }
            retval += dataProvider;
            if (!"".equals(shownAt)) {
                retval += hRefa;
            }
            retval += ". ";
        }
        if (!"".equals(rights)) {
            retval += aHref + rights + "\" " + rightsPage + ">" + rightsLabel + hRefa + ".";
        }
        return retval;
    } else {
        retval += title;
        retval += (!"".equals(title) && !"".equals(landingPage)) ? " - " : "";
        retval += landingPage;
        retval += (!"".equals(title) || !"".equals(landingPage)) ? ". " : "";
        retval += !"".equals(creator) ? creator + ". " : "";
        retval += dataProvider;
        retval += (!"".equals(dataProvider) && !"".equals(shownAt)) ? " - " : "";
        retval += shownAt;
        retval += (!"".equals(dataProvider) || !"".equals(shownAt)) ? ". " : "";
        retval += !"".equals(rights) ? rightsLabel + " - " + rights + "." : "";
        return retval;
    }
}

From source file:kina.cql.CqlRecordReader.java

/**
 * Initialized this object./*from  w  w w .  j a v  a 2s .  c o m*/
 * <p>Creates a new client and row iterator.</p>
 */
private void initialize() {
    cfName = config.getTable();

    if (!ArrayUtils.isEmpty(config.getInputColumns())) {
        columns = StringUtils.join(config.getInputColumns(), ",");
    }

    partitioner = Utils.newTypeInstance(config.getPartitionerClassName(), IPartitioner.class);

    try {
        session = createConnection();

        retrieveKeys();
    } catch (Exception e) {
        throw new IOException(e);
    }

    rowIterator = new RowIterator();
}

From source file:de.erdesignerng.visual.common.SQLComponent.java

/**
 * Display the CREATE SQL Statements for a given set of model items.
 *
 * @param aModelItems a set of model items
 *//*from w  ww.  jav a  2 s .c  o  m*/
public void displaySQLFor(ModelItem[] aModelItems) {
    logger.info("checkForValidConnection ");
    resetDisplay();

    Model theModel = ERDesignerComponent.getDefault().getModel();
    Dialect theDialect = theModel.getDialect();
    logger.info("theDialect-->{}", theDialect);
    if (theDialect != null && !ArrayUtils.isEmpty(aModelItems)) {
        StatementList theStatementList = new StatementList();
        SQLGenerator theGenerator = theDialect.createSQLGenerator();
        for (ModelItem aItem : aModelItems) {
            logger.info("ModelItem-->{}", aItem);
            if (aItem instanceof Table) {
                Table theTable = (Table) aItem;
                theStatementList.addAll(theGenerator.createAddTableStatement(theTable));
                for (Relation theRelation : theModel.getRelations().getForeignKeysFor(theTable)) {
                    theStatementList.addAll(theGenerator.createAddRelationStatement(theRelation));

                }
            }
            if (aItem instanceof View) {
                theStatementList.addAll(theGenerator.createAddViewStatement((View) aItem));
            }
            if (aItem instanceof Relation) {
                theStatementList.addAll(theGenerator.createAddRelationStatement((Relation) aItem));
            }
            if (aItem instanceof Attribute) {
                Attribute theAttribute = (Attribute) aItem;

                ModelItem theOwner = theAttribute.getOwner();
                if (theOwner instanceof Table) {
                    theStatementList.addAll(
                            theGenerator.createAddAttributeToTableStatement((Table) theOwner, theAttribute));
                }
            }
            if (aItem instanceof Index) {
                Index theIndex = (Index) aItem;
                if (theIndex.getIndexType() == IndexType.PRIMARYKEY) {
                    theStatementList
                            .addAll(theGenerator.createAddPrimaryKeyToTable(theIndex.getOwner(), theIndex));
                } else {
                    theStatementList
                            .addAll(theGenerator.createAddIndexToTableStatement(theIndex.getOwner(), theIndex));
                }
            }
            if (aItem instanceof CustomType) {
                CustomType theCustomType = (CustomType) aItem;
                theStatementList.addAll(theGenerator.createAddCustomTypeStatement(theCustomType));
            }
            if (aItem instanceof Domain) {
                Domain theDomain = (Domain) aItem;
                theStatementList.addAll(theGenerator.createAddDomainStatement(theDomain));
            }
        }

        if (theStatementList.size() > 0) {
            StringWriter theWriter = new StringWriter();
            PrintWriter thePW = new PrintWriter(theWriter);
            for (Statement theStatement : theStatementList) {
                thePW.print(theStatement.getSql());
                thePW.println(theGenerator.createScriptStatementSeparator());
            }
            thePW.flush();
            thePW.close();
            sql.setText(theWriter.toString());
        }
    } else {
        if (theDialect == null) {
            sql.setText(getResourceHelper().getText(ERDesignerBundle.PLEASEDEFINEADATABASECONNECTIONFIRST));
        }
    }
}

From source file:de.codesourcery.eve.skills.ui.spreadsheet.SpreadSheetTableModel.java

public void addRow(ITableCell... cells) {
    final TableRow r = factory.createRow(this);
    if (!ArrayUtils.isEmpty(cells)) {
        for (ITableCell c : cells) {
            r.addCell(c);//  w  ww  .ja  va  2 s . c  o m
        }
    }

    int index = rows.size();
    rows.add(r);
    fireTableStructureChanged();
    //      fireTableRowsInserted( index ,index );
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getAuthorizedStatementAmount() {
    BigDecimal total = new BigDecimal(0.0);
    Invoice[] authorizedStatementInvoices = getAuthorizedStatementInvoices();
    List<Invoice> tempList = new ArrayList<Invoice>();

    if (!ArrayUtils.isEmpty(authorizedStatementInvoices)) {
        for (int i = 0; i < authorizedStatementInvoices.length; i++) {
            total = total.add(authorizedStatementInvoices[i].getAmount());
            tempList.add(authorizedStatementInvoices[i]);
        }// ww  w . j a v a 2s. c o  m
    }
    return total;
}

From source file:edu.jhuapl.openessence.web.util.Filters.java

public List<Filter> getFilters(final Map<String, String[]> parameterValues, final OeDataSource ds,
        final String prePullArg, final int prePullInc, final String resolution, int calWeekStartDay,
        final boolean adjustDate) throws ErrorMessageException {

    final List<Filter> filters = new ArrayList<Filter>();
    for (final FilterDimension fd : ds.getFilterDimensions()) {
        final FieldType type = fd.getSqlType();

        for (final String sfx : parmSfx.keySet()) {
            final String key = fd.getId() + sfx;

            if (!reservedParameters.contains(key)) {
                final String[] values = parameterValues.get(key);

                // No values for a filter dimension is ok
                if (!ArrayUtils.isEmpty(values)) {
                    if (values.length == 1) {
                        Object argument = ControllerUtils.formatData(key, values[0], type, false).get(key);

                        final Relation rel = type == FieldType.TEXT ? Relation.LIKE : parmSfx.get(sfx);

                        try {
                            if (fd.getId().equals(prePullArg) && (rel == Relation.GTEQ)) {
                                argument = muckDate((Date) argument, prePullInc, resolution, calWeekStartDay);
                            }/* w  ww .  j a va  2 s  .  c om*/
                            // if end date, account for hours 00:00:00 to 23:59:59
                            if ((type == FieldType.DATE_TIME || type == FieldType.DATE)
                                    && (rel == Relation.LTEQ)) {
                                GregorianCalendar x = new GregorianCalendar();
                                x.setTime((Date) argument);

                                // Only perform this operation if it hasn't already been handled in a previous call.
                                // When generating a Chart, it will go to the end of the day and adjust the filter
                                // to be 23:59:59.999 (5/1/13 becomes 5/1/13-23:59:59.999).  But, when the user
                                // would click-through on a bar/slice, it would accidently perform this action again.
                                // This resulted in adding another day to the query; now becoming 5/2/13 23:59:59.998.
                                if (adjustDate) {
                                    x.add(Calendar.DATE, 1);
                                    x.add(Calendar.MILLISECOND, -1);
                                    argument = x.getTime();
                                }
                            }
                            filters.add(fd.makeFilter(rel, argument));
                        } catch (OeDataSourceException e) {
                            throw new ErrorMessageException("Could not create filter", e);
                        }
                    } else {
                        final Object[] arguments = new Object[values.length];
                        for (int i = 0; i < values.length; i++) {
                            arguments[i] = ControllerUtils.formatData(key, values[i], type, false).get(key);
                        }

                        try {
                            filters.add(fd.makeFilter(Relation.IN, arguments));
                        } catch (OeDataSourceException e) {
                            throw new ErrorMessageException("Could not create filter", e);
                        }
                    }
                }
            }
        }
    }

    return filters;
}