_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q16100
SparqlCall.addHeaders
train
static void addHeaders(HttpUriRequest req, String mimeType) { if (POST.equalsIgnoreCase(req.getMethod())) { req.addHeader(CONTENT_TYPE, FORM_ENCODED); } if (mimeType != null) req.setHeader(ACCEPT, mimeType); }
java
{ "resource": "" }
q16101
XMLHolidayManagerJapan.getHolidays
train
@Override public HolidayMap getHolidays (final int nYear, @Nullable final String... aArgs) { final HolidayMap aHolidays = super.getHolidays (nYear, aArgs); final HolidayMap aAdditionalHolidays = new HolidayMap (); for (final Map.Entry <LocalDate, ISingleHoliday> aEntry : aHolidays.getMap ().entrySet ()) { final LocalDate aTwoDaysLater = aEntry.getKey ().plusDays (2); if (aHolidays.containsHolidayForDate (aTwoDaysLater)) { final LocalDate aBridgingDate = aTwoDaysLater.minusDays (1); aAdditionalHolidays.add (aBridgingDate, new ResourceBundleHoliday (EHolidayType.OFFICIAL_HOLIDAY, BRIDGING_HOLIDAY_PROPERTIES_KEY)); } } aHolidays.addAll (aAdditionalHolidays); return aHolidays; }
java
{ "resource": "" }
q16102
Logger.setLogLevel
train
public final void setLogLevel(@NonNull final LogLevel logLevel) { Condition.INSTANCE.ensureNotNull(logLevel, "The log level may not be null"); this.logLevel = logLevel; }
java
{ "resource": "" }
q16103
Logger.logVerbose
train
public final void logVerbose(@NonNull final Class<?> tag, @NonNull final String message) { Condition.INSTANCE.ensureNotNull(tag, "The tag may not be null"); Condition.INSTANCE.ensureNotNull(message, "The message may not be null"); Condition.INSTANCE.ensureNotEmpty(message, "The message may not be empty"); if (LogLevel.VERBOSE.getRank() >= getLogLevel().getRank()) { Log.v(ClassUtil.INSTANCE.getTruncatedName(tag), message); } }
java
{ "resource": "" }
q16104
Logger.logDebug
train
public final void logDebug(@NonNull final Class<?> tag, @NonNull final String message) { Condition.INSTANCE.ensureNotNull(tag, "The tag may not be null"); Condition.INSTANCE.ensureNotNull(message, "The message may not be null"); Condition.INSTANCE.ensureNotEmpty(message, "The message may not be empty"); if (LogLevel.DEBUG.getRank() >= getLogLevel().getRank()) { Log.d(ClassUtil.INSTANCE.getTruncatedName(tag), message); } }
java
{ "resource": "" }
q16105
Logger.logInfo
train
public final void logInfo(@NonNull final Class<?> tag, @NonNull final String message) { Condition.INSTANCE.ensureNotNull(tag, "The tag may not be null"); Condition.INSTANCE.ensureNotNull(message, "The message may not be null"); Condition.INSTANCE.ensureNotEmpty(message, "The message may not be empty"); if (LogLevel.INFO.getRank() >= getLogLevel().getRank()) { Log.i(ClassUtil.INSTANCE.getTruncatedName(tag), message); } }
java
{ "resource": "" }
q16106
Logger.logWarn
train
public final void logWarn(@NonNull final Class<?> tag, @NonNull final String message, @NonNull final Throwable cause) { Condition.INSTANCE.ensureNotNull(tag, "The tag may not be null"); Condition.INSTANCE.ensureNotNull(message, "The message may not be null"); Condition.INSTANCE.ensureNotEmpty(message, "The message may not be empty"); Condition.INSTANCE.ensureNotNull(cause, "The cause may not be null"); if (LogLevel.WARN.getRank() >= getLogLevel().getRank()) { Log.w(ClassUtil.INSTANCE.getTruncatedName(tag), message, cause); } }
java
{ "resource": "" }
q16107
Logger.logError
train
public final void logError(@NonNull final Class<?> tag, @NonNull final String message) { Condition.INSTANCE.ensureNotNull(tag, "The tag may not be null"); Condition.INSTANCE.ensureNotNull(message, "The message may not be null"); Condition.INSTANCE.ensureNotEmpty(message, "The message may not be empty"); if (LogLevel.ERROR.getRank() >= getLogLevel().getRank()) { Log.e(ClassUtil.INSTANCE.getTruncatedName(tag), message); } }
java
{ "resource": "" }
q16108
DisplayUtil.getOrientation
train
public static Orientation getOrientation(@NonNull final Context context) { Condition.INSTANCE.ensureNotNull(context, "The context may not be null"); int orientation = context.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_UNDEFINED) { int width = getDisplayWidth(context); int height = getDisplayHeight(context); if (width > height) { return Orientation.LANDSCAPE; } else if (width < height) { return Orientation.PORTRAIT; } else { return Orientation.SQUARE; } } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { return Orientation.LANDSCAPE; } else if (orientation == Configuration.ORIENTATION_PORTRAIT) { return Orientation.PORTRAIT; } else { return Orientation.SQUARE; } }
java
{ "resource": "" }
q16109
DisplayUtil.getDeviceType
train
public static DeviceType getDeviceType(@NonNull final Context context) { Condition.INSTANCE.ensureNotNull(context, "The context may not be null"); return DeviceType.fromValue(context.getString(R.string.device_type)); }
java
{ "resource": "" }
q16110
DisplayUtil.getDisplayWidth
train
public static int getDisplayWidth(@NonNull final Context context) { Condition.INSTANCE.ensureNotNull(context, "The context may not be null"); return context.getResources().getDisplayMetrics().widthPixels; }
java
{ "resource": "" }
q16111
DisplayUtil.getDisplayHeight
train
public static int getDisplayHeight(@NonNull final Context context) { Condition.INSTANCE.ensureNotNull(context, "The context may not be null"); return context.getResources().getDisplayMetrics().heightPixels; }
java
{ "resource": "" }
q16112
DriverFactory.createDriver
train
public static Driver createDriver(FeedPartition feedPartition, Plan plan, MetricRegistry metricRegistry){ populateFeedMetricInfo(plan, feedPartition, metricRegistry); OperatorDesc desc = plan.getRootOperator(); Operator oper = buildOperator(desc, metricRegistry, plan.getName(), feedPartition); OffsetStorage offsetStorage = null; OffsetStorageDesc offsetDesc = plan.getOffsetStorageDesc(); if (offsetDesc != null && feedPartition.supportsOffsetManagement()){ offsetStorage = buildOffsetStorage(feedPartition, plan, offsetDesc); Offset offset = offsetStorage.findLatestPersistedOffset(); if (offset != null){ feedPartition.setOffset(new String(offset.serialize(), Charsets.UTF_8)); } } CollectorProcessor cp = new CollectorProcessor(); cp.setTupleRetry(plan.getTupleRetry()); int offsetCommitInterval = plan.getOffsetCommitInterval(); Driver driver = new Driver(feedPartition, oper, offsetStorage, cp, offsetCommitInterval, metricRegistry, plan.getName()); recurseOperatorAndDriverNode(desc, driver.getDriverNode(), metricRegistry, feedPartition); return driver; }
java
{ "resource": "" }
q16113
DriverFactory.nitDescFromDynamic
train
private static NitDesc nitDescFromDynamic(DynamicInstantiatable d){ NitDesc nd = new NitDesc(); nd.setScript(d.getScript()); nd.setTheClass(d.getTheClass()); if (d.getSpec() == null || "java".equals(d.getSpec())){ nd.setSpec(NitDesc.NitSpec.JAVA_LOCAL_CLASSPATH); } else if ("groovy".equals(d.getSpec())){ nd.setSpec(NitDesc.NitSpec.GROOVY_CLASS_LOADER); } else if ("groovyclosure".equals(d.getSpec())){ nd.setSpec(NitDesc.NitSpec.GROOVY_CLOSURE); } else if ("url".equals(d.getSpec())){ nd.setSpec(NitDesc.NitSpec.JAVA_URL_CLASSLOADER); } else { nd.setSpec(NitDesc.NitSpec.valueOf(d.getSpec())); } return nd; }
java
{ "resource": "" }
q16114
DriverFactory.buildOperator
train
public static Operator buildOperator(OperatorDesc operatorDesc, MetricRegistry metricRegistry, String planPath, FeedPartition feedPartition) { Operator operator = null; NitFactory nitFactory = new NitFactory(); NitDesc nitDesc = nitDescFromDynamic(operatorDesc); try { if (nitDesc.getSpec() == NitDesc.NitSpec.GROOVY_CLOSURE){ operator = new GroovyOperator((Closure) nitFactory.construct(nitDesc)); } else { operator = nitFactory.construct(nitDesc); } } catch (NitException e) { throw new RuntimeException(e); } operator.setProperties(operatorDesc.getParameters()); operator.setMetricRegistry(metricRegistry); operator.setPartitionId(feedPartition.getPartitionId()); String myName = operatorDesc.getName(); if (myName == null){ myName = operatorDesc.getTheClass(); if (myName.indexOf(".") > -1){ String[] parts = myName.split("\\."); myName = parts[parts.length-1]; } } operator.setPath(planPath + "." + myName); return operator; }
java
{ "resource": "" }
q16115
DriverFactory.buildFeed
train
public static Feed buildFeed(FeedDesc feedDesc){ Feed feed = null; NitFactory nitFactory = new NitFactory(); NitDesc nitDesc = nitDescFromDynamic(feedDesc); nitDesc.setConstructorParameters(new Class [] { Map.class }); nitDesc.setConstructorArguments(new Object[] { feedDesc.getProperties() }); try { feed = nitFactory.construct(nitDesc); } catch (NitException e) { throw new RuntimeException(e); } return feed; }
java
{ "resource": "" }
q16116
BitmapUtil.getSampleSize
train
private static int getSampleSize(@NonNull final Pair<Integer, Integer> imageDimensions, final int maxWidth, final int maxHeight) { Condition.INSTANCE.ensureNotNull(imageDimensions, "The image dimensions may not be null"); Condition.INSTANCE.ensureAtLeast(maxWidth, 1, "The maximum width must be at least 1"); Condition.INSTANCE.ensureAtLeast(maxHeight, 1, "The maximum height must be at least 1"); int width = imageDimensions.first; int height = imageDimensions.second; int sampleSize = 1; if (width > maxWidth || height > maxHeight) { int halfWidth = width / 2; int halfHeight = height / 2; while ((halfWidth / sampleSize) > maxWidth && (halfHeight / sampleSize) > maxHeight) { sampleSize *= 2; } } return sampleSize; }
java
{ "resource": "" }
q16117
BitmapUtil.clipCircle
train
public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size) { Bitmap squareBitmap = clipSquare(bitmap, size); int squareSize = squareBitmap.getWidth(); float radius = (float) squareSize / 2.0f; Bitmap clippedBitmap = Bitmap.createBitmap(squareSize, squareSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(clippedBitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); canvas.drawCircle(radius, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(squareBitmap, new Rect(0, 0, squareSize, squareSize), new Rect(0, 0, squareSize, squareSize), paint); return clippedBitmap; }
java
{ "resource": "" }
q16118
BitmapUtil.clipCircle
train
public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size, final int borderWidth, @ColorInt final int borderColor) { Condition.INSTANCE.ensureAtLeast(borderWidth, 0, "The border width must be at least 0"); Bitmap clippedBitmap = clipCircle(bitmap, size); Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); float offset = borderWidth / 2.0f; Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight()); RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset); canvas.drawBitmap(clippedBitmap, src, dst, null); if (borderWidth > 0 && Color.alpha(borderColor) != 0) { Paint paint = new Paint(); paint.setFilterBitmap(false); paint.setAntiAlias(true); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); paint.setColor(borderColor); offset = borderWidth / 2.0f; RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset); canvas.drawArc(bounds, 0, COMPLETE_ARC_ANGLE, false, paint); } return result; }
java
{ "resource": "" }
q16119
BitmapUtil.clipSquare
train
public static Bitmap clipSquare(@NonNull final Bitmap bitmap) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); return clipSquare(bitmap, bitmap.getWidth() >= bitmap.getHeight() ? bitmap.getHeight() : bitmap.getWidth()); }
java
{ "resource": "" }
q16120
BitmapUtil.clipSquare
train
@SuppressWarnings("SuspiciousNameCombination") public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int size) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Condition.INSTANCE.ensureAtLeast(size, 1, "The size must be at least 1"); Bitmap clippedBitmap = bitmap; int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (width > height) { clippedBitmap = Bitmap.createBitmap(bitmap, width / 2 - height / 2, 0, height, height); } else if (bitmap.getWidth() < bitmap.getHeight()) { clippedBitmap = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 2 - width / 2, width, width); } if (clippedBitmap.getWidth() != size) { clippedBitmap = resize(clippedBitmap, size, size); } return clippedBitmap; }
java
{ "resource": "" }
q16121
BitmapUtil.clipSquare
train
public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int borderWidth, @ColorInt final int borderColor) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); return clipSquare(bitmap, bitmap.getWidth() >= bitmap.getHeight() ? bitmap.getHeight() : bitmap.getWidth(), borderWidth, borderColor); }
java
{ "resource": "" }
q16122
BitmapUtil.clipSquare
train
public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int size, final int borderWidth, @ColorInt final int borderColor) { Condition.INSTANCE.ensureAtLeast(borderWidth, 0, "The border width must be at least 0"); Bitmap clippedBitmap = clipSquare(bitmap, size); Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); float offset = borderWidth / 2.0f; Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight()); RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset); canvas.drawBitmap(clippedBitmap, src, dst, null); if (borderWidth > 0 && Color.alpha(borderColor) != 0) { Paint paint = new Paint(); paint.setFilterBitmap(false); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); paint.setColor(borderColor); offset = borderWidth / 2.0f; RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset); canvas.drawRect(bounds, paint); } return result; }
java
{ "resource": "" }
q16123
BitmapUtil.resize
train
public static Bitmap resize(@NonNull final Bitmap bitmap, final int width, final int height) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Condition.INSTANCE.ensureAtLeast(width, 1, "The width must be at least 1"); Condition.INSTANCE.ensureAtLeast(height, 1, "The height must be at least 1"); return Bitmap.createScaledBitmap(bitmap, width, height, false); }
java
{ "resource": "" }
q16124
BitmapUtil.splitHorizontally
train
public static Pair<Bitmap, Bitmap> splitHorizontally(@NonNull final Bitmap bitmap) { return splitHorizontally(bitmap, bitmap.getHeight() / 2); }
java
{ "resource": "" }
q16125
BitmapUtil.splitHorizontally
train
public static Pair<Bitmap, Bitmap> splitHorizontally(@NonNull final Bitmap bitmap, final int splitPoint) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Condition.INSTANCE.ensureGreater(splitPoint, 0, "The split point must be greater than 0"); Condition.INSTANCE.ensureSmaller(splitPoint, bitmap.getHeight(), "The split point must be smaller than " + bitmap.getHeight()); Bitmap topBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), splitPoint); Bitmap bottomBitmap = Bitmap.createBitmap(bitmap, 0, splitPoint, bitmap.getWidth(), bitmap.getHeight() - splitPoint); return new Pair<>(topBitmap, bottomBitmap); }
java
{ "resource": "" }
q16126
BitmapUtil.splitVertically
train
public static Pair<Bitmap, Bitmap> splitVertically(@NonNull final Bitmap bitmap) { return splitVertically(bitmap, bitmap.getWidth() / 2); }
java
{ "resource": "" }
q16127
BitmapUtil.splitVertically
train
public static Pair<Bitmap, Bitmap> splitVertically(@NonNull final Bitmap bitmap, final int splitPoint) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Condition.INSTANCE.ensureGreater(splitPoint, 0, "The split point must be greater than 0"); Condition.INSTANCE.ensureSmaller(splitPoint, bitmap.getWidth(), "The split point must be smaller than " + bitmap.getWidth()); Bitmap leftBitmap = Bitmap.createBitmap(bitmap, 0, 0, splitPoint, bitmap.getHeight()); Bitmap rightBitmap = Bitmap.createBitmap(bitmap, splitPoint, 0, bitmap.getWidth() - splitPoint, bitmap.getHeight()); return new Pair<>(leftBitmap, rightBitmap); }
java
{ "resource": "" }
q16128
BitmapUtil.tile
train
public static Bitmap tile(final Bitmap bitmap, final int width, final int height) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Condition.INSTANCE.ensureAtLeast(width, 1, "The width must be at least 1"); Condition.INSTANCE.ensureAtLeast(height, 1, "The height must be at least 1"); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); int originalWidth = bitmap.getWidth(); int originalHeight = bitmap.getHeight(); for (int x = 0; x < width; x += originalWidth) { for (int y = 0; y < width; y += originalHeight) { int copyWidth = (width - x >= originalWidth) ? originalWidth : width - x; int copyHeight = (height - y >= originalHeight) ? originalHeight : height - y; Rect src = new Rect(0, 0, copyWidth, copyHeight); Rect dest = new Rect(x, y, x + copyWidth, y + copyHeight); canvas.drawBitmap(bitmap, src, dest, null); } } return result; }
java
{ "resource": "" }
q16129
BitmapUtil.tint
train
public static Bitmap tint(@NonNull final Bitmap bitmap, @ColorInt final int color) { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(color); canvas.drawRect(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), paint); return bitmap; }
java
{ "resource": "" }
q16130
BitmapUtil.drawableToBitmap
train
public static Bitmap drawableToBitmap(@NonNull final Drawable drawable) { Condition.INSTANCE.ensureNotNull(drawable, "The drawable may not be null"); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; if (bitmapDrawable.getBitmap() != null) { return bitmapDrawable.getBitmap(); } } Bitmap bitmap; if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
java
{ "resource": "" }
q16131
BitmapUtil.colorToBitmap
train
public static Bitmap colorToBitmap(final int width, final int height, @ColorInt final int color) { Condition.INSTANCE.ensureAtLeast(width, 1, "The width must be at least 1"); Condition.INSTANCE.ensureAtLeast(height, 1, "The height must be at least 1"); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(color); canvas.drawRect(0, 0, width, height, paint); return bitmap; }
java
{ "resource": "" }
q16132
BitmapUtil.getImageDimensions
train
public static Pair<Integer, Integer> getImageDimensions(@NonNull final File file) throws IOException { Condition.INSTANCE.ensureNotNull(file, "The file may not be null"); Condition.INSTANCE .ensureFileIsNoDirectory(file, "The file must exist and must not be a directory"); String path = file.getPath(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); int width = options.outWidth; int height = options.outHeight; if (width == -1 || height == -1) { throw new IOException("Failed to decode image \"" + path + "\""); } return Pair.create(width, height); }
java
{ "resource": "" }
q16133
BitmapUtil.getImageDimensions
train
public static Pair<Integer, Integer> getImageDimensions(@NonNull final Context context, @DrawableRes final int resourceId) throws IOException { Condition.INSTANCE.ensureNotNull(context, "The context may not be null"); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), resourceId, options); int width = options.outWidth; int height = options.outHeight; if (width == -1 || height == -1) { throw new IOException("Failed to decode image resource with id " + resourceId); } return Pair.create(width, height); }
java
{ "resource": "" }
q16134
BitmapUtil.loadThumbnail
train
public static Bitmap loadThumbnail(@NonNull final File file, final int maxWidth, final int maxHeight) throws IOException { Pair<Integer, Integer> imageDimensions = getImageDimensions(file); int sampleSize = getSampleSize(imageDimensions, maxWidth, maxHeight); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inSampleSize = sampleSize; String path = file.getAbsolutePath(); Bitmap thumbnail = BitmapFactory.decodeFile(path, options); if (thumbnail == null) { throw new IOException("Failed to decode image \"" + path + "\""); } return thumbnail; }
java
{ "resource": "" }
q16135
BitmapUtil.compressToFile
train
public static void compressToFile(@NonNull final Bitmap bitmap, @NonNull final File file, @NonNull final CompressFormat format, final int quality) throws IOException { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Condition.INSTANCE.ensureNotNull(file, "The file may not be null"); Condition.INSTANCE.ensureNotNull(format, "The format may not be null"); Condition.INSTANCE.ensureAtLeast(quality, 0, "The quality must be at least 0"); Condition.INSTANCE.ensureAtMaximum(quality, 100, "The quality must be at maximum 100"); OutputStream outputStream = null; try { outputStream = new FileOutputStream(file); boolean result = bitmap.compress(format, quality, outputStream); if (!result) { throw new IOException( "Failed to compress bitmap to file \"" + file + "\" using format " + format + " and quality " + quality); } } finally { StreamUtil.INSTANCE.close(outputStream); } }
java
{ "resource": "" }
q16136
BitmapUtil.compressToByteArray
train
public static byte[] compressToByteArray(@NonNull final Bitmap bitmap, @NonNull final CompressFormat format, final int quality) throws IOException { Condition.INSTANCE.ensureNotNull(bitmap, "The bitmap may not be null"); Condition.INSTANCE.ensureNotNull(format, "The format may not be null"); Condition.INSTANCE.ensureAtLeast(quality, 0, "The quality must be at least 0"); Condition.INSTANCE.ensureAtMaximum(quality, 100, "The quality must be at maximum 100"); ByteArrayOutputStream outputStream = null; try { outputStream = new ByteArrayOutputStream(); boolean result = bitmap.compress(format, quality, outputStream); if (result) { return outputStream.toByteArray(); } throw new IOException("Failed to compress bitmap to byte array using format " + format + " and quality " + quality); } finally { StreamUtil.INSTANCE.close(outputStream); } }
java
{ "resource": "" }
q16137
TeknekDaemon.isPlanSane
train
public boolean isPlanSane(Plan plan){ if (plan == null){ logger.warn("did not find plan"); return false; } if (plan.isDisabled()){ logger.debug("disabled "+ plan.getName()); return false; } if (plan.getFeedDesc() == null){ logger.warn("feed was null "+ plan.getName()); return false; } return true; }
java
{ "resource": "" }
q16138
ExpandableGridView.createItemClickListener
train
private OnItemClickListener createItemClickListener() { return new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { Pair<Integer, Integer> itemPosition = getItemPosition(position - getHeaderViewsCount()); int groupIndex = itemPosition.first; int childIndex = itemPosition.second; long packedId; if (childIndex != -1) { packedId = getPackedPositionForChild(groupIndex, childIndex); notifyOnChildClicked(view, groupIndex, childIndex, packedId); } else if (groupIndex != -1) { packedId = getPackedPositionForGroup(groupIndex); notifyOnGroupClicked(view, groupIndex, packedId); } else { packedId = getPackedPositionForChild(Integer.MAX_VALUE, position); } notifyOnItemClicked(view, getPackedPosition(position), packedId); } }; }
java
{ "resource": "" }
q16139
ExpandableGridView.createItemLongClickListener
train
private OnItemLongClickListener createItemLongClickListener() { return new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Pair<Integer, Integer> itemPosition = getItemPosition(position - getHeaderViewsCount()); int groupIndex = itemPosition.first; int childIndex = itemPosition.second; long packedId; if (childIndex != -1) { packedId = getPackedPositionForChild(groupIndex, childIndex); } else if (groupIndex != -1) { packedId = getPackedPositionForGroup(groupIndex); } else { packedId = getPackedPositionForChild(Integer.MAX_VALUE, position); } return notifyOnItemLongClicked(view, getPackedPosition(position), packedId); } }; }
java
{ "resource": "" }
q16140
ExpandableGridView.getPackedPosition
train
private int getPackedPosition(final int position) { if (position < getHeaderViewsCount()) { return position; } else { Pair<Integer, Integer> pair = getItemPosition(position - getHeaderViewsCount()); int groupIndex = pair.first; int childIndex = pair.second; if (childIndex == -1 && groupIndex == -1) { int childCount = 0; for (int i = 0; i < getExpandableListAdapter().getGroupCount(); i++) { childCount += getExpandableListAdapter().getChildrenCount(i); } return getHeaderViewsCount() + getExpandableListAdapter().getGroupCount() + childCount + position - (getHeaderViewsCount() + adapter.getCount()); } else if (childIndex != -1) { return getPackedChildPosition(groupIndex, childIndex); } else { return getPackedGroupPosition(groupIndex); } } }
java
{ "resource": "" }
q16141
ExpandableGridView.getPackedGroupPosition
train
private int getPackedGroupPosition(final int groupIndex) { int packedPosition = getHeaderViewsCount(); if (groupIndex > 0) { for (int i = groupIndex - 1; i >= 0; i--) { packedPosition += getExpandableListAdapter().getChildrenCount(i) + 1; } } return packedPosition; }
java
{ "resource": "" }
q16142
ExpandableGridView.getItemPosition
train
private Pair<Integer, Integer> getItemPosition(final int packedPosition) { int currentPosition = packedPosition; int groupIndex = -1; int childIndex = -1; int numColumns = getNumColumnsCompatible(); for (int i = 0; i < getExpandableListAdapter().getGroupCount(); i++) { if (currentPosition == 0) { groupIndex = i; break; } else if (currentPosition < numColumns) { break; } else { currentPosition -= numColumns; if (isGroupExpanded(i)) { int childCount = getExpandableListAdapter().getChildrenCount(i); if (currentPosition < childCount) { groupIndex = i; childIndex = currentPosition; break; } else { int lastLineCount = childCount % numColumns; currentPosition -= childCount + (lastLineCount > 0 ? numColumns - lastLineCount : 0); } } } } return new Pair<>(groupIndex, childIndex); }
java
{ "resource": "" }
q16143
ExpandableGridView.notifyOnGroupClicked
train
private boolean notifyOnGroupClicked(@NonNull final View view, final int groupIndex, final long id) { return groupClickListener != null && groupClickListener.onGroupClick(this, view, groupIndex, id); }
java
{ "resource": "" }
q16144
ExpandableGridView.notifyOnChildClicked
train
private boolean notifyOnChildClicked(@NonNull final View view, final int groupIndex, final int childIndex, final long id) { return childClickListener != null && childClickListener.onChildClick(this, view, groupIndex, childIndex, id); }
java
{ "resource": "" }
q16145
ExpandableGridView.notifyOnItemClicked
train
private void notifyOnItemClicked(@NonNull final View view, final int position, final long id) { if (itemClickListener != null) { itemClickListener.onItemClick(this, view, position, id); } }
java
{ "resource": "" }
q16146
ExpandableGridView.notifyOnItemLongClicked
train
private boolean notifyOnItemLongClicked(@NonNull final View view, final int position, final long id) { return itemLongClickListener != null && itemLongClickListener.onItemLongClick(this, view, position, id); }
java
{ "resource": "" }
q16147
ExpandableGridView.getPackedPositionType
train
public static int getPackedPositionType(final long packedPosition) { if (packedPosition == PACKED_POSITION_VALUE_NULL) { return PACKED_POSITION_TYPE_NULL; } return (packedPosition & PACKED_POSITION_MASK_TYPE) == PACKED_POSITION_MASK_TYPE ? PACKED_POSITION_TYPE_CHILD : PACKED_POSITION_TYPE_GROUP; }
java
{ "resource": "" }
q16148
ExpandableGridView.setAdapter
train
public final void setAdapter(@Nullable final ExpandableListAdapter adapter) { expandedGroups.clear(); if (adapter != null) { this.adapter = new AdapterWrapper(adapter); super.setAdapter(this.adapter); } else { this.adapter = null; super.setAdapter(null); } }
java
{ "resource": "" }
q16149
ExpandableGridView.expandGroup
train
public final boolean expandGroup(final int groupIndex) { ExpandableListAdapter adapter = getExpandableListAdapter(); if (adapter != null && !isGroupExpanded(groupIndex)) { expandedGroups.add(groupIndex); notifyDataSetChanged(); return true; } return false; }
java
{ "resource": "" }
q16150
ExpandableGridView.collapseGroup
train
public final boolean collapseGroup(final int groupIndex) { ExpandableListAdapter adapter = getExpandableListAdapter(); if (adapter != null && isGroupExpanded(groupIndex)) { expandedGroups.remove(groupIndex); notifyDataSetChanged(); return true; } return false; }
java
{ "resource": "" }
q16151
StringSerializer.validateString
train
private void validateString(Class<?> clazz) throws SerializerException { if (null != clazz && !clazz.isAssignableFrom(String.class)) { throw new SerializerException("String serializer is able to work only with data types assignable from java.lang.String"); } }
java
{ "resource": "" }
q16152
StringSerializer.validateString
train
private void validateString(Type type) throws SerializerException { if (null == type || !String.class.equals(TypeToken.of(type).getRawType())) { throw new SerializerException("String serializer is able to work only with data types assignable from java.lang.String"); } }
java
{ "resource": "" }
q16153
PreemptiveAuthInterceptor.process
train
@Override public final void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); AuthCache authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); context.setAttribute(HttpClientContext.AUTH_CACHE, authCache); } }
java
{ "resource": "" }
q16154
HttpClientRestEndpoint.executeRequest
train
@Override public final <RQ, RS> Maybe<Response<RS>> executeRequest(RestCommand<RQ, RS> command) throws RestEndpointIOException { URI uri = spliceUrl(command.getUri()); HttpUriRequest rq; Serializer serializer; switch (command.getHttpMethod()) { case GET: rq = new HttpGet(uri); break; case POST: if (command.isMultipart()) { MultiPartRequest rqData = (MultiPartRequest) command.getRequest(); rq = buildMultipartRequest(uri, rqData); } else { serializer = getSupportedSerializer(command.getRequest()); rq = new HttpPost(uri); ((HttpPost) rq) .setEntity(new ByteArrayEntity(serializer.serialize(command.getRequest()), ContentType.create( serializer.getMimeType()))); } break; case PUT: serializer = getSupportedSerializer(command.getRequest()); rq = new HttpPut(uri); ((HttpPut) rq).setEntity(new ByteArrayEntity(serializer.serialize(command.getRequest()), ContentType.create( serializer.getMimeType()))); break; case DELETE: rq = new HttpDelete(uri); break; case PATCH: serializer = getSupportedSerializer(command.getRequest()); rq = new HttpPatch(uri); ((HttpPatch) rq) .setEntity(new ByteArrayEntity(serializer.serialize(command.getRequest()), ContentType.create( serializer.getMimeType()))); break; default: throw new IllegalArgumentException("Method '" + command.getHttpMethod() + "' is unsupported"); } return executeInternal(rq, new TypeConverterCallback<RS>(serializers, command.getResponseType())); }
java
{ "resource": "" }
q16155
HttpClientRestEndpoint.getSupportedSerializer
train
private Serializer getSupportedSerializer(Object o) throws SerializerException { for (Serializer s : serializers) { if (s.canWrite(o)) { return s; } } throw new SerializerException("Unable to find serializer for object with type '" + o.getClass() + "'"); }
java
{ "resource": "" }
q16156
ViewRecycler.inflate
train
@SafeVarargs @NonNull public final Pair<View, Boolean> inflate(@NonNull final ItemType item, @Nullable final ViewGroup parent, final boolean useCache, @NonNull final ParamType... params) { Condition.INSTANCE.ensureNotNull(params, "The array may not be null"); Condition.INSTANCE.ensureNotNull(getAdapter(), "No adapter has been set", IllegalStateException.class); View view = getView(item); boolean inflated = false; if (view == null) { int viewType = getAdapter().getViewType(item); if (useCache) { view = pollUnusedView(viewType); } if (view == null) { view = getAdapter() .onInflateView(getLayoutInflater(), parent, item, viewType, params); inflated = true; getLogger().logInfo(getClass(), "Inflated view to visualize item " + item + " using view type " + viewType); } else { getLogger().logInfo(getClass(), "Reusing view to visualize item " + item + " using view type " + viewType); } getActiveViews().put(item, view); } getAdapter().onShowView(getContext(), view, item, inflated, params); getLogger().logDebug(getClass(), "Updated view of item " + item); return Pair.create(view, inflated); }
java
{ "resource": "" }
q16157
FileUtil.mkdir
train
private static void mkdir(@NonNull final File directory, final boolean createParents) throws IOException { Condition.INSTANCE.ensureNotNull(directory, "The directory may not be null"); boolean result = createParents ? directory.mkdirs() : directory.mkdir(); if (!result && !directory.exists()) { throw new IOException("Failed to create directory \"" + directory + "\""); } }
java
{ "resource": "" }
q16158
FileUtil.deleteRecursively
train
public static void deleteRecursively(@NonNull final File file) throws IOException { Condition.INSTANCE.ensureNotNull(file, "The file or directory may not be null"); if (file.isDirectory()) { for (File child : file.listFiles()) { deleteRecursively(child); } } delete(file); }
java
{ "resource": "" }
q16159
FileUtil.createNewFile
train
public static void createNewFile(@NonNull final File file, final boolean overwrite) throws IOException { Condition.INSTANCE.ensureNotNull(file, "The file may not be null"); boolean result = file.createNewFile(); if (!result) { if (overwrite) { try { delete(file); createNewFile(file, false); } catch (IOException e) { throw new IOException("Failed to overwrite file \"" + file + "\""); } } else if (file.exists()) { throw new IOException("File \"" + file + "\" does already exist"); } else { throw new IllegalArgumentException("The file must not be a directory"); } } }
java
{ "resource": "" }
q16160
Driver.maybeDoOffset
train
public void maybeDoOffset(){ long seen = tuplesSeen; if (offsetCommitInterval > 0 && seen % offsetCommitInterval == 0 && offsetStorage != null && fp.supportsOffsetManagement()){ doOffsetInternal(); } }
java
{ "resource": "" }
q16161
ThemeUtil.obtainStyledAttributes
train
private static TypedArray obtainStyledAttributes(@NonNull final Context context, @StyleRes final int themeResourceId, @AttrRes final int resourceId) { Condition.INSTANCE.ensureNotNull(context, "The context may not be null"); Theme theme = context.getTheme(); int[] attrs = new int[]{resourceId}; if (themeResourceId != -1) { return theme.obtainStyledAttributes(themeResourceId, attrs); } else { return theme.obtainStyledAttributes(attrs); } }
java
{ "resource": "" }
q16162
ThemeUtil.getBoolean
train
public static boolean getBoolean(@NonNull final Context context, @StyleRes final int themeResourceId, @AttrRes final int resourceId) { TypedArray typedArray = null; try { typedArray = obtainStyledAttributes(context, themeResourceId, resourceId); return typedArray.getBoolean(0, false); } finally { if (typedArray != null) { typedArray.recycle(); } } }
java
{ "resource": "" }
q16163
ThemeUtil.getBoolean
train
public static boolean getBoolean(@NonNull final Context context, @AttrRes final int resourceId, final boolean defaultValue) { return getBoolean(context, -1, resourceId, defaultValue); }
java
{ "resource": "" }
q16164
ThemeUtil.getInt
train
public static int getInt(@NonNull final Context context, @AttrRes final int resourceId, final int defaultValue) { return getInt(context, -1, resourceId, defaultValue); }
java
{ "resource": "" }
q16165
ThemeUtil.getFloat
train
public static float getFloat(@NonNull final Context context, @AttrRes final int resourceId, final float defaultValue) { return getFloat(context, -1, resourceId, defaultValue); }
java
{ "resource": "" }
q16166
ThemeUtil.getResId
train
public static int getResId(@NonNull final Context context, @AttrRes final int resourceId, final int defaultValue) { return getResId(context, -1, resourceId, defaultValue); }
java
{ "resource": "" }
q16167
ProtocolCommand.setRequest
train
void setRequest(HttpUriRequest request) { requestLock.lock(); try { if (this.request != null) { throw new SparqlException("Command is already executing a request."); } this.request = request; } finally { requestLock.unlock(); } }
java
{ "resource": "" }
q16168
ProtocolCommand.execute
train
private Result execute(ResultType cmdType) throws SparqlException { String mimeType = contentType; // Validate the user-supplied MIME type. if (mimeType != null && !ResultFactory.supports(mimeType, cmdType)) { logger.warn("Requested MIME content type '{}' does not support expected response type: {}", mimeType, cmdType); mimeType = null; } // Get the default MIME type to request if (mimeType == null) { mimeType = ResultFactory.getDefaultMediaType(cmdType); } if (logger.isDebugEnabled()) { logRequest(cmdType, mimeType); } try { HttpResponse response = SparqlCall.executeRequest(this, mimeType); return ResultFactory.getResult(this, response, cmdType); } catch (Throwable t) { release(); throw SparqlException.convert("Error creating SPARQL result from server response", t); } }
java
{ "resource": "" }
q16169
ProtocolCommand.logRequest
train
private void logRequest(ResultType cmdType, String mimeType) { StringBuilder sb = new StringBuilder("Executing SPARQL protocol request "); sb.append("to endpoint <").append(((ProtocolDataSource)getConnection().getDataSource()).getUrl()).append("> "); if (mimeType != null) { sb.append("for content type '").append(mimeType).append("' "); } else { sb.append("for unknown content type "); } if (cmdType != null) { sb.append("with expected results of type ").append(cmdType).append("."); } else { sb.append("with unknown expected result type."); } logger.debug(sb.toString()); }
java
{ "resource": "" }
q16170
DriverNode.initialize
train
public void initialize(){ thread = new Thread(collectorProcessor); thread.start(); for (DriverNode dn : this.children){ dn.initialize(); } }
java
{ "resource": "" }
q16171
DriverNode.addChild
train
public void addChild(DriverNode dn){ collectorProcessor.getChildren().add(dn.operator); children.add(dn); }
java
{ "resource": "" }
q16172
MetaWrapper.getNamespace
train
public static String getNamespace(JsonNode node) { JsonNode nodeNs = obj(node).get(ID_NAMESPACE); return (nodeNs != null) ? nodeNs.asText() : null; }
java
{ "resource": "" }
q16173
MetaWrapper.setVersion
train
public static void setVersion(JsonNode node, Long version) { obj(node).put(ID_VERSION, version); }
java
{ "resource": "" }
q16174
MetaWrapper.getTimestamp
train
public static Date getTimestamp(JsonNode node) { String text = obj(node).get(ID_TIMESTAMP).asText(); return isNotBlank(text) ? from(instantUtc(text)).toDate() : null; }
java
{ "resource": "" }
q16175
DragHelper.update
train
public final void update(final float position) { if (reset) { reset = false; distance = 0; thresholdReachedPosition = -1; dragStartTime = -1; dragStartPosition = position; reachedThreshold = false; minDragDistance = 0; maxDragDistance = 0; } if (!reachedThreshold) { if (reachedThreshold(position - dragStartPosition)) { dragStartTime = System.currentTimeMillis(); reachedThreshold = true; thresholdReachedPosition = position; } } else { float newDistance = position - thresholdReachedPosition; if (minDragDistance != 0 && minDragDistance > newDistance) { newDistance = minDragDistance; thresholdReachedPosition = position - minDragDistance; } if (maxDragDistance != 0 && maxDragDistance < newDistance) { newDistance = maxDragDistance; thresholdReachedPosition = position - maxDragDistance; } distance = newDistance; } }
java
{ "resource": "" }
q16176
DragHelper.setMaxDragDistance
train
public final void setMaxDragDistance(final float maxDragDistance) { if (maxDragDistance != 0) { Condition.INSTANCE.ensureGreater(maxDragDistance, threshold, "The maximum drag distance must be greater than " + threshold); } this.maxDragDistance = maxDragDistance; }
java
{ "resource": "" }
q16177
DragHelper.setMinDragDistance
train
public final void setMinDragDistance(final float minDragDistance) { if (minDragDistance != 0) { Condition.INSTANCE.ensureSmaller(minDragDistance, -threshold, "The minimum drag distance must be smaller than " + -threshold); } this.minDragDistance = minDragDistance; }
java
{ "resource": "" }
q16178
DragHelper.getDragSpeed
train
public final float getDragSpeed() { if (hasThresholdBeenReached()) { long interval = System.currentTimeMillis() - dragStartTime; return Math.abs(getDragDistance()) / (float) interval; } else { return -1; } }
java
{ "resource": "" }
q16179
MainActivity.createSeekBarListener
train
private OnSeekBarChangeListener createSeekBarListener() { return new OnSeekBarChangeListener() { @Override public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { adaptElevation(progress, parallelLightCheckBox.isChecked()); } @Override public void onStartTrackingTouch(final SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { } }; }
java
{ "resource": "" }
q16180
MainActivity.adaptElevation
train
private void adaptElevation(final int elevation, final boolean parallelLight) { elevationTextView.setText(String.format(getString(R.string.elevation), elevation)); elevationLeft.setShadowElevation(elevation); elevationLeft.emulateParallelLight(parallelLight); elevationTopLeft.setShadowElevation(elevation); elevationTopLeft.emulateParallelLight(parallelLight); elevationTop.setShadowElevation(elevation); elevationTop.emulateParallelLight(parallelLight); elevationTopRight.setShadowElevation(elevation); elevationTopRight.emulateParallelLight(parallelLight); elevationRight.setShadowElevation(elevation); elevationRight.emulateParallelLight(parallelLight); elevationBottomRight.setShadowElevation(elevation); elevationBottomRight.emulateParallelLight(parallelLight); elevationBottom.setShadowElevation(elevation); elevationBottom.emulateParallelLight(parallelLight); elevationBottomLeft.setShadowElevation(elevation); elevationBottomLeft.emulateParallelLight(parallelLight); }
java
{ "resource": "" }
q16181
SegmentFactory.getSegment
train
public Segment getSegment(SEGMENT_TYPE segmentType){ if(segmentType == null){ return null; } if(segmentType == SEGMENT_TYPE.LINEAR){ return new LinearSegment(); } else if(segmentType == SEGMENT_TYPE.SPATIAL){ return new SpatialSegment(); } else if(segmentType == SEGMENT_TYPE.TEMPORAL){ return new TemporalSegment(); } else if(segmentType == SEGMENT_TYPE.SPATIOTEMPORAL){ return new SpatioTemporalSegment(); } return null; }
java
{ "resource": "" }
q16182
Verjson.write
train
public String write(T obj) throws JsonProcessingException { Date ts = includeTimestamp ? Date.from(now()) : null; MetaWrapper wrapper = new MetaWrapper(getHighestSourceVersion(), getNamespace(), obj, ts); return mapper.writeValueAsString(wrapper); }
java
{ "resource": "" }
q16183
ScrimInsetsLayout.obtainInsetForeground
train
private void obtainInsetForeground(@NonNull final TypedArray typedArray) { int color = typedArray.getColor(R.styleable.ScrimInsetsLayout_insetDrawable, -1); if (color == -1) { Drawable drawable = typedArray.getDrawable(R.styleable.ScrimInsetsLayout_insetDrawable); if (drawable != null) { setInsetDrawable(drawable); } else { setInsetColor(ContextCompat.getColor(getContext(), R.color.scrim_insets_layout_insets_drawable_default_value)); } } else { setInsetColor(color); } }
java
{ "resource": "" }
q16184
RelativeToEasterSundayParser.parse
train
public void parse (final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) { for (final RelativeToEasterSunday aDay : aConfig.getRelativeToEasterSunday ()) { if (!isValid (aDay, nYear)) continue; final ChronoLocalDate aEasterSunday = getEasterSunday (nYear, aDay.getChronology ()); aEasterSunday.plus (aDay.getDays (), ChronoUnit.DAYS); final String sPropertiesKey = "christian." + aDay.getDescriptionPropertiesKey (); addChrstianHoliday (aEasterSunday, sPropertiesKey, XMLHolidayHelper.getType (aDay.getLocalizedType ()), aHolidayMap); } }
java
{ "resource": "" }
q16185
RelativeToEasterSundayParser.addChrstianHoliday
train
protected final void addChrstianHoliday (final ChronoLocalDate aDate, final String sPropertiesKey, final IHolidayType aHolidayType, final HolidayMap holidays) { final LocalDate convertedDate = LocalDate.from (aDate); holidays.add (convertedDate, new ResourceBundleHoliday (aHolidayType, sPropertiesKey)); }
java
{ "resource": "" }
q16186
RelativeToEasterSundayParser.getEasterSunday
train
public static ChronoLocalDate getEasterSunday (final int nYear) { return nYear <= CPDT.LAST_JULIAN_YEAR ? getJulianEasterSunday (nYear) : getGregorianEasterSunday (nYear); }
java
{ "resource": "" }
q16187
RelativeToEasterSundayParser.getJulianEasterSunday
train
public static JulianDate getJulianEasterSunday (final int nYear) { final int a = nYear % 4; final int b = nYear % 7; final int c = nYear % 19; final int d = (19 * c + 15) % 30; final int e = (2 * a + 4 * b - d + 34) % 7; final int x = d + e + 114; final int nMonth = x / 31; final int nDay = (x % 31) + 1; return JulianDate.of (nYear, (nMonth == 3 ? Month.MARCH : Month.APRIL).getValue (), nDay); }
java
{ "resource": "" }
q16188
RelativeToEasterSundayParser.getGregorianEasterSunday
train
public static LocalDate getGregorianEasterSunday (final int nYear) { final int a = nYear % 19; final int b = nYear / 100; final int c = nYear % 100; final int d = b / 4; final int e = b % 4; final int f = (b + 8) / 25; final int g = (b - f + 1) / 3; final int h = (19 * a + b - d - g + 15) % 30; final int i = c / 4; final int j = c % 4; final int k = (32 + 2 * e + 2 * i - h - j) % 7; final int l = (a + 11 * h + 22 * k) / 451; final int x = h + k - 7 * l + 114; final int nMonth = x / 31; final int nDay = (x % 31) + 1; return LocalDate.of (nYear, (nMonth == 3 ? Month.MARCH : Month.APRIL), nDay); }
java
{ "resource": "" }
q16189
ElevationUtil.createEdgeShadow
train
private static Bitmap createEdgeShadow(@NonNull final Context context, final int elevation, @NonNull final Orientation orientation, final boolean parallelLight) { if (elevation == 0) { return null; } else { float shadowWidth = getShadowWidth(context, elevation, orientation, parallelLight); int shadowColor = getShadowColor(elevation, orientation, parallelLight); int bitmapWidth = (int) Math .round((orientation == Orientation.LEFT || orientation == Orientation.RIGHT) ? Math.ceil(shadowWidth) : 1); int bitmapHeight = (int) Math .round((orientation == Orientation.TOP || orientation == Orientation.BOTTOM) ? Math.ceil(shadowWidth) : 1); Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Shader linearGradient = createLinearGradient(orientation, bitmapWidth, bitmapHeight, shadowWidth, shadowColor); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); paint.setShader(linearGradient); canvas.drawRect(0, 0, bitmapWidth, bitmapHeight, paint); return bitmap; } }
java
{ "resource": "" }
q16190
ElevationUtil.createCornerShadow
train
private static Bitmap createCornerShadow(@NonNull final Context context, final int elevation, @NonNull final Orientation orientation, final boolean parallelLight) { if (elevation == 0) { return null; } else { float horizontalShadowWidth = getHorizontalShadowWidth(context, elevation, orientation, parallelLight); float verticalShadowWidth = getVerticalShadowWidth(context, elevation, orientation, parallelLight); int horizontalShadowColor = getHorizontalShadowColor(elevation, orientation, parallelLight); int verticalShadowColor = getVerticalShadowColor(elevation, orientation, parallelLight); int bitmapWidth = (int) Math.round(Math.ceil(verticalShadowWidth)); int bitmapHeight = (int) Math.round(Math.ceil(horizontalShadowWidth)); int bitmapSize = Math.max(bitmapWidth, bitmapHeight); Bitmap bitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); RectF arcBounds = getCornerBounds(orientation, bitmapSize); float startAngle = getCornerAngle(orientation); int[] sweepColors = getCornerColors(orientation, horizontalShadowColor, verticalShadowColor); SweepGradient sweepGradient = new SweepGradient(arcBounds.left + arcBounds.width() / 2f, arcBounds.top + arcBounds.height() / 2f, sweepColors, new float[]{startAngle / FULL_ARC_DEGRESS, startAngle / FULL_ARC_DEGRESS + QUARTER_ARC_DEGRESS / FULL_ARC_DEGRESS}); paint.setShader(sweepGradient); canvas.drawArc(arcBounds, startAngle, QUARTER_ARC_DEGRESS, true, paint); Shader radialGradient = createRadialGradient(orientation, bitmapSize, Math.max(horizontalShadowWidth, verticalShadowWidth)); paint.setShader(radialGradient); paint.setColor(Color.BLACK); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); canvas.drawRect(0, 0, bitmapSize, bitmapSize, paint); return BitmapUtil.resize(bitmap, bitmapWidth, bitmapHeight); } }
java
{ "resource": "" }
q16191
ElevationUtil.getCornerBounds
train
private static RectF getCornerBounds(@NonNull final Orientation orientation, final int size) { switch (orientation) { case TOP_LEFT: return new RectF(0, 0, 2 * size, 2 * size); case TOP_RIGHT: return new RectF(-size, 0, size, 2 * size); case BOTTOM_LEFT: return new RectF(0, -size, 2 * size, size); case BOTTOM_RIGHT: return new RectF(-size, -size, size, size); default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } }
java
{ "resource": "" }
q16192
ElevationUtil.getHorizontalShadowWidth
train
private static float getHorizontalShadowWidth(@NonNull final Context context, final int elevation, @NonNull final Orientation orientation, final boolean parallelLight) { switch (orientation) { case TOP_LEFT: case TOP_RIGHT: return getShadowWidth(context, elevation, Orientation.TOP, parallelLight); case BOTTOM_LEFT: case BOTTOM_RIGHT: return getShadowWidth(context, elevation, Orientation.BOTTOM, parallelLight); default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } }
java
{ "resource": "" }
q16193
ElevationUtil.getShadowWidth
train
private static float getShadowWidth(@NonNull final Context context, final int elevation, @NonNull final Orientation orientation, final boolean parallelLight) { float referenceElevationWidth = (float) elevation / (float) REFERENCE_ELEVATION * REFERENCE_SHADOW_WIDTH; float shadowWidth; if (parallelLight) { shadowWidth = referenceElevationWidth * BOTTOM_SCALE_FACTOR; } else { switch (orientation) { case LEFT: shadowWidth = referenceElevationWidth * LEFT_SCALE_FACTOR; break; case TOP: shadowWidth = referenceElevationWidth * TOP_SCALE_FACTOR; break; case RIGHT: shadowWidth = referenceElevationWidth * RIGHT_SCALE_FACTOR; break; case BOTTOM: shadowWidth = referenceElevationWidth * BOTTOM_SCALE_FACTOR; break; default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } } return dpToPixels(context, shadowWidth); }
java
{ "resource": "" }
q16194
ElevationUtil.getHorizontalShadowColor
train
private static int getHorizontalShadowColor(final int elevation, @NonNull final Orientation orientation, final boolean parallelLight) { switch (orientation) { case TOP_LEFT: case TOP_RIGHT: return getShadowColor(elevation, Orientation.TOP, parallelLight); case BOTTOM_LEFT: case BOTTOM_RIGHT: return getShadowColor(elevation, Orientation.BOTTOM, parallelLight); default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } }
java
{ "resource": "" }
q16195
ElevationUtil.getVerticalShadowColor
train
private static int getVerticalShadowColor(final int elevation, @NonNull final Orientation orientation, final boolean parallelLight) { switch (orientation) { case TOP_LEFT: case BOTTOM_LEFT: return getShadowColor(elevation, Orientation.LEFT, parallelLight); case TOP_RIGHT: case BOTTOM_RIGHT: return getShadowColor(elevation, Orientation.RIGHT, parallelLight); default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } }
java
{ "resource": "" }
q16196
ElevationUtil.getShadowColor
train
private static int getShadowColor(final int elevation, @NonNull final Orientation orientation, final boolean parallelLight) { int alpha; if (parallelLight) { alpha = getShadowAlpha(elevation, MIN_BOTTOM_ALPHA, MAX_BOTTOM_ALPHA); } else { switch (orientation) { case LEFT: alpha = getShadowAlpha(elevation, MIN_LEFT_ALPHA, MAX_LEFT_ALPHA); break; case TOP: alpha = getShadowAlpha(elevation, MIN_TOP_ALPHA, MAX_TOP_ALPHA); break; case RIGHT: alpha = getShadowAlpha(elevation, MIN_RIGHT_ALPHA, MAX_RIGHT_ALPHA); break; case BOTTOM: alpha = getShadowAlpha(elevation, MIN_BOTTOM_ALPHA, MAX_BOTTOM_ALPHA); break; default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } } return Color.argb(alpha, 0, 0, 0); }
java
{ "resource": "" }
q16197
ElevationUtil.getShadowAlpha
train
private static int getShadowAlpha(final int elevation, final int minTransparency, final int maxTransparency) { float ratio = (float) elevation / (float) MAX_ELEVATION; int range = maxTransparency - minTransparency; return Math.round(minTransparency + ratio * range); }
java
{ "resource": "" }
q16198
ElevationUtil.createLinearGradient
train
private static Shader createLinearGradient(@NonNull final Orientation orientation, final int bitmapWidth, final int bitmapHeight, final float shadowWidth, @ColorInt final int shadowColor) { RectF bounds = new RectF(); switch (orientation) { case LEFT: bounds.left = bitmapWidth; bounds.right = bitmapWidth - shadowWidth; break; case TOP: bounds.top = bitmapHeight; bounds.bottom = bitmapHeight - shadowWidth; break; case RIGHT: bounds.right = shadowWidth; break; case BOTTOM: bounds.bottom = shadowWidth; break; default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } return new LinearGradient(bounds.left, bounds.top, bounds.right, bounds.bottom, shadowColor, Color.TRANSPARENT, Shader.TileMode.CLAMP); }
java
{ "resource": "" }
q16199
ElevationUtil.createRadialGradient
train
private static Shader createRadialGradient(@NonNull final Orientation orientation, final int bitmapSize, final float radius) { PointF center = new PointF(); switch (orientation) { case TOP_LEFT: center.x = bitmapSize; center.y = bitmapSize; break; case TOP_RIGHT: center.y = bitmapSize; break; case BOTTOM_LEFT: center.x = bitmapSize; break; case BOTTOM_RIGHT: break; default: throw new IllegalArgumentException("Invalid orientation: " + orientation); } return new RadialGradient(center.x, center.y, radius, Color.TRANSPARENT, Color.BLACK, Shader.TileMode.CLAMP); }
java
{ "resource": "" }