code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public Field getRelationshipField(Class<?> clazz, String fieldName) {
return relationshipFieldMap.get(clazz).get(fieldName);
} | java |
public Class<?> getRelationshipType(Class<?> clazz, String fieldName) {
return relationshipTypeMap.get(clazz).get(fieldName);
} | java |
public String getTypeName(Class<?> clazz) {
Type type = typeAnnotations.get(clazz);
if (type != null) {
return type.value();
}
return null;
} | java |
public Field getRelationshipMetaField(Class<?> clazz, String relationshipName) {
return relationshipMetaFieldMap.get(clazz).get(relationshipName);
} | java |
public Class<?> getRelationshipMetaType(Class<?> clazz, String relationshipName) {
return relationshipMetaTypeMap.get(clazz).get(relationshipName);
} | java |
public Field getRelationshipLinksField(Class<?> clazz, String relationshipName) {
return relationshipLinksFieldMap.get(clazz).get(relationshipName);
} | java |
public void setTypeResolver(RelationshipResolver resolver, Class<?> type) {
if (resolver != null) {
String typeName = ReflectionUtils.getTypeName(type);
if (typeName != null) {
typedResolvers.put(type, resolver);
}
}
} | java |
@Deprecated
public <T> T readObject(byte [] data, Class<T> clazz) {
return readDocument(data, clazz).get();
} | java |
@Deprecated
public <T> List<T> readObjectCollection(byte [] data, Class<T> clazz) {
return readDocumentCollection(data, clazz).get();
} | java |
private <T> T readObject(JsonNode source, Class<T> clazz, boolean handleRelationships)
throws IOException, IllegalAccessException, InstantiationException {
String identifier = createIdentifier(source);
T result = (T) resourceCache.get(identifier);
if (result == null) {
Class<?> type = getActualType(source,... | java |
private Map<String, Object> parseIncluded(JsonNode parent)
throws IOException, IllegalAccessException, InstantiationException {
Map<String, Object> result = new HashMap<>();
if (parent.has(INCLUDED)) {
// Get resources
Map<String, Object> includedResources = getIncludedResources(parent);
if (!included... | java |
private Map<String, Object> getIncludedResources(JsonNode parent)
throws IOException, IllegalAccessException, InstantiationException {
Map<String, Object> result = new HashMap<>();
if (parent.has(INCLUDED)) {
for (JsonNode jsonNode : parent.get(INCLUDED)) {
String type = jsonNode.get(TYPE).asText();
... | java |
private Object parseRelationship(JsonNode relationshipDataNode, Class<?> type)
throws IOException, IllegalAccessException, InstantiationException {
if (ValidationUtils.isRelationshipParsable(relationshipDataNode)) {
String identifier = createIdentifier(relationshipDataNode);
if (resourceCache.contains(ident... | java |
private void setIdValue(Object target, JsonNode idValue) throws IllegalAccessException {
Field idField = configuration.getIdField(target.getClass());
ResourceIdHandler idHandler = configuration.getIdHandler(target.getClass());
if (idValue != null) {
idField.set(target, idHandler.fromString(idValue.asText()));... | java |
private RelationshipResolver getResolver(Class<?> type) {
RelationshipResolver resolver = typedResolvers.get(type);
return resolver != null ? resolver : globalResolver;
} | java |
public boolean registerType(Class<?> type) {
if (!configuration.isRegisteredType(type) && ConverterConfiguration.isEligibleType(type)) {
return configuration.registerType(type);
}
return false;
} | java |
public static List<Field> getAnnotatedFields(Class<?> clazz, Class<? extends Annotation> annotation,
boolean checkSuperclass) {
Field [] fields = clazz.getDeclaredFields();
List<Field> result = new ArrayList<>();
for (Field field : fields) {
if (field.isAnnotationPresent(annotation)) {
resul... | java |
public static String getTypeName(Class<?> clazz) {
Type typeAnnotation = clazz.getAnnotation(Type.class);
return typeAnnotation != null ? typeAnnotation.value() : null;
} | java |
public void init() {
if (initDepth.get() == null) {
initDepth.set(1);
} else {
initDepth.set(initDepth.get() + 1);
}
if (resourceCache.get() == null) {
resourceCache.set(new HashMap<String, Object>());
}
if (cacheLocked.get() == null) {
cacheLocked.set(Boolean.FALSE);
}
} | java |
public void clear() {
verifyState();
initDepth.set(initDepth.get() - 1);
if (initDepth.get() == 0) {
resourceCache.set(null);
cacheLocked.set(null);
initDepth.set(null);
}
} | java |
public void cache(Map<String, Object> resources) {
verifyState();
if (!cacheLocked.get()) {
resourceCache.get().putAll(resources);
}
} | java |
public void cache(String identifier, Object resource) {
verifyState();
if (!cacheLocked.get()) {
resourceCache.get().put(identifier, resource);
}
} | java |
public static <T extends Errors> T parseErrorResponse(ObjectMapper mapper, ResponseBody errorResponse, Class<T> cls) throws IOException {
return mapper.readValue(errorResponse.bytes(), cls);
} | java |
public static <T extends Errors> T parseError(ObjectMapper mapper, JsonNode errorResponse, Class<T> cls) throws JsonProcessingException {
return mapper.treeToValue(errorResponse, cls);
} | java |
public static <L, R> Either<L, R> left(L l) {
return new Left<>(l);
} | java |
public static <L, R> Either<L, R> right(R r) {
return new Right<>(r);
} | java |
public static <X> Lens.Simple<List<X>, List<X>> asCopy() {
return simpleLens(ArrayList::new, (xs, ys) -> ys);
} | java |
public static <T extends Throwable, A> Try<T, A> success(A a) {
return new Success<>(a);
} | java |
public static <T extends Throwable, A> Try<T, A> failure(T t) {
return new Failure<>(t);
} | java |
public <B> State<S, B> mapState(Fn1<? super Tuple2<A, S>, ? extends Product2<B, S>> fn) {
return state(s -> fn.apply(run(s)));
} | java |
public State<S, A> withState(Fn1<? super S, ? extends S> fn) {
return state(s -> run(fn.apply(s)));
} | java |
public static <Head, Tail extends HList> HCons<Head, Tail> cons(Head head, Tail tail) {
return new HCons<>(head, tail);
} | java |
@SuppressWarnings("JavaDoc")
public static <_1, _2> Tuple2<_1, _2> tuple(_1 _1, _2 _2) {
return singletonHList(_2).cons(_1);
} | java |
@SuppressWarnings("JavaDoc")
public static <_1, _2, _3> Tuple3<_1, _2, _3> tuple(_1 _1, _2 _2, _3 _3) {
return tuple(_2, _3).cons(_1);
} | java |
@SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4> Tuple4<_1, _2, _3, _4> tuple(_1 _1, _2 _2, _3 _3, _4 _4) {
return tuple(_2, _3, _4).cons(_1);
} | java |
@SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5> Tuple5<_1, _2, _3, _4, _5> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5) {
return tuple(_2, _3, _4, _5).cons(_1);
} | java |
@SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6> Tuple6<_1, _2, _3, _4, _5, _6> tuple(_1 _1, _2 _2, _3 _3, _4 _4, _5 _5,
_6 _6) {
return tuple(_2, _3, _4, _5, _6).cons(_1);
} | java |
@SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6, _7> Tuple7<_1, _2, _3, _4, _5, _6, _7> tuple(_1 _1, _2 _2, _3 _3, _4 _4,
_5 _5, _6 _6, _7 _7) {
return tuple(_2, _3, _4, _5, _6, _7).cons(_1);
} | java |
@SuppressWarnings("JavaDoc")
public static <_1, _2, _3, _4, _5, _6, _7, _8> Tuple8<_1, _2, _3, _4, _5, _6, _7, _8> tuple(_1 _1, _2 _2, _3 _3,
_4 _4, _5 _5, _6 _6,
... | java |
public static <A> Lazy<A> lazy(Supplier<A> supplier) {
return new Later<>(fn0(supplier));
} | java |
public static <K, V> Lens.Simple<Map<K, V>, Map<K, V>> asCopy() {
return adapt(asCopy(HashMap::new));
} | java |
public static <K, V> Lens.Simple<Map<K, V>, Set<K>> keys() {
return simpleLens(m -> new HashSet<>(m.keySet()), (m, ks) -> {
HashSet<K> ksCopy = new HashSet<>(ks);
Map<K, V> updated = new HashMap<>(m);
Set<K> keys = updated.keySet();
keys.retainAll(ksCopy);
... | java |
@SuppressWarnings("unchecked")
public <A, B> Maybe<B> get(TypeSafeKey<A, B> key) {
return maybe((A) table.get(key)).fmap(view(key));
} | java |
public <V> HMap put(TypeSafeKey<?, V> key, V value) {
return alter(t -> t.put(key, view(key.mirror(), value)));
} | java |
public static <V> HMap singletonHMap(TypeSafeKey<?, V> key, V value) {
return emptyHMap().put(key, value);
} | java |
public static <V1, V2> HMap hMap(TypeSafeKey<?, V1> key1, V1 value1,
TypeSafeKey<?, V2> key2, V2 value2) {
return singletonHMap(key1, value1).put(key2, value2);
} | java |
public static <V1, V2, V3> HMap hMap(TypeSafeKey<?, V1> key1, V1 value1,
TypeSafeKey<?, V2> key2, V2 value2,
TypeSafeKey<?, V3> key3, V3 value3) {
return hMap(key1, value1,
key2, value2)
.put(ke... | java |
public final Command createVerbosityCommand(CountDownLatch latch, int level, boolean noreply) {
return new TextVerbosityCommand(latch, level, noreply);
} | java |
protected final int blockingRead() throws ClosedChannelException, IOException {
int n = 0;
int readCount = 0;
Selector readSelector = SelectorFactory.getSelector();
SelectionKey tmpKey = null;
try {
if (this.selectableChannel.isOpen()) {
tmpKey = this.selectableChannel.register(readSel... | java |
protected byte[] encodeString(String in) {
byte[] rv = null;
try {
rv = in.getBytes(this.charset);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return rv;
} | java |
@SuppressWarnings("unchecked")
public final Command optimiezeMergeBuffer(Command optimiezeCommand, final Queue writeQueue,
final Queue<Command> executingCmds, int sendBufferSize) {
if (log.isDebugEnabled()) {
log.debug("Optimieze merge buffer:" + optimiezeCommand.toString());
}
if (this.optimi... | java |
@SuppressWarnings("unchecked")
public final Command optimiezeGet(final Queue writeQueue, final Queue<Command> executingCmds,
Command optimiezeCommand) {
if (optimiezeCommand.getCommandType() == CommandType.GET_ONE
|| optimiezeCommand.getCommandType() == CommandType.GETS_ONE) {
if (this.optimie... | java |
public static AuthInfo plain(String username, String password) {
return new AuthInfo(new PlainCallbackHandler(username, password), new String[] {"PLAIN"});
} | java |
public static AuthInfo cramMD5(String username, String password) {
return new AuthInfo(new PlainCallbackHandler(username, password), new String[] {"CRAM-MD5"});
} | java |
@Override
public AWSElasticCacheClient build() throws IOException {
AWSElasticCacheClient memcachedClient =
new AWSElasticCacheClient(this.sessionLocator, this.sessionComparator, this.bufferAllocator,
this.configuration, this.socketOptions, this.commandFactory, this.transcoder,
th... | java |
public static URL getResourceURL(String resource) throws IOException {
URL url = null;
ClassLoader loader = ResourcesUtils.class.getClassLoader();
if (loader != null) {
url = loader.getResource(resource);
}
if (url == null) {
url = ClassLoader.getSystemResource(resource);
}
if (u... | java |
public static InputStream getResourceAsStream(String resource) throws IOException {
InputStream in = null;
ClassLoader loader = ResourcesUtils.class.getClassLoader();
if (loader != null) {
in = loader.getResourceAsStream(resource);
}
if (in == null) {
in = ClassLoader.getSystemResourceAs... | java |
protected void initialSelectorManager() throws IOException {
if (this.selectorManager == null) {
this.selectorManager = new SelectorManager(this.selectorPoolSize, this, this.configuration);
this.selectorManager.start();
}
} | java |
public void onRead(SelectionKey key) {
if (this.readEventDispatcher == null) {
dispatchReadEvent(key);
} else {
this.readEventDispatcher.dispatch(new ReadTask(key));
}
} | java |
public void onWrite(final SelectionKey key) {
if (this.writeEventDispatcher == null) {
dispatchWriteEvent(key);
} else {
this.writeEventDispatcher.dispatch(new WriteTask(key));
}
} | java |
public void closeSelectionKey(SelectionKey key) {
if (key.attachment() instanceof Session) {
Session session = (Session) key.attachment();
if (session != null) {
session.close();
}
}
} | java |
protected final NioSessionConfig buildSessionConfig(SelectableChannel sc,
Queue<WriteMessage> queue) {
final NioSessionConfig sessionConfig =
new NioSessionConfig(sc, getHandler(), this.selectorManager, getCodecFactory(),
getStatistics(), queue, this.dispatchMessageDispatcher, isHandleRead... | java |
protected void readHeader(ByteBuffer buffer) {
super.readHeader(buffer);
if (this.responseStatus != ResponseStatus.NO_ERROR) {
if (ByteUtils.stepBuffer(buffer, this.responseTotalBodyLength)) {
this.decodeStatus = BinaryDecodeStatus.DONE;
}
}
} | java |
public ClusterConfigration getConfig(String key)
throws MemcachedException, InterruptedException, TimeoutException {
Command cmd = this.commandFactory.createAWSElasticCacheConfigCommand("get", key);
final Session session = this.sendCommand(cmd);
this.latchWait(cmd, opTimeout, session);
cmd.getIoBu... | java |
public static final String nextLine(ByteBuffer buffer) {
if (buffer == null) {
return null;
}
int index = MemcachedDecoder.SPLIT_MATCHER
.matchFirst(com.google.code.yanf4j.buffer.IoBuffer.wrap(buffer));
if (index >= 0) {
int limit = buffer.limit();
buffer.limit(index);
b... | java |
protected final void configureSocketChannel(SocketChannel sc) throws IOException {
sc.socket().setSoTimeout(this.soTimeout);
sc.configureBlocking(false);
if (this.socketOptions.get(StandardSocketOption.SO_REUSEADDR) != null) {
sc.socket().setReuseAddress(StandardSocketOption.SO_REUSEADDR.type()
... | java |
protected void readHeader(ByteBuffer buffer) {
super.readHeader(buffer);
if (this.responseStatus == ResponseStatus.NO_ERROR) {
this.decodeStatus = BinaryDecodeStatus.DONE;
}
} | java |
public void bind(InetSocketAddress inetSocketAddress) throws IOException {
if (inetSocketAddress == null) {
throw new IllegalArgumentException("Null inetSocketAddress");
}
setLocalSocketAddress(inetSocketAddress);
start();
} | java |
@Override
public final void onMessageReceived(final Session session, final Object msg) {
Command command = (Command) msg;
if (this.statisticsHandler.isStatistics()) {
if (command.getCopiedMergeCount() > 0 && command instanceof MapReturnValueAware) {
Map<String, CachedData> returnValues = ((MapRe... | java |
@Override
public void onSessionStarted(Session session) {
session.setUseBlockingRead(true);
session.setAttribute(HEART_BEAT_FAIL_COUNT_ATTR, new AtomicInteger(0));
for (MemcachedClientStateListener listener : this.client.getStateListeners()) {
listener.onConnected(this.client, session.getRemoteSocke... | java |
protected void reconnect(MemcachedTCPSession session) {
if (!this.client.isShutdown()) {
// Prevent reconnecting repeatedly
synchronized (session) {
if (!session.isAllowReconnect()) {
return;
}
session.setAllowReconnect(false);
}
MemcachedSession memcachedTC... | java |
public static void setAllocator(IoBufferAllocator newAllocator) {
if (newAllocator == null) {
throw new NullPointerException("allocator");
}
IoBufferAllocator oldAllocator = allocator;
allocator = newAllocator;
if (null != oldAllocator) {
oldAllocator.dispose();
}
} | java |
public static IoBuffer allocate(int capacity, boolean direct) {
if (capacity < 0) {
throw new IllegalArgumentException("capacity: " + capacity);
}
return allocator.allocate(capacity, direct);
} | java |
public static IoBuffer wrap(byte[] byteArray, int offset, int length) {
return wrap(ByteBuffer.wrap(byteArray, offset, length));
} | java |
private boolean lookJVMBug(long before, int selected, long wait) throws IOException {
boolean seeing = false;
long now = System.currentTimeMillis();
if (JVMBUG_THRESHHOLD > 0 && selected == 0 && wait > JVMBUG_THRESHHOLD
&& now - before < wait / 4 && !wakenUp.get() /* waken up */
&& !Thread.... | java |
public final void dispatchEvent(Set<SelectionKey> selectedKeySet) {
Iterator<SelectionKey> it = selectedKeySet.iterator();
boolean skipOpRead = false;
while (it.hasNext()) {
SelectionKey key = it.next();
it.remove();
if (!key.isValid()) {
if (key.attachment() != null) {
c... | java |
public final void addServer(final String server, final int port, int weight) throws IOException {
if (weight <= 0) {
throw new IllegalArgumentException("weight<=0");
}
this.checkServerPort(server, port);
this.connect(new InetSocketAddressWrapper(this.newSocketAddress(server, port),
this.se... | java |
private final Collection<List<String>> catalogKeys(final Collection<String> keyCollections) {
final Map<Session, List<String>> catalogMap = new HashMap<Session, List<String>>();
for (String key : keyCollections) {
Session index = this.sessionLocator.getSessionByKey(key);
List<String> tmpKeys = cata... | java |
public final void deleteWithNoReply(final String key, final int time)
throws InterruptedException, MemcachedException {
try {
this.delete0(key, time, 0, true, this.opTimeout);
} catch (TimeoutException e) {
throw new MemcachedException(e);
}
} | java |
public String getNamespace(String ns)
throws TimeoutException, InterruptedException, MemcachedException {
String key = this.keyProvider.process(this.getNSKey(ns));
byte[] keyBytes = ByteUtils.getBytes(key);
ByteUtils.checkKey(keyBytes);
Object item = this.fetch0(key, keyBytes, CommandType.GET_ONE,... | java |
public final static void setMaxSelectors(int size) throws IOException {
synchronized (selectors) {
if (size < maxSelectors) {
reduce(size);
} else if (size > maxSelectors) {
grow(size);
}
maxSelectors = size;
}
} | java |
private boolean advanceHead(QNode h, QNode nh) {
if (h == this.head.get() && this.head.compareAndSet(h, nh)) {
h.next = h; // forget old next
return true;
}
return false;
} | java |
private QNode getValidatedTail() {
for (;;) {
QNode h = this.head.get();
QNode first = h.next;
if (first != null && first.next == first) { // help advance
advanceHead(h, first);
continue;
}
QNode t = this.tail.get();
QNode last = t.next;
if (t == this.tail.g... | java |
QNode traversalHead() {
for (;;) {
QNode t = this.tail.get();
QNode h = this.head.get();
if (h != null && t != null) {
QNode last = t.next;
QNode first = h.next;
if (t == this.tail.get()) {
if (last != null) {
this.tail.compareAndSet(t, last);
... | java |
public static ClusterConfigration parseConfiguration(String line) {
String[] lines = line.trim().split("(?:\\r?\\n)");
if (lines.length < 2) {
throw new IllegalArgumentException("Incorrect config response:" + line);
}
String configversion = lines[0];
String nodeListStr = lines[1];
if (!Byt... | java |
public long get() throws MemcachedException, InterruptedException, TimeoutException {
Object result = this.memcachedClient.get(this.key);
if (result == null) {
throw new MemcachedClientException("key is not existed.");
} else {
if (result instanceof Long)
return (Long) result;
else... | java |
public void set(long value) throws MemcachedException, InterruptedException, TimeoutException {
this.memcachedClient.set(this.key, 0, String.valueOf(value));
} | java |
public long addAndGet(long delta)
throws MemcachedException, InterruptedException, TimeoutException {
if (delta >= 0) {
return this.memcachedClient.incr(this.key, delta, this.initialValue);
} else {
return this.memcachedClient.decr(this.key, -delta, this.initialValue);
}
} | java |
public static char[] getAllowedFunctionCharacters() {
char[] chars = new char[53];
int count = 0;
for (int i = 65; i < 91; i++) {
chars[count++] = (char) i;
}
for (int i = 97; i < 123; i++) {
chars[count++] = (char) i;
}
chars[count] = '_';... | java |
public static Function getBuiltinFunction(final String name) {
if (name.equals("sin")) {
return builtinFunctions[INDEX_SIN];
} else if (name.equals("cos")) {
return builtinFunctions[INDEX_COS];
} else if (name.equals("tan")) {
return builtinFunctions[INDEX_TA... | java |
public static List<Boolean> unmodifiableView(boolean[] array, int length)
{
return Collections.unmodifiableList(view(array, length));
} | java |
public static BooleanList view(boolean[] array, int length)
{
if(length > array.length || length < 0)
throw new IllegalArgumentException("length must be non-negative and no more than the size of the array("+array.length+"), not " + length);
return new BooleanList(array, length);
} | java |
public void setMomentum(double momentum)
{
if(momentum < 0 || Double.isNaN(momentum) || Double.isInfinite(momentum))
throw new ArithmeticException("Momentum must be non negative, not " + momentum);
this.momentum = momentum;
} | java |
public void setWeightDecay(double weightDecay)
{
if(weightDecay < 0 || weightDecay >= 1 || Double.isNaN(weightDecay))
throw new ArithmeticException("Weight decay must be in [0,1), not " + weightDecay);
this.weightDecay = weightDecay;
} | java |
private void setUp(Random rand)
{
Ws = new ArrayList<>(npl.length);
bs = new ArrayList<>(npl.length);
//First Hiden layer takes input raw
DenseMatrix W = new DenseMatrix(npl[0], inputSize);
Vec b = new DenseVector(W.rows());
initializeWeights(W, rand);
... | java |
private double computeOutputDelta(DataSet dataSet, final int idx, Vec delta_out, Vec a_i, Vec d_i)
{
double error = 0;
if (dataSet instanceof ClassificationDataSet)
{
ClassificationDataSet cds = (ClassificationDataSet) dataSet;
final int ct = cds.getDataPointCategory(... | java |
private void feedForward(Vec input, List<Vec> activations, List<Vec> derivatives)
{
Vec x = input;
for(int i = 0; i < Ws.size(); i++)
{
Matrix W_i = Ws.get(i);
Vec b_i = bs.get(i);
Vec a_i = activations.get(i);
a_i.zeroOut();
W_i.m... | java |
private Vec feedForward(Vec input)
{
Vec x = input;
for(int i = 0; i < Ws.size(); i++)
{
Matrix W_i = Ws.get(i);
Vec b_i = bs.get(i);
Vec a_i = W_i.multiply(x);
a_i.mutableAdd(b_i);
a_i.applyFunction(f);
... | java |
public void setRegularization(double regularization)
{
if(Double.isNaN(regularization) || Double.isInfinite(regularization) || regularization <= 0)
throw new ArithmeticException("Regularization must be a positive constant, not " + regularization);
this.regularization = regularization;
... | java |
public void sortByEigenValue(Comparator<Double> cmp)
{
if(isComplex())
throw new ArithmeticException("Eigen values can not be sorted due to complex results");
IndexTable it = new IndexTable(DoubleList.unmodifiableView(d, d.length), cmp);
for(int i = 0; i < d.length; i++)... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.