Java Code Examples for com.google.common.base.Objects#firstNonNull()
The following examples show how to use
com.google.common.base.Objects#firstNonNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InverseEvaluator.java From emodb with Apache License 2.0 | 7 votes |
@Nullable @Override public Condition visit(MapCondition condition, Void context) { // A map condition is basically an AND of all provided key conditions. So the inverse is an OR or // of the same with each key condition inverted. As with the AND operation allow "not(sub-condition)" // when a sub-condition has no inverse. List<Condition> conditions = Lists.newArrayListWithCapacity(condition.getEntries().size()); for (Map.Entry<String, Condition> entry : condition.getEntries().entrySet()) { Condition keyCond = entry.getValue(); Condition inverted = Objects.firstNonNull(keyCond.visit(this, null), Conditions.not(keyCond)); conditions.add(Conditions.mapBuilder().matches(entry.getKey(), inverted).build()); } // Since evaluating map conditions returns false if the value is not a map that needs to be inverted as well. conditions.add(Conditions.isMap().visit(this, null)); return Conditions.or(conditions); }
Example 2
Source File: AstyanaxBlockedDataReaderDAO.java From emodb with Apache License 2.0 | 5 votes |
/** * Queries for records across multiple tables. Data is returned in order by by shard then table. If the caller * wants to get all rows for a table he will need to stitch the data together. */ @Override public Iterator<MultiTableScanResult> multiTableScan(final MultiTableScanOptions query, final TableSet tables, final LimitCounter limit, final ReadConsistency consistency, @Nullable Instant cutoffTime) { checkNotNull(query, "query"); String placementName = checkNotNull(query.getPlacement(), "placement"); final DeltaPlacement placement = (DeltaPlacement) _placementCache.get(placementName); ScanRange scanRange = Objects.firstNonNull(query.getScanRange(), ScanRange.all()); // Since the range may wrap from high to low end of the token range we need to unwrap it List<ScanRange> ranges = scanRange.unwrapped(); return touch(FluentIterable.from(ranges) .transformAndConcat(new Function<ScanRange, Iterable<MultiTableScanResult>>() { @Override public Iterable<MultiTableScanResult> apply(final ScanRange rowRange) { return new Iterable<MultiTableScanResult>() { @Override public Iterator<MultiTableScanResult> iterator() { return scanMultiTableRows( tables, placement, rowRange.asByteBufferRange(), limit, query.isIncludeDeletedTables(), query.isIncludeMirrorTables(), _maxColumnsRange.getLimit(), consistency, cutoffTime); } }; } }) .iterator()); }
Example 3
Source File: AvroToCQL.java From hdfs2cass with Apache License 2.0 | 5 votes |
@Override public CQLRecord map(GenericRecord record) { if (!posInitialized) { initPos(record); } Object rowkey = null; long timestamp = DateTimeUtils.currentTimeMillis() * 1000; int ttl = 0; List<Object> values = Lists.newArrayList(); for (Schema.Field field : record.getSchema().getFields()) { int pos = field.pos(); if (pos == rowkeyPos) { rowkey = record.get(pos); if (!ignorePos.contains(pos)) { values.add(rowkey); } } else if (pos == ttlPos) { ttl = (int) Objects.firstNonNull(record.get(ttlPos), 0); } else if (pos == timestampPos) { timestamp = (long) Objects.firstNonNull(record.get(timestampPos), timestamp); } else if (!ignorePos.contains(pos)) { values.add(record.get(pos)); } } return CQLRecord.create(rowkey, timestamp, ttl, values); }
Example 4
Source File: PersistS3.java From h2o-2 with Apache License 2.0 | 5 votes |
@Override public AWSCredentials getCredentials() { File credentials = new File(Objects.firstNonNull(H2O.OPT_ARGS.aws_credentials, DEFAULT_CREDENTIALS_LOCATION)); try { return new PropertiesCredentials(credentials); } catch (IOException e) { throw new AmazonClientException("Unable to load AWS credentials from file " + credentials); } }
Example 5
Source File: ReturnEmptyListIterator.java From levelup-java-examples with Apache License 2.0 | 5 votes |
/** * Used for exception example */ @SuppressWarnings("unused") private void return_empty_list_iterator_guava_exception () { DomainObject domain = null; // dao populate domain ListIterator<String> strings = Objects.firstNonNull( domain != null ? domain.getStrings() : null, ImmutableList.<String>of().listIterator()); //... }
Example 6
Source File: CassandraConfiguration.java From emodb with Apache License 2.0 | 5 votes |
public AstyanaxCluster cluster() { checkNotNull(_cluster, "cluster"); String metricName; ConnectionPoolConfiguration poolConfig; if (_keyspace == null) { // Use the shared pool configuration metricName = Objects.firstNonNull(_clusterMetric, _cluster); poolConfig = CassandraConfiguration.this; } else { // Use the configuration specifically for this keyspace KeyspaceConfiguration keyspaceConfig = checkNotNull(_keyspaces.get(_keyspace), "keyspaceConfig"); metricName = Objects.firstNonNull(keyspaceConfig.getKeyspaceMetric(), _keyspace); poolConfig = keyspaceConfig; } AstyanaxContext.Builder builder = newAstyanaxBuilder(_cluster, poolConfig, _metricRegistry) .forCluster(_cluster); if (!_disableClusterMetrics) { builder = builder .withTracerFactory(new InstrumentedTracerFactory(metricName, _metricRegistry)) .withConnectionPoolMonitor(new MetricConnectionPoolMonitor(metricName, _metricRegistry)); } AstyanaxContext<Cluster> astyanaxContext = builder.buildCluster(ThriftFamilyFactory.getInstance()); return new AstyanaxCluster(astyanaxContext, _cluster, _dataCenter); }
Example 7
Source File: CreateTableResource.java From emodb with Apache License 2.0 | 5 votes |
@JsonCreator public CreateTableResource(@JsonProperty("name") String name, @JsonProperty("placement") String placement, @JsonProperty("attributes") Map<String, ?> attributes) { _name = checkNotNull(name, "name"); _placement = checkNotNull(placement, "placement"); _attributes = Objects.firstNonNull(attributes, ImmutableMap.<String, Object>of()); }
Example 8
Source File: AWSCatalogMetastoreClient.java From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 | 5 votes |
private AWSCatalogMetastoreClient(Builder builder) throws MetaException { conf = Objects.firstNonNull(builder.conf, new HiveConf()); if (builder.wh != null) { this.wh = builder.wh; } else { this.wh = new Warehouse(conf); } if (builder.catalogId != null) { this.catalogId = builder.catalogId; } else { this.catalogId = null; } GlueClientFactory clientFactory = Objects.firstNonNull(builder.clientFactory, new AWSGlueClientFactory(conf)); AWSGlueMetastoreFactory metastoreFactory = Objects.firstNonNull(builder.metastoreFactory, new AWSGlueMetastoreFactory()); glueClient = clientFactory.newClient(); AWSGlueMetastore glueMetastore = metastoreFactory.newMetastore(conf); glueMetastoreClientDelegate = new GlueMetastoreClientDelegate(this.conf, glueMetastore, wh); /** * It seems weird to create databases as part of glueClient construction. This * part should probably be moved to the section in hive code right after the * metastore glueClient is instantiated. For now, simply copying the * functionality in the thrift server */ if(builder.createDefaults && !doesDefaultDBExist()) { createDefaultDatabase(); } }
Example 9
Source File: DrawableFactory.java From OpenPeripheral-Addons with MIT License | 4 votes |
private static Float defaultOpacity(Float opacity) { return Objects.firstNonNull(opacity, 1.0f); }
Example 10
Source File: RateLimiterCache.java From emodb with Apache License 2.0 | 4 votes |
private double getRate(String key) { Double rate = _rates.get(key); return Objects.firstNonNull(rate, _defaultRate); }
Example 11
Source File: EmoTableAllTablesReportDAO.java From emodb with Apache License 2.0 | 4 votes |
/** * Accepts the table portion of a table report entry and converts it to a TableReportEntryTable. If the * entry doesn't match all of the configured filters then null is returned. */ @Nullable private TableReportEntryTable convertToTableReportEntryTable( String tableId, Map<String, Object> map, Predicate<String> placementFilter, Predicate<Boolean> droppedFilter, Predicate<Boolean> facadeFilter) { // Check the filters for placement, dropped, and facade String placement = (String) map.get("placement"); if (!placementFilter.apply(placement)) { return null; } Boolean dropped = Objects.firstNonNull((Boolean) map.get("dropped"), false); if (!droppedFilter.apply(dropped)) { return null; } Boolean facade = Objects.firstNonNull((Boolean) map.get("facade"), false); if (!facadeFilter.apply(facade)) { return null; } List<Integer> shards = Lists.newArrayList(); // Aggregate the column, size and update statistics across all shards. TableStatistics.Aggregator aggregator = TableStatistics.newAggregator(); Object shardJson = map.get("shards"); if (shardJson != null) { Map<String, TableStatistics> shardMap = JsonHelper.convert( shardJson, new TypeReference<Map<String, TableStatistics>>() { }); for (Map.Entry<String, TableStatistics> entry : shardMap.entrySet()) { Integer shardId = Integer.parseInt(entry.getKey()); shards.add(shardId); aggregator.add(entry.getValue()); } } TableStatistics tableStatistics = aggregator.aggregate(); Collections.sort(shards); return new TableReportEntryTable(tableId, placement, shards, dropped, facade, tableStatistics.getRecordCount(), tableStatistics.getColumnStatistics().toStatistics(), tableStatistics.getSizeStatistics().toStatistics(), tableStatistics.getUpdateTimeStatistics().toStatistics()); }
Example 12
Source File: EmoRoleKey.java From emodb with Apache License 2.0 | 4 votes |
@JsonCreator public EmoRoleKey(@JsonProperty("group") String group, @JsonProperty("id") String id) { _group = Objects.firstNonNull(group, NO_GROUP); _id = checkNotNull(id, "id"); }
Example 13
Source File: DefaultCacheRegistry.java From emodb with Apache License 2.0 | 4 votes |
private HandleImpl getOrPut(String name) { HandleImpl handle = new HandleImpl(name); return Objects.firstNonNull(_handles.putIfAbsent(name, handle), handle); }
Example 14
Source File: StashFileSystem.java From emodb with Apache License 2.0 | 4 votes |
@Override public void initialize(URI location, Configuration conf) throws IOException { // The location is either a table or a split. Get the root path depending on which it is. // Strip the trailing slash if present String locationPath = Objects.firstNonNull(location.getPath(), "/"); if (locationPath.length() > 0 && locationPath.endsWith("/")) { locationPath = locationPath.substring(0, locationPath.length() - 1); } // Get the parent directory String basePath = location.getPath(); int lastSlash = locationPath.lastIndexOf('/'); // If it's a split go to the parent's parent. boolean isSplit = isSplitFile(basePath.substring(lastSlash + 1)); for (int i=0; i < (isSplit ? 2 : 1); i++) { basePath = lastSlash != 0 ? basePath.substring(0, lastSlash) : "/"; lastSlash = basePath.lastIndexOf('/'); } _uri = UriBuilder.fromUri(location).replacePath(basePath).build(); _rootPath = new Path(_uri); _s3 = createS3Client(conf); addS3ClientReference("instance"); StashLocation stashLocation = LocationUtil.getStashLocation(_uri); /** * Some locations are fixed in that the root directory directly contains the table directories. * Other locations, such as "emostash://ci.us", are dynamic in that the actual root directory is * in a directory beneath the root directory. Which subdirectory to use is determined by reading the * content of a signal file called "_LATEST". This is handled by the StandardStashReader. * */ boolean useLatestDirectory = stashLocation.isUseLatestDirectory(); if (useLatestDirectory) { _stashReader = StandardStashReader.getInstance(stashLocation.getUri(), _s3); } else { _stashReader = FixedStashReader.getInstance(stashLocation.getUri(), _s3); } super.initialize(_uri, conf); }
Example 15
Source File: MultiwayPoolBuilder.java From multiway-pool with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") ResourceLifecycle<? super K, ? super R> getResourceLifecycle() { return (ResourceLifecycle<? super K, ? super R>) Objects.firstNonNull( lifecycle, DISCARDING_LIFECYCLE); }
Example 16
Source File: CrossMojoState.java From emodb with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public static List<EmoExec> getEmoProcesses(Map pluginContext) { List<EmoExec> processes = (List<EmoExec>) pluginContext.get(EMO_PROCESSES); return Objects.firstNonNull(processes, Collections.<EmoExec>emptyList()); }
Example 17
Source File: CassandraReplication.java From emodb with Apache License 2.0 | 4 votes |
public int getReplicationFactorForDataCenter(String dataCenter) { return Objects.firstNonNull(_replicationFactorByDataCenter.get(dataCenter), 0); }
Example 18
Source File: CreateEmoApiKeyRequest.java From emodb with Apache License 2.0 | 4 votes |
public CreateEmoApiKeyRequest setRoles(Set<EmoRoleKey> roles) { _roles = Objects.firstNonNull(roles, ImmutableSet.<EmoRoleKey>of()); return this; }
Example 19
Source File: MaintenanceOp.java From emodb with Apache License 2.0 | 4 votes |
static MaintenanceOp forData(String name, Instant when, String dataCenter, MaintenanceTask task) { return new MaintenanceOp(name, when, MaintenanceType.DATA, Objects.firstNonNull(dataCenter, "<n/a>"), checkNotNull(task, "task")); }
Example 20
Source File: GetFirstNonNullObject.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void get_first_non_null_guava () { String first = null; String second = "Go Badgers!"; String firstNullObject = Objects.firstNonNull(first, second); assertEquals(second, firstNullObject); }