Example usage for java.util Objects nonNull

List of usage examples for java.util Objects nonNull

Introduction

In this page you can find the example usage for java.util Objects nonNull.

Prototype

public static boolean nonNull(Object obj) 

Source Link

Document

Returns true if the provided reference is non- null otherwise returns false .

Usage

From source file:com.fantasy.Application.java

public static void main(String[] args) throws ParseException, Exception {
    ConfigurableApplicationContext context;
    context = SpringApplication.run(AggregatorConfig.class);

    SpaceDelimitedCommandLineParser<YearFlag, YearContainer> argParser;
    argParser = context.getBean(SpaceDelimitedCommandLineParser.class);
    YearContainer container = argParser.parseFor(YearFlag.class, args);

    String packageName = container.getPackageName();
    String className = container.getClassName();
    int year = container.getYear();

    List<Class> taskRunners = findTypes(packageName);
    Class runner = null;/*  w w  w  .  ja  v a 2 s  .c  o  m*/

    if (Objects.nonNull(taskRunners)) {
        for (Class cl : taskRunners) {
            if (cl.getSimpleName().equalsIgnoreCase(className)) {
                runner = cl;
                break;
            }
        }

        if (Objects.nonNull(runner)) {
            Task task = (Task) context.getBean(runner);

            if (Objects.nonNull(task)) {
                if (task instanceof ContextUser) {
                    ((ContextUser) task).haveContext(context);
                }
                if (task instanceof YearlyTask) {
                    ((YearlyTask) task).setYear(year);
                }

                try {
                    task.run();
                } catch (InterruptedException ex) {
                    Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    if (Objects.nonNull(context)) {
                        context.close();
                    }
                }
            }
        }
    }
}

From source file:de.bruse.c2x.cli.Main.java

public static void main(String[] args) {
    CommandLineParser parser = new GnuParser();
    Options options = new Options();

    Option input = new Option("i", INPUT, HAS_ARGS, "CityGML file to be converted.");
    input.setArgs(ONE);// w w  w.j  a v a2s.  c  o m
    input.setArgName(INPUT);
    input.setRequired(Boolean.TRUE);
    options.addOption(input);

    Option levelOfDetail = new Option("l", LEVEL_OF_DETAIL, HAS_ARGS,
            "Level of detail to be converted. Possible values are LOD1 and LOD2.");
    levelOfDetail.setArgs(ONE);
    levelOfDetail.setArgName(LEVEL_OF_DETAIL);
    levelOfDetail.setRequired(Boolean.TRUE);
    options.addOption(levelOfDetail);

    Option geometryType = new Option("t", GEOMETRY_TYPE, HAS_ARGS,
            "Geometry type to be converted. Possible values are SOLID and MULTI_SURFACE.");
    geometryType.setArgs(ONE);
    geometryType.setArgName(GEOMETRY_TYPE);
    geometryType.setRequired(Boolean.TRUE);
    options.addOption(geometryType);

    Option output = new Option("o", OUTPUT, HAS_ARGS, "File path of the output file.");
    output.setArgs(ONE);
    output.setArgName(OUTPUT);
    output.setRequired(Boolean.FALSE);
    options.addOption(output);

    Option targetFormat = new Option("f", FORMAT, HAS_ARGS,
            "Format of the output file. Possible values are X3D and COLLADA.");
    targetFormat.setArgs(ONE);
    targetFormat.setArgName(FORMAT);
    targetFormat.setRequired(Boolean.TRUE);
    options.addOption(targetFormat);

    Option split = new Option("s", SPLIT, NO_ARGS, "Generate one scene node for each building (X3D only).");
    split.setArgName(SPLIT);
    split.setRequired(Boolean.FALSE);
    options.addOption(split);

    Option validate = new Option("v", VALIDATE, NO_ARGS, "Validate the CityGML file.");
    validate.setArgName(VALIDATE);
    validate.setRequired(Boolean.FALSE);
    options.addOption(validate);

    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption(INPUT) && line.hasOption(LEVEL_OF_DETAIL) && line.hasOption(GEOMETRY_TYPE)
                && line.hasOption(FORMAT)) {
            String inputValue = line.getOptionValue(INPUT);
            String levelOfDetailValue = line.getOptionValue(LEVEL_OF_DETAIL);
            String geometryTypeValue = line.getOptionValue(GEOMETRY_TYPE);
            String targetFormatValue = line.getOptionValue(FORMAT);
            String outputValue = line.getOptionValue(OUTPUT);
            LevelOfDetail lod = LevelOfDetail.valueOf(levelOfDetailValue);
            GeometryType type = GeometryType.valueOf(geometryTypeValue);
            if (Objects.isNull(lod) || Objects.isNull(type)
                    || (!targetFormatValue.equals(X3D) && !targetFormatValue.equals(COLLADA))) {
                printHelp(options);
            } else {
                if (line.hasOption(VALIDATE)) {
                    triggerValidation(inputValue);
                }
                if (targetFormatValue.equals(X3D)) {
                    boolean splitValue = false;
                    if (line.hasOption(SPLIT)) {
                        splitValue = true;
                    }
                    if (Objects.isNull(outputValue) || outputValue.isEmpty()) {
                        outputValue = inputValue + X3D_FILE_EXT;
                    }
                    triggerX3DConversion(inputValue, lod, type, outputValue, splitValue);
                } else if (targetFormatValue.equals(COLLADA)) {
                    if (Objects.isNull(outputValue) || outputValue.isEmpty()) {
                        outputValue = inputValue + COLLADA_FILE_EXT;
                    }
                    triggerColladaConversion(inputValue, lod, type, outputValue);
                }
                System.out.println("Conversion succeeded.");
            }
        } else {
            printHelp(options);
        }
    } catch (ParseException | IllegalArgumentException e) {
        printHelp(options);
    } catch (ValidationException e) {
        System.out.println("Input file is invalid. Operation canceled.\n" + e.getMessage());
    } catch (ConversionException e) {
        String message = "Failed to convert CityGML.";
        if (Objects.nonNull(e.getMessage())) {
            message += " " + e.getMessage();
        }
        System.out.println(message);
    } catch (IOException e) {
        System.out.println("Failed to read from file '" + input + "'.");
    }
}

