code
stringlengths
73
34.1k
label
stringclasses
1 value
public void setClassLoaderProvider(String id, ClassLoaderProvider classLoaderProvider) { if (classLoaderProvider != null) { classLoaderProviderMap.put(id, classLoaderProvider); } else { classLoaderProviderMap.remove(id); } }
java
public SortedSet<String> findClassNames(String search, Integer limit) { Map<Package, ClassLoader[]> packageMap = Packages.getPackageMap(getClassLoaders(), ignorePackages); return findClassNamesInPackages(search, limit, packageMap); }
java
public SortedMap<String, Class<?>> getAllClassesMap() { Package[] packages = Package.getPackages(); return getClassesMap(packages); }
java
public SortedMap<String, Class<?>> getClassesMap(Package... packages) { SortedMap<String, Class<?>> answer = new TreeMap<String, Class<?>>(); Map<String, ClassResource> urlSet = new HashMap<String, ClassResource>(); for (Package aPackage : packages) { addPackageResources(aPackage, ur...
java
public Class<?> findClass(String className) throws ClassNotFoundException { for (String skip : SKIP_CLASSES) { if (skip.equals(className)) { return null; } } for (ClassLoader classLoader : getClassLoaders()) { try { return clas...
java
public List<Class<?>> optionallyFindClasses(Iterable<String> classNames) { List<Class<?>> answer = new ArrayList<Class<?>>(); for (String className : classNames) { Class<?> aClass = optionallyFindClass(className); if (aClass != null) { answer.add(aClass); ...
java
protected boolean withinLimit(Integer limit, Collection<?> collection) { if (limit == null) { return true; } else { int value = limit.intValue(); return value <= 0 || value > collection.size(); } }
java
protected static Class findClass(final String className) throws ClassNotFoundException { try { return Thread.currentThread().getContextClassLoader().loadClass(className); } catch (ClassNotFoundException e) { try { return Class.forName(className); } cat...
java
public File getConfigDirectory() { String dirName = getConfigDir(); File answer = null; if (Strings.isNotBlank(dirName)) { answer = new File(dirName); } else { answer = new File(".hawtio"); } answer.mkdirs(); return answer; }
java
public void start() { MBeanServer server = getMbeanServer(); if (server != null) { registerMBeanServer(server); } else { LOG.error("No MBeanServer available so cannot register mbean"); } }
java
protected String checkAgentUrl(Object pVm) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Properties systemProperties = getAgentSystemProperties(pVm); return systemProperties.getProperty(JvmAgent.JOLOKIA_AGENT_URL); }
java
protected int indexOf(String text, String... values) { int answer = -1; for (String value : values) { int idx = text.indexOf(value); if (idx >= 0) { if (answer < 0 || idx < answer) { answer = idx; } } } ...
java
public static FileLocker getLock(File lockFile) { lockFile.getParentFile().mkdirs(); if (!lockFile.exists()) { try { IOHelper.write(lockFile, "I have the lock!"); lockFile.deleteOnExit(); return new FileLocker(lockFile); } catch (IO...
java
public static String getVersion(Class<?> aClass, String groupId, String artifactId) { String version = null; // lets try find the maven property - as the Java API rarely works :) InputStream is = null; String fileName = "/META-INF/maven/" + groupId + "/" + artifactId + ...
java
public void clear() { mCardNumberEditText.setText(""); mExpiryDateEditText.setText(""); mCvcEditText.setText(""); mPostalCodeEditText.setText(""); mCardNumberEditText.setShouldShowError(false); mExpiryDateEditText.setShouldShowError(false); mCvcEditText.setShouldS...
java
public boolean validateCardNumber() { boolean cardNumberIsValid = CardUtils.isValidCardNumber(mCardNumberEditText.getCardNumber()); mCardNumberEditText.setShouldShowError(!cardNumberIsValid); return cardNumberIsValid; }
java
public void setExpiryDate( @IntRange(from = 1, to = 12) int month, @IntRange(from = 0, to = 9999) int year) { mExpiryDateEditText.setText(DateUtils.createDateStringFromIntegerInput(month, year)); }
java
public void clear() { if (mCardNumberEditText.hasFocus() || mExpiryDateEditText.hasFocus() || mCvcNumberEditText.hasFocus() || this.hasFocus()) { mCardNumberEditText.requestFocus(); } mCvcNumberEditText.setText(""); mExpiryDateE...
java
public void setEnabled(boolean isEnabled) { mCardNumberEditText.setEnabled(isEnabled); mExpiryDateEditText.setEnabled(isEnabled); mCvcNumberEditText.setEnabled(isEnabled); }
java
public void setHintDelayed(@StringRes final int hintResource, long delayMilliseconds) { final Runnable hintRunnable = new Runnable() { @Override public void run() { setHint(hintResource); } }; mHandler.postDelayed(hintRunnable, delayMillisecond...
java
public void setShouldShowError(boolean shouldShowError) { if (mErrorMessage != null && mErrorMessageListener != null) { String errorMessage = shouldShowError ? mErrorMessage : null; mErrorMessageListener.displayErrorMessage(errorMessage); mShouldShowError = shouldShowError; ...
java
private void showDialog(@NonNull final Source source) { // Caching the source object here because this app makes a lot of them. mRedirectSource = source; final SourceRedirect sourceRedirect = source.getRedirect(); final String redirectUrl = sourceRedirect != null ? sourceRedirect.getUrl...
java
private void handlePostAuthReturn() { final Uri intentUri = getIntent().getData(); if (intentUri != null) { if ("stripe".equals(intentUri.getScheme()) && "payment-auth-return".equals(intentUri.getHost())) { final String paymentIntentClientSecret = ...
java
@Size(2) @NonNull static String[] separateDateStringParts(@NonNull @Size(max = 4) String expiryInput) { String[] parts = new String[2]; if (expiryInput.length() >= 2) { parts[0] = expiryInput.substring(0, 2); parts[1] = expiryInput.substring(2); } else { ...
java
@IntRange(from = 1000, to = 9999) static int convertTwoDigitYearToFour(@IntRange(from = 0, to = 99) int inputYear) { return convertTwoDigitYearToFour(inputYear, Calendar.getInstance()); }
java
@NonNull public static SourceParams createSourceFromTokenParams(String tokenId) { SourceParams sourceParams = SourceParams.createCustomParams(); sourceParams.setType(Source.CARD); sourceParams.setToken(tokenId); return sourceParams; }
java
@NonNull public static Map<String, Object> createRetrieveSourceParams( @NonNull @Size(min = 1) String clientSecret) { final Map<String, Object> params = new HashMap<>(); params.put(API_PARAM_CLIENT_SECRET, clientSecret); return params; }
java
public void clearReferences() { if (mAsyncTaskController != null) { mAsyncTaskController.detach(); } if (mRxTokenController != null) { mRxTokenController.detach(); } if (mIntentServiceTokenController != null) { mIntentServiceTokenController....
java
public Surface rotate (float angle) { float sr = (float) Math.sin(angle); float cr = (float) Math.cos(angle); transform(cr, sr, -sr, cr, 0, 0); return this; }
java
public Surface transform (float m00, float m01, float m10, float m11, float tx, float ty) { AffineTransform top = tx(); Transforms.multiply(top, m00, m01, m10, m11, tx, ty, top); return this; }
java
public boolean intersects (float x, float y, float w, float h) { tx().transform(intersectionTestPoint.set(x, y), intersectionTestPoint); tx().transform(intersectionTestSize.set(w, h), intersectionTestSize); float ix = intersectionTestPoint.x, iy = intersectionTestPoint.y; float iw = intersectionTestSize...
java
public Surface fillRect (float x, float y, float width, float height) { if (patternTex != null) { batch.addQuad(patternTex, tint, tx(), x, y, width, height); } else { batch.addQuad(colorTex, Tint.combine(fillColor, tint), tx(), x, y, width, height); } return this; }
java
private String[] platformNames(String libraryName) { if (isWindows) return new String[] { libraryName + (is64Bit ? "64.dll" : ".dll") }; if (isLinux) return new String[] { "lib" + libraryName + (is64Bit ? "64.so" : ".so") }; if (isMac) return new String[] { "lib" + libraryName + ".jnilib", ...
java
private String crc(InputStream input) { if (input == null) throw new IllegalArgumentException("input cannot be null."); CRC32 crc = new CRC32(); byte[] buffer = new byte[4096]; try { while (true) { int length = input.read(buffer); if (length == -1) break; crc.update(b...
java
public CharBuffer put (String str, int start, int end) { int length = str.length(); if (start < 0 || end < start || end > length) { throw new IndexOutOfBoundsException(); } if (end - start > remaining()) { throw new BufferOverflowException(); } fo...
java
public RFuture<String> get(String url) { return req(url).execute().map(GET_PAYLOAD); }
java
public RFuture<String> post(String url, String data) { return req(url).setPayload(data).execute().map(GET_PAYLOAD); }
java
public Region region (final float rx, final float ry, final float rwidth, final float rheight) { final Image image = this; return new Region() { private Tile tile; @Override public boolean isLoaded () { return image.isLoaded(); } @Override public Tile tile () { if (tile == null) tile =...
java
public void resize (float width, float height) { if (canvas != null) canvas.close(); canvas = gfx.createCanvas(width, height); }
java
public void end () { Texture tex = (Texture)tile(); Image image = canvas.image; // if our texture is already the right size, just update it if (tex != null && tex.pixelWidth == image.pixelWidth() && tex.pixelHeight == image.pixelHeight()) tex.update(image); // otherwise we need to create a n...
java
@Override public void close() { if (parent != null) parent.remove(this); setState(State.DISPOSED); setBatch(null); }
java
public AffineTransform transform() { if (isSet(Flag.XFDIRTY)) { float sina = FloatMath.sin(rotation), cosa = FloatMath.cos(rotation); float m00 = cosa * scaleX, m01 = sina * scaleX; float m10 = -sina * scaleY, m11 = cosa * scaleY; float tx = transform.tx(), ty = transform.ty(); transf...
java
public float originX () { if (isSet(Flag.ODIRTY)) { float width = width(); if (width > 0) { this.originX = origin.ox(width); this.originY = origin.oy(height()); setFlag(Flag.ODIRTY, false); } } return originX; }
java
public float originY () { if (isSet(Flag.ODIRTY)) { float height = height(); if (height > 0) { this.originX = origin.ox(width()); this.originY = origin.oy(height); setFlag(Flag.ODIRTY, false); } } return originY; }
java
public Layer setOrigin (Origin origin) { this.origin = origin; setFlag(Flag.ODIRTY, true); return this; }
java
public void debugPrint(final Log log) { this.visit(new Visitor() { public void visit(Layer layer, int depth) { String prefix = repeat('.', depth); log.debug(prefix + layer.toString()); } }); }
java
public SoundImpl<?> createSound(AssetFileDescriptor fd) { PooledSound sound = new PooledSound(pool.load(fd, 1)); loadingSounds.put(sound.soundId, sound); return sound; }
java
public SoundImpl<?> createSound(FileDescriptor fd, long offset, long length) { PooledSound sound = new PooledSound(pool.load(fd, offset, length, 1)); loadingSounds.put(sound.soundId, sound); return sound; }
java
public int compareTo (ByteBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; byte thisByte, otherByte; while (compareRemaining > 0) { ...
java
public final ByteBuffer get (byte[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } for (int ...
java
public ByteBuffer put (byte[] src, int off, int len) { int length = src.length; if (off < 0 || len < 0 || off + len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferOverflowException(); } for (int i = 0...
java
@Override public void close () { if (!disposed) { disposed = true; if (gfx.exec().isMainThread()) { gfx.gl.glDeleteTexture(id); } else { gfx.exec().invokeNextFrame(new Runnable() { public void run () { gfx.gl.glDeleteTexture(id); } }); } } }
java
public void onSurfaceChanged (int pixelWidth, int pixelHeight, int orient) { viewportChanged(pixelWidth, pixelHeight); screenSize.setSize(viewSize); switch (orient) { case Configuration.ORIENTATION_LANDSCAPE: orientDetailM.update(OrientationDetail.LANDSCAPE_LEFT); break; case Configurati...
java
void viewDidInit(CGRect bounds) { defaultFramebuffer = gl.glGetInteger(GL20.GL_FRAMEBUFFER_BINDING); if (defaultFramebuffer == 0) throw new IllegalStateException( "Failed to determine defaultFramebuffer"); boundsChanged(bounds); }
java
public RFuture<String> getText (Keyboard.TextType textType, String label, String initialValue) { return getText(textType, label, initialValue, "Ok", "Cancel"); }
java
public RFuture<String> getText (Keyboard.TextType textType, String label, String initialValue, String ok, String cancel) { return RFuture.failure(new Exception("getText not supported")); }
java
public RFuture<Boolean> sysDialog (String title, String text, String ok, String cancel) { return RFuture.failure(new Exception("sysDialog not supported")); }
java
public static Point layerToScreen(Layer layer, float x, float y) { Point into = new Point(x, y); return layerToScreen(layer, into, into); }
java
public static Point layerToParent(Layer layer, Layer parent, float x, float y) { Point into = new Point(x, y); return layerToParent(layer, parent, into, into); }
java
public static Point screenToLayer(Layer layer, float x, float y) { Point into = new Point(x, y); return screenToLayer(layer, into, into); }
java
public static Layer layerUnderPoint (Layer root, float x, float y) { Point p = new Point(x, y); root.transform().inverseTransform(p, p); p.x += root.originX(); p.y += root.originY(); return layerUnderPoint(root, p); }
java
public static int indexInParent (Layer layer) { GroupLayer parent = layer.parent(); if (parent == null) return -1; for (int ii = parent.children()-1; ii >= 0; ii--) { if (parent.childAt(ii) == layer) return ii; } throw new AssertionError(); }
java
public void bind () { gfx.gl.glBindFramebuffer(GL_FRAMEBUFFER, id()); gfx.gl.glViewport(0, 0, width(), height()); }
java
@Override public void close () { gl.glDeleteShader(vertexShader); gl.glDeleteShader(fragmentShader); gl.glDeleteProgram(id); }
java
private void emitStringValue(String s) { raw('"'); char b = 0, c = 0; for (int i = 0; i < s.length(); i++) { b = c; c = s.charAt(i); switch (c) { case '\\': case '"': raw('\\'); raw(c); break; case '/': // Special case to ens...
java
FontRenderContext aaFontContext() { if (aaFontContext == null) { // set up the dummy font contexts Graphics2D aaGfx = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics(); aaGfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); aaFontConte...
java
public int compareTo (DoubleBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; // BEGIN android-changed double thisDouble, otherDouble...
java
public DoubleBuffer get (double[] dest, int off, int len) { int length = dest.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferUnderflowException(); } ...
java
public DoubleBuffer put (double[] src, int off, int len) { int length = src.length; if (off < 0 || len < 0 || (long)off + (long)len > length) { throw new IndexOutOfBoundsException(); } if (len > remaining()) { throw new BufferOverflowException(); } ...
java
public synchronized void succeed (I impl) { this.impl = impl; setVolumeImpl(volume); setLoopingImpl(looping); if (playing) playImpl(); ((RPromise<Sound>)state).succeed(this); }
java
private int toModifierFlags (int mods) { return modifierFlags((mods & GLFW_MOD_ALT) != 0, (mods & GLFW_MOD_CONTROL) != 0, (mods & GLFW_MOD_SUPER) != 0, (mods & GLFW_MOD_SHIFT) != 0); }
java
public <T> RPromise<T> deferredPromise () { return new RPromise<T>() { @Override public void succeed (final T value) { invokeLater(new Runnable() { public void run () { superSucceed(value); } }); } @Override public void fail (final Throwable cause) { invokeLater(n...
java
public void addTris (Texture tex, int tint, AffineTransform xf, float[] xys, int xysOffset, int xysLen, float tw, float th, int[] indices, int indicesOffset, int indicesLen, int indexBase) { setTexture(tex); prepare(tint, xf); addTris(xys, xysOffset, xysLen, tw,...
java
public float adjustWidth(float width) { // Canvas.measureText does not account for the extra width consumed by italic characters, so we // fudge in a fraction of an em and hope the font isn't too slanted switch (font.style) { case ITALIC: return width + emwidth/8; case BOLD_ITALIC: return width...
java
private File getWarDirectory(TreeLogger logger) throws UnableToCompleteException { File currentDirectory = new File("."); try { String canonicalPath = currentDirectory.getCanonicalPath(); logger.log(TreeLogger.INFO, "Current directory in which this generator is executing: " + canonicalPath...
java
protected void paintScene () { viewSurf.saveTx(); viewSurf.begin(); viewSurf.clear(cred, cgreen, cblue, calpha); try { rootLayer.paint(viewSurf); } finally { viewSurf.end(); viewSurf.restoreTx(); } }
java
protected Resource requireResource(String path) throws IOException { URL url = getClass().getClassLoader().getResource(pathPrefix + path); if (url != null) { return url.getProtocol().equals("file") ? new FileResource(new File(URLDecoder.decode(url.getPath(), "UTF-8"))) : new URLResource(ur...
java
protected void prepareDraw() { VertexAttribArrayState previousNio = null; int previousElementSize = 0; if (useNioBuffer == 0 && enabledArrays == previouslyEnabledArrays) { return; } for(int i = 0; i < VERTEX_ATTRIB_ARRAY_COUNT; i++) { int mask = 1 << i; int enabled = enabledArray...
java
private void setFillColor(Color3f color) { if (cacheFillR == color.x && cacheFillG == color.y && cacheFillB == color.z) { // no need to re-set the fill color, just use the cached values } else { cacheFillR = color.x; cacheFillG = color.y; cacheFillB = color.z; setFillColorFromCache...
java
private void setStrokeColor(Color3f color) { if (cacheStrokeR == color.x && cacheStrokeG == color.y && cacheStrokeB == color.z) { // no need to re-set the stroke color, just use the cached values } else { cacheStrokeR = color.x; cacheStrokeG = color.y; cacheStrokeB = color.z; setSt...
java
public void start () { if (config.activationKey != null) { input().keyboardEvents.connect(new Slot<Keyboard.Event>() { public void onEmit (Keyboard.Event event) { if (event instanceof Keyboard.KeyEvent) { Keyboard.KeyEvent kevent = (Keyboard.KeyEvent)event; if (kevent...
java
public static IntBuffer allocate (int capacity) { if (capacity < 0) { throw new IllegalArgumentException(); } ByteBuffer bb = ByteBuffer.allocateDirect(capacity * 4); bb.order(ByteOrder.nativeOrder()); return bb.asIntBuffer(); }
java
public int compareTo (IntBuffer otherBuffer) { int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining(); int thisPos = position; int otherPos = otherBuffer.position; // BEGIN android-changed int thisInt, otherInt; wh...
java
public TextFormat withFont(String name, Font.Style style, float size) { return withFont(new Font(name, style, size)); }
java
public Image getImageSync (String path) { ImageImpl image = createImage(false, 0, 0, path); try { image.succeed(load(path)); } catch (Throwable t) { image.fail(t); } return image; }
java
public RFuture<String> getText (final String path) { final RPromise<String> result = exec.deferredPromise(); exec.invokeAsync(new Runnable() { public void run () { try { result.succeed(getTextSync(path)); } catch (Throwable t) { result.fail(t); } } });...
java
public RFuture<ByteBuffer> getBytes (final String path) { final RPromise<ByteBuffer> result = exec.deferredPromise(); exec.invokeAsync(new Runnable() { public void run () { try { result.succeed(getBytesSync(path)); } catch (Throwable t) { result.fail(t); } ...
java
static float getRelativeX (NativeEvent e, Element target) { return (e.getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() + target.getOwnerDocument().getScrollLeft()) / HtmlGraphics.experimentalScale; }
java
static float getRelativeY (NativeEvent e, Element target) { return (e.getClientY() - target.getAbsoluteTop() + target.getScrollTop() + target.getOwnerDocument().getScrollTop()) / HtmlGraphics.experimentalScale; }
java
public synchronized void succeed (Data data) { scale = data.scale; pixelWidth = data.pixelWidth; assert pixelWidth > 0; pixelHeight = data.pixelHeight; assert pixelHeight > 0; setBitmap(data.bitmap); ((RPromise<Image>)state).succeed(this); // state is a deferred promise }
java
public synchronized void fail (Throwable error) { if (pixelWidth == 0) pixelWidth = 50; if (pixelHeight == 0) pixelHeight = 50; setBitmap(createErrorBitmap(pixelWidth, pixelHeight)); ((RPromise<Image>)state).fail(error); // state is a deferred promise }
java
protected boolean accept(String path) { // GWT Development Mode files if (path.equals("hosted.html") || path.endsWith(".devmode.js")) { return false; } // Default or welcome file if (path.equals("/")) { return true; } // Whitelisted file extension int pos = path.lastIndexO...
java
public Texture createTexture (float width, float height, Texture.Config config) { int texWidth = config.toTexWidth(scale.scaledCeil(width)); int texHeight = config.toTexHeight(scale.scaledCeil(height)); if (texWidth <= 0 || texHeight <= 0) throw new IllegalArgumentException( "Invalid texture size: " +...
java
protected void viewportChanged (int pixelWidth, int pixelHeight) { viewPixelWidth = pixelWidth; viewPixelHeight = pixelHeight; viewSizeM.width = scale.invScaled(pixelWidth); viewSizeM.height = scale.invScaled(pixelHeight); plat.log().info("viewPortChanged " + pixelWidth + "x" + pixelHeight + " / " +...
java
public static ShortBuffer allocate (int capacity) { if (capacity < 0) { throw new IllegalArgumentException(); } ByteBuffer bb = ByteBuffer.allocateDirect(capacity * 2); bb.order(ByteOrder.nativeOrder()); return bb.asShortBuffer(); }
java
@SuppressWarnings("unchecked") <T> T parse(Class<T> clazz) throws JsonParserException { advanceToken(); Object parsed = currentValue(); if (advanceToken() != Token.EOF) throw createParseException(null, "Expected end of input, got " + token, true); if (clazz != Object.class && (parsed == null || ...
java
private Object currentValue() throws JsonParserException { // Only a value start token should appear when we're in the context of parsing a JSON value if (token.isValue) return value; throw createParseException(null, "Expected JSON value, got " + token, true); }
java
private void consumeKeyword(char first, char[] expected) throws JsonParserException { for (int i = 0; i < expected.length; i++) if (advanceChar() != expected[i]) throw createHelpfulException(first, expected, i); // The token should end with something other than an ASCII letter if (isAsciiLett...
java
private char stringChar() throws JsonParserException { int c = advanceChar(); if (c == -1) throw createParseException(null, "String was not terminated before end of input", true); if (c < 32) throw createParseException(null, "Strings may not contain control characters: 0x" + Integer.to...
java
private int stringHexChar() throws JsonParserException { // GWT-compatible Character.digit(char, int) int c = "0123456789abcdef0123456789ABCDEF".indexOf(advanceChar()) % 16; if (c == -1) throw createParseException(null, "Expected unicode hex escape character", false); return c; }
java