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:net.jforum.services.ModerationService.java

/**
 * Lock or unlock a set of topics//from w  w w.ja  v  a  2 s.c  om
 * @param topicIds the id of the topics to lock or unlock
 * @param moderationLog
 */
public void lockUnlock(int[] topicIds, ModerationLog moderationLog) {
    if (ArrayUtils.isEmpty(topicIds)) {
        return;
    }

    for (int topicId : topicIds) {
        Topic topic = this.topicRepository.get(topicId);

        if (topic.isLocked()) {
            topic.unlock();
        } else {
            topic.lock();
        }
    }

    this.moderationLogService.registerLockedTopics(moderationLog, topicIds);
}

From source file:com.kcs.action.GenerateXmlDfFxuAction.java

public String generateXml() throws Exception {
    logger.debug("generateXml : begin...");
    logger.debug("dataSetDate : " + tmpDataSetDate);

    byte[] xmlBytes = generateXmlService.generateXmlFxu(tmpDataSetDate, tmpTcb);

    if (ArrayUtils.isEmpty(xmlBytes)) {
        throw new RuntimeException("Can't generate xml.");
    } else {//from ww  w .  ja  v  a 2 s  . com
        inputStream = new ByteArrayInputStream(xmlBytes);
    }
    setCookieDownloadStatus("complete");
    fileName = Utility.createXmlFileName("DF_FXU", tmpDataSetDate);

    logger.debug("generateXml : end...");
    return XML;
}

From source file:com.adobe.acs.commons.util.InfoWriter.java

/**
 * Creates a message with optional var injection.
 * Message format: "A String with any number of {} placeholders that will have the vars injected in order"
 * @param message the message string with the injection placeholders ({})
 * @param vars the vars to inject into the the message template; some type conversion will occur for common data
 *             types/*from  ww w  . jav a2  s. c  o m*/
 */
public void message(String message, final Object... vars) {
    if (ArrayUtils.isEmpty(vars)) {
        pw.println(message);
    } else {
        for (final Object var : vars) {
            try {
                message = StringUtils.replaceOnce(message, "{}", TypeUtil.toString(var));
            } catch (Exception e) {
                log.error("Could not derive a valid String representation for {} using TypeUtil.toString(..)",
                        var, e);

                message = StringUtils.replaceOnce(message, "{}", "???");
            }
        }

        pw.println(message);
    }
}

From source file:com.adobe.acs.commons.workflow.process.impl.ParameterizedActivatePageProcess.java

@Override
protected ReplicationOptions prepareOptions(ReplicationOptions opts) {

    if (opts == null) {
        opts = new ReplicationOptions();
    }//from w ww.  j a  va 2 s .  co  m
    opts.setFilter(new AgentFilter() {

        @Override
        public boolean isIncluded(Agent agent) {

            if (ArrayUtils.isEmpty(agentId.get())) {
                return false;
            }
            return ArrayUtils.contains(agentId.get(), agent.getId());
        }
    });
    return opts;
}

From source file:com.autonomy.aci.client.transport.impl.AbstractEncryptionCodec.java

/**
 * This method should firstly Base64 decode {@code bytes}, then decrypt it and finally inflate it.
 * @param bytes A Base64 encoded, encrypted and deflated array of bytes
 * @return The original unencrypted content as a byte array
 * @throws EncryptionCodecException if there was a problem during any of the three stages of processing
 *///from  www .j  a va2  s  .c om
public byte[] decrypt(final byte[] bytes) throws EncryptionCodecException {
    LOGGER.trace("decrypt() called...");

    if (ArrayUtils.isEmpty(bytes)) {
        throw new IllegalArgumentException("The byte array to decrypt must not be null or empty.");
    }

    // Do all the work...
    return inflateInternal(decryptInternal(decodeInternal(bytes)));
}

From source file:de.codesourcery.asm.util.ASMUtil.java

/**
 * Create an ASM <code>ClassReader</code> for a given class , searching an optional classpath.
 * // w  w  w  .  j  a va  2  s. c  o m
 * <p>If a classpath is specified, it is searched before the system class path.</p>
 * 
 * @param classToAnalyze
 * @param classPathEntries optional classpath that may contain directories or ZIP/JAR archives, may be <code>null</code>.
 * @param logger Logger used to output debug messages
 * @return
 * @throws IOException
 */