From source file:com.qpark.eip.core.model.analysis.operation.GetFlowOperation.java

/**
 * Translate the pattern do SQL <i>like</i>.
 *
 * @param namePattern/*from w  w  w.  j  av a 2s.  co m*/
 *            the given name pattern.
 * @return the translated pattern.
 */
private static Optional<String> translateNamePattern(final String namePattern) {
    Optional<String> value = Optional.empty();
    if (Objects.nonNull(namePattern)) {
        String s = namePattern.replace('*', '%');
        if (!s.endsWith("%")) {
            s = String.format("%s%s", s, "%");
        }
        if (!s.startsWith("%")) {
            s = String.format("%s%s", "%", s);
        }
        value = Optional.of(s);
    }
    return value;
}

From source file:multimodule.App.java

/**
 * Returns concatination of two strings into one divided by special symbol.
 *
 * @deprecated As of version 1.0, use {@link org.apache.commons.lang.StringUtils#join(Object[], char)}
 *
 * @param part1/*from   w ww .  j av a 2s . c o m*/
 *          part 1 to concat.
 * @param part2
 *          part 2 to concat.
 * @param divider
 *          divider of part1 and part2.
 * @return concatination of two strings into one.
 *
 * @throws NullPointerException
 *       if one of the part has null value.
 */
public static String concat(String part1, String part2, char divider) throws NullPointerException {
    Objects.nonNull(part1);
    Objects.nonNull(part2);

    return part1 + divider + part2;
}

From source file:de.unigoettingen.sub.search.opac.ConfigOpac.java

private static XMLConfiguration getConfig() throws FileNotFoundException {
    if (Objects.nonNull(config)) {
        return config;
    }//from w w  w.java2 s  .c o m

    KitodoConfigFile opacConfiguration = KitodoConfigFile.OPAC_CONFIGURATION;

    if (!opacConfiguration.exists()) {
        throw new FileNotFoundException("File not found: " + opacConfiguration.getAbsolutePath());
    }
    try {
        config = new XMLConfiguration(opacConfiguration.getFile());
    } catch (ConfigurationException e) {
        logger.error(e.getMessage(), e);
        config = new XMLConfiguration();
    }
    config.setListDelimiter('&');
    config.setReloadingStrategy(new FileChangedReloadingStrategy());
    return config;
}

From source file:org.eclipse.winery.yaml.common.Utils.java

