_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q174100 | LossFunctions.nonZeroCount | test | private static SDVariable nonZeroCount(SDVariable weights, SDVariable labels){
SameDiff sd = weights.getSameDiff();
SDVariable present = sd.neq(weights, 0.0);
SDVariable presentBroadcast = sd.zerosLike(labels).add(present);
return sd.sum(presentBroadcast);
} | java | {
"resource": ""
} |
q174101 | LossFunctions.doReduce | test | private static LossInfo doReduce(SameDiff sd, String outputName, boolean isMean, LossInfo.Builder b, Reduction reduction,
SDVariable preReduceLoss, SDVariable label, SDVariable weights, int[] dimensions){
switch (reduction){
case NONE:
//Return same shape as... | java | {
"resource": ""
} |
q174102 | TypeUtils.getNoArgConstructor | test | public static <T> Constructor<T> getNoArgConstructor(Class<T> clazz) {
try {
Constructor<T> ctor = clazz.getDeclaredConstructor(new Class[0]);
ctor.setAccessible(true);
return ctor;
}
catch (NoSuchMethodException e) {
// lame there is no way to tell if the class is a nonstatic inner class
if (clazz... | java | {
"resource": ""
} |
q174103 | TypeUtils.getConstructor | test | public static MethodHandle getConstructor(Class<?> clazz, Class<?>... args) {
try {
// We use unreflect so that we can make the constructor accessible
Constructor<?> ctor = clazz.getDeclaredConstructor(args);
ctor.setAccessible(true);
return MethodHandles.lookup().unreflectConstructor(ctor);
}
catch (... | java | {
"resource": ""
} |
q174104 | TypeUtils.invoke | test | public static <T> T invoke(MethodHandle methodHandle, Object... params) {
try {
return (T)methodHandle.invokeWithArguments(params);
} catch (RuntimeException e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
} | java | {
"resource": ""
} |
q174105 | TypeUtils.getAnnotation | test | @SuppressWarnings("unchecked")
public static <A extends Annotation> A getAnnotation(Annotation[] annotations, Class<A> annotationType) {
for (Annotation anno: annotations)
if (annotationType.isAssignableFrom(anno.getClass()))
return (A)anno;
return null;
} | java | {
"resource": ""
} |
q174106 | TypeUtils.getDeclaredAnnotation | test | public static <A extends Annotation> A getDeclaredAnnotation(Class<?> onClass, Class<A> annotationType) {
return getAnnotation(onClass.getDeclaredAnnotations(), annotationType);
} | java | {
"resource": ""
} |
q174107 | TypeUtils.isDeclaredAnnotationPresent | test | public static <A extends Annotation> boolean isDeclaredAnnotationPresent(Class<?> onClass, Class<A> annotationType) {
return getDeclaredAnnotation(onClass, annotationType) != null;
} | java | {
"resource": ""
} |
q174108 | ResultProxy.create | test | @SuppressWarnings("unchecked")
public static <S> S create(Class<? super S> interf, Result<S> result) {
return (S)Proxy.newProxyInstance(result.getClass().getClassLoader(), new Class[] { interf }, new ResultProxy<>(result));
} | java | {
"resource": ""
} |
q174109 | EntityMetadata.load | test | public P load(final BaseEntity<?> ent, final LoadContext ctx) {
try {
// The context needs to know the root entity for any given point
ctx.setCurrentRoot(Key.create((com.google.cloud.datastore.Key)ent.getKey()));
final EntityValue entityValue = makeLoadEntityValue(ent);
return translator.load(entityValue... | java | {
"resource": ""
} |
q174110 | EntityMetadata.save | test | public FullEntity<?> save(final P pojo, final SaveContext ctx) {
try {
return translator.save(pojo, false, ctx, Path.root()).get();
}
catch (SaveException ex) { throw ex; }
catch (Exception ex) {
throw new SaveException(pojo, ex);
}
} | java | {
"resource": ""
} |
q174111 | MemcacheServiceRetryProxy.createProxy | test | public static MemcacheService createProxy(final MemcacheService raw, final int retryCount) {
return (MemcacheService)java.lang.reflect.Proxy.newProxyInstance(
raw.getClass().getClassLoader(),
raw.getClass().getInterfaces(),
new MemcacheServiceRetryProxy(raw, retryCount));
} | java | {
"resource": ""
} |
q174112 | Registrar.getMetadataSafe | test | public <T> EntityMetadata<T> getMetadataSafe(String kind) throws IllegalArgumentException {
EntityMetadata<T> metadata = this.getMetadata(kind);
if (metadata == null)
throw new IllegalArgumentException("No entity class has been registered which matches kind '" + kind + "'");
else
return metadata;
} | java | {
"resource": ""
} |
q174113 | QueryEngine.queryKeysOnly | test | public <T> QueryResults<Key<T>> queryKeysOnly(final KeyQuery query) {
log.trace("Starting keys-only query");
return new KeyQueryResults<>(ds.run(query));
} | java | {
"resource": ""
} |
q174114 | QueryEngine.queryHybrid | test | public <T> QueryResults<T> queryHybrid(final KeyQuery query, final int chunkSize) {
log.trace("Starting hybrid query");
final QueryResults<Key<T>> results = new KeyQueryResults<>(ds.run(query));
return new HybridQueryResults<>(loader.createLoadEngine(), results, chunkSize);
} | java | {
"resource": ""
} |
q174115 | QueryEngine.queryNormal | test | public <T> QueryResults<T> queryNormal(final EntityQuery query, final int chunkSize) {
log.trace("Starting normal query");
// Normal queries are actually more complex than hybrid queries because we need the fetched entities to
// be stuffed back into the engine to satisfy @Load instructions without extra fet... | java | {
"resource": ""
} |
q174116 | QueryEngine.queryProjection | test | public <T> QueryResults<T> queryProjection(final ProjectionEntityQuery query) {
log.trace("Starting projection query");
final LoadEngine loadEngine = loader.createLoadEngine();
return new ProjectionQueryResults<>(ds.run(query), loadEngine);
} | java | {
"resource": ""
} |
q174117 | QueryEngine.queryCount | test | public int queryCount(final KeyQuery query) {
log.trace("Starting count query");
final QueryResults<com.google.cloud.datastore.Key> results = ds.run(query);
return Iterators.size(results);
} | java | {
"resource": ""
} |
q174118 | HybridQueryResults.safePartition | test | private <T> Iterator<Iterator<T>> safePartition(final Iterator<T> input, int chunkSize) {
// Cloud Datastore library errors if you try to fetch more than 1000 keys at a time
if (chunkSize > 1000) {
chunkSize = 1000;
}
return Iterators.transform(Iterators.partition(input, chunkSize), IterateFunction.instance(... | java | {
"resource": ""
} |
q174119 | HybridQueryResults.load | test | private Iterator<ResultWithCursor<T>> load(final Iterator<ResultWithCursor<Key<T>>> keys) {
final List<Entry<ResultWithCursor<Key<T>>, Result<T>>> results = Lists.newArrayList();
while (keys.hasNext()) {
final ResultWithCursor<Key<T>> next = keys.next();
results.add(Maps.immutableEntry(next, loadEngine.load(... | java | {
"resource": ""
} |
q174120 | LogUtils.msg | test | public static String msg(Path path, String msg) {
StringBuilder bld = new StringBuilder();
bld.append("\t.");
bld.append(path.toPathString());
if (bld.length() < PATH_PADDING)
while (bld.length() < PATH_PADDING)
bld.append(' ');
else
bld.append('\t');
bld.append(msg);
return ... | java | {
"resource": ""
} |
q174121 | Key.create | test | public static <T> Key<T> create(final T pojo) {
return ObjectifyService.factory().keys().keyOf(pojo);
} | java | {
"resource": ""
} |
q174122 | Key.compareToWithIdentityHash | test | private int compareToWithIdentityHash(final Object k1, final Object k2) {
return Integer.compare(System.identityHashCode(k1), System.identityHashCode(k2));
} | java | {
"resource": ""
} |
q174123 | Key.key | test | public static <V> Key<V> key(final com.google.cloud.datastore.Key raw) {
if (raw == null)
return null;
else
return new Key<>(raw);
} | java | {
"resource": ""
} |
q174124 | Key.key | test | public static com.google.cloud.datastore.Key key(final Key<?> typed) {
if (typed == null)
return null;
else
return typed.getRaw();
} | java | {
"resource": ""
} |
q174125 | Key.getKindHere | test | private static String getKindHere(final Class<?> clazz) {
// @Entity is inherited so we have to be explicit about the declared annotations
final Entity ourAnn = TypeUtils.getDeclaredAnnotation(clazz, Entity.class);
if (ourAnn != null)
if (ourAnn.name().length() != 0)
return ourAnn.name();
else
... | java | {
"resource": ""
} |
q174126 | GenericTypeReflector.isMissingTypeParameters | test | static boolean isMissingTypeParameters(Type type) {
if (type instanceof Class) {
for (Class<?> clazz = (Class<?>) type; clazz != null; clazz = clazz.getEnclosingClass()) {
if (clazz.getTypeParameters().length != 0)
return true;
}
return false;
} else if (type instanceof ParameterizedType) {
ret... | java | {
"resource": ""
} |
q174127 | GenericTypeReflector.isSuperType | test | public static boolean isSuperType(Type superType, Type subType) {
if (superType instanceof ParameterizedType || superType instanceof Class || superType instanceof GenericArrayType) {
Class<?> superClass = erase(superType);
Type mappedSubType = getExactSuperType(capture(subType), superClass);
if (mappedSubTyp... | java | {
"resource": ""
} |
q174128 | GenericTypeReflector.getExactDirectSuperTypes | test | private static Type[] getExactDirectSuperTypes(Type type) {
if (type instanceof ParameterizedType || type instanceof Class) {
Class<?> clazz;
if (type instanceof ParameterizedType) {
clazz = (Class<?>)((ParameterizedType)type).getRawType();
} else {
// TODO primitive types?
clazz = (Class<?>)type... | java | {
"resource": ""
} |
q174129 | GenericTypeReflector.capture | test | public static Type capture(Type type) {
if (type instanceof ParameterizedType) {
return capture((ParameterizedType)type);
} else {
return type;
}
} | java | {
"resource": ""
} |
q174130 | CreateContext.getTranslator | test | public <P, D> Translator<P, D> getTranslator(final TypeKey<P> tk, final CreateContext ctx, final Path path) {
return factory.getTranslators().get(tk, ctx, path);
} | java | {
"resource": ""
} |
q174131 | CreateContext.getPopulator | test | @SuppressWarnings("unchecked")
public <P> Populator<P> getPopulator(final Class<P> clazz, final Path path) {
if (clazz == null || clazz.equals(Object.class)) {
return (Populator<P>)NullPopulator.INSTANCE;
} else {
final ClassTranslator<P> classTranslator = (ClassTranslator<P>)this.<P, FullEntity<?>>getTransl... | java | {
"resource": ""
} |
q174132 | ClassPopulator.getIndexInstruction | test | private Boolean getIndexInstruction(Class<P> clazz) {
Index ind = clazz.getAnnotation(Index.class);
Unindex unind = clazz.getAnnotation(Unindex.class);
if (ind != null && unind != null)
throw new IllegalStateException("You cannot have @Index and @Unindex on the same class: " + clazz);
if (ind != null)
r... | java | {
"resource": ""
} |
q174133 | ClassPopulator.isOfInterest | test | private boolean isOfInterest(Method method) {
for (Annotation[] annos: method.getParameterAnnotations())
if (TypeUtils.getAnnotation(annos, AlsoLoad.class) != null)
return true;
return false;
} | java | {
"resource": ""
} |
q174134 | ClassPopulator.getDeclaredProperties | test | private List<Property> getDeclaredProperties(ObjectifyFactory fact, Class<?> clazz) {
List<Property> good = new ArrayList<>();
for (Field field: clazz.getDeclaredFields())
if (isOfInterest(field))
good.add(new FieldProperty(fact, clazz, field));
for (Method method: clazz.getDeclaredMethods())
if (isOf... | java | {
"resource": ""
} |
q174135 | ClassPopulator.getKeyMetadata | test | public KeyMetadata<P> getKeyMetadata() {
final Populator<Object> populator = props.get(0);
Preconditions.checkState(populator instanceof KeyPopulator, "Cannot get KeyMetadata for non-@Entity class " + this.clazz);
return ((KeyPopulator<P>)populator).getKeyMetadata();
} | java | {
"resource": ""
} |
q174136 | Round.get | test | public <T> Result<T> get(final Key<T> key) {
assert !isExecuted();
SessionValue<T> sv = getSession().get(key);
if (sv == null) {
log.trace("Adding to round (session miss): {}", key);
this.pending.add(key.getRaw());
Result<T> result = new ResultCache<T>() {
@Override
@SuppressWarnings("unchecke... | java | {
"resource": ""
} |
q174137 | Round.execute | test | public void execute() {
if (needsExecution()) {
log.trace("Executing round: {}", pending);
Result<Map<com.google.cloud.datastore.Key, Entity>> fetched = fetchPending();
translated = loadEngine.translate(fetched);
// If we're in a transaction (and beyond the first round), force all subsequent rounds to c... | java | {
"resource": ""
} |
q174138 | Round.fetchPending | test | private Result<Map<com.google.cloud.datastore.Key, Entity>> fetchPending() {
// We don't need to fetch anything that has been stuffed
final Map<com.google.cloud.datastore.Key, Entity> combined = new HashMap<>();
Set<com.google.cloud.datastore.Key> fetch = new HashSet<>();
for (com.google.cloud.datastore.Key k... | java | {
"resource": ""
} |
q174139 | ClassTranslator.addIndexedDiscriminators | test | private void addIndexedDiscriminators(final Class<?> clazz) {
if (clazz == Object.class)
return;
this.addIndexedDiscriminators(clazz.getSuperclass());
final Subclass sub = clazz.getAnnotation(Subclass.class);
if (sub != null && sub.index()) {
final String disc = (sub.name().length() > 0) ? sub.name() : ... | java | {
"resource": ""
} |
q174140 | ClassTranslator.registerSubclass | test | public void registerSubclass(ClassTranslator<? extends P> translator) {
byDiscriminator.put(translator.getDiscriminator(), translator);
Subclass sub = translator.getDeclaredClass().getAnnotation(Subclass.class);
for (String alsoLoad: sub.alsoLoad())
byDiscriminator.put(alsoLoad, translator);
byClass.put(tr... | java | {
"resource": ""
} |
q174141 | GenericUtils.getCollectionComponentType | test | public static Type getCollectionComponentType(Type collectionType) {
Type componentType = GenericTypeReflector.getTypeParameter(collectionType, Collection.class.getTypeParameters()[0]);
if (componentType == null) // if it was a raw type, just assume Object
return Object.class;
else
return componentType;
} | java | {
"resource": ""
} |
q174142 | GenericUtils.getMapKeyType | test | public static Type getMapKeyType(Type mapType) {
Type componentType = GenericTypeReflector.getTypeParameter(mapType, Map.class.getTypeParameters()[0]);
if (componentType == null) // if it was a raw type, just assume Object
return Object.class;
else
return componentType;
} | java | {
"resource": ""
} |
q174143 | ForwardPath.of | test | public static ForwardPath of(Path path) {
ForwardPath next = new ForwardPath(path);
if (path.getPrevious() == Path.root())
return next;
ForwardPath previous = of(path.getPrevious());
previous.next = next;
return previous;
} | java | {
"resource": ""
} |
q174144 | ForwardPath.getFinalPath | test | public Path getFinalPath() {
ForwardPath here = this;
while (here.next != null)
here = here.next;
return here.getPath();
} | java | {
"resource": ""
} |
q174145 | Path.toPathString | test | public String toPathString() {
if (this == ROOT) {
return "";
} else {
StringBuilder builder = new StringBuilder();
toPathString(builder);
return builder.toString();
}
} | java | {
"resource": ""
} |
q174146 | Path.depth | test | public int depth() {
int depth = 0;
Path here = this;
while (here != ROOT) {
depth++;
here = here.previous;
}
return depth;
} | java | {
"resource": ""
} |
q174147 | EntityMemcache.putAll | test | public void putAll(final Collection<Bucket> updates) {
final Set<Key> good = this.cachePutIfUntouched(updates);
if (good.size() == updates.size())
return;
// Figure out which ones were bad
final List<Key> bad = updates.stream()
.map(Bucket::getKey)
.filter(key -> !good.contains(key))
... | java | {
"resource": ""
} |
q174148 | EntityMemcache.empty | test | public void empty(final Iterable<Key> keys) {
final Map<Key, Object> updates = new HashMap<>();
for (final Key key: keys)
if (cacheControl.isCacheable(key))
updates.put(key, null);
this.memcacheWithRetry.putAll(updates);
} | java | {
"resource": ""
} |
q174149 | EntityMemcache.cachePutIfUntouched | test | private Set<Key> cachePutIfUntouched(final Iterable<Bucket> buckets) {
final Map<Key, CasPut> payload = new HashMap<>();
final Set<Key> successes = new HashSet<>();
for (final Bucket buck: buckets) {
if (!buck.isCacheable()) {
successes.add(buck.getKey());
continue;
}
final Integer ex... | java | {
"resource": ""
} |
q174150 | EntityMemcache.cacheGetAll | test | private Map<Key, Object> cacheGetAll(final Collection<Key> keys) {
try {
return this.memcache.getAll(keys);
} catch (Exception ex) {
// Some sort of serialization error, just wipe out the values
log.warn("Error fetching values from memcache, deleting keys", ex);
this.memcache.deleteAll(keys);
... | java | {
"resource": ""
} |
q174151 | EntityMemcache.keysOf | test | public static Set<Key> keysOf(final Collection<Bucket> buckets) {
return buckets.stream().map(Bucket::getKey).collect(Collectors.toSet());
} | java | {
"resource": ""
} |
q174152 | KeyMetadata.findKeyFields | test | private void findKeyFields(Class<?> inspect, CreateContext ctx, Path path) {
if (inspect == Object.class)
return;
findKeyFields(inspect.getSuperclass(), ctx, path);
for (Field field: inspect.getDeclaredFields()) {
if (field.getAnnotation(Id.class) != null) {
if (this.idMeta != null)
throw new Ill... | java | {
"resource": ""
} |
q174153 | KeyMetadata.setKey | test | @SuppressWarnings("unchecked")
public <K extends IncompleteKey> void setKey(final FullEntity.Builder<K> container, final P pojo) {
final IncompleteKey rawKey = getIncompleteKey(pojo);
if (!(rawKey instanceof com.google.cloud.datastore.Key)) {
// it's incomplete, make sure we can save it
Preconditions.checkS... | java | {
"resource": ""
} |
q174154 | KeyMetadata.setLongId | test | public void setLongId(P pojo, Long id) {
if (!clazz.isAssignableFrom(pojo.getClass()))
throw new IllegalArgumentException("Trying to use metadata for " + clazz.getName() + " to set key of " + pojo.getClass().getName());
this.idMeta.getProperty().set(pojo, id);
} | java | {
"resource": ""
} |
q174155 | KeyMetadata.getParentRaw | test | private com.google.cloud.datastore.Key getParentRaw(P pojo) {
if (parentMeta == null)
return null;
final Value<Object> value = parentMeta.getValue(pojo, new SaveContext(), Path.root());
return (value == null || value.getType() == ValueType.NULL)
? null
: (com.google.cloud.datastore.Key)value.get();
} | java | {
"resource": ""
} |
q174156 | ClassTranslatorFactory.registerSubclass | test | private void registerSubclass(final ClassTranslator<P> translator, final TypeKey<? super P> superclassTypeKey, final CreateContext ctx, final Path path) {
if (superclassTypeKey.getTypeAsClass() == Object.class)
return;
@SuppressWarnings("unchecked")
final ClassTranslator<? super P> superTranslator = create((T... | java | {
"resource": ""
} |
q174157 | TypeFactory.couldHaveCommonSubtype | test | private static boolean couldHaveCommonSubtype(Type type1, Type type2) {
// this is an optimistically naive implementation.
// if they are parameterized types their parameters need to be checked,...
// so we're just a bit too lenient here
Class<?> erased1 = GenericTypeReflector.erase(type1);
Class<?> erased... | java | {
"resource": ""
} |
q174158 | TypeFactory.transformOwner | test | private static Type transformOwner(Type givenOwner, Class<?> clazz) {
if (givenOwner == null) {
// be lenient: if this is an inner class but no owner was specified, assume a raw owner type
// (or if there is no owner just return null)
return clazz.getDeclaringClass();
} else {
// If the specified owner ... | java | {
"resource": ""
} |
q174159 | TypeKey.getAnnotationAnywhere | test | public <A extends Annotation> A getAnnotationAnywhere(Class<A> annotationType) {
A anno = getAnnotation(annotationType);
if (anno == null) {
Class<?> clazz = (Class<?>) GenericTypeReflector.erase(type);
return clazz.getAnnotation(annotationType);
} else {
return anno;
}
} | java | {
"resource": ""
} |
q174160 | Session.addAll | test | public void addAll(final Session other) {
if (log.isTraceEnabled())
log.trace("Adding all values to session: {}", other.map.keySet());
map.putAll(other.map);
} | java | {
"resource": ""
} |
q174161 | LoadEngine.load | test | public <T> Result<T> load(final Key<T> key) {
if (key == null)
throw new NullPointerException("You tried to load a null key!");
final Result<T> result = round.get(key);
// If we are running a transaction, enlist the result so that it gets processed on commit even
// if the client never materializes ... | java | {
"resource": ""
} |
q174162 | LoadEngine.execute | test | public void execute() {
if (round.needsExecution()) {
Round old = round;
round = old.next();
old.execute();
}
} | java | {
"resource": ""
} |
q174163 | LoadEngine.translate | test | public Result<Map<Key<?>, Object>> translate(final Result<Map<com.google.cloud.datastore.Key, Entity>> raw) {
return new ResultCache<Map<Key<?>, Object>>() {
/** */
private LoadContext ctx;
/** */
@Override
public Map<Key<?>, Object> nowUncached() {
final Map<Key<?>, Object> result = new... | java | {
"resource": ""
} |
q174164 | LoadEngine.fetch | test | public Result<Map<com.google.cloud.datastore.Key, Entity>> fetch(Set<com.google.cloud.datastore.Key> keys) {
log.debug("Fetching {} keys: {}", keys.size(), keys);
final Future<Map<com.google.cloud.datastore.Key, Entity>> fut = datastore.get(keys, readOptions.toArray(new ReadOption[readOptions.size()]));
retu... | java | {
"resource": ""
} |
q174165 | LoadEngine.load | test | @SuppressWarnings("unchecked")
public <T> T load(final BaseEntity<com.google.cloud.datastore.Key> ent, final LoadContext ctx) {
if (ent == null)
return null;
final EntityMetadata<T> meta = ofy.factory().getMetadata(ent.getKey().getKind());
if (meta == null)
return (T)ent;
else
return meta.lo... | java | {
"resource": ""
} |
q174166 | Keys.createRawAny | test | public com.google.cloud.datastore.Key createRawAny(final com.google.cloud.datastore.Key parent, final String kind, final Object id) {
if (id instanceof String)
return createRaw(parent, kind, (String)id);
else if (id instanceof Long)
return createRaw(parent, kind, (Long)id);
else
throw new IllegalArgument... | java | {
"resource": ""
} |
q174167 | Keys.raw | test | public static com.google.cloud.datastore.Key raw(final Key<?> key) {
return key == null ? null : key.getRaw();
} | java | {
"resource": ""
} |
q174168 | Keys.getIdValue | test | @SuppressWarnings("unchecked")
public static <S> Value<S> getIdValue(final IncompleteKey key) {
if (key instanceof com.google.cloud.datastore.Key) {
final com.google.cloud.datastore.Key completeKey = (com.google.cloud.datastore.Key)key;
if (completeKey.hasId())
return (Value<S>)LongValue.of(completeKey.get... | java | {
"resource": ""
} |
q174169 | Keys.fromUrlSafe | test | @SneakyThrows
public static com.google.cloud.datastore.Key fromUrlSafe(final String urlSafeKey) {
if (urlSafeKey.startsWith("a")) {
return KeyFormat.INSTANCE.parseOldStyleAppEngineKey(urlSafeKey);
} else {
return com.google.cloud.datastore.Key.fromUrlSafe(urlSafeKey);
}
} | java | {
"resource": ""
} |
q174170 | TransactorYes.transactionless | test | @Override
public ObjectifyImpl transactionless(final ObjectifyImpl parent) {
return parent.makeNew(next -> new TransactorNo(next, parentTransactor.getSession()));
} | java | {
"resource": ""
} |
q174171 | TransactorYes.transactNew | test | @Override
public <R> R transactNew(final ObjectifyImpl parent, final int limitTries, final Work<R> work) {
return transactionless(parent).transactNew(limitTries, work);
} | java | {
"resource": ""
} |
q174172 | TransactorNo.transactOnce | test | private <R> R transactOnce(final ObjectifyImpl parent, final Work<R> work) {
final ObjectifyImpl txnOfy = factory.open(parent.getOptions(), next -> new TransactorYes(next, this));
boolean committedSuccessfully = false;
try {
final R result = work.run();
txnOfy.flush();
txnOfy.getTransaction().com... | java | {
"resource": ""
} |
q174173 | FieldProperty.matches | test | private boolean matches(Object onPojo, If<?, ?>[] conditions) {
if (conditions == null)
return false;
Object value = this.get(onPojo);
for (If<?, ?> condition: conditions) {
@SuppressWarnings("unchecked")
If<Object, Object> cond = (If<Object, Object>)condition;
if (cond.matchesValue(value))
r... | java | {
"resource": ""
} |
q174174 | LiveRef.ofy | test | private Objectify ofy() {
// If we have an expired transaction context, we need a new context
if (ofy == null || (ofy.getTransaction() != null && !ofy.getTransaction().isActive()))
ofy = ObjectifyService.ofy();
return ofy;
} | java | {
"resource": ""
} |
q174175 | ObjectifyFactory.asyncDatastore | test | public AsyncDatastore asyncDatastore(final boolean enableGlobalCache) {
if (this.entityMemcache != null && enableGlobalCache && this.registrar.isCacheEnabled())
return new CachingAsyncDatastore(asyncDatastore(), this.entityMemcache);
else
return asyncDatastore();
} | java | {
"resource": ""
} |
q174176 | ObjectifyFactory.getMetadataForEntity | test | @SuppressWarnings("unchecked")
public <T> EntityMetadata<T> getMetadataForEntity(final T obj) throws IllegalArgumentException {
// Type erasure sucks
return (EntityMetadata<T>)this.getMetadata(obj.getClass());
} | java | {
"resource": ""
} |
q174177 | ObjectifyFactory.allocate | test | private <T> KeyRange<T> allocate(final IncompleteKey incompleteKey, final int num) {
final IncompleteKey[] allocations = new IncompleteKey[num];
Arrays.fill(allocations, incompleteKey);
final List<Key<T>> typedKeys = datastore().allocateId(allocations).stream()
.map(Key::<T>create)
.collect(Collect... | java | {
"resource": ""
} |
q174178 | ObjectifyFactory.open | test | public ObjectifyImpl open(final ObjectifyOptions opts, final TransactorSupplier transactorSupplier) {
final ObjectifyImpl objectify = new ObjectifyImpl(this, opts, transactorSupplier);
stacks.get().add(objectify);
return objectify;
} | java | {
"resource": ""
} |
q174179 | ObjectifyFactory.close | test | public void close(final Objectify ofy) {
final Deque<Objectify> stack = stacks.get();
if (stack.isEmpty())
throw new IllegalStateException("You have already destroyed the Objectify context.");
final Objectify popped = stack.removeLast();
assert popped == ofy : "Mismatched objectify instances; somehow ... | java | {
"resource": ""
} |
q174180 | Values.homogenizeIndexes | test | public static void homogenizeIndexes(final List<Value<?>> list) {
if (isIndexHomogeneous(list))
return;
for (int i=0; i<list.size(); i++) {
final Value<?> value = list.get(i);
if (value.excludeFromIndexes())
list.set(i, index(value, true));
}
} | java | {
"resource": ""
} |
q174181 | Ref.create | test | public static <T> Ref<T> create(T value) {
Key<T> key = Key.create(value);
return create(key);
} | java | {
"resource": ""
} |
q174182 | Ref.safe | test | final public T safe() throws NotFoundException {
T t = this.get();
if (t == null)
throw new NotFoundException(key());
else
return t;
} | java | {
"resource": ""
} |
q174183 | IdentityMultimapList.add | test | public boolean add(K key, V value) {
List<V> list = this.get(key);
if (list == null) {
list = new ArrayList<>();
this.put(key, list);
}
return list.add(value);
} | java | {
"resource": ""
} |
q174184 | TriggerFuture.isDone | test | @Override
public boolean isDone() {
boolean done = this.raw.isDone();
if (!triggered && done) {
this.triggered = true;
PendingFutures.removePending(this);
this.trigger();
}
return done;
} | java | {
"resource": ""
} |
q174185 | IfConditionGenerator.generateIfConditions | test | public If<?, ?>[] generateIfConditions(Class<? extends If<?, ?>>[] ifClasses, Field field) {
if (ifClasses.length == 0)
return ALWAYS;
If<?, ?>[] result = new If<?, ?>[ifClasses.length];
for (int i=0; i<ifClasses.length; i++) {
Class<? extends If<?, ?>> ifClass = ifClasses[i];
result[i] = this.cr... | java | {
"resource": ""
} |
q174186 | LoadContext.done | test | public void done() {
engine.execute();
while (deferred != null) {
final List<Runnable> runme = deferred;
deferred = null; // reset this because it might get filled with more
for (final Runnable run: runme) {
log.trace("Executing {}", run);
run.run();
}
}
} | java | {
"resource": ""
} |
q174187 | LoadContext.getContainer | test | public Object getContainer(Type containerType, Path path) {
Class<?> containerClass = GenericTypeReflector.erase(containerType);
Iterator<Object> containersIt = containers.descendingIterator();
// We have always entered the current 'this' context when processing properties, so the first thing
// we get will... | java | {
"resource": ""
} |
q174188 | EntityMemcacheStats.getStat | test | private Stat getStat(String kind)
{
Stat stat = this.stats.get(kind);
if (stat == null)
{
stat = new Stat();
this.stats.put(kind, stat);
}
return stat;
} | java | {
"resource": ""
} |
q174189 | FutureHelper.unwrapAndThrow | test | public static void unwrapAndThrow(Throwable ex)
{
if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else if (ex instanceof Error)
throw (Error)ex;
else if (ex instanceof ExecutionException)
unwrapAndThrow(ex.getCause());
else
throw new UndeclaredThrowableException(ex);
} | java | {
"resource": ""
} |
q174190 | Translators.get | test | public <P, D> Translator<P, D> get(final TypeKey tk, final CreateContext ctx, final Path path) {
Translator<?, ?> translator = translators.get(tk);
if (translator == null) {
translator = create(tk, ctx, path);
translators.put(tk, translator);
}
//noinspection unchecked
return (Translator<P, D>)transla... | java | {
"resource": ""
} |
q174191 | Translators.getRoot | test | public <P> Translator<P, FullEntity<?>> getRoot(final Class<P> clazz) {
return get(new TypeKey(clazz), new CreateContext(fact), Path.root());
} | java | {
"resource": ""
} |
q174192 | Translators.create | test | private Translator<?, ?> create(final TypeKey tk, final CreateContext ctx, final Path path) {
for (final TranslatorFactory<?, ?> trans: this.translatorFactories) {
@SuppressWarnings("unchecked")
final Translator<?, ?> soFar = trans.create(tk, ctx, path);
if (soFar != null)
return soFar;
}
throw new ... | java | {
"resource": ""
} |
q174193 | PropertyPopulator.load | test | @Override
public void load(final FullEntity<?> container, final LoadContext ctx, final Path containerPath, final P intoPojo) {
try {
if (translator instanceof Recycles)
ctx.recycle(property.get(intoPojo));
final Value<D> value = (translator instanceof Synthetic)
? null
: getPropertyFromContainer(c... | java | {
"resource": ""
} |
q174194 | PropertyPopulator.getPropertyFromContainer | test | private Value<D> getPropertyFromContainer(final FullEntity<?> container, final Path containerPath) {
String foundName = null;
Value<D> value = null;
for (String name: property.getLoadNames()) {
if (container.contains(name)) {
if (foundName != null)
throw new IllegalStateException("Collision trying to... | java | {
"resource": ""
} |
q174195 | PropertyPopulator.setValue | test | public void setValue(final Object pojo, final Value<D> value, final LoadContext ctx, final Path containerPath) throws SkipException {
final Path propertyPath = containerPath.extend(property.getName());
final P loaded = translator.load(value, ctx, propertyPath);
setOnPojo(pojo, loaded, ctx, propertyPath);
} | java | {
"resource": ""
} |
q174196 | PropertyPopulator.save | test | @Override
public void save(final P onPojo, boolean index, final SaveContext ctx, final Path containerPath, final FullEntity.Builder<?> into) {
if (property.isSaved(onPojo)) {
// Look for an override on indexing
final Boolean propertyIndexInstruction = property.getIndexInstruction(onPojo);
if (propertyIndexI... | java | {
"resource": ""
} |
q174197 | PropertyPopulator.getValue | test | public Value<D> getValue(final Object pojo, final SaveContext ctx, final Path containerPath) {
@SuppressWarnings("unchecked")
final P value = (P)property.get(pojo);
return translator.save(value, false, ctx, containerPath.extend(property.getName()));
} | java | {
"resource": ""
} |
q174198 | AbstractOpenRtbJsonWriter.writeExtensions | test | @SuppressWarnings("unchecked")
protected final <EM extends ExtendableMessage<EM>>
void writeExtensions(EM msg, JsonGenerator gen) throws IOException {
boolean openExt = false;
for (Map.Entry<FieldDescriptor, Object> field : msg.getAllFields().entrySet()) {
FieldDescriptor fd = field.getKey();
i... | java | {
"resource": ""
} |
q174199 | AbstractOpenRtbJsonWriter.writeContentCategory | test | protected final boolean writeContentCategory(String cat, JsonGenerator gen) throws IOException {
if (!factory.isStrict() || OpenRtbUtils.categoryFromName(cat) != null) {
gen.writeString(cat);
return true;
} else {
return false;
}
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.