public static ClassReader createClassReader(String classToAnalyze, File[] classPathEntries, ILogger logger)
        throws IOException {
    if (!ArrayUtils.isEmpty(classPathEntries)) {
        // convert class name file-system path         
        String relPath = classToAnalyze.replace(".", File.separator);
        if (!relPath.endsWith(".class")) {
            relPath += ".class";
        }
        // look through search-path entries
        for (File parent : classPathEntries) {
            logger.logVerbose("Searching class in " + parent.getAbsolutePath());
            if (parent.isDirectory()) // path entry is a directory
            {
                final File classFile = new File(parent, relPath);
                if (!classFile.exists()) {
                    continue;
                }
                try {
                    logger.logVerbose(
                            "Loading class '" + classToAnalyze + "' from " + classFile.getAbsolutePath() + "");
                    return new ClassReader(new FileInputStream(classFile));
                } catch (IOException e) {
                    throw new IOException(
                            "Failed to load class '" + classToAnalyze + "' from " + classFile.getAbsolutePath(),
                            e);
                }
            } else if (parent.isFile()) // path entry is a (ZIP/JAR) file 
            {
                final Path archive = Paths.get(parent.getAbsolutePath());
                final FileSystem fs = FileSystems.newFileSystem(archive, null);
                final Path classFilePath = fs.getPath(relPath);

                if (Files.exists(classFilePath)) {
                    // load class from archive
                    try {
                        logger.logVerbose("Loading class '" + classToAnalyze + "' from archive "
                                + archive.toAbsolutePath());
                        InputStream in = fs.provider().newInputStream(classFilePath);
                        return new ClassReader(in);
                    } catch (IOException e) {
                        throw new IOException("Failed to load class '" + classToAnalyze + "' from "
                                + classFilePath.toAbsolutePath(), e);
                    }
                }
                continue;
            }
            throw new IOException("Invalid entry on search classpath: '" + parent.getAbsolutePath()
                    + "' is neither a directory nor JAR/ZIP archive");
        }
    }

    // fall-back to using standard classpath
    logger.logVerbose("Trying to load class " + classToAnalyze + " using system classloader.");

    try {
        return new ClassReader(classToAnalyze);
    } catch (IOException e) {
        throw new IOException("Failed to load class '" + classToAnalyze + "'", e);
    }
}

From source file:com.taobao.itest.matcher.AssertPropertiesEquals.java

/**
 * assertPropertiesEquals //ww  w .  ja  v a 2 s  .c o  m
 * Mainly used to compare two objects of the specified attribute value is equal,
 * to support complex type of attribute comparison
 * 
 * <li>Eg: Person class contains a type of property Address: 
 *          address, Address type contains a String property: street.<br>
 *     Then compare two Person objects are equal when the street can be written<br>
 *     AssertUtil.assertPropertiesEquals(person1,person2,"address.street")<br>
 *     Written about the time when the form<br>
 *     AssertUtil.assertPropertiesEquals(person1,person2,"address")<br>
 *     Can compare the address of each property is equal to
 * 
 * @param expect  Expect the object
 * @param actual  actual the object
 * @param propertyNames  Need to compare the property values,
 *           support for complex types, you can enter multiple comma-separated string, 
 *           you can also enter the array
 * 
 */
public static void assertPropertiesEquals(Object expect, Object actual, String... propertyNames) {
    Assert.assertNotNull("bean is null" + expect, expect);
    Assert.assertNotNull("bean is null" + actual, actual);
    //Assert.assertFalse("to compare the property is empty", ArrayUtils.isEmpty(propertyNames));
    Object valueExpect = null;
    Object valueActual = null;
    List<String> errorMessages = new ArrayList<String>();
    /*
     * If the attribute name is empty, then compare the two object
     * the current value of all the fields.
     * This parameter is empty,
     * the situation has in the upper control and verified directly through reflection
     */
    if (ArrayUtils.isEmpty(propertyNames)) {
        PropertyDescriptor[] props = BeanUtilsBean.getInstance().getPropertyUtils()
                .getPropertyDescriptors(expect);
        propertyNames = new String[props.length - 1];
        int j = 0;
        for (int i = 0; i < props.length; i++) {
            if (!props[i].getName().equals("class")) {
                propertyNames[j] = props[i].getName();
                j++;
            }
        }
    }
    //Cycle to compare different properties
    for (int i = 0; i < propertyNames.length; i++) {
        try {

            valueExpect = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(expect, propertyNames[i]);
            valueActual = BeanUtilsBean.getInstance().getPropertyUtils().getProperty(actual, propertyNames[i]);
            if (valueExpect == null || valueActual == null)
                Assert.assertEquals(valueExpect, valueActual);
            else if (valueExpect.getClass().getName().startsWith("java.lang") || valueExpect instanceof Date) {
                Assert.assertEquals(valueExpect, valueActual);
                /*
                 * If taken out of the object is still a complex structure, 
                 * then the recursive call, then the property name set to null, 
                 * compare the value of all the attributes of the object
                 */
            } else {
                assertPropertiesEquals(valueExpect, valueActual);
            }
        } catch (Exception e) {
            throw new RuntimeException("error property" + propertyNames[i], e.fillInStackTrace());
        } catch (AssertionError err) {
            errorMessages.add("\nexpect property" + propertyNames[i] + " value is " + valueExpect
                    + "but actual value is" + valueActual);
            if (StringUtils.isNotBlank(err.getMessage())) {
                errorMessages.add("\ncaused by" + err.getMessage());
            }
        }
    }
    if (errorMessages.size() > 0) {
        throw new ComparisonFailure(errorMessages.toString(), "", "");
    }
}

