@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int size = in.readInt(); MutableSet<T> deserializedSet = UnifiedSet.newSet(size); for (int i = 0; i < size; i++) { deserializedSet.add((T) in.readObject()); } this.set = deserializedSet.toImmutable(); }
/** * Returns an Immutable version of powerset where the inner sets are also immutable. */ public static <T> ImmutableSet<ImmutableSet<T>> immutablePowerSet(Set<T> set) { return powerSet(set).collect(MutableSet::toImmutable).toImmutable(); }
@Override public float getFractionLoaded() { int expected = 0; try (AutoLock al = expectedUserIDsLock.autoReadLock()) { expected += expectedUserIDs.size(); } try (AutoLock al = expectedItemIDsLock.autoReadLock()) { expected += expectedItemIDs.size(); } if (expected == 0) { return 1.0f; } float loaded = (float) X.size() + Y.size(); return loaded / (loaded + expected); }
@Override public ImmutableSet<T> newWithAll(Iterable<? extends T> elements) { MutableSet<T> result = UnifiedSet.newSet(elements); result.addAll(this); return result.toImmutable(); }
@Override public void setVector(String id, float[] vector) { try (AutoLock al = lock.autoWriteLock()) { if (vectors.put(id, vector) == null) { // ID was actually new recentIDs.add(id); } } }
@Override public ImmutableSet<T> newWithout(T element) { if (this.contains(element)) { MutableSet<T> result = UnifiedSet.newSet(this); result.remove(element); return result.toImmutable(); } return this; }
private Customer getOrCreateCustomer(String customerName) { Customer customer = this.customers.detectWithIfNone(Customer::named, customerName, () -> new Customer(customerName)); if (!this.customers.contains(customer)) { this.customers.add(customer); } return customer; }
@Override public ImmutableSet<T> union(SetIterable<? extends T> set) { return SetIterables.union(this, set).toImmutable(); }
@VisibleForTesting MutableSet<SchemaObjectRow> getInvalidObjects(Connection conn, RichIterable<PhysicalSchema> physicalSchemas) { LOG.info("Checking for invalid objects"); String schemaInClause = physicalSchemas.collect(new Function<PhysicalSchema, String>() { @Override public String valueOf(PhysicalSchema physicalSchema) { return physicalSchema.getPhysicalName(); } }).makeString("('", "','", "')"); MutableSet<SchemaObjectRow> oldInvalidObjects = queryOldInvalidObjects(conn, schemaInClause); try { MutableSet<SchemaObjectRow> newInvalidObjects = queryNewInvalidObjects(conn, schemaInClause); if (oldInvalidObjects.isEmpty() && newInvalidObjects.notEmpty()) { deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInNew", true); } else if (oldInvalidObjects.notEmpty() && newInvalidObjects.isEmpty()) { deployMetricsCollector.addMetric("invalidObjectQuery.resultsOnlyInOld", true); } return oldInvalidObjects.withAll(newInvalidObjects); } catch (DataAccessException e) { deployMetricsCollector.addMetric("oldInvalidObjectQueryRequired", true); LOG.debug("Failed to execute new invalid objects SQL; falling back to old query"); return oldInvalidObjects; } }
String replaceSnippet(String sqlSnippet) { for (RevengPatternOutput objectOutput : objectNames) { MutableSet<String> replacerSchemas = objectToSchemasMap.get(objectOutput.getPrimaryName()); if (replacerSchemas == null || replacerSchemas.isEmpty()) { replacerSchemas = objectToSchemasMap.valuesView().toSet(); if (replacerSubSchemas == null || replacerSubSchemas.isEmpty()) { replacerSubSchemas = objectToSubSchemasMap.valuesView().toSet(); if (replacerSubSchemas.notEmpty()) { LazyIterable<Pair<String, String>> pairs = replacerSchemas.cartesianProduct(replacerSubSchemas); for (Pair<String, String> pair : pairs) { String replacerSchema = pair.getOne();
@Override public <V> MutableSet<V> collect(Function<? super T, ? extends V> function) { return this.getDelegate().collect(function); }
ArtifactRestrictions(MutableSet<String> includes, MutableSet<String> excludes) { this.includes = includes == null ? UnifiedSet.<String>newSet() : includes; this.excludes = excludes == null ? UnifiedSet.<String>newSet() : excludes; if (!this.includes.isEmpty() && !this.excludes.isEmpty()) { throw new IllegalArgumentException("Cannot specify both include and exclude"); } }
/** * @param user user to get known items for * @return set of known items for the user (immutable, but thread-safe) */ public Set<String> getKnownItems(String user) { MutableSet<String> knownItemsForUser = doGetKnownItems(user); if (knownItemsForUser == null) { return Collections.emptySet(); } synchronized (knownItemsForUser) { if (knownItemsForUser.isEmpty()) { return Collections.emptySet(); } // Must copy since the original object is synchronized return knownItemsForUser.clone().asUnmodifiable(); } }
private static void mergePartialMatches(MutableList<IndexMap> finalRowIndices, MutableList<UnmatchedIndexMap> allMissingRows, MutableList<UnmatchedIndexMap> allSurplusRows) { MutableSet<IndexMap> partiallyMatchedSurplus = UnifiedSet.newSet(); for (UnmatchedIndexMap expected : allMissingRows) { UnmatchedIndexMap actual = expected.getBestMutualMatch(); if (actual == null) { finalRowIndices.add(expected); } else { // todo: can we avoi newing up another index map - update expected in place? finalRowIndices.add(new IndexMap(expected.getExpectedIndex(), actual.getActualIndex())); partiallyMatchedSurplus.add(actual); } } for (IndexMap indexMap : allSurplusRows) { if (!partiallyMatchedSurplus.contains(indexMap)) { finalRowIndices.add(indexMap); } } }
void setUserVector(String user, float[] vector) { Preconditions.checkArgument(vector.length == features); X.setVector(user, vector); try (AutoLock al = expectedUserIDsLock.autoWriteLock()) { expectedUserIDs.remove(user); } }