public static Path unzipFile(InputStream in) {
    Path dir = Utils.getTmpDir(Paths.get("zip"));
    FileUtils.forceDelete(dir);/*from  ww  w . j  a  v a2  s .  c om*/
    try (ZipInputStream inputStream = new ZipInputStream(in)) {
        ZipEntry entry;
        while (Objects.nonNull(entry = inputStream.getNextEntry())) {
            if (!entry.isDirectory()) {
                Path targetPath = dir.resolve(entry.getName());
                Files.createDirectories(targetPath.getParent());
                Files.copy(inputStream, targetPath);
                logger.debug("Write tmp file: {}", targetPath.toString());
            }
        }
    } catch (Exception e) {
        logger.error("Create zip tmp file error: ", e);
    }
    return dir;
}

From source file:com.mac.holdempoker.game.impl.util.GameManager.java

public void addGame(Game game) {
    this.games.add(game);
    GameSetting settings = game.getGameSetting();
    if (Objects.nonNull(settings)) {
        gameRepo.create(settings);// w  w  w  .  j av  a2  s. com
    }
}

From source file:com.mac.holdempoker.app.impl.SimpleHandAggregator.java

@Override
public long scoreHand(Hand hand) throws Exception {
    if (Objects.nonNull(hand)) {
        AbstractHand ah = hand.getHand();
        HandType ht = ah.getHandType();//  ww  w.  java  2 s.  c o  m
        Card[] cards = ah.getHand();
        Arrays.sort(cards, this);
        switch (ht) {
        case ROYAL_FLUSH: {
            return ht.getInterValue();
        }
        case STRAIGHT_FLUSH: {
            return ht.getInterValue() + scoreHighHand(cards);
        }
        case FOUR_OF_A_KIND: {
            return ht.getInterValue() + scoreTripsBoatQuads(cards);
        }
        case FULL_HOUSE: {
            return ht.getInterValue() + scoreTripsBoatQuads(cards);
        }
        case FLUSH: {
            return ht.getInterValue() + scoreHighHand(cards);
        }
        case STRAIGHT: {
            return ht.getInterValue() + scoreHighHand(cards);
        }
        case THREE_OF_A_KIND: {
            return ht.getInterValue() + scoreTripsBoatQuads(cards);
        }
        case TWO_PAIR: {
            return ht.getInterValue() + scoreTwoPair(cards);
        }
        case PAIR: {
            return ht.getInterValue() + scorePair(cards);
        }
        case HIGH: {
            return scoreHighHand(cards);
        }
        default: {
            return 0L;
        }
        }
    }
    return 0;
}

From source file:org.kisoonlineapp.uc.view.KostenView.java

public String formatKosten(Kosten kosten) {
    final StringBuilder sb = new StringBuilder();

    BigDecimal kostenWert = null;
    String kostenHinweisText = null;
    if (kosten != null) {
        if (kosten.getBetragEuro() != null) {
            kostenWert = kosten.getBetragEuro();
        }/*from  w w w  .  j  a v  a2  s  .  c  o m*/
        if (StringUtils.isNotBlank(kosten.getHinweis())) {
            kostenHinweisText = kosten.getHinweis();
        }
    }
    //---
    if (Objects.nonNull(kostenWert) && Objects.nonNull(kostenHinweisText)) {
        sb.append(messageResolver.retrieveMessageFor("kostenKostenHinweis", kostenWert, kostenHinweisText));
    } else if (Objects.nonNull(kostenWert) && Objects.isNull(kostenHinweisText)) {
        sb.append(messageResolver.retrieveMessageFor("kostenKosten", kostenWert));
    } else if (Objects.isNull(kostenWert) && Objects.nonNull(kostenHinweisText)) {
        sb.append(messageResolver.retrieveMessageFor("kostenKeineKostenHinweis", kostenHinweisText));
    } else {
        sb.append(messageResolver.retrieveMessageFor("kostenKeineAngaben", kostenHinweisText));
    }

    return sb.toString();
}

From source file:com.fantasy.stataggregator.workers.TeamRetrieverTask.java

@Override
public void run() throws IllegalAccessException, ParseException, NoSuchFieldException, JSONException {
    JSONObject teams = makeRequest();// www  .j  ava 2s .  c  o m

    if (Objects.nonNull(teams)) {
        JSONArray jsonArr = teams.getJSONArray(TEAM_ARRAY_KEY);
        List<Team> tms = getEntities(jsonArr);

        if (!tms.isEmpty()) {
            tr = ctx.getBean(TeamRepository.class);
            tms.stream().forEach((team) -> {
                tr.create(team);
            });
        }
    }
}