From source file:de.codesourcery.asm.rewrite.ProfilingClassTransformer.java

public static void premain(String agentArgs, Instrumentation inst) {
    // parse options
    final Map<String, String> options = parseArgs(agentArgs);

    if (StringUtils.isBlank(options.get(OPTION_PACKAGES))) {
        throw new RuntimeException(
                "Agent " + ProfilingClassTransformer.class.getName() + " requires the 'packages=....' option");
    }//from  w  w w .j av a2s .c  o  m

    final boolean debug = options.containsKey(OPTION_DEBUG);

    final String[] packages = options.get(OPTION_PACKAGES).split(",");

    if (ArrayUtils.isEmpty(packages)) {
        throw new RuntimeException("Agent " + ProfilingClassTransformer.class.getName()
                + " requires at least one pattern with the 'packages=....' option");
    }

    if (debug) {
        System.out.println(
                "ProfilingClassTransformer activated (packages: " + StringUtils.join(packages, " , ") + ")");
    }

    final IJoinpointFilter filter = new IJoinpointFilter() {

        @Override
        public boolean matches(String clazz, String methodName) {
            return true;
        }

        @Override
        public boolean matches(String clazz) {
            for (String p : packages) {
                if (clazz.contains(p)) {
                    return true;
                }
            }
            return false;
        }
    };

    final File debugOutputDir = options.containsKey(OPTION_DEBUG_WRITE_CLASSFILES)
            ? new File(options.get(OPTION_DEBUG_WRITE_CLASSFILES))
            : null;
    inst.addTransformer(new MyTransformer(filter, debug, debugOutputDir), false); // no re-transformation support
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.SlideShowTemplate.java

SlideShowTemplate(final InputStream inputStream) throws TemplateLoadException {
    try {/*ww  w .  j a  v a 2s.c o m*/
        // There should be a doughnut chart in slide 1 and a scatterplot chart in slide 2
        pptx = new XMLSlideShow(inputStream);

        final List<XSLFSlide> slides = pptx.getSlides();

        if (slides.size() != 2) {
            throw new TemplateLoadException(
                    "Template powerpoint should have two slides, doughnut chart on slide 1 and time-axis xy scatterplot chart on slide 2");
        }

        XSLFSlide slide = slides.get(0);

        doughnutChart = getChart(slide, "First slide should have a doughnut chart");

        if (ArrayUtils.isEmpty(doughnutChart.getLeft().getCTChart().getPlotArea().getDoughnutChartArray())) {
            throw new TemplateLoadException(
                    "First slide has the wrong chart type, should have a doughnut chart");
        }

        graphChart = getChart(slides.get(1), "Second slide should have a time-axis xy scatterplot chart");

        if (ArrayUtils.isEmpty(graphChart.getLeft().getCTChart().getPlotArea().getScatterChartArray())) {
            throw new TemplateLoadException(
                    "Second slide has the wrong chart type, should have a time-axis xy scatterplot chart");
        }

        // Remove the slides afterwards
        pptx.removeSlide(1);
        pptx.removeSlide(0);
    } catch (IOException e) {
        throw new TemplateLoadException("Error while loading slide show", e);
    }
}

From source file:net.shopxx.controller.shop.GoodsController.java

@RequestMapping(value = "/compare_bar", method = RequestMethod.GET)
public @ResponseBody List<Map<String, Object>> compareBar(Long[] goodsIds) {
    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
    if (ArrayUtils.isEmpty(goodsIds) || goodsIds.length > MAX_COMPARE_GOODS_COUNT) {
        return data;
    }/*from w w w.  j av a 2 s . c o m*/

    List<Goods> goodsList = goodsService.findList(goodsIds);
    for (Goods goods : goodsList) {
        Map<String, Object> item = new HashMap<String, Object>();
        item.put("id", goods.getId());
        item.put("name", goods.getName());
        item.put("price", goods.getPrice());
        item.put("marketPrice", goods.getMarketPrice());
        item.put("thumbnail", goods.getThumbnail());
        item.put("url", goods.getUrl());
        data.add(item);
    }
    return data;
}