code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public List<C> findAllChildren() {
List<String> objects = getChildrenList();
List<C> children = new ArrayList<C>();
try {
Model dummy = (Model) childClazz.newInstance();
dummy.setContext(context);
for (String id : objects) {
children.add((C)... | java |
private Collection<Facet> filter(Collection<Facet> facets) {
if (NotStopWordPredicate == null) {
return facets;
}
return facets.stream()
.filter(NotStopWordPredicate)
.collect(Collectors.toList());
} | java |
public ConsistentHashRing getRing(String type) {
ConsistentHashRing ring = rings.get(type);
if (ring != null) {
return ring;
}
if (type == null) {
//If there's no ring without a type, then any type will do
//Use weighted random among the types, based on how many servers are serving each type
int sel... | java |
public void add(DOCUMENT doc) {
if (doc != null) {
documents.add(doc);
int id = documents.size() - 1;
for (KEY key : documentMapper.apply(doc)) {
index.put(key, id);
}
}
} | java |
public ScriptEnvironment getEnvironment(String environmentName) {
Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName),
"Environment name cannot be null or empty"
);
ScriptEngine engine = engineManager.getEngineByName(en... | java |
public static ScriptEnvironment getTemporaryEnvironment(String environmentName) {
Preconditions.checkArgument(StringUtils.isNotNullOrBlank(environmentName),
"Environment name cannot be null or empty"
);
ScriptEngine engine = ScriptEnvironmen... | java |
public String getEnvironmentNameForExtension(String extension) {
Preconditions.checkArgument(StringUtils.isNotNullOrBlank(extension), "Extension name cannot be null or empty");
ScriptEngine engine = engineManager.getEngineByExtension(extension);
Preconditions.checkArgument(engine != null, extension + ... | java |
public Set<Constructor<?>> getConstructors(boolean privileged) {
if (privileged) {
return Collections.unmodifiableSet(Sets.union(constructors, declaredConstructors));
} else {
return Collections.unmodifiableSet(constructors);
}
} | java |
public Set<Field> getFields(boolean privileged) {
if (privileged) {
return Collections.unmodifiableSet(Sets.union(fields, declaredFields));
} else {
return Collections.unmodifiableSet(fields);
}
} | java |
protected T getParentFromConfig() {
//TODO: Move this to a converter
String parentName = Config.get(canonicalName(), "parent").asString(null);
if (parentName != null && DynamicEnum.isDefined(Cast.as(getClass()), parentName)) {
return DynamicEnum.valueOf(Cast.as(getClass()), parentName);
... | java |
public static HttpHandler createRootHandler(
List<MappedEndpoint> mappedEndpoints,
List<Interceptor> rootInterceptors,
List<Interceptor> endpointInterceptors,
ExceptionMapper exceptionMapper,
String basePath,
boolean httpTracer) {
final Ro... | java |
private void increaseLevel(boolean list)
{
level++;
if(hasData.length == level)
{
// Grow lists when needed
hasData = Arrays.copyOf(hasData, hasData.length * 2);
lists = Arrays.copyOf(lists, hasData.length * 2);
}
hasData[level] = false;
lists[level] = list;
} | java |
private void writeName(String name)
throws IOException
{
if(shouldOutputName())
{
out.write(TAG_KEY);
writeStringNoTag(name);
}
} | java |
private void writeIntegerNoTag(int value)
throws IOException
{
while(true)
{
if((value & ~0x7F) == 0)
{
out.write(value);
break;
}
else
{
out.write((value & 0x7f) | 0x80);
value >>>= 7;
}
}
} | java |
private void writeInteger(int value)
throws IOException
{
if(value < 0)
{
out.write(TAG_NEGATIVE_INT);
writeIntegerNoTag(-value);
}
else
{
out.write(TAG_POSITIVE_INT);
writeIntegerNoTag(value);
}
} | java |
public static boolean check(String passwd, String hashed) {
try {
String[] parts = hashed.split("\\$");
if (parts.length != 5 || !parts[1].equals("s0")) {
throw new IllegalArgumentException("Invalid hashed value");
}
long params = Long.parseLong(... | java |
public static Platform detect() throws UnsupportedPlatformException {
String osArch = getProperty("os.arch");
String osName = getProperty("os.name");
for (Arch arch : Arch.values()) {
if (arch.pattern.matcher(osArch).matches()) {
for (OS os : OS.values()) {
... | java |
public <T> T getNodeMetaData(Object key) {
if (metaDataMap == null) {
return (T) null;
}
return (T) metaDataMap.get(key);
} | java |
public void copyNodeMetaData(ASTNode other) {
if (other.metaDataMap == null) {
return;
}
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
metaDataMap.putAll(other.metaDataMap);
} | java |
public void setNodeMetaData(Object key, Object value) {
if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
Object old = metaDataMap.put(key,value);
if (old!=null) ... | java |
public Object putNodeMetaData(Object key, Object value) {
if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + ".");
if (metaDataMap == null) {
metaDataMap = new ListHashMap();
}
return metaDataMap.put(key, value);
} | java |
public void removeNodeMetaData(Object key) {
if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+".");
if (metaDataMap == null) {
return;
}
metaDataMap.remove(key);
} | java |
public RangeInfo subListBorders(int size) {
if (inclusive == null) throw new IllegalStateException("Should not call subListBorders on a non-inclusive aware IntRange");
int tempFrom = from;
if (tempFrom < 0) {
tempFrom += size;
}
int tempTo = to;
if (tempTo < 0... | java |
protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock) {
MethodNode setter = new MethodNode(
setterName,
propertyNode.getModifiers(),
ClassHelper.VOID_TYPE,
params(param... | java |
public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body) throws CompilationFailedException {
Iterator classNodes = getPrimaryClassNodes(body.needSortedInput()).iterator();
while (classNodes.hasNext()) {
SourceUnit context = null;
try {
ClassNode classN... | java |
public static <T> T withStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.InputStream","java.io.OutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
try {
T ... | java |
public static <T> T withObjectStreams(Socket socket, @ClosureParams(value=SimpleType.class, options={"java.io.ObjectInputStream","java.io.ObjectOutputStream"}) Closure<T> closure) throws IOException {
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
Ob... | java |
public MethodKey createCopy() {
int size = getParameterCount();
Class[] paramTypes = new Class[size];
for (int i = 0; i < size; i++) {
paramTypes[i] = getParameterType(i);
}
return new DefaultMethodKey(sender, name, paramTypes, isCallToSuper);
} | java |
public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) {
if (cNode.isInterface()) return;
boolean isItselfTrait = Traits.isTrait(cNode);
SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit);
if (isItselfTr... | java |
public SyntaxException getSyntaxError(int index) {
SyntaxException exception = null;
Message message = getError(index);
if (message != null && message instanceof SyntaxErrorMessage) {
exception = ((SyntaxErrorMessage) message).getCause();
}
return exception;
} | java |
private void gobble(Iterator iter)
{
if (eatTheRest)
{
while (iter.hasNext())
{
tokens.add(iter.next());
}
}
} | java |
public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args) {
if (params==null) {
params = Parameter.EMPTY_ARRAY;
}
int dist = 0;
if (args.length<params.length) return -1;
// we already know the lengths are equal
for (int i = 0; i < ... | java |
static int excessArgumentsMatchesVargsParameter(Parameter[] params, ClassNode[] args) {
// we already know parameter length is bigger zero and last is a vargs
// the excess arguments are all put in an array for the vargs call
// so check against the component type
int dist = 0;
C... | java |
static int lastArgMatchesVarg(Parameter[] params, ClassNode... args) {
if (!isVargs(params)) return -1;
// case length ==0 handled already
// we have now two cases,
// the argument is wrapped in the vargs array or
// the argument is an array that can be used for the vargs part di... | java |
private static Parameter buildParameter(final Map<String, GenericsType> genericFromReceiver, final Map<String, GenericsType> placeholdersFromContext, final Parameter methodParameter, final ClassNode paramType) {
if (genericFromReceiver.isEmpty() && (placeholdersFromContext==null||placeholdersFromContext.isEmpty... | java |
public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) {
GenericsType[] genericsTypes = classNode.getGenericsTypes();
return ClassHelper.CLASS_Type.equals(classNode)
&& classNode.isUsingGenerics()
&& genericsTypes!=null
&& !generic... | java |
public static <T> T splitEachLine(InputStream stream, String regex, String charset, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException {
return splitEachLine(new BufferedReader(new InputStreamReader(stream, charset)), regex, closure);
} | java |
public static void transformChar(Reader self, Writer writer, @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) throws IOException {
int c;
try {
char[] chars = new char[1];
while ((c = self.read()) != -1) {
chars[0] = (char) c;
... | java |
public static <T, U extends Closeable> T withCloseable(U self, @ClosureParams(value=FirstParam.class) Closure<T> action) throws IOException {
try {
T result = action.call(self);
Closeable temp = self;
self = null;
temp.close();
return result;
... | java |
public Object getProperty(Object object) {
return java.lang.reflect.Array.getLength(object);
} | java |
protected MethodVisitor makeDelegateCall(final String name, final String desc, final String signature, final String[] exceptions, final int accessFlags) {
MethodVisitor mv = super.visitMethod(accessFlags, name, desc, signature, exceptions);
mv.visitVarInsn(ALOAD, 0); // load this
mv.visitFieldIn... | java |
public static Method getSAMMethod(Class<?> c) {
// SAM = single public abstract method
// if the class is not abstract there is no abstract method
if (!Modifier.isAbstract(c.getModifiers())) return null;
if (c.isInterface()) {
Method[] methods = c.getMethods();
//... | java |
protected void generateMopCalls(LinkedList<MethodNode> mopCalls, boolean useThis) {
for (MethodNode method : mopCalls) {
String name = getMopMethodName(method, useThis);
Parameter[] parameters = method.getParameters();
String methodDescriptor = BytecodeHelper.getMethodDescrip... | java |
public static ClassNode getWrapper(ClassNode cn) {
cn = cn.redirect();
if (!isPrimitiveType(cn)) return cn;
if (cn==boolean_TYPE) {
return Boolean_TYPE;
} else if (cn==byte_TYPE) {
return Byte_TYPE;
} else if (cn==char_TYPE) {
return Character_... | java |
public static MethodNode findSAM(ClassNode type) {
if (!Modifier.isAbstract(type.getModifiers())) return null;
if (type.isInterface()) {
List<MethodNode> methods = type.getMethods();
MethodNode found=null;
for (MethodNode mi : methods) {
// ignore meth... | java |
public static int getPrecedence( int type, boolean throwIfInvalid ) {
switch( type ) {
case LEFT_PARENTHESIS:
return 0;
case EQUAL:
case PLUS_EQUAL:
case MINUS_EQUAL:
case MULTIPLY_EQUAL:
case DIVIDE_EQUAL:
ca... | java |
public <T> T with( Closure<T> closure ) {
return DefaultGroovyMethods.with( null, closure ) ;
} | java |
private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) {
List methods = classNode.getMethods();
if (argTypes == null || argTypes.length ==0) {
for (Iterator i = methods.iterator(); i.hasNext();) {
MethodNode mn = (MethodNode) i.n... | java |
public String getTypeDescriptor() {
if (typeDescriptor == null) {
StringBuilder buf = new StringBuilder(name.length() + parameters.length * 10);
buf.append(returnType.getName());
buf.append(' ');
buf.append(name);
buf.append('(');
for (int ... | java |
@Override
public String getText() {
String retType = AstToTextHelper.getClassText(returnType);
String exceptionTypes = AstToTextHelper.getThrowsClauseText(exceptions);
String parms = AstToTextHelper.getParametersText(parameters);
return AstToTextHelper.getModifiersText(modifiers) + "... | java |
public GroovyConstructorDoc[] constructors() {
Collections.sort(constructors);
return constructors.toArray(new GroovyConstructorDoc[constructors.size()]);
} | java |
public GroovyClassDoc[] innerClasses() {
Collections.sort(nested);
return nested.toArray(new GroovyClassDoc[nested.size()]);
} | java |
public GroovyFieldDoc[] fields() {
Collections.sort(fields);
return fields.toArray(new GroovyFieldDoc[fields.size()]);
} | java |
public GroovyFieldDoc[] properties() {
Collections.sort(properties);
return properties.toArray(new GroovyFieldDoc[properties.size()]);
} | java |
public GroovyFieldDoc[] enumConstants() {
Collections.sort(enumConstants);
return enumConstants.toArray(new GroovyFieldDoc[enumConstants.size()]);
} | java |
public GroovyMethodDoc[] methods() {
Collections.sort(methods);
return methods.toArray(new GroovyMethodDoc[methods.size()]);
} | java |
public void add(Map<String, Object> map) throws SQLException {
if (withinDataSetBatch) {
if (batchData.size() == 0) {
batchKeys = map.keySet();
} else {
if (!map.keySet().equals(batchKeys)) {
throw new IllegalArgumentException("Inconsis... | java |
public void each(int offset, int maxRows, Closure closure) throws SQLException {
eachRow(getSql(), getParameters(), offset, maxRows, closure);
} | java |
private void wrapSetterMethod(ClassNode classNode, boolean bindable, String propertyName) {
String getterName = "get" + MetaClassHelper.capitalize(propertyName);
MethodNode setter = classNode.getSetterMethod("set" + MetaClassHelper.capitalize(propertyName));
if (setter != null) {
... | java |
public static long directorySize(File self) throws IOException, IllegalArgumentException
{
final long[] size = {0L};
eachFileRecurse(self, FileType.FILES, new Closure<Void>(null) {
public void doCall(Object[] args) {
size[0] += ((File) args[0]).length();
}
... | java |
public static <T> T splitEachLine(File self, String regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure<T> closure) throws IOException {
return IOGroovyMethods.splitEachLine(newReader(self), regex, closure);
} | java |
public static void write(File file, String text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file);
writeUTF16BomIfRequired(charset, out);
writer = new OutputStreamWriter(out, charset);
write... | java |
public static void append(File file, Object text) throws IOException {
Writer writer = null;
try {
writer = new FileWriter(file, true);
InvokerHelper.write(writer, text);
writer.flush();
Writer temp = writer;
writer = null;
temp.cl... | java |
public static void append(File file, Object text, String charset) throws IOException {
Writer writer = null;
try {
FileOutputStream out = new FileOutputStream(file, true);
if (!file.exists()) {
writeUTF16BomIfRequired(charset, out);
}
write... | java |
public static void append(File file, Writer writer, String charset) throws IOException {
appendBuffered(file, writer, charset);
} | java |
private static void writeUtf16Bom(OutputStream stream, boolean bigEndian) throws IOException {
if (bigEndian) {
stream.write(-2);
stream.write(-1);
} else {
stream.write(-1);
stream.write(-2);
}
} | java |
protected Class getClassCacheEntry(String name) {
if (name == null) return null;
synchronized (classCache) {
return classCache.get(name);
}
} | java |
public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners() {
synchronized (changeListenerList) {
ArrayList<MetaClassRegistryChangeEventListener> ret =
new ArrayList<MetaClassRegistryChangeEventListener>(changeListenerList.size()+nonRemoveableChangeLi... | java |
public static MetaClassRegistry getInstance(int includeExtension) {
if (includeExtension != DONT_LOAD_DEFAULT) {
if (instanceInclude == null) {
instanceInclude = new MetaClassRegistryImpl();
}
return instanceInclude;
} else {
if (instanceEx... | java |
public CSTNode get( int index )
{
CSTNode element = null;
if( index < size() )
{
element = (CSTNode)elements.get( index );
}
return element;
} | java |
public CSTNode set( int index, CSTNode element )
{
if( elements == null )
{
throw new GroovyBugError( "attempt to set() on a EMPTY Reduction" );
}
if( index == 0 && !(element instanceof Token) )
{
//
// It's not the greatest o... | java |
public void add(T value) {
Element<T> element = new Element<T>(bundle, value);
element.previous = tail;
if (tail != null) tail.next = element;
tail = element;
if (head == null) head = element;
} | java |
public T[] toArray(T[] tArray) {
List<T> array = new ArrayList<T>(100);
for (Iterator<T> it = iterator(); it.hasNext();) {
T val = it.next();
if (val != null) array.add(val);
}
return array.toArray(tArray);
} | java |
public Value get(Object key) {
/* If the length is under and we are asking for the key, then just look for the key. Don't build the map. */
if (map == null && items.length < 20) {
for (Object item : items) {
MapItemValue miv = (MapItemValue) item;
if (key.equa... | java |
public static <T> Iterator<T> unique(Iterator<T> self) {
return toList((Iterable<T>) unique(toList(self))).listIterator();
} | java |
public static int numberAwareCompareTo(Comparable self, Comparable other) {
NumberAwareComparator<Comparable> numberAwareComparator = new NumberAwareComparator<Comparable>();
return numberAwareComparator.compare(self, other);
} | java |
public static boolean any(Object self, Closure closure) {
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
if (bcw.call(iter.next())) return true;
}
return false;
} | java |
public static Object findResult(Object self, Object defaultResult, Closure closure) {
Object result = findResult(self, closure);
if (result == null) return defaultResult;
return result;
} | java |
protected static <K, T> void groupAnswer(final Map<K, List<T>> answer, T element, K value) {
if (answer.containsKey(value)) {
answer.get(value).add(element);
} else {
List<T> groupedElements = new ArrayList<T>();
groupedElements.add(element);
answer.put(va... | java |
public static <K,V> Map<K,V> asImmutable(Map<? extends K, ? extends V> self) {
return Collections.unmodifiableMap(self);
} | java |
public static <K,V> SortedMap<K,V> asImmutable(SortedMap<K, ? extends V> self) {
return Collections.unmodifiableSortedMap(self);
} | java |
public static <T> List<T> asImmutable(List<? extends T> self) {
return Collections.unmodifiableList(self);
} | java |
public static <T> Set<T> asImmutable(Set<? extends T> self) {
return Collections.unmodifiableSet(self);
} | java |
public static <T> SortedSet<T> asImmutable(SortedSet<T> self) {
return Collections.unmodifiableSortedSet(self);
} | java |
public static <T> T[] sort(T[] self, Comparator<T> comparator) {
return sort(self, true, comparator);
} | java |
public static <T> boolean addAll(Collection<T> self, Iterator<T> items) {
boolean changed = false;
while (items.hasNext()) {
T next = items.next();
if (self.add(next)) changed = true;
}
return changed;
} | java |
public static <T> boolean addAll(Collection<T> self, Iterable<T> items) {
boolean changed = false;
for (T next : items) {
if (self.add(next)) changed = true;
}
return changed;
} | java |
public static <K,V> Map<K,V> minus(Map<K,V> self, Map removeMe) {
final Map<K,V> ansMap = createSimilarMap(self);
ansMap.putAll(self);
if (removeMe != null && removeMe.size() > 0) {
for (Map.Entry<K, V> e1 : self.entrySet()) {
for (Object e2 : removeMe.entrySet()) {
... | java |
public static int findLastIndexOf(Object self, int startIndex, Closure closure) {
int result = -1;
int i = 0;
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext(); i++) {
Object value = iter.next()... | java |
public static List<Number> findIndexValues(Object self, Closure closure) {
return findIndexValues(self, 0, closure);
} | java |
public static List<Number> findIndexValues(Object self, Number startIndex, Closure closure) {
List<Number> result = new ArrayList<Number>();
long count = 0;
long startCount = startIndex.longValue();
BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
for (Iterator ite... | java |
public Object getProperty(String property) {
if(ExpandoMetaClass.isValidExpandoProperty(property)) {
if(property.equals(ExpandoMetaClass.STATIC_QUALIFIER) ||
property.equals(ExpandoMetaClass.CONSTRUCTOR) ||
myMetaClass.hasProperty(this, property) == null) {
... | java |
public static Message create( String text, Object data, ProcessingUnit owner )
{
return new SimpleMessage( text, data, owner);
} | java |
public Object invokeMethod(String name, Object args) {
Object val = null;
if (args != null && Object[].class.isAssignableFrom(args.getClass())) {
Object[] arr = (Object[]) args;
if (arr.length == 1) {
val = arr[0];
} else if (arr.length == 2 && arr[0]... | java |
public void setVariable(String name, Object value) {
if (variables == null)
variables = new LinkedHashMap();
variables.put(name, value);
} | java |
public Object getProperty(Object object) {
MetaMethod getter = getGetter();
if (getter == null) {
if (field != null) return field.getProperty(object);
//TODO: create a WriteOnlyException class?
throw new GroovyRuntimeException("Cannot read write-only property: " + nam... | java |
public void setProperty(Object object, Object newValue) {
MetaMethod setter = getSetter();
if (setter == null) {
if (field != null && !Modifier.isFinal(field.getModifiers())) {
field.setProperty(object, newValue);
return;
}
throw new Gr... | java |
public int getModifiers() {
MetaMethod getter = getGetter();
MetaMethod setter = getSetter();
if (setter != null && getter == null) return setter.getModifiers();
if (getter != null && setter == null) return getter.getModifiers();
int modifiers = getter.getModifiers() | setter.get... | java |
public static boolean isTrait(final ClassNode cNode) {
return cNode!=null
&& ((cNode.isInterface() && !cNode.getAnnotations(TRAIT_CLASSNODE).isEmpty())
|| isAnnotatedWithTrait(cNode));
} | java |
public static Method getBridgeMethodTarget(Method someMethod) {
TraitBridge annotation = someMethod.getAnnotation(TraitBridge.class);
if (annotation==null) {
return null;
}
Class aClass = annotation.traitClass();
String desc = annotation.desc();
for (Method me... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.