code
stringlengths
73
34.1k
label
stringclasses
1 value
public void updateBuildpackInstallations(String appName, List<String> buildpacks) { connection.execute(new BuildpackInstallationUpdate(appName, buildpacks), apiKey); }
java
static Artifact resolveConstrained(MavenProject project, String gav, Pattern versionRegex, ArtifactResolver resolver) throws VersionRangeResolutionException, ArtifactResolutionException { boolean latest = gav.endsWith(":LATEST"); if (latest || gav.endsWith(":RELEASE")) { ...
java
public static <X> ServiceTypeLoader<X> load(Class<X> serviceType) { return load(serviceType, Thread.currentThread().getContextClassLoader()); }
java
public static String stringifyJavascriptObject(Object object) { StringBuilder bld = new StringBuilder(); stringify(object, bld); return bld.toString(); }
java
@Nullable @SuppressWarnings("unchecked") protected <T extends JavaElement> ActiveElements<T> popIfActive() { return (ActiveElements<T>) (!activations.isEmpty() && activations.peek().depth == depth ? activations.pop() : null); }
java
@Nonnull public static Builder builder(Revapi revapi) { List<String> knownExtensionIds = new ArrayList<>(); addExtensionIds(revapi.getPipelineConfiguration().getApiAnalyzerTypes(), knownExtensionIds); addExtensionIds(revapi.getPipelineConfiguration().getTransformTypes(), knownExtensionIds);...
java
public AnalysisContext copyWithConfiguration(ModelNode configuration) { return new AnalysisContext(this.locale, configuration, this.oldApi, this.newApi, this.data); }
java
public static PipelineConfiguration.Builder parse(ModelNode json) { ModelNode analyzerIncludeNode = json.get("analyzers").get("include"); ModelNode analyzerExcludeNode = json.get("analyzers").get("exclude"); ModelNode filterIncludeNode = json.get("filters").get("include"); ModelNode filt...
java
private static void firstDotConstellation(int[] dollarPositions, int[] dotPositions, int nestingLevel) { int i = 0; int unassigned = dotPositions.length - nestingLevel; for (; i < unassigned; ++i) { dotPositions[i] = -1; } for (; i < dotPositions.length; ++i) { ...
java
public static AnalysisResult fakeSuccess() { return new AnalysisResult(null, new Extensions(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap())); }
java
static PlexusConfiguration convert(ModelNode configuration, ModelNode jsonSchema, String extensionId, String id) { ConversionContext ctx = new ConversionContext(); ctx.currentSchema = jsonSchema; ctx.rootSchema = jsonSchema; ctx.pushTag(extensionId); ctx.id = id; return c...
java
@SuppressWarnings("unchecked") public <T extends Annotation> T getAnnotation(Class<T> annotationType) { for (Annotation annotation : this.annotations) { if (annotation.annotationType().equals(annotationType)) { return (T) annotation; } } for (Annotation metaAnn : this.annotations) { T ann = metaAnn....
java
public static String encodeScheme(String scheme, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(scheme, encoding, HierarchicalUriComponents.Type.SCHEME); }
java
public static String encodeAuthority(String authority, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(authority, encoding, HierarchicalUriComponents.Type.AUTHORITY); }
java
public static String encodeUserInfo(String userInfo, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(userInfo, encoding, HierarchicalUriComponents.Type.USER_INFO); }
java
public static String encodeHost(String host, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(host, encoding, HierarchicalUriComponents.Type.HOST_IPV4); }
java
public static String encodePort(String port, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(port, encoding, HierarchicalUriComponents.Type.PORT); }
java
public static String encodePath(String path, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(path, encoding, HierarchicalUriComponents.Type.PATH); }
java
public static String encodePathSegment(String segment, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(segment, encoding, HierarchicalUriComponents.Type.PATH_SEGMENT); }
java
public static String encodeQuery(String query, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(query, encoding, HierarchicalUriComponents.Type.QUERY); }
java
public static String encodeQueryParam(String queryParam, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(queryParam, encoding, HierarchicalUriComponents.Type.QUERY_PARAM); }
java
public static String encodeFragment(String fragment, String encoding) throws UnsupportedEncodingException { return HierarchicalUriComponents.encodeUriComponent(fragment, encoding, HierarchicalUriComponents.Type.FRAGMENT); }
java
public void setReadTimeout(int readTimeout) { this.client = this.client.newBuilder() .readTimeout(readTimeout, TimeUnit.MILLISECONDS) .build(); }
java
public void setWriteTimeout(int writeTimeout) { this.client = this.client.newBuilder() .writeTimeout(writeTimeout, TimeUnit.MILLISECONDS) .build(); }
java
public void setConnectTimeout(int connectTimeout) { this.client = this.client.newBuilder() .connectTimeout(connectTimeout, TimeUnit.MILLISECONDS) .build(); }
java
public void addComparator(Comparator<T> comparator, boolean ascending) { this.comparators.add(new InvertibleComparator<T>(comparator, ascending)); }
java
public static void copy(String in, Writer out) throws IOException { Assert.notNull(in, "No input String specified"); Assert.notNull(out, "No Writer specified"); try { out.write(in); } finally { try { out.close(); } catch (IOException ex) { } } }
java
public boolean matches(String uri) { if (uri == null) { return false; } Matcher matcher = this.matchPattern.matcher(uri); return matcher.matches(); }
java
public boolean exists() { // Try file existence: can we find the file in the file system? try { return getFile().exists(); } catch (IOException ex) { // Fall back to stream existence: can we open the stream? try { InputStream is = getInputStream(); is.close(); return true; } catch (Th...
java
static String expandUriComponent(String source, UriTemplateVariables uriVariables) { if (source == null) { return null; } if (source.indexOf('{') == -1) { return source; } Matcher matcher = NAMES_PATTERN.matcher(source); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String match ...
java
public static boolean isAssignable(Type lhsType, Type rhsType) { Assert.notNull(lhsType, "Left-hand side type must not be null"); Assert.notNull(rhsType, "Right-hand side type must not be null"); // all types are assignable to themselves and to class Object if (lhsType.equals(rhsType) || lhsType.equals(Object....
java
static String encodeUriComponent(String source, String encoding, Type type) throws UnsupportedEncodingException { if (source == null) { return null; } Assert.hasLength(encoding, "Encoding must not be empty"); byte[] bytes = encodeBytes(source.getBytes(encoding), type); return new String(bytes, "US-ASCII");...
java
protected HttpUriRequest createHttpRequest(HttpMethod httpMethod, URI uri) { switch (httpMethod) { case GET: return new HttpGet(uri); case DELETE: return new HttpDelete(uri); case HEAD: return new HttpHead(uri); case OPTIONS: return new HttpOptions(uri); case POST: return new HttpPo...
java
public static void registerConverters(Set<?> converters, ConverterRegistry registry) { if (converters != null) { for (Object converter : converters) { if (converter instanceof GenericConverter) { registry.addConverter((GenericConverter) converter); } else if (converter instanceof Converter<?, ?>) ...
java
public static <K,V> MultiValueMap<K,V> unmodifiableMultiValueMap(MultiValueMap<? extends K, ? extends V> map) { Assert.notNull(map, "'map' must not be null"); Map<K, List<V>> result = new LinkedHashMap<K, List<V>>(map.size()); for (Map.Entry<? extends K, ? extends List<? extends V>> entry : map.entrySet()) { L...
java
public static String copyToString(InputStream in, Charset charset) throws IOException { Assert.notNull(in, "No InputStream specified"); StringBuilder out = new StringBuilder(); InputStreamReader reader = new InputStreamReader(in, charset); char[] buffer = new char[BUFFER_SIZE]; int bytesRead = -1; while ((b...
java
public static void copy(byte[] in, OutputStream out) throws IOException { Assert.notNull(in, "No input byte array specified"); Assert.notNull(out, "No OutputStream specified"); out.write(in); }
java
private int handleIOException(IOException ex) throws IOException { if (AUTH_ERROR.equals(ex.getMessage()) || AUTH_ERROR_JELLY_BEAN.equals(ex.getMessage())) { return HttpStatus.UNAUTHORIZED.value(); } else if (PROXY_AUTH_ERROR.equals(ex.getMessage())) { return HttpStatus.PROXY_AUTHENTICATION_REQUIRED.value(); ...
java
public static TextEncryptor queryableText(CharSequence password, CharSequence salt) { return new HexEncodingTextEncryptor(new AndroidAesBytesEncryptor(password.toString(), salt, AndroidKeyGenerators.shared(16))); }
java
public static UriComponentsBuilder fromPath(String path) { UriComponentsBuilder builder = new UriComponentsBuilder(); builder.path(path); return builder; }
java
public UriComponentsBuilder uri(URI uri) { Assert.notNull(uri, "'uri' must not be null"); this.scheme = uri.getScheme(); if (uri.isOpaque()) { this.ssp = uri.getRawSchemeSpecificPart(); resetHierarchicalComponents(); } else { if (uri.getRawUserInfo() != null) { this.userInfo = uri.getRawUserInfo(...
java
public UriComponentsBuilder pathSegment(String... pathSegments) throws IllegalArgumentException { Assert.notNull(pathSegments, "'segments' must not be null"); this.pathBuilder.addPathSegments(pathSegments); resetSchemeSpecificPart(); return this; }
java
public UriComponentsBuilder queryParams(MultiValueMap<String, String> params) { Assert.notNull(params, "'params' must not be null"); this.queryParams.putAll(params); return this; }
java
public UriComponentsBuilder replaceQueryParam(String name, Object... values) { Assert.notNull(name, "'name' must not be null"); this.queryParams.remove(name); if (!ObjectUtils.isEmpty(values)) { queryParam(name, values); } resetSchemeSpecificPart(); return this; }
java
private static void registerCommonClasses(Class<?>... commonClasses) { for (Class<?> clazz : commonClasses) { commonClassCache.put(clazz.getName(), clazz); } }
java
public static ClassLoader overrideThreadContextClassLoader(ClassLoader classLoaderToUse) { Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); if (classLoaderToUse != null && !classLoaderToUse.equals(threadContextClassLoader)) { currentTh...
java
public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); try { ClassLoader target = clazz.getClassLoader(); if (target == null) { return true; } ClassLoader cur = classLoader; if (cur == target) { return true; } while ...
java
public static String getShortName(String className) { Assert.hasLength(className, "Class name must not be empty"); int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR); int nameEndIndex = className.indexOf(CGLIB_CLASS_SEPARATOR); if (nameEndIndex == -1) { nameEndIndex = className.length(); } Strin...
java
public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>... args) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); try { Method method = clazz.getMethod(methodName, args); return Modifier.isStatic(method.getModifiers()) ? ...
java
public static boolean isPrimitiveArray(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isArray() && clazz.getComponentType().isPrimitive()); }
java
public static boolean isPrimitiveWrapperArray(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType())); }
java
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz); }
java
public static Class<?>[] toClassArray(Collection<Class<?>> collection) { if (collection == null) { return null; } return collection.toArray(new Class<?>[collection.size()]); }
java
public static Class<?> determineCommonAncestor(Class<?> clazz1, Class<?> clazz2) { if (clazz1 == null) { return clazz2; } if (clazz2 == null) { return clazz1; } if (clazz1.isAssignableFrom(clazz2)) { return clazz1; } if (clazz2.isAssignableFrom(clazz1)) { return clazz2; } Class<?> ancestor...
java
public static Class<?> resolveReturnType(Method method, Class<?> clazz) { Assert.notNull(method, "Method must not be null"); Type genericType = method.getGenericReturnType(); Assert.notNull(clazz, "Class must not be null"); Map<TypeVariable, Type> typeVariableMap = getTypeVariableMap(clazz); Type rawType = ge...
java
public static Class<?> resolveReturnTypeArgument(Method method, Class<?> genericIfc) { Assert.notNull(method, "method must not be null"); Type returnType = method.getReturnType(); Type genericReturnType = method.getGenericReturnType(); if (returnType.equals(genericIfc)) { if (genericReturnType instanceof Par...
java
public static Class<?> resolveTypeArgument(Class<?> clazz, Class<?> genericIfc) { Class<?>[] typeArgs = resolveTypeArguments(clazz, genericIfc); if (typeArgs == null) { return null; } if (typeArgs.length != 1) { throw new IllegalArgumentException("Expected 1 type argument on generic interface [" + ge...
java
private static Class<?> extractClass(Class<?> ownerClass, Type arg) { if (arg instanceof ParameterizedType) { return extractClass(ownerClass, ((ParameterizedType) arg).getRawType()); } else if (arg instanceof GenericArrayType) { GenericArrayType gat = (GenericArrayType) arg; Type gt = gat.getGenericCompo...
java
static Type getRawType(Type genericType, Map<TypeVariable, Type> typeVariableMap) { Type resolvedType = genericType; if (genericType instanceof TypeVariable) { TypeVariable tv = (TypeVariable) genericType; resolvedType = typeVariableMap.get(tv); if (resolvedType == null) { resolvedType = extractBoundFo...
java
public static Class<?> getMapValueFieldType(Field mapField, int nestingLevel) { return getGenericFieldType(mapField, Map.class, 1, null, nestingLevel); }
java
private static Class<?> getGenericReturnType(Method method, Class<?> source, int typeIndex, int nestingLevel) { return extractType(method.getGenericReturnType(), source, typeIndex, null, null, nestingLevel, 1); }
java
private static Class<?> extractTypeFromClass(Class<?> clazz, Class<?> source, int typeIndex, Map<TypeVariable, Type> typeVariableMap, Map<Integer, Integer> typeIndexesPerLevel, int nestingLevel, int currentLevel) { if (clazz.getName().startsWith("java.util.")) { return null; } if (clazz.getSuperclass() ...
java
@Override public boolean exists() { try { InputStream inputStream = this.assetManager.open(this.fileName); if (inputStream != null) { return true; } else { return false; } } catch (IOException e) { return false; } }
java
static void addHeaders(HttpUriRequest httpRequest, HttpHeaders headers) { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); if (HttpHeaders.COOKIE.equalsIgnoreCase(headerName)) { // RFC 6265 String headerValue = StringUtils.collectionToDelimitedString(en...
java
public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) { Assert.notNull(targetType, "The targetType to convert to cannot be null"); if (sourceType == null) { return true; } GenericConverter converter = getConverter(sourceType, targetType); return (converter == NO_OP_CONVERTER...
java
protected static int calculateShift(int minimumValue, int maximumValue) { int shift = 0; int value = 1; while (value < minimumValue && value < maximumValue) { value <<= 1; shift++; } return shift; }
java
public MediaType copyQualityValue(MediaType mediaType) { if (!mediaType.parameters.containsKey(PARAM_QUALITY_FACTOR)) { return this; } Map<String, String> params = new LinkedHashMap<String, String>(this.parameters); params.put(PARAM_QUALITY_FACTOR, mediaType.parameters.get(PARAM_QUALITY_FACTOR)); return ne...
java
public MediaType removeQualityValue() { if (!this.parameters.containsKey(PARAM_QUALITY_FACTOR)) { return this; } Map<String, String> params = new LinkedHashMap<String, String>(this.parameters); params.remove(PARAM_QUALITY_FACTOR); return new MediaType(this, params); }
java
@Override public String getFirst(String headerName) { List<String> headerValues = headers.get(headerName); return headerValues != null ? headerValues.get(0) : null; }
java
@Override public void add(String headerName, String headerValue) { List<String> headerValues = headers.get(headerName); if (headerValues == null) { headerValues = new LinkedList<String>(); this.headers.put(headerName, headerValues); } headerValues.add(headerValue); }
java
@Override public void set(String headerName, String headerValue) { List<String> headerValues = new LinkedList<String>(); headerValues.add(headerValue); headers.put(headerName, headerValues); }
java
private void setViewPagerScroller() { try { Field scrollerField = ViewPager.class.getDeclaredField("mScroller"); scrollerField.setAccessible(true); Field interpolatorField = ViewPager.class.getDeclaredField("sInterpolator"); interpolatorField.setAccessible(true); ...
java
public void scrollOnce() { PagerAdapter adapter = getAdapter(); int currentItem = getCurrentItem(); int totalCount; if (adapter == null || (totalCount = adapter.getCount()) <= 1) { return; } int nextItem = (direction == LEFT) ? --currentItem : ++currentItem; ...
java
public void setHomeAsUpIndicator(Drawable indicator) { if(!deviceSupportMultiPane()) { pulsante.setHomeAsUpIndicator(indicator); } else { actionBar.setHomeAsUpIndicator(indicator); } }
java
public MaterialSection getSectionByTitle(String title) { for(MaterialSection section : sectionList) { if(section.getTitle().equals(title)) { return section; } } for(MaterialSection section : bottomSectionList) { if(section.getTitle().equals(t...
java
public List<MaterialSection> getSectionList() { List<MaterialSection> list = new LinkedList<>(); for(MaterialSection section : sectionList) list.add(section); for(MaterialSection section : bottomSectionList) list.add(section); return list; }
java
public MaterialAccount getAccountAtCurrentPosition(int position) { if (position < 0 || position >= accountManager.size()) throw new RuntimeException("Account Index Overflow"); return findAccountNumber(position); }
java
public MaterialAccount getAccountByTitle(String title) { for(MaterialAccount account : accountManager) if(currentAccount.getTitle().equals(title)) return account; return null; }
java
@Override @SuppressLint("NewApi") public boolean onTouch(View v, MotionEvent event) { if(touchable) { if (event.getAction() == MotionEvent.ACTION_DOWN) { view.setBackgroundColor(colorPressed); return true; } if (event.getAction() == ...
java
public void setBackgroundColor(int color) { colorUnpressed = color; if(!isSelected()) { if (rippleAnimationSupport()) { ripple.setRippleBackground(colorUnpressed); } else { view.setBackgroundColor(colorUnpressed); } ...
java
public List<NodeInfo> getNodes() { final URI uri = uriWithPath("./nodes/"); return Arrays.asList(this.rt.getForObject(uri, NodeInfo[].class)); }
java
public NodeInfo getNode(String name) { final URI uri = uriWithPath("./nodes/" + encodePathSegment(name)); return this.rt.getForObject(uri, NodeInfo.class); }
java
public List<ConnectionInfo> getConnections() { final URI uri = uriWithPath("./connections/"); return Arrays.asList(this.rt.getForObject(uri, ConnectionInfo[].class)); }
java
public ConnectionInfo getConnection(String name) { final URI uri = uriWithPath("./connections/" + encodePathSegment(name)); return this.rt.getForObject(uri, ConnectionInfo.class); }
java
public List<ChannelInfo> getChannels() { final URI uri = uriWithPath("./channels/"); return Arrays.asList(this.rt.getForObject(uri, ChannelInfo[].class)); }
java
public List<ChannelInfo> getChannels(String connectionName) { final URI uri = uriWithPath("./connections/" + encodePathSegment(connectionName) + "/channels/"); return Arrays.asList(this.rt.getForObject(uri, ChannelInfo[].class)); }
java
public ChannelInfo getChannel(String name) { final URI uri = uriWithPath("./channels/" + encodePathSegment(name)); return this.rt.getForObject(uri, ChannelInfo.class); }
java
public List<BindingInfo> getQueueBindings(String vhost, String queue) { final URI uri = uriWithPath("./queues/" + encodePathSegment(vhost) + "/" + encodePathSegment(queue) + "/bindings"); final BindingInfo[] result = this.rt.getForObject(uri, BindingInfo[].class); return asListOrNull(result); }
java
public void declareShovel(String vhost, ShovelInfo info) { Map<String, Object> props = info.getDetails().getPublishProperties(); if(props != null && props.isEmpty()) { throw new IllegalArgumentException("Shovel publish properties must be a non-empty map or null"); } final URI uri = uriWithPath("./...
java
public void deleteShovel(String vhost, String shovelname) { this.deleteIgnoring404(uriWithPath("./parameters/shovel/" + encodePathSegment(vhost) + "/" + encodePathSegment(shovelname))); }
java
public void setCharTranslator(CharacterTranslator charTranslator) { if(charTranslator!=null){ this.charTranslator = charTranslator; this.htmlElementTranslator = null; this.targetTranslator = null; } }
java
public void setHtmlElementTranslator(HtmlElementTranslator htmlElementTranslator) { if(htmlElementTranslator!=null){ this.htmlElementTranslator = htmlElementTranslator; this.charTranslator = null; this.targetTranslator = null; } }
java
public AT_CellContext setPadding(int padding){ if(padding>-1){ this.paddingTop = padding; this.paddingBottom = padding; this.paddingLeft = padding; this.paddingRight = padding; } return this; }
java
public void setTargetTranslator(TargetTranslator targetTranslator) { if(targetTranslator!=null){ this.targetTranslator = targetTranslator; this.charTranslator = null; this.htmlElementTranslator = null; } }
java
public static int[] longestWord(LinkedList<AT_Row> rows, int colNumbers){ if(rows==null){ return null; } if(rows.size()==0){ return new int[0]; } int[] ret = new int[colNumbers]; for(AT_Row row : rows){ if(row.getType()==TableRowType.CONTENT) { LinkedList<AT_Cell> cells = row.ge...
java
public static AT_Row createRule(TableRowType type, TableRowStyle style){ Validate.notNull(type); Validate.validState(type!=TableRowType.UNKNOWN); Validate.validState(type!=TableRowType.CONTENT); Validate.notNull(style); Validate.validState(style!=TableRowStyle.UNKNOWN); return new AT_Row(){ @Ove...
java
public static AT_Row createContentRow(Object[] content, TableRowStyle style){ Validate.notNull(content); Validate.notNull(style); Validate.validState(style!=TableRowStyle.UNKNOWN); LinkedList<AT_Cell> cells = new LinkedList<AT_Cell>(); for(Object o : content){ cells.add(new AT_Cell(o)); } r...
java
public AT_Row setPadding(int padding){ if(this.hasCells()){ for(AT_Cell cell : this.getCells()){ cell.getContext().setPadding(padding); } } return this; }
java
public AT_Row setPaddingBottom(int paddingBottom) { if(this.hasCells()){ for(AT_Cell cell : this.getCells()){ cell.getContext().setPaddingBottom(paddingBottom); } } return this; }
java
public AT_Row setPaddingBottomChar(Character paddingBottomChar) { if(this.hasCells()){ for(AT_Cell cell : this.getCells()){ cell.getContext().setPaddingBottomChar(paddingBottomChar); } } return this; }
java