List of usage examples for java.util Objects nonNull
public static boolean nonNull(Object obj)
From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java
@Transactional(readOnly = false) public void create(T entity) { if (Objects.nonNull(entity)) { em.persist(entity); } }
From source file:com.fantasy.stataggregator.workers.ScheduleRetrieverTask.java
@Override public void run() { JSONObject schedule = makeRequest(); if (Objects.nonNull(schedule)) { try {/*from w w w. j a v a 2 s.c o m*/ JSONArray jsonArr = schedule.getJSONArray(SCHEDULE_ARRAY_KEY); List<GameSchedule> gs = getSchedules(jsonArr); if (!gs.isEmpty()) { setTrueGameId(gs); gsr = ctx.getBean(GameScheduleRepository.class); gs.stream().forEach((gameSched) -> { gsr.create(gameSched); }); } } catch (JSONException | IllegalArgumentException | IllegalAccessException | ParseException | NoSuchFieldException ex) { Logger.getLogger(ScheduleRetrieverTask.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.kitodo.production.forms.dataeditor.TextMetadataTableRow.java
TextMetadataTableRow(MetadataPanel panel, FieldedMetadataTableRow container, SimpleMetadataViewInterface settings, MetadataEntry value) { super(panel, container, settings); if (Objects.nonNull(value)) { this.value = value.getValue(); }//from w w w . j a v a 2s . c om }
From source file:org.openecomp.sdc.heat.datatypes.DefinedHeatParameterTypes.java
/** * Is value is from given type boolean.//from w w w .j a va 2 s.com * * @param value the value * @param parameterType the parameter type * @return the boolean */ public static boolean isValueIsFromGivenType(Object value, String parameterType) { DefinedHeatParameterTypes definedType = findByHeatResource(parameterType); if (Objects.nonNull(definedType)) { switch (definedType) { case NUMBER: return NumberUtils.isNumber(String.valueOf(value)); case BOOLEAN: return HeatBoolean.isValueBoolean(value); case COMMA_DELIMITED_LIST: String valAsString = String.valueOf(value); return valAsString.split(",") instanceof String[]; case JSON: return (value instanceof Map) || (value instanceof List); case STRING: //return value instanceof String; return true; default: // return false; } } return false; }
From source file:org.kitodo.sruimport.ResponseHandler.java
/** * Create and return SearchResult for given HttpResponse. * @param response HttpResponse for which a SearchResult is created * @return SearchResult created from given HttpResponse *///from w w w . j ava 2 s .com static SearchResult getSearchResult(HttpResponse response) { SearchResult result = new SearchResult(); Document resultDocument = transformResponseToDocument(response); if (Objects.nonNull(resultDocument)) { result.setHits(extractHits(resultDocument)); result.setNumberOfRecords(extractNumberOfRecords(resultDocument)); } return result; }
From source file:com.mac.halendpoint.endpoints.ProtocolRouter.java
public Protocol router(Protocol protocol) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException { log.info("incoming protocol: " + protocol); if (Objects.nonNull(protocol)) { Method[] methods = this.getClass().getDeclaredMethods(); log.info("protocol NOT null"); for (Method method : methods) { if (!method.getName().equals("router")) { log.info("current method: " + method.getName()); method.setAccessible(true); ProtocolMapping protoMapping = method.getAnnotation(ProtocolMapping.class); log.info("ProtocolMapping: " + protoMapping); if (Objects.nonNull(protoMapping)) { log.info("ProtocolMapping not null"); if (protoMapping.routeTo().equalsIgnoreCase(protocol.getRoutedTo())) { log.info("routing to: " + protoMapping.routeTo()); int numParams = protoMapping.numParams(); String[] parameters = protocol.getParameters(); if (Objects.nonNull(parameters) && parameters.length == numParams) { log.info("parameter lengths match"); Object response = method.invoke(this, (Object[]) parameters); log.info("response after invocation"); protocol.setRespondTo(protoMapping.respondTo()); if (!(response instanceof String)) { protocol.setResponse(JsonConverter.toJsonString(response)); } else { protocol.setResponse((String) response); }/*from w ww . j a v a2 s . co m*/ protocol.setIsModified(true); log.info(response.toString()); log.info("final protocol: " + protocol); log.info("final protocol: " + protocol.getRespondTo()); log.info("final protocol: " + protocol.getResponse()); log.info("final protocol: " + protocol.getRoutedTo()); log.info("final protocol: " + Arrays.toString(protocol.getParameters())); } } } method.setAccessible(false); } } return protocol; } return new FailedProtocol(); }
From source file:com.fantasy.stataggregator.workers.PlayerRetrieverTask.java
@Override public void run() throws IllegalAccessException, ParseException, NoSuchFieldException, JSONException { JSONObject players = makeRequest();//from ww w . j av a 2 s . c o m if (Objects.nonNull(players)) { JSONArray jsonArr = players.getJSONArray(PLAYER_ARRAY_KEY); List<Player> plyrs = getEntities(jsonArr); if (!plyrs.isEmpty()) { pr = ctx.getBean(PlayerRepository.class); plyrs.stream().forEach((player) -> { pr.create(player); }); } } }
From source file:com.fantasy.stataggregator.entities.dao.AbstractRepository.java
public T find(Object id) { T entity = null; if (Objects.nonNull(id)) { entity = em.find(entityClass, id); } return entity; }
From source file:com.mac.holdempoker.app.hands.HandEvaluator.java
public AbstractHand evaluateHand(Player p, Board b) throws IllegalArgumentException, IllegalAccessException, Exception { Card[] cards = ArrayUtils.addAll(p.getHoleCards(), b.getBoard()); Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true);/* ww w. j a v a 2s. c o m*/ AbstractHand ah = (AbstractHand) field.get(this); ah.haveCards(cards); Card[] hand = ah.getHand(); if (Objects.nonNull(hand)) { return ah; } field.setAccessible(false); } throw new Exception("Invalid hand"); }
From source file:com.github.yongchristophertang.engine.java.handler.JsonTransformer.java
/** * Parse the result into a sub part json via evaluation of expression. And create another {@link com.github * .yongchristophertang.engine.web.ResultActions} instance which incorporate this json as response for further * processing.// w ww . j a va2s . co m * * @param expression the JSON path expression */ public JsonTransformer parse(String expression) { Objects.nonNull(expression); return new JsonTransformer(JsonPath.compile(expression).read(context).toString()); }