List of usage examples for java.util Objects nonNull
public static boolean nonNull(Object obj)
From source file:org.apache.streams.riak.binary.RiakBinaryPersistWriter.java
@Override public void write(StreamsDatum entry) { Objects.nonNull(client); String id = null;//from ww w . ja va2 s. c om String document; String bucket; String bucketType; String contentType; String charset; if (StringUtils.isNotBlank(entry.getId())) { id = entry.getId(); } if (entry.getDocument() instanceof String) { document = (String) entry.getDocument(); } else { try { document = MAPPER.writeValueAsString(entry.getDocument()); } catch (Exception e) { LOGGER.warn("Exception", e); return; } } if (entry.getMetadata() != null && entry.getMetadata().containsKey("bucket") && entry.getMetadata().get("bucket") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("bucket"))) { bucket = (String) entry.getMetadata().get("bucket"); } else { bucket = configuration.getDefaultBucket(); } if (entry.getMetadata() != null && entry.getMetadata().containsKey("bucketType") && entry.getMetadata().get("bucketType") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("bucketType"))) { bucketType = (String) entry.getMetadata().get("bucketType"); } else { bucketType = configuration.getDefaultBucketType(); } if (entry.getMetadata() != null && entry.getMetadata().containsKey("charset") && entry.getMetadata().get("charset") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("charset"))) { charset = (String) entry.getMetadata().get("charset"); } else { charset = configuration.getDefaultCharset(); } if (entry.getMetadata() != null && entry.getMetadata().containsKey("contentType") && entry.getMetadata().get("contentType") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("contentType"))) { contentType = (String) entry.getMetadata().get("contentType"); } else { contentType = configuration.getDefaultContentType(); } try { RiakObject riakObject = new RiakObject(); riakObject.setContentType(contentType); riakObject.setCharset(charset); riakObject.setValue(BinaryValue.create(document)); Namespace ns = new Namespace(bucketType, bucket); StoreValue.Builder storeValueBuilder = new StoreValue.Builder(riakObject); if (id != null && StringUtils.isNotBlank(id)) { Location location = new Location(ns, id); storeValueBuilder = storeValueBuilder.withLocation(location); } else { storeValueBuilder = storeValueBuilder.withNamespace(ns); } StoreValue store = storeValueBuilder.build(); StoreValue.Response storeResponse = client.client().execute(store); LOGGER.debug("storeResponse", storeResponse); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } }
From source file:com.mac.holdempoker.app.hands.Boat.java
private boolean hasThree(Card[] all) { int index = 0; for (Card c : all) { if (Objects.nonNull(c)) { index++;//from ww w . jav a2 s . c om if (index == 3) { return true; } } } return false; }
From source file:org.apache.streams.riak.http.RiakHttpPersistWriter.java
@Override public void write(StreamsDatum entry) { Objects.nonNull(client); String id = null;//w ww . j a v a 2 s .co m String document; String bucket; String bucketType; String contentType; String charset; if (StringUtils.isNotBlank(entry.getId())) { id = entry.getId(); } if (entry.getDocument() instanceof String) { document = (String) entry.getDocument(); } else { try { document = MAPPER.writeValueAsString(entry.getDocument()); } catch (Exception e) { LOGGER.warn("Exception", e); return; } } if (entry.getMetadata() != null && entry.getMetadata().containsKey("bucket") && entry.getMetadata().get("bucket") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("bucket"))) { bucket = (String) entry.getMetadata().get("bucket"); } else { bucket = configuration.getDefaultBucket(); } if (entry.getMetadata() != null && entry.getMetadata().containsKey("bucketType") && entry.getMetadata().get("bucketType") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("bucketType"))) { bucketType = (String) entry.getMetadata().get("bucketType"); } else { bucketType = configuration.getDefaultBucketType(); } if (entry.getMetadata() != null && entry.getMetadata().containsKey("charset") && entry.getMetadata().get("charset") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("charset"))) { charset = (String) entry.getMetadata().get("charset"); } else { charset = configuration.getDefaultCharset(); } if (entry.getMetadata() != null && entry.getMetadata().containsKey("contentType") && entry.getMetadata().get("contentType") instanceof String && StringUtils.isNotBlank((String) entry.getMetadata().get("contentType"))) { contentType = (String) entry.getMetadata().get("contentType"); } else { contentType = configuration.getDefaultContentType(); } URIBuilder uriBuilder = new URIBuilder(client.baseURI); if (bucket != null && StringUtils.isNotBlank(bucket)) { uriBuilder.setPath("/riak/" + bucket); } if (id != null && StringUtils.isNotBlank(id)) { uriBuilder.setPath("/riak/" + bucket + "/" + id); } URI uri; try { uri = uriBuilder.build(); } catch (URISyntaxException e) { LOGGER.warn("URISyntaxException", e); return; } HttpPost post = new HttpPost(); post.setHeader("Content-Type", contentType + "; charset=" + charset); post.setURI(uri); HttpEntity entity; try { entity = new StringEntity(document); post.setEntity(entity); } catch (UnsupportedEncodingException e) { LOGGER.warn("UnsupportedEncodingException", e); return; } try { HttpResponse response = client.client().execute(post); } catch (IOException e) { LOGGER.warn("IOException", e); return; } }
From source file:org.apache.streams.neo4j.bolt.Neo4jBoltClient.java
public void start() throws Exception { Objects.nonNull(config); assertThat("config.getScheme().startsWith(\"tcp\")", config.getScheme().startsWith("tcp")); LOGGER.info("Neo4jConfiguration.start {}", config); AuthToken authToken = null;/*from w w w.j av a2s. c o m*/ if (StringUtils.isNotBlank(config.getUsername()) && StringUtils.isNotBlank(config.getPassword())) { authToken = AuthTokens.basic(config.getUsername(), config.getPassword()); } if (authToken == null) { client = GraphDatabase.driver("bolt://" + config.getHosts().get(0) + ":" + config.getPort()); } else { client = GraphDatabase.driver("bolt://" + config.getHosts().get(0) + ":" + config.getPort(), authToken); } Objects.nonNull(client); }
From source file:org.codenergic.theskeleton.core.data.S3ClientConfig.java
@Bean public ScheduledFuture<List<String>> createBuckets(MinioClient minioClient, ScheduledExecutorService executorService, S3ClientProperties clientProps) { return executorService.schedule(() -> clientProps.buckets.stream() .peek(bucket -> logger.info("Checking bucket [{}]", bucket.name)).peek(bucket -> { try { if (!minioClient.bucketExists(bucket.name)) { logger.info("Bucket doesn't exists, creating one"); minioClient.makeBucket(bucket.name); logger.info("Bucket created"); } else { logger.info("Bucket already exists"); }//from w w w . j a v a 2 s . c om } catch (Exception e) { logger.error(e.getMessage(), e); } }) .peek(bucket -> bucket.getPolicies().stream().filter(Objects::nonNull) .filter(policy -> Objects.nonNull(policy.policy)) .filter(policy -> StringUtils.isNotBlank(policy.prefix)) .peek(policy -> logger.info("Setting policy [{}] to bucket [{}] with prefix [{}]", policy.policy, bucket.name, policy.prefix)) .forEach(policy -> { try { minioClient.setBucketPolicy(bucket.name, policy.prefix, policy.policy); } catch (Exception e) { logger.error(e.getMessage(), e); } })) .map(bucket -> bucket.name).collect(Collectors.toList()), 5, TimeUnit.SECONDS); }
From source file:br.com.elotech.sits.service.AbstractService.java
public CastorMarshaller getCastorMarshallerByXSD(Node node) { if (Objects.nonNull(node) && Objects.nonNull(node.getNodeValue()) && node.getNodeValue().contains(XSD_VERSAO_2_03)) { return castorMarshallerNfse203; }/* w w w . ja v a 2 s. c om*/ return castorMarshaller; }
From source file:com.amanmehara.programming.android.activities.LanguageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedPreferences = getSharedPreferences("Programming", MODE_PRIVATE); setContentView(R.layout.activity_language); setActionBar(R.id.toolbar, true);//from w w w .java 2 s .c o m recyclerView = setRecyclerView(R.id.language_recycler_view); Bundle bundle = getIntent().getExtras(); accessToken = bundle.getString("accessToken"); String url = Constants.ENDPOINT + LANGUAGES_PATH; if (isConnected()) { String response = sharedPreferences.getString(url, null); if (Objects.nonNull(response)) { getLanguagesResponseCallback(url, true).accept(response); } else { new GithubAPIClient(this, getLanguagesResponseCallback(url, false)).execute(withAccessToken(url)); } } else { setAdapter(); Map<String, Serializable> extrasMap = new HashMap<>(); extrasMap.put("enumeration.Activity", Activity.LANGUAGE); extrasMap.put("accessToken", accessToken); startActivity(ConnectionActivity.class, extrasMap); } }
From source file:com.mac.holdempoker.app.impl.util.HandMatrix.java
public void haveCard(Card card) { if (Objects.nonNull(card)) { Rank rank = card.getRank();//from w w w . ja v a2 s.com Suit suit = card.getSuit(); Rank[] suitedRank = hand.get(suit); if (Objects.nonNull(suitedRank)) { suitedRank[rank.value() - 2] = rank; } else { Rank[] newSet = new Rank[13]; newSet[rank.value() - 2] = rank; hand.put(suit, newSet); } Integer count = rankHistogram.get(rank); if (Objects.nonNull(count)) { rankHistogram.put(rank, ++count); } else { count = 1; rankHistogram.put(rank, count); } } }
From source file:org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil.java
/** * Build list of files to search optional. * * @param heatFileName the heat file name * @param filesDataList the files data list * @param types the types/*from w w w . j a v a 2 s . c o m*/ * @return the optional */ public static Optional<List<FileData>> buildListOfFilesToSearch(String heatFileName, List<FileData> filesDataList, FileData.Type... types) { List<FileData> list = new ArrayList<>(filesDataList); Optional<FileData> resourceFileData = HeatToToscaUtil.getFileData(heatFileName, filesDataList); if (resourceFileData.isPresent() && Objects.nonNull(resourceFileData.get().getData())) { list.addAll(resourceFileData.get().getData()); } return Optional.ofNullable(HeatToToscaUtil.getFilteredListOfFileDataByTypes(list, types)); }
From source file:pe.chalk.telegram.type.message.Message.java
public boolean isReply() { return Objects.nonNull(this.getReplyToMessage()); }