id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
32,300 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/FileUtils.java | FileUtils.createGetContentIntent | public static Intent createGetContentIntent() {
// Implicitly allow the user to select a particular kind of data
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// The MIME data type filter
intent.setType("*/*");
// Only return URIs that can be opened with ContentResolver
intent.addCategory(Intent.CATEGORY_OPENABLE);
return intent;
} | java | public static Intent createGetContentIntent() {
// Implicitly allow the user to select a particular kind of data
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// The MIME data type filter
intent.setType("*/*");
// Only return URIs that can be opened with ContentResolver
intent.addCategory(Intent.CATEGORY_OPENABLE);
return intent;
} | [
"public",
"static",
"Intent",
"createGetContentIntent",
"(",
")",
"{",
"// Implicitly allow the user to select a particular kind of data",
"final",
"Intent",
"intent",
"=",
"new",
"Intent",
"(",
"Intent",
".",
"ACTION_GET_CONTENT",
")",
";",
"// The MIME data type filter",
... | Get the Intent for selecting content to be used in an Intent Chooser.
@return The intent for opening a file with Intent.createChooser()
@author paulburke | [
"Get",
"the",
"Intent",
"for",
"selecting",
"content",
"to",
"be",
"used",
"in",
"an",
"Intent",
"Chooser",
"."
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/FileUtils.java#L513-L521 |
32,301 | Tourenathan-G5organisation/SiliCompressor | app/src/main/java/com/iceteck/silicompressor/SelectPictureActivity.java | SelectPictureActivity.requestPermissions | private void requestPermissions(int mediaType) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (mediaType == TYPE_IMAGE) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_STORAGE);
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_STORAGE_VID);
}
} else {
if (mediaType == TYPE_IMAGE) {
// Want to compress an image
dispatchTakePictureIntent();
} else if (mediaType == TYPE_VIDEO) {
// Want to compress a video
dispatchTakeVideoIntent();
}
}
} | java | private void requestPermissions(int mediaType) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (mediaType == TYPE_IMAGE) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_STORAGE);
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_WRITE_STORAGE_VID);
}
} else {
if (mediaType == TYPE_IMAGE) {
// Want to compress an image
dispatchTakePictureIntent();
} else if (mediaType == TYPE_VIDEO) {
// Want to compress a video
dispatchTakeVideoIntent();
}
}
} | [
"private",
"void",
"requestPermissions",
"(",
"int",
"mediaType",
")",
"{",
"if",
"(",
"ContextCompat",
".",
"checkSelfPermission",
"(",
"this",
",",
"Manifest",
".",
"permission",
".",
"WRITE_EXTERNAL_STORAGE",
")",
"!=",
"PackageManager",
".",
"PERMISSION_GRANTED"... | Request Permission for writing to External Storage in 6.0 and up | [
"Request",
"Permission",
"for",
"writing",
"to",
"External",
"Storage",
"in",
"6",
".",
"0",
"and",
"up"
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/app/src/main/java/com/iceteck/silicompressor/SelectPictureActivity.java#L86-L109 |
32,302 | Tourenathan-G5organisation/SiliCompressor | app/src/main/java/com/iceteck/silicompressor/SelectPictureActivity.java | SelectPictureActivity.onActivityResult | @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//verify if the image was gotten successfully
if (requestCode == REQUEST_TAKE_CAMERA_PHOTO && resultCode == Activity.RESULT_OK) {
new ImageCompressionAsyncTask(this).execute(mCurrentPhotoPath,
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Silicompressor/images");
} else if (requestCode == REQUEST_TAKE_VIDEO && resultCode == RESULT_OK) {
if (data.getData() != null) {
//create destination directory
File f = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) + "/Silicompressor/videos");
if (f.mkdirs() || f.isDirectory())
//compress and output new video specs
new VideoCompressAsyncTask(this).execute(mCurrentPhotoPath, f.getPath());
}
}
} | java | @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//verify if the image was gotten successfully
if (requestCode == REQUEST_TAKE_CAMERA_PHOTO && resultCode == Activity.RESULT_OK) {
new ImageCompressionAsyncTask(this).execute(mCurrentPhotoPath,
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Silicompressor/images");
} else if (requestCode == REQUEST_TAKE_VIDEO && resultCode == RESULT_OK) {
if (data.getData() != null) {
//create destination directory
File f = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) + "/Silicompressor/videos");
if (f.mkdirs() || f.isDirectory())
//compress and output new video specs
new VideoCompressAsyncTask(this).execute(mCurrentPhotoPath, f.getPath());
}
}
} | [
"@",
"Override",
"public",
"void",
"onActivityResult",
"(",
"int",
"requestCode",
",",
"int",
"resultCode",
",",
"Intent",
"data",
")",
"{",
"super",
".",
"onActivityResult",
"(",
"requestCode",
",",
"resultCode",
",",
"data",
")",
";",
"//verify if the image wa... | Method which will process the captured image | [
"Method",
"which",
"will",
"process",
"the",
"captured",
"image"
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/app/src/main/java/com/iceteck/silicompressor/SelectPictureActivity.java#L223-L246 |
32,303 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.with | public static SiliCompressor with(Context context) {
if (singleton == null) {
synchronized (SiliCompressor.class) {
if (singleton == null) {
singleton = new Builder(context).build();
}
}
}
return singleton;
} | java | public static SiliCompressor with(Context context) {
if (singleton == null) {
synchronized (SiliCompressor.class) {
if (singleton == null) {
singleton = new Builder(context).build();
}
}
}
return singleton;
} | [
"public",
"static",
"SiliCompressor",
"with",
"(",
"Context",
"context",
")",
"{",
"if",
"(",
"singleton",
"==",
"null",
")",
"{",
"synchronized",
"(",
"SiliCompressor",
".",
"class",
")",
"{",
"if",
"(",
"singleton",
"==",
"null",
")",
"{",
"singleton",
... | initialise the class and set the context | [
"initialise",
"the",
"class",
"and",
"set",
"the",
"context"
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L50-L60 |
32,304 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.compress | public String compress(String imagePath, File destination, boolean deleteSourceImage) {
String compressedImagePath = compressImage(imagePath, destination);
if (deleteSourceImage) {
boolean isdeleted = deleteImageFile(imagePath);
Log.d(LOG_TAG, (isdeleted) ? "Source image file deleted" : "Error: Source image file not deleted.");
}
return compressedImagePath;
} | java | public String compress(String imagePath, File destination, boolean deleteSourceImage) {
String compressedImagePath = compressImage(imagePath, destination);
if (deleteSourceImage) {
boolean isdeleted = deleteImageFile(imagePath);
Log.d(LOG_TAG, (isdeleted) ? "Source image file deleted" : "Error: Source image file not deleted.");
}
return compressedImagePath;
} | [
"public",
"String",
"compress",
"(",
"String",
"imagePath",
",",
"File",
"destination",
",",
"boolean",
"deleteSourceImage",
")",
"{",
"String",
"compressedImagePath",
"=",
"compressImage",
"(",
"imagePath",
",",
"destination",
")",
";",
"if",
"(",
"deleteSourceIm... | Compress the image at with the specified path and return the filepath of the compressed image.
@param imagePath The path of the image you wish to compress.
@param destination The destination directory where the compressed image will be stored.
@param deleteSourceImage if True will delete the original file
@return filepath The path of the compressed image file | [
"Compress",
"the",
"image",
"at",
"with",
"the",
"specified",
"path",
"and",
"return",
"the",
"filepath",
"of",
"the",
"compressed",
"image",
"."
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L81-L92 |
32,305 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.compress | public String compress(int drawableID) throws IOException {
// Create a bitmap from this drawable
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getApplicationContext().getResources(), drawableID);
if (null != bitmap) {
// Create a file from the bitmap
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
FileOutputStream out = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
// Compress the new file
Uri copyImageUri = FileProvider.getUriForFile(mContext, FILE_PROVIDER_AUTHORITY, image);
String compressedImagePath = compressImage(image.getAbsolutePath(), new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Silicompressor/images"));
// Delete the file created from the drawable Id
if (image.exists()) {
deleteImageFile(image.getAbsolutePath());
}
// return the path to the compressed image
return compressedImagePath;
}
return null;
} | java | public String compress(int drawableID) throws IOException {
// Create a bitmap from this drawable
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getApplicationContext().getResources(), drawableID);
if (null != bitmap) {
// Create a file from the bitmap
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
FileOutputStream out = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
// Compress the new file
Uri copyImageUri = FileProvider.getUriForFile(mContext, FILE_PROVIDER_AUTHORITY, image);
String compressedImagePath = compressImage(image.getAbsolutePath(), new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Silicompressor/images"));
// Delete the file created from the drawable Id
if (image.exists()) {
deleteImageFile(image.getAbsolutePath());
}
// return the path to the compressed image
return compressedImagePath;
}
return null;
} | [
"public",
"String",
"compress",
"(",
"int",
"drawableID",
")",
"throws",
"IOException",
"{",
"// Create a bitmap from this drawable",
"Bitmap",
"bitmap",
"=",
"BitmapFactory",
".",
"decodeResource",
"(",
"mContext",
".",
"getApplicationContext",
"(",
")",
".",
"getRes... | Compress drawable file with specified drawableID
@param drawableID ID of the drawable file to compress
@return The path to the compressed file or null if the could not access drawable file
@throws IOException | [
"Compress",
"drawable",
"file",
"with",
"specified",
"drawableID"
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L101-L136 |
32,306 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.getCompressBitmap | public Bitmap getCompressBitmap(String imagePath, boolean deleteSourceImage) throws IOException {
File imageFile = new File(compressImage(imagePath, new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Silicompressor/images")));
Uri newImageUri = FileProvider.getUriForFile(mContext, FILE_PROVIDER_AUTHORITY, imageFile);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), newImageUri);
if (deleteSourceImage) {
boolean isdeleted = deleteImageFile(imagePath);
Log.d(LOG_TAG, (isdeleted) ? "Source image file deleted" : "Error: Source image file not deleted.");
}
// Delete the file created during the image compression
deleteImageFile(imageFile.getAbsolutePath());
// Return the required bitmap
return bitmap;
} | java | public Bitmap getCompressBitmap(String imagePath, boolean deleteSourceImage) throws IOException {
File imageFile = new File(compressImage(imagePath, new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Silicompressor/images")));
Uri newImageUri = FileProvider.getUriForFile(mContext, FILE_PROVIDER_AUTHORITY, imageFile);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), newImageUri);
if (deleteSourceImage) {
boolean isdeleted = deleteImageFile(imagePath);
Log.d(LOG_TAG, (isdeleted) ? "Source image file deleted" : "Error: Source image file not deleted.");
}
// Delete the file created during the image compression
deleteImageFile(imageFile.getAbsolutePath());
// Return the required bitmap
return bitmap;
} | [
"public",
"Bitmap",
"getCompressBitmap",
"(",
"String",
"imagePath",
",",
"boolean",
"deleteSourceImage",
")",
"throws",
"IOException",
"{",
"File",
"imageFile",
"=",
"new",
"File",
"(",
"compressImage",
"(",
"imagePath",
",",
"new",
"File",
"(",
"Environment",
... | Compress the image at with the specified path and return the bitmap data of the compressed image.
@param imagePath The path of the image file you wish to compress.
@param deleteSourceImage If True will delete the source file
@return Compress image bitmap
@throws IOException | [
"Compress",
"the",
"image",
"at",
"with",
"the",
"specified",
"path",
"and",
"return",
"the",
"bitmap",
"data",
"of",
"the",
"compressed",
"image",
"."
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L161-L178 |
32,307 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.compressVideo | public String compressVideo(String videoFilePath, String destinationDir) throws URISyntaxException {
return compressVideo(videoFilePath, destinationDir, 0, 0, 0);
} | java | public String compressVideo(String videoFilePath, String destinationDir) throws URISyntaxException {
return compressVideo(videoFilePath, destinationDir, 0, 0, 0);
} | [
"public",
"String",
"compressVideo",
"(",
"String",
"videoFilePath",
",",
"String",
"destinationDir",
")",
"throws",
"URISyntaxException",
"{",
"return",
"compressVideo",
"(",
"videoFilePath",
",",
"destinationDir",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"}"
] | Perform background video compression. Make sure the videofileUri and destinationUri are valid
resources because this method does not account for missing directories hence your converted file
could be in an unknown location
This uses default values for the converted videos
@param videoFilePath source path for the video file
@param destinationDir destination directory where converted file should be saved
@return The Path of the compressed video file | [
"Perform",
"background",
"video",
"compression",
".",
"Make",
"sure",
"the",
"videofileUri",
"and",
"destinationUri",
"are",
"valid",
"resources",
"because",
"this",
"method",
"does",
"not",
"account",
"for",
"missing",
"directories",
"hence",
"your",
"converted",
... | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L315-L317 |
32,308 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.compressVideo | public String compressVideo(String videoFilePath, String destinationDir, int outWidth, int outHeight, int bitrate) throws URISyntaxException {
boolean isconverted = MediaController.getInstance().convertVideo(videoFilePath, new File(destinationDir), outWidth, outHeight, bitrate);
if (isconverted) {
Log.v(LOG_TAG, "Video Conversion Complete");
} else {
Log.v(LOG_TAG, "Video conversion in progress");
}
return MediaController.cachedFile.getPath();
} | java | public String compressVideo(String videoFilePath, String destinationDir, int outWidth, int outHeight, int bitrate) throws URISyntaxException {
boolean isconverted = MediaController.getInstance().convertVideo(videoFilePath, new File(destinationDir), outWidth, outHeight, bitrate);
if (isconverted) {
Log.v(LOG_TAG, "Video Conversion Complete");
} else {
Log.v(LOG_TAG, "Video conversion in progress");
}
return MediaController.cachedFile.getPath();
} | [
"public",
"String",
"compressVideo",
"(",
"String",
"videoFilePath",
",",
"String",
"destinationDir",
",",
"int",
"outWidth",
",",
"int",
"outHeight",
",",
"int",
"bitrate",
")",
"throws",
"URISyntaxException",
"{",
"boolean",
"isconverted",
"=",
"MediaController",
... | Perform background video compression. Make sure the videofileUri and destinationUri are valid
resources because this method does not account for missing directories hence your converted file
could be in an unknown location
@param videoFilePath source path for the video file
@param destinationDir destination directory where converted file should be saved
@param outWidth the target width of the compressed video or 0 to use default width
@param outHeight the target height of the compressed video or 0 to use default height
@param bitrate the target bitrate of the compressed video or 0 to user default bitrate
@return The Path of the compressed video file | [
"Perform",
"background",
"video",
"compression",
".",
"Make",
"sure",
"the",
"videofileUri",
"and",
"destinationUri",
"are",
"valid",
"resources",
"because",
"this",
"method",
"does",
"not",
"account",
"for",
"missing",
"directories",
"hence",
"your",
"converted",
... | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L332-L342 |
32,309 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.getFilename | private String getFilename(String filename, File file) {
if (!file.exists()) {
file.mkdirs();
}
String ext = ".jpg";
//get extension
/*if (Pattern.matches("^[.][p][n][g]", filename)){
ext = ".png";
}*/
return (file.getAbsolutePath() + "/IMG_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ext);
} | java | private String getFilename(String filename, File file) {
if (!file.exists()) {
file.mkdirs();
}
String ext = ".jpg";
//get extension
/*if (Pattern.matches("^[.][p][n][g]", filename)){
ext = ".png";
}*/
return (file.getAbsolutePath() + "/IMG_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ext);
} | [
"private",
"String",
"getFilename",
"(",
"String",
"filename",
",",
"File",
"file",
")",
"{",
"if",
"(",
"!",
"file",
".",
"exists",
"(",
")",
")",
"{",
"file",
".",
"mkdirs",
"(",
")",
";",
"}",
"String",
"ext",
"=",
"\".jpg\"",
";",
"//get extensio... | Get the file path of the compressed file
@param filename
@param file Destination directory
@return | [
"Get",
"the",
"file",
"path",
"of",
"the",
"compressed",
"file"
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L371-L383 |
32,310 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.getRealPathFromURI | private String getRealPathFromURI(String contentURI) {
Uri contentUri = Uri.parse(contentURI);
Cursor cursor = mContext.getContentResolver().query(contentUri, null, null, null, null);
if (cursor == null) {
return contentUri.getPath();
} else {
cursor.moveToFirst();
int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
Log.e(LOG_TAG, String.format("%d", index));
String str = cursor.getString(index);
cursor.close();
return str;
}
} | java | private String getRealPathFromURI(String contentURI) {
Uri contentUri = Uri.parse(contentURI);
Cursor cursor = mContext.getContentResolver().query(contentUri, null, null, null, null);
if (cursor == null) {
return contentUri.getPath();
} else {
cursor.moveToFirst();
int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
Log.e(LOG_TAG, String.format("%d", index));
String str = cursor.getString(index);
cursor.close();
return str;
}
} | [
"private",
"String",
"getRealPathFromURI",
"(",
"String",
"contentURI",
")",
"{",
"Uri",
"contentUri",
"=",
"Uri",
".",
"parse",
"(",
"contentURI",
")",
";",
"Cursor",
"cursor",
"=",
"mContext",
".",
"getContentResolver",
"(",
")",
".",
"query",
"(",
"conten... | Gets a valid path from the supply contentURI
@param contentURI
@return A validPath of the image | [
"Gets",
"a",
"valid",
"path",
"from",
"the",
"supply",
"contentURI"
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L391-L407 |
32,311 | Tourenathan-G5organisation/SiliCompressor | silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java | SiliCompressor.deleteImageFile | static boolean deleteImageFile(String imagePath) {
// Get the file
File imageFile = new File(imagePath);
boolean deleted = false;
// Delete the image
if (imageFile.exists()) {
deleted = imageFile.delete();
}
return deleted;
} | java | static boolean deleteImageFile(String imagePath) {
// Get the file
File imageFile = new File(imagePath);
boolean deleted = false;
// Delete the image
if (imageFile.exists()) {
deleted = imageFile.delete();
}
return deleted;
} | [
"static",
"boolean",
"deleteImageFile",
"(",
"String",
"imagePath",
")",
"{",
"// Get the file",
"File",
"imageFile",
"=",
"new",
"File",
"(",
"imagePath",
")",
";",
"boolean",
"deleted",
"=",
"false",
";",
"// Delete the image",
"if",
"(",
"imageFile",
".",
"... | Deletes image file for a given path.
@param imagePath The path of the photo to be deleted.
@return True if the file is deleted and False otherwise | [
"Deletes",
"image",
"file",
"for",
"a",
"given",
"path",
"."
] | 546f6cd7b2a7a783e1122df46c1e237f8938fe72 | https://github.com/Tourenathan-G5organisation/SiliCompressor/blob/546f6cd7b2a7a783e1122df46c1e237f8938fe72/silicompressor/src/main/java/com/iceteck/silicompressorr/SiliCompressor.java#L446-L457 |
32,312 | datastax/spark-cassandra-connector | spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/rdd/CassandraTableScanJavaRDD.java | CassandraTableScanJavaRDD.keyBy | public <K> CassandraJavaPairRDD<K, R> keyBy(
ClassTag<K> keyClassTag,
RowReaderFactory<K> rrf,
RowWriterFactory<K> rwf,
ColumnRef... columns) {
Seq<ColumnRef> columnRefs = JavaApiHelper.toScalaSeq(columns);
CassandraRDD<Tuple2<K, R>> resultRDD =
columns.length == 0
? rdd().keyBy(keyClassTag, rrf, rwf)
: rdd().keyBy(columnRefs, keyClassTag, rrf, rwf);
return new CassandraJavaPairRDD<>(resultRDD, keyClassTag, classTag());
} | java | public <K> CassandraJavaPairRDD<K, R> keyBy(
ClassTag<K> keyClassTag,
RowReaderFactory<K> rrf,
RowWriterFactory<K> rwf,
ColumnRef... columns) {
Seq<ColumnRef> columnRefs = JavaApiHelper.toScalaSeq(columns);
CassandraRDD<Tuple2<K, R>> resultRDD =
columns.length == 0
? rdd().keyBy(keyClassTag, rrf, rwf)
: rdd().keyBy(columnRefs, keyClassTag, rrf, rwf);
return new CassandraJavaPairRDD<>(resultRDD, keyClassTag, classTag());
} | [
"public",
"<",
"K",
">",
"CassandraJavaPairRDD",
"<",
"K",
",",
"R",
">",
"keyBy",
"(",
"ClassTag",
"<",
"K",
">",
"keyClassTag",
",",
"RowReaderFactory",
"<",
"K",
">",
"rrf",
",",
"RowWriterFactory",
"<",
"K",
">",
"rwf",
",",
"ColumnRef",
"...",
"co... | Selects a subset of columns mapped to the key of a JavaPairRDD.
The selected columns must be available in the CassandraRDD.
If no selected columns are given, all available columns are selected.
@param rrf row reader factory to convert the key to desired type K
@param rwf row writer factory for creating a partitioner for key type K
@param keyClassTag class tag of K, required to construct the result JavaPairRDD
@param columns list of columns passed to the rrf to create the row reader,
useful when the key is mapped to a tuple or a single value | [
"Selects",
"a",
"subset",
"of",
"columns",
"mapped",
"to",
"the",
"key",
"of",
"a",
"JavaPairRDD",
".",
"The",
"selected",
"columns",
"must",
"be",
"available",
"in",
"the",
"CassandraRDD",
".",
"If",
"no",
"selected",
"columns",
"are",
"given",
"all",
"av... | 23c09965c34576e17b4315772eb78af399ec9df1 | https://github.com/datastax/spark-cassandra-connector/blob/23c09965c34576e17b4315772eb78af399ec9df1/spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/rdd/CassandraTableScanJavaRDD.java#L91-L103 |
32,313 | datastax/spark-cassandra-connector | spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/PairRDDJavaFunctions.java | PairRDDJavaFunctions.spanByKey | public JavaPairRDD<K, Collection<V>> spanByKey(ClassTag<K> keyClassTag) {
ClassTag<Tuple2<K, Collection<V>>> tupleClassTag = classTag(Tuple2.class);
ClassTag<Collection<V>> vClassTag = classTag(Collection.class);
RDD<Tuple2<K, Collection<V>>> newRDD = pairRDDFunctions.spanByKey()
.map(JavaApiHelper.<K, V, Seq<V>>valuesAsJavaCollection(), tupleClassTag);
return new JavaPairRDD<>(newRDD, keyClassTag, vClassTag);
} | java | public JavaPairRDD<K, Collection<V>> spanByKey(ClassTag<K> keyClassTag) {
ClassTag<Tuple2<K, Collection<V>>> tupleClassTag = classTag(Tuple2.class);
ClassTag<Collection<V>> vClassTag = classTag(Collection.class);
RDD<Tuple2<K, Collection<V>>> newRDD = pairRDDFunctions.spanByKey()
.map(JavaApiHelper.<K, V, Seq<V>>valuesAsJavaCollection(), tupleClassTag);
return new JavaPairRDD<>(newRDD, keyClassTag, vClassTag);
} | [
"public",
"JavaPairRDD",
"<",
"K",
",",
"Collection",
"<",
"V",
">",
">",
"spanByKey",
"(",
"ClassTag",
"<",
"K",
">",
"keyClassTag",
")",
"{",
"ClassTag",
"<",
"Tuple2",
"<",
"K",
",",
"Collection",
"<",
"V",
">",
">",
">",
"tupleClassTag",
"=",
"cl... | Groups items with the same key, assuming the items with the same key are next to each other in the
collection. It does not perform shuffle, therefore it is much faster than using much more
universal Spark RDD `groupByKey`. For this method to be useful with Cassandra tables, the key must
represent a prefix of the primary key, containing at least the partition key of the Cassandra
table. | [
"Groups",
"items",
"with",
"the",
"same",
"key",
"assuming",
"the",
"items",
"with",
"the",
"same",
"key",
"are",
"next",
"to",
"each",
"other",
"in",
"the",
"collection",
".",
"It",
"does",
"not",
"perform",
"shuffle",
"therefore",
"it",
"is",
"much",
"... | 23c09965c34576e17b4315772eb78af399ec9df1 | https://github.com/datastax/spark-cassandra-connector/blob/23c09965c34576e17b4315772eb78af399ec9df1/spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/PairRDDJavaFunctions.java#L31-L38 |
32,314 | datastax/spark-cassandra-connector | spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/rdd/CassandraJavaRDD.java | CassandraJavaRDD.selectedColumnRefs | @SuppressWarnings("RedundantCast")
public ColumnRef[] selectedColumnRefs() {
ClassTag<ColumnRef> classTag = getClassTag(ColumnRef.class);
return (ColumnRef[]) rdd().selectedColumnRefs().toArray(classTag);
} | java | @SuppressWarnings("RedundantCast")
public ColumnRef[] selectedColumnRefs() {
ClassTag<ColumnRef> classTag = getClassTag(ColumnRef.class);
return (ColumnRef[]) rdd().selectedColumnRefs().toArray(classTag);
} | [
"@",
"SuppressWarnings",
"(",
"\"RedundantCast\"",
")",
"public",
"ColumnRef",
"[",
"]",
"selectedColumnRefs",
"(",
")",
"{",
"ClassTag",
"<",
"ColumnRef",
">",
"classTag",
"=",
"getClassTag",
"(",
"ColumnRef",
".",
"class",
")",
";",
"return",
"(",
"ColumnRef... | Returns the columns to be selected from the table. | [
"Returns",
"the",
"columns",
"to",
"be",
"selected",
"from",
"the",
"table",
"."
] | 23c09965c34576e17b4315772eb78af399ec9df1 | https://github.com/datastax/spark-cassandra-connector/blob/23c09965c34576e17b4315772eb78af399ec9df1/spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/rdd/CassandraJavaRDD.java#L108-L112 |
32,315 | datastax/spark-cassandra-connector | spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/rdd/CassandraJavaRDD.java | CassandraJavaRDD.selectedColumnNames | @SuppressWarnings("RedundantCast")
public String[] selectedColumnNames() {
ClassTag<String> classTag = getClassTag(String.class);
return (String[]) rdd().selectedColumnNames().toArray(classTag);
} | java | @SuppressWarnings("RedundantCast")
public String[] selectedColumnNames() {
ClassTag<String> classTag = getClassTag(String.class);
return (String[]) rdd().selectedColumnNames().toArray(classTag);
} | [
"@",
"SuppressWarnings",
"(",
"\"RedundantCast\"",
")",
"public",
"String",
"[",
"]",
"selectedColumnNames",
"(",
")",
"{",
"ClassTag",
"<",
"String",
">",
"classTag",
"=",
"getClassTag",
"(",
"String",
".",
"class",
")",
";",
"return",
"(",
"String",
"[",
... | Returns the names of columns to be selected from the table. | [
"Returns",
"the",
"names",
"of",
"columns",
"to",
"be",
"selected",
"from",
"the",
"table",
"."
] | 23c09965c34576e17b4315772eb78af399ec9df1 | https://github.com/datastax/spark-cassandra-connector/blob/23c09965c34576e17b4315772eb78af399ec9df1/spark-cassandra-connector/src/main/java/com/datastax/spark/connector/japi/rdd/CassandraJavaRDD.java#L117-L121 |
32,316 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/VectorGraphicsEncoder.java | VectorGraphicsEncoder.addFileExtension | public static String addFileExtension(
String fileName, VectorGraphicsFormat vectorGraphicsFormat) {
String fileNameWithFileExtension = fileName;
final String newFileExtension = "." + vectorGraphicsFormat.toString().toLowerCase();
if (fileName.length() <= newFileExtension.length()
|| !fileName
.substring(fileName.length() - newFileExtension.length(), fileName.length())
.equalsIgnoreCase(newFileExtension)) {
fileNameWithFileExtension = fileName + newFileExtension;
}
return fileNameWithFileExtension;
} | java | public static String addFileExtension(
String fileName, VectorGraphicsFormat vectorGraphicsFormat) {
String fileNameWithFileExtension = fileName;
final String newFileExtension = "." + vectorGraphicsFormat.toString().toLowerCase();
if (fileName.length() <= newFileExtension.length()
|| !fileName
.substring(fileName.length() - newFileExtension.length(), fileName.length())
.equalsIgnoreCase(newFileExtension)) {
fileNameWithFileExtension = fileName + newFileExtension;
}
return fileNameWithFileExtension;
} | [
"public",
"static",
"String",
"addFileExtension",
"(",
"String",
"fileName",
",",
"VectorGraphicsFormat",
"vectorGraphicsFormat",
")",
"{",
"String",
"fileNameWithFileExtension",
"=",
"fileName",
";",
"final",
"String",
"newFileExtension",
"=",
"\".\"",
"+",
"vectorGrap... | Only adds the extension of the VectorGraphicsFormat to the filename if the filename doesn't
already have it.
@param fileName
@param vectorGraphicsFormat
@return filename (if extension already exists), otherwise;: filename + "." + extension | [
"Only",
"adds",
"the",
"extension",
"of",
"the",
"VectorGraphicsFormat",
"to",
"the",
"filename",
"if",
"the",
"filename",
"doesn",
"t",
"already",
"have",
"it",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/VectorGraphicsEncoder.java#L72-L84 |
32,317 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java | AxisPair.overrideMinMaxForXAxis | private void overrideMinMaxForXAxis() {
double overrideXAxisMinValue = xAxis.getMin();
double overrideXAxisMaxValue = xAxis.getMax();
// override min and maxValue if specified
if (chart.getStyler().getXAxisMin() != null) {
overrideXAxisMinValue = chart.getStyler().getXAxisMin();
}
if (chart.getStyler().getXAxisMax() != null) {
overrideXAxisMaxValue = chart.getStyler().getXAxisMax();
}
xAxis.setMin(overrideXAxisMinValue);
xAxis.setMax(overrideXAxisMaxValue);
} | java | private void overrideMinMaxForXAxis() {
double overrideXAxisMinValue = xAxis.getMin();
double overrideXAxisMaxValue = xAxis.getMax();
// override min and maxValue if specified
if (chart.getStyler().getXAxisMin() != null) {
overrideXAxisMinValue = chart.getStyler().getXAxisMin();
}
if (chart.getStyler().getXAxisMax() != null) {
overrideXAxisMaxValue = chart.getStyler().getXAxisMax();
}
xAxis.setMin(overrideXAxisMinValue);
xAxis.setMax(overrideXAxisMaxValue);
} | [
"private",
"void",
"overrideMinMaxForXAxis",
"(",
")",
"{",
"double",
"overrideXAxisMinValue",
"=",
"xAxis",
".",
"getMin",
"(",
")",
";",
"double",
"overrideXAxisMaxValue",
"=",
"xAxis",
".",
"getMax",
"(",
")",
";",
"// override min and maxValue if specified",
"if... | Here we can add special case min max calculations and take care of manual min max settings. | [
"Here",
"we",
"can",
"add",
"special",
"case",
"min",
"max",
"calculations",
"and",
"take",
"care",
"of",
"manual",
"min",
"max",
"settings",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisPair.java#L324-L339 |
32,318 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_.java | AxisTickCalculator_.willLabelsFitInTickSpaceHint | boolean willLabelsFitInTickSpaceHint(List<String> tickLabels, int tickSpacingHint) {
// Assume that for Y-Axis the ticks will all fit based on their tickSpace hint because the text
// is usually horizontal and "short". This more applies to the X-Axis.
if (this.axisDirection == Direction.Y) {
return true;
}
String sampleLabel = " ";
// find the longest String in all the labels
for (String tickLabel : tickLabels) {
if (tickLabel != null && tickLabel.length() > sampleLabel.length()) {
sampleLabel = tickLabel;
}
}
// System.out.println("longestLabel: " + sampleLabel);
TextLayout textLayout =
new TextLayout(
sampleLabel, styler.getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
AffineTransform rot =
styler.getXAxisLabelRotation() == 0
? null
: AffineTransform.getRotateInstance(
-1 * Math.toRadians(styler.getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
double largestLabelWidth = rectangle.getWidth();
// System.out.println("largestLabelWidth: " + largestLabelWidth);
// System.out.println("tickSpacingHint: " + tickSpacingHint);
// if (largestLabelWidth * 1.1 >= tickSpacingHint) {
// System.out.println("WILL NOT FIT!!!");
// }
return (largestLabelWidth * 1.1 < tickSpacingHint);
} | java | boolean willLabelsFitInTickSpaceHint(List<String> tickLabels, int tickSpacingHint) {
// Assume that for Y-Axis the ticks will all fit based on their tickSpace hint because the text
// is usually horizontal and "short". This more applies to the X-Axis.
if (this.axisDirection == Direction.Y) {
return true;
}
String sampleLabel = " ";
// find the longest String in all the labels
for (String tickLabel : tickLabels) {
if (tickLabel != null && tickLabel.length() > sampleLabel.length()) {
sampleLabel = tickLabel;
}
}
// System.out.println("longestLabel: " + sampleLabel);
TextLayout textLayout =
new TextLayout(
sampleLabel, styler.getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
AffineTransform rot =
styler.getXAxisLabelRotation() == 0
? null
: AffineTransform.getRotateInstance(
-1 * Math.toRadians(styler.getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
double largestLabelWidth = rectangle.getWidth();
// System.out.println("largestLabelWidth: " + largestLabelWidth);
// System.out.println("tickSpacingHint: " + tickSpacingHint);
// if (largestLabelWidth * 1.1 >= tickSpacingHint) {
// System.out.println("WILL NOT FIT!!!");
// }
return (largestLabelWidth * 1.1 < tickSpacingHint);
} | [
"boolean",
"willLabelsFitInTickSpaceHint",
"(",
"List",
"<",
"String",
">",
"tickLabels",
",",
"int",
"tickSpacingHint",
")",
"{",
"// Assume that for Y-Axis the ticks will all fit based on their tickSpace hint because the text",
"// is usually horizontal and \"short\". This more applies... | Given the generated tickLabels, will they fit side-by-side without overlapping each other and
looking bad? Sometimes the given tickSpacingHint is simply too small.
@param tickLabels
@param tickSpacingHint
@return | [
"Given",
"the",
"generated",
"tickLabels",
"will",
"they",
"fit",
"side",
"-",
"by",
"-",
"side",
"without",
"overlapping",
"each",
"other",
"and",
"looking",
"bad?",
"Sometimes",
"the",
"given",
"tickSpacingHint",
"is",
"simply",
"too",
"small",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/AxisTickCalculator_.java#L89-L125 |
32,319 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/QuickChart.java | QuickChart.getChart | public static XYChart getChart(
String chartTitle,
String xTitle,
String yTitle,
String[] seriesNames,
double[] xData,
double[][] yData) {
// Create Chart
XYChart chart = new XYChart(WIDTH, HEIGHT);
// Customize Chart
chart.setTitle(chartTitle);
chart.setXAxisTitle(xTitle);
chart.setYAxisTitle(yTitle);
// Series
for (int i = 0; i < yData.length; i++) {
XYSeries series;
if (seriesNames != null) {
series = chart.addSeries(seriesNames[i], xData, yData[i]);
} else {
chart.getStyler().setLegendVisible(false);
series = chart.addSeries(" " + i, xData, yData[i]);
}
series.setMarker(SeriesMarkers.NONE);
}
return chart;
} | java | public static XYChart getChart(
String chartTitle,
String xTitle,
String yTitle,
String[] seriesNames,
double[] xData,
double[][] yData) {
// Create Chart
XYChart chart = new XYChart(WIDTH, HEIGHT);
// Customize Chart
chart.setTitle(chartTitle);
chart.setXAxisTitle(xTitle);
chart.setYAxisTitle(yTitle);
// Series
for (int i = 0; i < yData.length; i++) {
XYSeries series;
if (seriesNames != null) {
series = chart.addSeries(seriesNames[i], xData, yData[i]);
} else {
chart.getStyler().setLegendVisible(false);
series = chart.addSeries(" " + i, xData, yData[i]);
}
series.setMarker(SeriesMarkers.NONE);
}
return chart;
} | [
"public",
"static",
"XYChart",
"getChart",
"(",
"String",
"chartTitle",
",",
"String",
"xTitle",
",",
"String",
"yTitle",
",",
"String",
"[",
"]",
"seriesNames",
",",
"double",
"[",
"]",
"xData",
",",
"double",
"[",
"]",
"[",
"]",
"yData",
")",
"{",
"/... | Creates a Chart with multiple Series for the same X-Axis data with default style
@param chartTitle the Chart title
@param xTitle The X-Axis title
@param yTitle The Y-Axis title
@param seriesNames An array of the name of the multiple series
@param xData An array containing the X-Axis data
@param yData An array of double arrays containing multiple Y-Axis data
@return a Chart Object | [
"Creates",
"a",
"Chart",
"with",
"multiple",
"Series",
"for",
"the",
"same",
"X",
"-",
"Axis",
"data",
"with",
"default",
"style"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/QuickChart.java#L57-L85 |
32,320 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/RadarChart.java | RadarChart.addSeries | public RadarSeries addSeries(String seriesName, double[] values, String[] tooltipOverrides) {
// Sanity checks
sanityCheck(seriesName, values, tooltipOverrides);
RadarSeries series = new RadarSeries(seriesName, values, tooltipOverrides);
seriesMap.put(seriesName, series);
return series;
} | java | public RadarSeries addSeries(String seriesName, double[] values, String[] tooltipOverrides) {
// Sanity checks
sanityCheck(seriesName, values, tooltipOverrides);
RadarSeries series = new RadarSeries(seriesName, values, tooltipOverrides);
seriesMap.put(seriesName, series);
return series;
} | [
"public",
"RadarSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"[",
"]",
"values",
",",
"String",
"[",
"]",
"tooltipOverrides",
")",
"{",
"// Sanity checks",
"sanityCheck",
"(",
"seriesName",
",",
"values",
",",
"tooltipOverrides",
")",
";",
... | Add a series for a Radar type chart
@param seriesName
@param values
@param tooltipOverrides
@return | [
"Add",
"a",
"series",
"for",
"a",
"Radar",
"type",
"chart"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/RadarChart.java#L87-L97 |
32,321 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CSVImporter.java | CSVImporter.getSeriesDataFromCSVRows | private static String[] getSeriesDataFromCSVRows(File csvFile) {
String[] xAndYData = new String[3];
BufferedReader bufferedReader = null;
try {
int counter = 0;
String line;
bufferedReader = new BufferedReader(new FileReader(csvFile));
while ((line = bufferedReader.readLine()) != null) {
xAndYData[counter++] = line;
}
} catch (Exception e) {
System.out.println("Exception while reading csv file: " + e);
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return xAndYData;
} | java | private static String[] getSeriesDataFromCSVRows(File csvFile) {
String[] xAndYData = new String[3];
BufferedReader bufferedReader = null;
try {
int counter = 0;
String line;
bufferedReader = new BufferedReader(new FileReader(csvFile));
while ((line = bufferedReader.readLine()) != null) {
xAndYData[counter++] = line;
}
} catch (Exception e) {
System.out.println("Exception while reading csv file: " + e);
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return xAndYData;
} | [
"private",
"static",
"String",
"[",
"]",
"getSeriesDataFromCSVRows",
"(",
"File",
"csvFile",
")",
"{",
"String",
"[",
"]",
"xAndYData",
"=",
"new",
"String",
"[",
"3",
"]",
";",
"BufferedReader",
"bufferedReader",
"=",
"null",
";",
"try",
"{",
"int",
"coun... | Get the series's data from a file
@param csvFile
@return | [
"Get",
"the",
"series",
"s",
"data",
"from",
"a",
"file"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CSVImporter.java#L110-L134 |
32,322 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CSVImporter.java | CSVImporter.getAllFiles | private static File[] getAllFiles(String dirName, String regex) {
File[] allFiles = getAllFiles(dirName);
List<File> matchingFiles = new ArrayList<File>();
for (File allFile : allFiles) {
if (allFile.getName().matches(regex)) {
matchingFiles.add(allFile);
}
}
return matchingFiles.toArray(new File[matchingFiles.size()]);
} | java | private static File[] getAllFiles(String dirName, String regex) {
File[] allFiles = getAllFiles(dirName);
List<File> matchingFiles = new ArrayList<File>();
for (File allFile : allFiles) {
if (allFile.getName().matches(regex)) {
matchingFiles.add(allFile);
}
}
return matchingFiles.toArray(new File[matchingFiles.size()]);
} | [
"private",
"static",
"File",
"[",
"]",
"getAllFiles",
"(",
"String",
"dirName",
",",
"String",
"regex",
")",
"{",
"File",
"[",
"]",
"allFiles",
"=",
"getAllFiles",
"(",
"dirName",
")",
";",
"List",
"<",
"File",
">",
"matchingFiles",
"=",
"new",
"ArrayLis... | This method returns the files found in the given directory matching the given regular
expression.
@param dirName - ex. "./path/to/directory/" *make sure you have the '/' on the end
@param regex - ex. ".*.csv"
@return File[] - an array of files | [
"This",
"method",
"returns",
"the",
"files",
"found",
"in",
"the",
"given",
"directory",
"matching",
"the",
"given",
"regular",
"expression",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CSVImporter.java#L201-L215 |
32,323 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CSVImporter.java | CSVImporter.getAllFiles | private static File[] getAllFiles(String dirName) {
File dir = new File(dirName);
File[] files = dir.listFiles(); // returns files and folders
if (files != null) {
List<File> filteredFiles = new ArrayList<File>();
for (File file : files) {
if (file.isFile()) {
filteredFiles.add(file);
}
}
return filteredFiles.toArray(new File[filteredFiles.size()]);
} else {
System.out.println(dirName + " does not denote a valid directory!");
return new File[0];
}
} | java | private static File[] getAllFiles(String dirName) {
File dir = new File(dirName);
File[] files = dir.listFiles(); // returns files and folders
if (files != null) {
List<File> filteredFiles = new ArrayList<File>();
for (File file : files) {
if (file.isFile()) {
filteredFiles.add(file);
}
}
return filteredFiles.toArray(new File[filteredFiles.size()]);
} else {
System.out.println(dirName + " does not denote a valid directory!");
return new File[0];
}
} | [
"private",
"static",
"File",
"[",
"]",
"getAllFiles",
"(",
"String",
"dirName",
")",
"{",
"File",
"dir",
"=",
"new",
"File",
"(",
"dirName",
")",
";",
"File",
"[",
"]",
"files",
"=",
"dir",
".",
"listFiles",
"(",
")",
";",
"// returns files and folders",... | This method returns the Files found in the given directory
@param dirName - ex. "./path/to/directory/" *make sure you have the '/' on the end
@return File[] - an array of files | [
"This",
"method",
"returns",
"the",
"Files",
"found",
"in",
"the",
"given",
"directory"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CSVImporter.java#L223-L242 |
32,324 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/RadarSeries.java | RadarSeries.setLineStyle | public RadarSeries setLineStyle(BasicStroke basicStroke) {
stroke = basicStroke;
if (this.lineWidth > 0.0f) {
stroke =
new BasicStroke(
lineWidth,
this.stroke.getEndCap(),
this.stroke.getLineJoin(),
this.stroke.getMiterLimit(),
this.stroke.getDashArray(),
this.stroke.getDashPhase());
}
return this;
} | java | public RadarSeries setLineStyle(BasicStroke basicStroke) {
stroke = basicStroke;
if (this.lineWidth > 0.0f) {
stroke =
new BasicStroke(
lineWidth,
this.stroke.getEndCap(),
this.stroke.getLineJoin(),
this.stroke.getMiterLimit(),
this.stroke.getDashArray(),
this.stroke.getDashPhase());
}
return this;
} | [
"public",
"RadarSeries",
"setLineStyle",
"(",
"BasicStroke",
"basicStroke",
")",
"{",
"stroke",
"=",
"basicStroke",
";",
"if",
"(",
"this",
".",
"lineWidth",
">",
"0.0f",
")",
"{",
"stroke",
"=",
"new",
"BasicStroke",
"(",
"lineWidth",
",",
"this",
".",
"s... | Set the line style of the series
@param basicStroke | [
"Set",
"the",
"line",
"style",
"of",
"the",
"series"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/RadarSeries.java#L65-L79 |
32,325 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/DialChart.java | DialChart.addSeries | public DialSeries addSeries(String seriesName, double value, String annotation) {
// Sanity checks
sanityCheck(seriesName, value);
DialSeries series = new DialSeries(seriesName, value, annotation);
seriesMap.put(seriesName, series);
return series;
} | java | public DialSeries addSeries(String seriesName, double value, String annotation) {
// Sanity checks
sanityCheck(seriesName, value);
DialSeries series = new DialSeries(seriesName, value, annotation);
seriesMap.put(seriesName, series);
return series;
} | [
"public",
"DialSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"value",
",",
"String",
"annotation",
")",
"{",
"// Sanity checks",
"sanityCheck",
"(",
"seriesName",
",",
"value",
")",
";",
"DialSeries",
"series",
"=",
"new",
"DialSeries",
"(",
... | Add a series for a Dial type chart
@param seriesName
@param value
@param annotation
@return | [
"Add",
"a",
"series",
"for",
"a",
"Dial",
"type",
"chart"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/DialChart.java#L84-L94 |
32,326 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/BubbleChart.java | BubbleChart.addSeries | public BubbleSeries addSeries(
String seriesName,
List<? extends Number> xData,
List<? extends Number> yData,
List<? extends Number> bubbleData) {
return addSeries(
seriesName,
Utils.getDoubleArrayFromNumberList(xData),
Utils.getDoubleArrayFromNumberList(yData),
Utils.getDoubleArrayFromNumberList(bubbleData));
} | java | public BubbleSeries addSeries(
String seriesName,
List<? extends Number> xData,
List<? extends Number> yData,
List<? extends Number> bubbleData) {
return addSeries(
seriesName,
Utils.getDoubleArrayFromNumberList(xData),
Utils.getDoubleArrayFromNumberList(yData),
Utils.getDoubleArrayFromNumberList(bubbleData));
} | [
"public",
"BubbleSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"List",
"<",
"?",
"extends",
"Number",
">",
"xData",
",",
"List",
"<",
"?",
"extends",
"Number",
">",
"yData",
",",
"List",
"<",
"?",
"extends",
"Number",
">",
"bubbleData",
")",
"{... | Add a series for a Bubble type chart using using double arrays
@param seriesName
@param xData the X-Axis data
@param xData the Y-Axis data
@param bubbleData the bubble data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"Bubble",
"type",
"chart",
"using",
"using",
"double",
"arrays"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/BubbleChart.java#L81-L92 |
32,327 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/BubbleChart.java | BubbleChart.addSeries | public BubbleSeries addSeries(
String seriesName, double[] xData, double[] yData, double[] bubbleData) {
// Sanity checks
sanityCheck(seriesName, xData, yData, bubbleData);
BubbleSeries series;
if (xData != null) {
// Sanity check
if (xData.length != yData.length) {
throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!");
}
series = new BubbleSeries(seriesName, xData, yData, bubbleData);
} else { // generate xData
series =
new BubbleSeries(
seriesName, Utils.getGeneratedDataAsArray(yData.length), yData, bubbleData);
}
seriesMap.put(seriesName, series);
return series;
} | java | public BubbleSeries addSeries(
String seriesName, double[] xData, double[] yData, double[] bubbleData) {
// Sanity checks
sanityCheck(seriesName, xData, yData, bubbleData);
BubbleSeries series;
if (xData != null) {
// Sanity check
if (xData.length != yData.length) {
throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!");
}
series = new BubbleSeries(seriesName, xData, yData, bubbleData);
} else { // generate xData
series =
new BubbleSeries(
seriesName, Utils.getGeneratedDataAsArray(yData.length), yData, bubbleData);
}
seriesMap.put(seriesName, series);
return series;
} | [
"public",
"BubbleSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"[",
"]",
"xData",
",",
"double",
"[",
"]",
"yData",
",",
"double",
"[",
"]",
"bubbleData",
")",
"{",
"// Sanity checks",
"sanityCheck",
"(",
"seriesName",
",",
"xData",
",",
... | Add a series for a Bubble type chart using using Lists
@param seriesName
@param xData the X-Axis data
@param xData the Y-Axis data
@param bubbleData the bubble data
@return | [
"Add",
"a",
"series",
"for",
"a",
"Bubble",
"type",
"chart",
"using",
"using",
"Lists"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/BubbleChart.java#L103-L127 |
32,328 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/PieChart.java | PieChart.addSeries | public PieSeries addSeries(String seriesName, Number value) {
PieSeries series = new PieSeries(seriesName, value);
if (seriesMap.keySet().contains(seriesName)) {
throw new IllegalArgumentException(
"Series name >"
+ seriesName
+ "< has already been used. Use unique names for each series!!!");
}
seriesMap.put(seriesName, series);
return series;
} | java | public PieSeries addSeries(String seriesName, Number value) {
PieSeries series = new PieSeries(seriesName, value);
if (seriesMap.keySet().contains(seriesName)) {
throw new IllegalArgumentException(
"Series name >"
+ seriesName
+ "< has already been used. Use unique names for each series!!!");
}
seriesMap.put(seriesName, series);
return series;
} | [
"public",
"PieSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"Number",
"value",
")",
"{",
"PieSeries",
"series",
"=",
"new",
"PieSeries",
"(",
"seriesName",
",",
"value",
")",
";",
"if",
"(",
"seriesMap",
".",
"keySet",
"(",
")",
".",
"contains",
... | Add a series for a Pie type chart
@param seriesName
@param value
@return | [
"Add",
"a",
"series",
"for",
"a",
"Pie",
"type",
"chart"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/PieChart.java#L74-L87 |
32,329 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/PieChart.java | PieChart.updatePieSeries | public PieSeries updatePieSeries(String seriesName, Number value) {
Map<String, PieSeries> seriesMap = getSeriesMap();
PieSeries series = seriesMap.get(seriesName);
if (series == null) {
throw new IllegalArgumentException("Series name >" + seriesName + "< not found!!!");
}
series.replaceData(value);
return series;
} | java | public PieSeries updatePieSeries(String seriesName, Number value) {
Map<String, PieSeries> seriesMap = getSeriesMap();
PieSeries series = seriesMap.get(seriesName);
if (series == null) {
throw new IllegalArgumentException("Series name >" + seriesName + "< not found!!!");
}
series.replaceData(value);
return series;
} | [
"public",
"PieSeries",
"updatePieSeries",
"(",
"String",
"seriesName",
",",
"Number",
"value",
")",
"{",
"Map",
"<",
"String",
",",
"PieSeries",
">",
"seriesMap",
"=",
"getSeriesMap",
"(",
")",
";",
"PieSeries",
"series",
"=",
"seriesMap",
".",
"get",
"(",
... | Update a series by updating the pie slide value
@param seriesName
@param value
@return | [
"Update",
"a",
"series",
"by",
"updating",
"the",
"pie",
"slide",
"value"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/PieChart.java#L96-L106 |
32,330 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CategoryChart.java | CategoryChart.addSeries | public CategorySeries addSeries(String seriesName, double[] xData, double[] yData) {
return addSeries(seriesName, xData, yData, null);
} | java | public CategorySeries addSeries(String seriesName, double[] xData, double[] yData) {
return addSeries(seriesName, xData, yData, null);
} | [
"public",
"CategorySeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"[",
"]",
"xData",
",",
"double",
"[",
"]",
"yData",
")",
"{",
"return",
"addSeries",
"(",
"seriesName",
",",
"xData",
",",
"yData",
",",
"null",
")",
";",
"}"
] | Add a series for a Category type chart using using double arrays
@param seriesName
@param xData the X-Axis data
@param xData the Y-Axis data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"Category",
"type",
"chart",
"using",
"using",
"double",
"arrays"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CategoryChart.java#L83-L86 |
32,331 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CategoryChart.java | CategoryChart.addSeries | public CategorySeries addSeries(
String seriesName, double[] xData, double[] yData, double[] errorBars) {
return addSeries(
seriesName,
Utils.getNumberListFromDoubleArray(xData),
Utils.getNumberListFromDoubleArray(yData),
Utils.getNumberListFromDoubleArray(errorBars));
} | java | public CategorySeries addSeries(
String seriesName, double[] xData, double[] yData, double[] errorBars) {
return addSeries(
seriesName,
Utils.getNumberListFromDoubleArray(xData),
Utils.getNumberListFromDoubleArray(yData),
Utils.getNumberListFromDoubleArray(errorBars));
} | [
"public",
"CategorySeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"[",
"]",
"xData",
",",
"double",
"[",
"]",
"yData",
",",
"double",
"[",
"]",
"errorBars",
")",
"{",
"return",
"addSeries",
"(",
"seriesName",
",",
"Utils",
".",
"getNumbe... | Add a series for a Category type chart using using double arrays with error bars
@param seriesName
@param xData the X-Axis data
@param xData the Y-Axis data
@param errorBars the error bar data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"Category",
"type",
"chart",
"using",
"using",
"double",
"arrays",
"with",
"error",
"bars"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CategoryChart.java#L97-L105 |
32,332 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CategoryChart.java | CategoryChart.addSeries | public CategorySeries addSeries(
String seriesName,
List<?> xData,
List<? extends Number> yData,
List<? extends Number> errorBars) {
// Sanity checks
sanityCheck(seriesName, xData, yData, errorBars);
CategorySeries series;
if (xData != null) {
// Sanity check
if (xData.size() != yData.size()) {
throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!");
}
series = new CategorySeries(seriesName, xData, yData, errorBars, getDataType(xData));
} else { // generate xData
xData = Utils.getGeneratedDataAsList(yData.size());
series = new CategorySeries(seriesName, xData, yData, errorBars, getDataType(xData));
}
seriesMap.put(seriesName, series);
return series;
} | java | public CategorySeries addSeries(
String seriesName,
List<?> xData,
List<? extends Number> yData,
List<? extends Number> errorBars) {
// Sanity checks
sanityCheck(seriesName, xData, yData, errorBars);
CategorySeries series;
if (xData != null) {
// Sanity check
if (xData.size() != yData.size()) {
throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!");
}
series = new CategorySeries(seriesName, xData, yData, errorBars, getDataType(xData));
} else { // generate xData
xData = Utils.getGeneratedDataAsList(yData.size());
series = new CategorySeries(seriesName, xData, yData, errorBars, getDataType(xData));
}
seriesMap.put(seriesName, series);
return series;
} | [
"public",
"CategorySeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"List",
"<",
"?",
">",
"xData",
",",
"List",
"<",
"?",
"extends",
"Number",
">",
"yData",
",",
"List",
"<",
"?",
"extends",
"Number",
">",
"errorBars",
")",
"{",
"// Sanity checks",... | Add a series for a Category type chart using Lists with error bars
@param seriesName
@param xData the X-Axis data
@param yData the Y-Axis data
@param errorBars the error bar data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"Category",
"type",
"chart",
"using",
"Lists",
"with",
"error",
"bars"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CategoryChart.java#L160-L186 |
32,333 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CategoryChart.java | CategoryChart.setCustomCategoryLabels | public void setCustomCategoryLabels(Map<Object, Object> customCategoryLabels) {
// get the first series
AxesChartSeriesCategory axesChartSeries = getSeriesMap().values().iterator().next();
// get the first categories, could be Number Date or String
List<?> categories = (List<?>) axesChartSeries.getXData();
Map<Double, Object> axisTickValueLabelMap = new LinkedHashMap<Double, Object>();
for (Entry<Object, Object> entry : customCategoryLabels.entrySet()) {
int index = categories.indexOf(entry.getKey());
if (index == -1) {
throw new IllegalArgumentException("Could not find category index for " + entry.getKey());
}
axisTickValueLabelMap.put((double) index, entry.getValue());
}
setXAxisLabelOverrideMap(axisTickValueLabelMap);
} | java | public void setCustomCategoryLabels(Map<Object, Object> customCategoryLabels) {
// get the first series
AxesChartSeriesCategory axesChartSeries = getSeriesMap().values().iterator().next();
// get the first categories, could be Number Date or String
List<?> categories = (List<?>) axesChartSeries.getXData();
Map<Double, Object> axisTickValueLabelMap = new LinkedHashMap<Double, Object>();
for (Entry<Object, Object> entry : customCategoryLabels.entrySet()) {
int index = categories.indexOf(entry.getKey());
if (index == -1) {
throw new IllegalArgumentException("Could not find category index for " + entry.getKey());
}
axisTickValueLabelMap.put((double) index, entry.getValue());
}
setXAxisLabelOverrideMap(axisTickValueLabelMap);
} | [
"public",
"void",
"setCustomCategoryLabels",
"(",
"Map",
"<",
"Object",
",",
"Object",
">",
"customCategoryLabels",
")",
"{",
"// get the first series",
"AxesChartSeriesCategory",
"axesChartSeries",
"=",
"getSeriesMap",
"(",
")",
".",
"values",
"(",
")",
".",
"itera... | Set custom X-Axis category labels
@param customCategoryLabels Map containing category name -> label mappings | [
"Set",
"custom",
"X",
"-",
"Axis",
"category",
"labels"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CategoryChart.java#L351-L368 |
32,334 | knowm/XChart | xchart-demo/src/main/java/org/knowm/xchart/standalone/Example2.java | Example2.getRandomWalk | private static double[] getRandomWalk(int numPoints) {
double[] y = new double[numPoints];
y[0] = 0;
for (int i = 1; i < y.length; i++) {
y[i] = y[i - 1] + Math.random() - .5;
}
return y;
} | java | private static double[] getRandomWalk(int numPoints) {
double[] y = new double[numPoints];
y[0] = 0;
for (int i = 1; i < y.length; i++) {
y[i] = y[i - 1] + Math.random() - .5;
}
return y;
} | [
"private",
"static",
"double",
"[",
"]",
"getRandomWalk",
"(",
"int",
"numPoints",
")",
"{",
"double",
"[",
"]",
"y",
"=",
"new",
"double",
"[",
"numPoints",
"]",
";",
"y",
"[",
"0",
"]",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i... | Generates a set of random walk data
@param numPoints
@return | [
"Generates",
"a",
"set",
"of",
"random",
"walk",
"data"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart-demo/src/main/java/org/knowm/xchart/standalone/Example2.java#L43-L51 |
32,335 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CSVExporter.java | CSVExporter.writeCSVRows | public static void writeCSVRows(XYSeries series, String path2Dir) {
File newFile = new File(path2Dir + series.getName() + ".csv");
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), "UTF8"));
String csv = join(series.getXData(), ",") + System.getProperty("line.separator");
out.write(csv);
csv = join(series.getYData(), ",") + System.getProperty("line.separator");
out.write(csv);
if (series.getExtraValues() != null) {
csv = join(series.getExtraValues(), ",") + System.getProperty("line.separator");
out.write(csv);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
// NOP
}
}
}
} | java | public static void writeCSVRows(XYSeries series, String path2Dir) {
File newFile = new File(path2Dir + series.getName() + ".csv");
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), "UTF8"));
String csv = join(series.getXData(), ",") + System.getProperty("line.separator");
out.write(csv);
csv = join(series.getYData(), ",") + System.getProperty("line.separator");
out.write(csv);
if (series.getExtraValues() != null) {
csv = join(series.getExtraValues(), ",") + System.getProperty("line.separator");
out.write(csv);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
// NOP
}
}
}
} | [
"public",
"static",
"void",
"writeCSVRows",
"(",
"XYSeries",
"series",
",",
"String",
"path2Dir",
")",
"{",
"File",
"newFile",
"=",
"new",
"File",
"(",
"path2Dir",
"+",
"series",
".",
"getName",
"(",
")",
"+",
"\".csv\"",
")",
";",
"Writer",
"out",
"=",
... | Export a XYChart series into rows in a CSV file.
@param series
@param path2Dir - ex. "./path/to/directory/" *make sure you have the '/' on the end | [
"Export",
"a",
"XYChart",
"series",
"into",
"rows",
"in",
"a",
"CSV",
"file",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CSVExporter.java#L33-L60 |
32,336 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CSVExporter.java | CSVExporter.join | private static String join(double[] seriesData, String separator) {
// two or more elements
StringBuilder sb = new StringBuilder(256); // Java default is 16, probably too small
sb.append(seriesData[0]);
for (int i = 1; i < seriesData.length; i++) {
if (separator != null) {
sb.append(separator);
}
sb.append(seriesData[i]);
}
return sb.toString();
} | java | private static String join(double[] seriesData, String separator) {
// two or more elements
StringBuilder sb = new StringBuilder(256); // Java default is 16, probably too small
sb.append(seriesData[0]);
for (int i = 1; i < seriesData.length; i++) {
if (separator != null) {
sb.append(separator);
}
sb.append(seriesData[i]);
}
return sb.toString();
} | [
"private",
"static",
"String",
"join",
"(",
"double",
"[",
"]",
"seriesData",
",",
"String",
"separator",
")",
"{",
"// two or more elements",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
"256",
")",
";",
"// Java default is 16, probably too small",
"sb"... | Joins a series into an entire row of comma separated values.
@param seriesData
@param separator
@return | [
"Joins",
"a",
"series",
"into",
"an",
"entire",
"row",
"of",
"comma",
"separated",
"values",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CSVExporter.java#L69-L83 |
32,337 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CSVExporter.java | CSVExporter.writeCSVColumns | public static void writeCSVColumns(XYChart chart, String path2Dir) {
for (XYSeries xySeries : chart.getSeriesMap().values()) {
writeCSVColumns(xySeries, path2Dir);
}
} | java | public static void writeCSVColumns(XYChart chart, String path2Dir) {
for (XYSeries xySeries : chart.getSeriesMap().values()) {
writeCSVColumns(xySeries, path2Dir);
}
} | [
"public",
"static",
"void",
"writeCSVColumns",
"(",
"XYChart",
"chart",
",",
"String",
"path2Dir",
")",
"{",
"for",
"(",
"XYSeries",
"xySeries",
":",
"chart",
".",
"getSeriesMap",
"(",
")",
".",
"values",
"(",
")",
")",
"{",
"writeCSVColumns",
"(",
"xySeri... | Export all XYChart series as columns in separate CSV files.
@param chart
@param path2Dir | [
"Export",
"all",
"XYChart",
"series",
"as",
"columns",
"in",
"separate",
"CSV",
"files",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CSVExporter.java#L91-L96 |
32,338 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/CSVExporter.java | CSVExporter.writeCSVColumns | public static void writeCSVColumns(XYSeries series, String path2Dir) {
File newFile = new File(path2Dir + series.getName() + ".csv");
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), "UTF8"));
double[] xData = series.getXData();
double[] yData = series.getYData();
double[] errorBarData = series.getExtraValues();
for (int i = 0; i < xData.length; i++) {
StringBuilder sb = new StringBuilder();
sb.append(xData[i]).append(",");
sb.append(yData[i]).append(",");
if (errorBarData != null) {
sb.append(errorBarData[i]).append(",");
}
sb.setLength(sb.length() - 1);
sb.append(System.getProperty("line.separator"));
// String csv = xDataPoint + "," + yDataPoint + errorBarValue == null ? "" : ("," +
// errorBarValue) + System.getProperty("line.separator");
// String csv = + yDataPoint + System.getProperty("line.separator");
out.write(sb.toString());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
// NOP
}
}
}
} | java | public static void writeCSVColumns(XYSeries series, String path2Dir) {
File newFile = new File(path2Dir + series.getName() + ".csv");
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), "UTF8"));
double[] xData = series.getXData();
double[] yData = series.getYData();
double[] errorBarData = series.getExtraValues();
for (int i = 0; i < xData.length; i++) {
StringBuilder sb = new StringBuilder();
sb.append(xData[i]).append(",");
sb.append(yData[i]).append(",");
if (errorBarData != null) {
sb.append(errorBarData[i]).append(",");
}
sb.setLength(sb.length() - 1);
sb.append(System.getProperty("line.separator"));
// String csv = xDataPoint + "," + yDataPoint + errorBarValue == null ? "" : ("," +
// errorBarValue) + System.getProperty("line.separator");
// String csv = + yDataPoint + System.getProperty("line.separator");
out.write(sb.toString());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
// NOP
}
}
}
} | [
"public",
"static",
"void",
"writeCSVColumns",
"(",
"XYSeries",
"series",
",",
"String",
"path2Dir",
")",
"{",
"File",
"newFile",
"=",
"new",
"File",
"(",
"path2Dir",
"+",
"series",
".",
"getName",
"(",
")",
"+",
"\".csv\"",
")",
";",
"Writer",
"out",
"=... | Export a Chart series in columns in a CSV file.
@param series
@param path2Dir - ex. "./path/to/directory/" *make sure you have the '/' on the end | [
"Export",
"a",
"Chart",
"series",
"in",
"columns",
"in",
"a",
"CSV",
"file",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/CSVExporter.java#L104-L142 |
32,339 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/XYChart.java | XYChart.addSeries | public XYSeries addSeries(String seriesName, int[] xData, int[] yData) {
return addSeries(seriesName, xData, yData, null);
} | java | public XYSeries addSeries(String seriesName, int[] xData, int[] yData) {
return addSeries(seriesName, xData, yData, null);
} | [
"public",
"XYSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"int",
"[",
"]",
"xData",
",",
"int",
"[",
"]",
"yData",
")",
"{",
"return",
"addSeries",
"(",
"seriesName",
",",
"xData",
",",
"yData",
",",
"null",
")",
";",
"}"
] | Add a series for a X-Y type chart using using int arrays
@param seriesName
@param xData the X-Axis data
@param yData the Y-Axis data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"X",
"-",
"Y",
"type",
"chart",
"using",
"using",
"int",
"arrays"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/XYChart.java#L165-L168 |
32,340 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/XYChart.java | XYChart.addSeries | public XYSeries addSeries(String seriesName, int[] xData, int[] yData, int[] errorBars) {
return addSeries(
seriesName,
Utils.getDoubleArrayFromIntArray(xData),
Utils.getDoubleArrayFromIntArray(yData),
Utils.getDoubleArrayFromIntArray(errorBars),
DataType.Number);
} | java | public XYSeries addSeries(String seriesName, int[] xData, int[] yData, int[] errorBars) {
return addSeries(
seriesName,
Utils.getDoubleArrayFromIntArray(xData),
Utils.getDoubleArrayFromIntArray(yData),
Utils.getDoubleArrayFromIntArray(errorBars),
DataType.Number);
} | [
"public",
"XYSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"int",
"[",
"]",
"xData",
",",
"int",
"[",
"]",
"yData",
",",
"int",
"[",
"]",
"errorBars",
")",
"{",
"return",
"addSeries",
"(",
"seriesName",
",",
"Utils",
".",
"getDoubleArrayFromIntAr... | Add a series for a X-Y type chart using using int arrays with error bars
@param seriesName
@param xData the X-Axis data
@param xData the Y-Axis data
@param errorBars the error bar data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"X",
"-",
"Y",
"type",
"chart",
"using",
"using",
"int",
"arrays",
"with",
"error",
"bars"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/XYChart.java#L179-L187 |
32,341 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/XYChart.java | XYChart.addSeries | public XYSeries addSeries(
String seriesName,
List<?> xData,
List<? extends Number> yData,
List<? extends Number> errorBars) {
DataType dataType = getDataType(xData);
switch (dataType) {
case Date:
return addSeries(
seriesName,
Utils.getDoubleArrayFromDateList(xData),
Utils.getDoubleArrayFromNumberList(yData),
Utils.getDoubleArrayFromNumberList(errorBars),
DataType.Date);
default:
return addSeries(
seriesName,
Utils.getDoubleArrayFromNumberList(xData),
Utils.getDoubleArrayFromNumberList(yData),
Utils.getDoubleArrayFromNumberList(errorBars),
DataType.Number);
}
} | java | public XYSeries addSeries(
String seriesName,
List<?> xData,
List<? extends Number> yData,
List<? extends Number> errorBars) {
DataType dataType = getDataType(xData);
switch (dataType) {
case Date:
return addSeries(
seriesName,
Utils.getDoubleArrayFromDateList(xData),
Utils.getDoubleArrayFromNumberList(yData),
Utils.getDoubleArrayFromNumberList(errorBars),
DataType.Date);
default:
return addSeries(
seriesName,
Utils.getDoubleArrayFromNumberList(xData),
Utils.getDoubleArrayFromNumberList(yData),
Utils.getDoubleArrayFromNumberList(errorBars),
DataType.Number);
}
} | [
"public",
"XYSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"List",
"<",
"?",
">",
"xData",
",",
"List",
"<",
"?",
"extends",
"Number",
">",
"yData",
",",
"List",
"<",
"?",
"extends",
"Number",
">",
"errorBars",
")",
"{",
"DataType",
"dataType",... | Add a series for a X-Y type chart using Lists
@param seriesName
@param xData the X-Axis data
@param yData the Y-Axis data
@param errorBars the error bar data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"X",
"-",
"Y",
"type",
"chart",
"using",
"Lists"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/XYChart.java#L223-L247 |
32,342 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/XYChart.java | XYChart.addSeries | private XYSeries addSeries(
String seriesName, double[] xData, double[] yData, double[] errorBars, DataType dataType) {
// Sanity checks
sanityCheck(seriesName, xData, yData, errorBars);
XYSeries series;
if (xData != null) {
// Sanity check
if (xData.length != yData.length) {
throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!");
}
series = new XYSeries(seriesName, xData, yData, errorBars, dataType);
} else { // generate xData
series =
new XYSeries(
seriesName, Utils.getGeneratedDataAsArray(yData.length), yData, errorBars, dataType);
}
seriesMap.put(seriesName, series);
return series;
} | java | private XYSeries addSeries(
String seriesName, double[] xData, double[] yData, double[] errorBars, DataType dataType) {
// Sanity checks
sanityCheck(seriesName, xData, yData, errorBars);
XYSeries series;
if (xData != null) {
// Sanity check
if (xData.length != yData.length) {
throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!");
}
series = new XYSeries(seriesName, xData, yData, errorBars, dataType);
} else { // generate xData
series =
new XYSeries(
seriesName, Utils.getGeneratedDataAsArray(yData.length), yData, errorBars, dataType);
}
seriesMap.put(seriesName, series);
return series;
} | [
"private",
"XYSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"[",
"]",
"xData",
",",
"double",
"[",
"]",
"yData",
",",
"double",
"[",
"]",
"errorBars",
",",
"DataType",
"dataType",
")",
"{",
"// Sanity checks",
"sanityCheck",
"(",
"seriesN... | Add a series for a X-Y type chart using Lists with error bars
@param seriesName
@param xData the X-Axis data
@param yData the Y-Axis data
@param errorBars the error bar data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"X",
"-",
"Y",
"type",
"chart",
"using",
"Lists",
"with",
"error",
"bars"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/XYChart.java#L283-L307 |
32,343 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/SwingWrapper.java | SwingWrapper.repaintChart | public void repaintChart(int index) {
chartPanels.get(index).revalidate();
chartPanels.get(index).repaint();
} | java | public void repaintChart(int index) {
chartPanels.get(index).revalidate();
chartPanels.get(index).repaint();
} | [
"public",
"void",
"repaintChart",
"(",
"int",
"index",
")",
"{",
"chartPanels",
".",
"get",
"(",
"index",
")",
".",
"revalidate",
"(",
")",
";",
"chartPanels",
".",
"get",
"(",
"index",
")",
".",
"repaint",
"(",
")",
";",
"}"
] | Repaint the XChartPanel given the provided index.
@param index | [
"Repaint",
"the",
"XChartPanel",
"given",
"the",
"provided",
"index",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/SwingWrapper.java#L192-L196 |
32,344 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java | Legend_.getBoundsHintVertical | private Rectangle2D getBoundsHintVertical() {
if (!chart.getStyler().isLegendVisible()) {
return new Rectangle2D
.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
// 0).
}
boolean containsBox = false;
// determine legend text content max width
double legendTextContentMaxWidth = 0;
// determine total legend content height
double legendContentHeight = 0;
Map<String, S> map = chart.getSeriesMap();
for (S series : map.values()) {
if (!series.isShowInLegend()) {
continue;
}
if (!series.isEnabled()) {
continue;
}
Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
double legendEntryHeight = 0; // could be multi-line
for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) {
legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE;
legendTextContentMaxWidth =
Math.max(legendTextContentMaxWidth, entry.getValue().getWidth());
}
legendEntryHeight -= MULTI_LINE_SPACE; // subtract away the bottom MULTI_LINE_SPACE
legendEntryHeight = Math.max(legendEntryHeight, (getSeriesLegendRenderGraphicHeight(series)));
legendContentHeight += legendEntryHeight + chart.getStyler().getLegendPadding();
if (series.getLegendRenderType() == LegendRenderType.Box) {
containsBox = true;
}
}
// determine legend content width
double legendContentWidth;
if (!containsBox) {
legendContentWidth =
chart.getStyler().getLegendSeriesLineLength()
+ chart.getStyler().getLegendPadding()
+ legendTextContentMaxWidth;
} else {
legendContentWidth =
BOX_SIZE + chart.getStyler().getLegendPadding() + legendTextContentMaxWidth;
}
// Legend Box
double width = legendContentWidth + 2 * chart.getStyler().getLegendPadding();
double height = legendContentHeight + chart.getStyler().getLegendPadding();
return new Rectangle2D.Double(0, 0, width, height); // 0 indicates not sure yet.
} | java | private Rectangle2D getBoundsHintVertical() {
if (!chart.getStyler().isLegendVisible()) {
return new Rectangle2D
.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
// 0).
}
boolean containsBox = false;
// determine legend text content max width
double legendTextContentMaxWidth = 0;
// determine total legend content height
double legendContentHeight = 0;
Map<String, S> map = chart.getSeriesMap();
for (S series : map.values()) {
if (!series.isShowInLegend()) {
continue;
}
if (!series.isEnabled()) {
continue;
}
Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
double legendEntryHeight = 0; // could be multi-line
for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) {
legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE;
legendTextContentMaxWidth =
Math.max(legendTextContentMaxWidth, entry.getValue().getWidth());
}
legendEntryHeight -= MULTI_LINE_SPACE; // subtract away the bottom MULTI_LINE_SPACE
legendEntryHeight = Math.max(legendEntryHeight, (getSeriesLegendRenderGraphicHeight(series)));
legendContentHeight += legendEntryHeight + chart.getStyler().getLegendPadding();
if (series.getLegendRenderType() == LegendRenderType.Box) {
containsBox = true;
}
}
// determine legend content width
double legendContentWidth;
if (!containsBox) {
legendContentWidth =
chart.getStyler().getLegendSeriesLineLength()
+ chart.getStyler().getLegendPadding()
+ legendTextContentMaxWidth;
} else {
legendContentWidth =
BOX_SIZE + chart.getStyler().getLegendPadding() + legendTextContentMaxWidth;
}
// Legend Box
double width = legendContentWidth + 2 * chart.getStyler().getLegendPadding();
double height = legendContentHeight + chart.getStyler().getLegendPadding();
return new Rectangle2D.Double(0, 0, width, height); // 0 indicates not sure yet.
} | [
"private",
"Rectangle2D",
"getBoundsHintVertical",
"(",
")",
"{",
"if",
"(",
"!",
"chart",
".",
"getStyler",
"(",
")",
".",
"isLegendVisible",
"(",
")",
")",
"{",
"return",
"new",
"Rectangle2D",
".",
"Double",
"(",
")",
";",
"// Constructs a new Rectangle2D, i... | determine the width and height of the chart legend | [
"determine",
"the",
"width",
"and",
"height",
"of",
"the",
"chart",
"legend"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java#L160-L222 |
32,345 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java | Legend_.getBoundsHintHorizontal | private Rectangle2D getBoundsHintHorizontal() {
if (!chart.getStyler().isLegendVisible()) {
return new Rectangle2D
.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
// 0).
}
// determine legend text content max height
double legendTextContentMaxHeight = 0;
// determine total legend content width
double legendContentWidth = 0;
Map<String, S> map = chart.getSeriesMap();
for (S series : map.values()) {
if (!series.isShowInLegend()) {
continue;
}
if (!series.isEnabled()) {
continue;
}
Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
double legendEntryHeight = 0; // could be multi-line
double legendEntryMaxWidth = 0; // could be multi-line
for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) {
legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE;
legendEntryMaxWidth = Math.max(legendEntryMaxWidth, entry.getValue().getWidth());
}
legendEntryHeight -= MULTI_LINE_SPACE; // subtract away the bottom MULTI_LINE_SPACE
legendTextContentMaxHeight =
Math.max(legendEntryHeight, getSeriesLegendRenderGraphicHeight(series));
legendContentWidth += legendEntryMaxWidth + chart.getStyler().getLegendPadding();
if (series.getLegendRenderType() == LegendRenderType.Line) {
legendContentWidth =
chart.getStyler().getLegendSeriesLineLength()
+ chart.getStyler().getLegendPadding()
+ legendContentWidth;
} else {
legendContentWidth = BOX_SIZE + chart.getStyler().getLegendPadding() + legendContentWidth;
}
}
// Legend Box
double width = legendContentWidth + chart.getStyler().getLegendPadding();
double height = legendTextContentMaxHeight + chart.getStyler().getLegendPadding() * 2;
return new Rectangle2D.Double(0, 0, width, height); // 0 indicates not sure yet.
} | java | private Rectangle2D getBoundsHintHorizontal() {
if (!chart.getStyler().isLegendVisible()) {
return new Rectangle2D
.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
// 0).
}
// determine legend text content max height
double legendTextContentMaxHeight = 0;
// determine total legend content width
double legendContentWidth = 0;
Map<String, S> map = chart.getSeriesMap();
for (S series : map.values()) {
if (!series.isShowInLegend()) {
continue;
}
if (!series.isEnabled()) {
continue;
}
Map<String, Rectangle2D> seriesTextBounds = getSeriesTextBounds(series);
double legendEntryHeight = 0; // could be multi-line
double legendEntryMaxWidth = 0; // could be multi-line
for (Map.Entry<String, Rectangle2D> entry : seriesTextBounds.entrySet()) {
legendEntryHeight += entry.getValue().getHeight() + MULTI_LINE_SPACE;
legendEntryMaxWidth = Math.max(legendEntryMaxWidth, entry.getValue().getWidth());
}
legendEntryHeight -= MULTI_LINE_SPACE; // subtract away the bottom MULTI_LINE_SPACE
legendTextContentMaxHeight =
Math.max(legendEntryHeight, getSeriesLegendRenderGraphicHeight(series));
legendContentWidth += legendEntryMaxWidth + chart.getStyler().getLegendPadding();
if (series.getLegendRenderType() == LegendRenderType.Line) {
legendContentWidth =
chart.getStyler().getLegendSeriesLineLength()
+ chart.getStyler().getLegendPadding()
+ legendContentWidth;
} else {
legendContentWidth = BOX_SIZE + chart.getStyler().getLegendPadding() + legendContentWidth;
}
}
// Legend Box
double width = legendContentWidth + chart.getStyler().getLegendPadding();
double height = legendTextContentMaxHeight + chart.getStyler().getLegendPadding() * 2;
return new Rectangle2D.Double(0, 0, width, height); // 0 indicates not sure yet.
} | [
"private",
"Rectangle2D",
"getBoundsHintHorizontal",
"(",
")",
"{",
"if",
"(",
"!",
"chart",
".",
"getStyler",
"(",
")",
".",
"isLegendVisible",
"(",
")",
")",
"{",
"return",
"new",
"Rectangle2D",
".",
"Double",
"(",
")",
";",
"// Constructs a new Rectangle2D,... | determine the width and height of the chart legend with horizontal layout | [
"determine",
"the",
"width",
"and",
"height",
"of",
"the",
"chart",
"legend",
"with",
"horizontal",
"layout"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java#L225-L279 |
32,346 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java | Legend_.getSeriesTextBounds | Map<String, Rectangle2D> getSeriesTextBounds(S series) {
// FontMetrics fontMetrics = g.getFontMetrics(getChartPainter().getstyler().getLegendFont());
// float fontDescent = fontMetrics.getDescent();
String lines[] = series.getName().split("\\n");
Map<String, Rectangle2D> seriesTextBounds =
new LinkedHashMap<String, Rectangle2D>(lines.length);
for (String line : lines) {
TextLayout textLayout =
new TextLayout(
line, chart.getStyler().getLegendFont(), new FontRenderContext(null, true, false));
Shape shape = textLayout.getOutline(null);
Rectangle2D bounds = shape.getBounds2D();
// System.out.println(tl.getAscent());
// System.out.println(tl.getDescent());
// System.out.println(tl.getBounds());
// seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(),
// bounds.getWidth(), bounds.getHeight() - tl.getDescent()));
// seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(),
// bounds.getWidth(), tl.getAscent()));
seriesTextBounds.put(line, bounds);
}
return seriesTextBounds;
} | java | Map<String, Rectangle2D> getSeriesTextBounds(S series) {
// FontMetrics fontMetrics = g.getFontMetrics(getChartPainter().getstyler().getLegendFont());
// float fontDescent = fontMetrics.getDescent();
String lines[] = series.getName().split("\\n");
Map<String, Rectangle2D> seriesTextBounds =
new LinkedHashMap<String, Rectangle2D>(lines.length);
for (String line : lines) {
TextLayout textLayout =
new TextLayout(
line, chart.getStyler().getLegendFont(), new FontRenderContext(null, true, false));
Shape shape = textLayout.getOutline(null);
Rectangle2D bounds = shape.getBounds2D();
// System.out.println(tl.getAscent());
// System.out.println(tl.getDescent());
// System.out.println(tl.getBounds());
// seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(),
// bounds.getWidth(), bounds.getHeight() - tl.getDescent()));
// seriesTextBounds.put(line, new Rectangle2D.Double(bounds.getX(), bounds.getY(),
// bounds.getWidth(), tl.getAscent()));
seriesTextBounds.put(line, bounds);
}
return seriesTextBounds;
} | [
"Map",
"<",
"String",
",",
"Rectangle2D",
">",
"getSeriesTextBounds",
"(",
"S",
"series",
")",
"{",
"// FontMetrics fontMetrics = g.getFontMetrics(getChartPainter().getstyler().getLegendFont());",
"// float fontDescent = fontMetrics.getDescent();",
"String",
"lines",
"[",
"]",
"=... | Normally each legend entry just has one line of text, but it can be made multi-line by adding
"\\n". This method returns a Map for each single legend entry, which is normally just a Map
with one single entry.
@param series
@return | [
"Normally",
"each",
"legend",
"entry",
"just",
"has",
"one",
"line",
"of",
"text",
"but",
"it",
"can",
"be",
"made",
"multi",
"-",
"line",
"by",
"adding",
"\\\\",
"n",
".",
"This",
"method",
"returns",
"a",
"Map",
"for",
"each",
"single",
"legend",
"en... | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_.java#L289-L313 |
32,347 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/OHLCChart.java | OHLCChart.addSeries | public OHLCSeries addSeries(
String seriesName,
int[] xData,
int[] openData,
int[] highData,
int[] lowData,
int[] closeData) {
return addSeries(
seriesName,
Utils.getDoubleArrayFromIntArray(xData),
Utils.getDoubleArrayFromIntArray(openData),
Utils.getDoubleArrayFromIntArray(highData),
Utils.getDoubleArrayFromIntArray(lowData),
Utils.getDoubleArrayFromIntArray(closeData),
DataType.Number);
} | java | public OHLCSeries addSeries(
String seriesName,
int[] xData,
int[] openData,
int[] highData,
int[] lowData,
int[] closeData) {
return addSeries(
seriesName,
Utils.getDoubleArrayFromIntArray(xData),
Utils.getDoubleArrayFromIntArray(openData),
Utils.getDoubleArrayFromIntArray(highData),
Utils.getDoubleArrayFromIntArray(lowData),
Utils.getDoubleArrayFromIntArray(closeData),
DataType.Number);
} | [
"public",
"OHLCSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"int",
"[",
"]",
"xData",
",",
"int",
"[",
"]",
"openData",
",",
"int",
"[",
"]",
"highData",
",",
"int",
"[",
"]",
"lowData",
",",
"int",
"[",
"]",
"closeData",
")",
"{",
"return... | Add a series for a OHLC type chart using using int arrays
@param seriesName
@param xData the x-axis data
@param openData the open data
@param highData the high data
@param lowData the low data
@param closeData the close data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"OHLC",
"type",
"chart",
"using",
"using",
"int",
"arrays"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/OHLCChart.java#L148-L164 |
32,348 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/OHLCChart.java | OHLCChart.addSeries | private OHLCSeries addSeries(
String seriesName,
double[] xData,
double[] openData,
double[] highData,
double[] lowData,
double[] closeData,
DataType dataType) {
if (seriesMap.keySet().contains(seriesName)) {
throw new IllegalArgumentException(
"Series name >"
+ seriesName
+ "< has already been used. Use unique names for each series!!!");
}
// Sanity checks
sanityCheck(seriesName, openData, highData, lowData, closeData);
final double[] xDataToUse;
if (xData != null) {
// Sanity check
checkDataLengths(seriesName, "X-Axis", "Close", xData, closeData);
xDataToUse = xData;
} else { // generate xData
xDataToUse = Utils.getGeneratedDataAsArray(closeData.length);
}
OHLCSeries series =
new OHLCSeries(seriesName, xDataToUse, openData, highData, lowData, closeData, dataType);
;
seriesMap.put(seriesName, series);
return series;
} | java | private OHLCSeries addSeries(
String seriesName,
double[] xData,
double[] openData,
double[] highData,
double[] lowData,
double[] closeData,
DataType dataType) {
if (seriesMap.keySet().contains(seriesName)) {
throw new IllegalArgumentException(
"Series name >"
+ seriesName
+ "< has already been used. Use unique names for each series!!!");
}
// Sanity checks
sanityCheck(seriesName, openData, highData, lowData, closeData);
final double[] xDataToUse;
if (xData != null) {
// Sanity check
checkDataLengths(seriesName, "X-Axis", "Close", xData, closeData);
xDataToUse = xData;
} else { // generate xData
xDataToUse = Utils.getGeneratedDataAsArray(closeData.length);
}
OHLCSeries series =
new OHLCSeries(seriesName, xDataToUse, openData, highData, lowData, closeData, dataType);
;
seriesMap.put(seriesName, series);
return series;
} | [
"private",
"OHLCSeries",
"addSeries",
"(",
"String",
"seriesName",
",",
"double",
"[",
"]",
"xData",
",",
"double",
"[",
"]",
"openData",
",",
"double",
"[",
"]",
"highData",
",",
"double",
"[",
"]",
"lowData",
",",
"double",
"[",
"]",
"closeData",
",",
... | Add a series for a OHLC type chart
@param seriesName
@param xData the x-axis data
@param openData the open data
@param highData the high data
@param lowData the low data
@param closeData the close data
@return A Series object that you can set properties on | [
"Add",
"a",
"series",
"for",
"a",
"OHLC",
"type",
"chart"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/OHLCChart.java#L291-L326 |
32,349 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/OHLCChart.java | OHLCChart.setSeriesStyles | private void setSeriesStyles() {
SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler =
new SeriesColorMarkerLineStyleCycler(
getStyler().getSeriesColors(),
getStyler().getSeriesMarkers(),
getStyler().getSeriesLines());
for (OHLCSeries series : getSeriesMap().values()) {
SeriesColorMarkerLineStyle seriesColorMarkerLineStyle =
seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle();
if (series.getLineStyle() == null) { // wasn't set manually
series.setLineStyle(seriesColorMarkerLineStyle.getStroke());
}
if (series.getLineColor() == null) { // wasn't set manually
series.setLineColor(seriesColorMarkerLineStyle.getColor());
}
if (series.getFillColor() == null) { // wasn't set manually
series.setFillColor(seriesColorMarkerLineStyle.getColor());
}
if (series.getUpColor() == null) { // wasn't set manually
series.setUpColor(Color.GREEN);
}
if (series.getDownColor() == null) { // wasn't set manually
series.setDownColor(Color.RED);
}
}
} | java | private void setSeriesStyles() {
SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler =
new SeriesColorMarkerLineStyleCycler(
getStyler().getSeriesColors(),
getStyler().getSeriesMarkers(),
getStyler().getSeriesLines());
for (OHLCSeries series : getSeriesMap().values()) {
SeriesColorMarkerLineStyle seriesColorMarkerLineStyle =
seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle();
if (series.getLineStyle() == null) { // wasn't set manually
series.setLineStyle(seriesColorMarkerLineStyle.getStroke());
}
if (series.getLineColor() == null) { // wasn't set manually
series.setLineColor(seriesColorMarkerLineStyle.getColor());
}
if (series.getFillColor() == null) { // wasn't set manually
series.setFillColor(seriesColorMarkerLineStyle.getColor());
}
if (series.getUpColor() == null) { // wasn't set manually
series.setUpColor(Color.GREEN);
}
if (series.getDownColor() == null) { // wasn't set manually
series.setDownColor(Color.RED);
}
}
} | [
"private",
"void",
"setSeriesStyles",
"(",
")",
"{",
"SeriesColorMarkerLineStyleCycler",
"seriesColorMarkerLineStyleCycler",
"=",
"new",
"SeriesColorMarkerLineStyleCycler",
"(",
"getStyler",
"(",
")",
".",
"getSeriesColors",
"(",
")",
",",
"getStyler",
"(",
")",
".",
... | set the series color, marker and line style based on theme | [
"set",
"the",
"series",
"color",
"marker",
"and",
"line",
"style",
"based",
"on",
"theme"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/OHLCChart.java#L476-L504 |
32,350 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java | Axis.getXAxisHeightHint | private double getXAxisHeightHint(double workingSpace) {
// Axis title
double titleHeight = 0.0;
if (chart.getXAxisTitle() != null
&& !chart.getXAxisTitle().trim().equalsIgnoreCase("")
&& axesChartStyler.isXAxisTitleVisible()) {
TextLayout textLayout =
new TextLayout(
chart.getXAxisTitle(),
axesChartStyler.getAxisTitleFont(),
new FontRenderContext(null, true, false));
Rectangle2D rectangle = textLayout.getBounds();
titleHeight = rectangle.getHeight() + axesChartStyler.getAxisTitlePadding();
}
this.axisTickCalculator = getAxisTickCalculator(workingSpace);
// Axis tick labels
double axisTickLabelsHeight = 0.0;
if (axesChartStyler.isXAxisTicksVisible()) {
// get some real tick labels
// System.out.println("XAxisHeightHint");
// System.out.println("workingSpace: " + workingSpace);
String sampleLabel = "";
// find the longest String in all the labels
for (int i = 0; i < axisTickCalculator.getTickLabels().size(); i++) {
// System.out.println("label: " + axisTickCalculator.getTickLabels().get(i));
if (axisTickCalculator.getTickLabels().get(i) != null
&& axisTickCalculator.getTickLabels().get(i).length() > sampleLabel.length()) {
sampleLabel = axisTickCalculator.getTickLabels().get(i);
}
}
// System.out.println("sampleLabel: " + sampleLabel);
// get the height of the label including rotation
TextLayout textLayout =
new TextLayout(
sampleLabel.length() == 0 ? " " : sampleLabel,
axesChartStyler.getAxisTickLabelsFont(),
new FontRenderContext(null, true, false));
AffineTransform rot =
axesChartStyler.getXAxisLabelRotation() == 0
? null
: AffineTransform.getRotateInstance(
-1 * Math.toRadians(axesChartStyler.getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
axisTickLabelsHeight =
rectangle.getHeight()
+ axesChartStyler.getAxisTickPadding()
+ axesChartStyler.getAxisTickMarkLength();
}
return titleHeight + axisTickLabelsHeight;
} | java | private double getXAxisHeightHint(double workingSpace) {
// Axis title
double titleHeight = 0.0;
if (chart.getXAxisTitle() != null
&& !chart.getXAxisTitle().trim().equalsIgnoreCase("")
&& axesChartStyler.isXAxisTitleVisible()) {
TextLayout textLayout =
new TextLayout(
chart.getXAxisTitle(),
axesChartStyler.getAxisTitleFont(),
new FontRenderContext(null, true, false));
Rectangle2D rectangle = textLayout.getBounds();
titleHeight = rectangle.getHeight() + axesChartStyler.getAxisTitlePadding();
}
this.axisTickCalculator = getAxisTickCalculator(workingSpace);
// Axis tick labels
double axisTickLabelsHeight = 0.0;
if (axesChartStyler.isXAxisTicksVisible()) {
// get some real tick labels
// System.out.println("XAxisHeightHint");
// System.out.println("workingSpace: " + workingSpace);
String sampleLabel = "";
// find the longest String in all the labels
for (int i = 0; i < axisTickCalculator.getTickLabels().size(); i++) {
// System.out.println("label: " + axisTickCalculator.getTickLabels().get(i));
if (axisTickCalculator.getTickLabels().get(i) != null
&& axisTickCalculator.getTickLabels().get(i).length() > sampleLabel.length()) {
sampleLabel = axisTickCalculator.getTickLabels().get(i);
}
}
// System.out.println("sampleLabel: " + sampleLabel);
// get the height of the label including rotation
TextLayout textLayout =
new TextLayout(
sampleLabel.length() == 0 ? " " : sampleLabel,
axesChartStyler.getAxisTickLabelsFont(),
new FontRenderContext(null, true, false));
AffineTransform rot =
axesChartStyler.getXAxisLabelRotation() == 0
? null
: AffineTransform.getRotateInstance(
-1 * Math.toRadians(axesChartStyler.getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
axisTickLabelsHeight =
rectangle.getHeight()
+ axesChartStyler.getAxisTickPadding()
+ axesChartStyler.getAxisTickMarkLength();
}
return titleHeight + axisTickLabelsHeight;
} | [
"private",
"double",
"getXAxisHeightHint",
"(",
"double",
"workingSpace",
")",
"{",
"// Axis title",
"double",
"titleHeight",
"=",
"0.0",
";",
"if",
"(",
"chart",
".",
"getXAxisTitle",
"(",
")",
"!=",
"null",
"&&",
"!",
"chart",
".",
"getXAxisTitle",
"(",
")... | The vertical Y-Axis is drawn first, but to know the lower bounds of it, we need to know how
high the X-Axis paint zone is going to be. Since the tick labels could be rotated, we need to
actually determine the tick labels first to get an idea of how tall the X-Axis tick labels will
be.
@return | [
"The",
"vertical",
"Y",
"-",
"Axis",
"is",
"drawn",
"first",
"but",
"to",
"know",
"the",
"lower",
"bounds",
"of",
"it",
"we",
"need",
"to",
"know",
"how",
"high",
"the",
"X",
"-",
"Axis",
"paint",
"zone",
"is",
"going",
"to",
"be",
".",
"Since",
"t... | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java#L257-L314 |
32,351 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java | Axis.getChartValue | public double getChartValue(double screenPoint) {
// a check if all axis data are the exact same values
if (min == max) {
return min;
}
double minVal = min;
double maxVal = max;
// min & max is not set in category charts with string labels
if (min > max) {
if (getDirection() == Direction.X) {
if (axesChartStyler instanceof CategoryStyler) {
AxesChartSeriesCategory axesChartSeries =
(AxesChartSeriesCategory) chart.getSeriesMap().values().iterator().next();
int count = axesChartSeries.getXData().size();
minVal = 0;
maxVal = count;
}
}
}
double workingSpace;
double startOffset;
if (direction == Direction.X) {
startOffset = bounds.getX();
workingSpace = bounds.getWidth();
} else {
startOffset = 0; //bounds.getY();
workingSpace = bounds.getHeight();
screenPoint = bounds.getHeight() - screenPoint + bounds.getY(); // y increments top to bottom
}
// tick space - a percentage of the working space available for ticks
double tickSpace = axesChartStyler.getPlotContentSize() * workingSpace; // in plot space
// this prevents an infinite loop when the plot gets sized really small.
if (tickSpace < axesChartStyler.getXAxisTickMarkSpacingHint()) {
return minVal;
}
// where the tick should begin in the working space in pixels
double margin =
Utils.getTickStartOffset(
workingSpace,
tickSpace);
// given tickLabelPositon (screenPoint) find value
// double tickLabelPosition =
// margin + ((value - min) / (max - min) * tickSpace);
double value = ((screenPoint - margin - startOffset) * (maxVal - minVal) / tickSpace) + minVal;
return value;
} | java | public double getChartValue(double screenPoint) {
// a check if all axis data are the exact same values
if (min == max) {
return min;
}
double minVal = min;
double maxVal = max;
// min & max is not set in category charts with string labels
if (min > max) {
if (getDirection() == Direction.X) {
if (axesChartStyler instanceof CategoryStyler) {
AxesChartSeriesCategory axesChartSeries =
(AxesChartSeriesCategory) chart.getSeriesMap().values().iterator().next();
int count = axesChartSeries.getXData().size();
minVal = 0;
maxVal = count;
}
}
}
double workingSpace;
double startOffset;
if (direction == Direction.X) {
startOffset = bounds.getX();
workingSpace = bounds.getWidth();
} else {
startOffset = 0; //bounds.getY();
workingSpace = bounds.getHeight();
screenPoint = bounds.getHeight() - screenPoint + bounds.getY(); // y increments top to bottom
}
// tick space - a percentage of the working space available for ticks
double tickSpace = axesChartStyler.getPlotContentSize() * workingSpace; // in plot space
// this prevents an infinite loop when the plot gets sized really small.
if (tickSpace < axesChartStyler.getXAxisTickMarkSpacingHint()) {
return minVal;
}
// where the tick should begin in the working space in pixels
double margin =
Utils.getTickStartOffset(
workingSpace,
tickSpace);
// given tickLabelPositon (screenPoint) find value
// double tickLabelPosition =
// margin + ((value - min) / (max - min) * tickSpace);
double value = ((screenPoint - margin - startOffset) * (maxVal - minVal) / tickSpace) + minVal;
return value;
} | [
"public",
"double",
"getChartValue",
"(",
"double",
"screenPoint",
")",
"{",
"// a check if all axis data are the exact same values",
"if",
"(",
"min",
"==",
"max",
")",
"{",
"return",
"min",
";",
"}",
"double",
"minVal",
"=",
"min",
";",
"double",
"maxVal",
"="... | Converts a screen coordinate to chart coordinate value. Reverses the AxisTickCalculators calculation.
@param screenPoint Coordinate of screen. eg: MouseEvent.getX(), MouseEvent.getY()
@return value in chart coordinate system | [
"Converts",
"a",
"screen",
"coordinate",
"to",
"chart",
"coordinate",
"value",
".",
"Reverses",
"the",
"AxisTickCalculators",
"calculation",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java#L575-L630 |
32,352 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java | ChartTitle.getBoundsHint | private Rectangle2D getBoundsHint() {
if (chart.getStyler().isChartTitleVisible() && chart.getTitle().length() > 0) {
TextLayout textLayout =
new TextLayout(
chart.getTitle(),
chart.getStyler().getChartTitleFont(),
new FontRenderContext(null, true, false));
Rectangle2D rectangle = textLayout.getBounds();
double width = 2 * chart.getStyler().getChartTitlePadding() + rectangle.getWidth();
double height = 2 * chart.getStyler().getChartTitlePadding() + rectangle.getHeight();
return new Rectangle2D.Double(
Double.NaN, Double.NaN, width, height); // Double.NaN indicates not sure yet.
} else {
return new Rectangle2D
.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
// 0).
}
} | java | private Rectangle2D getBoundsHint() {
if (chart.getStyler().isChartTitleVisible() && chart.getTitle().length() > 0) {
TextLayout textLayout =
new TextLayout(
chart.getTitle(),
chart.getStyler().getChartTitleFont(),
new FontRenderContext(null, true, false));
Rectangle2D rectangle = textLayout.getBounds();
double width = 2 * chart.getStyler().getChartTitlePadding() + rectangle.getWidth();
double height = 2 * chart.getStyler().getChartTitlePadding() + rectangle.getHeight();
return new Rectangle2D.Double(
Double.NaN, Double.NaN, width, height); // Double.NaN indicates not sure yet.
} else {
return new Rectangle2D
.Double(); // Constructs a new Rectangle2D, initialized to location (0, 0) and size (0,
// 0).
}
} | [
"private",
"Rectangle2D",
"getBoundsHint",
"(",
")",
"{",
"if",
"(",
"chart",
".",
"getStyler",
"(",
")",
".",
"isChartTitleVisible",
"(",
")",
"&&",
"chart",
".",
"getTitle",
"(",
")",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"TextLayout",
"textLa... | get the height of the chart title including the chart title padding
@return a Rectangle2D defining the height of the chart title including the chart title padding | [
"get",
"the",
"height",
"of",
"the",
"chart",
"title",
"including",
"the",
"chart",
"title",
"padding"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartTitle.java#L102-L122 |
32,353 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_.java | PlotContent_.closePath | void closePath(
Graphics2D g, Path2D.Double path, double previousX, Rectangle2D bounds, double yTopMargin) {
if (path != null) {
double yBottomOfArea = getBounds().getY() + getBounds().getHeight() - yTopMargin;
path.lineTo(previousX, yBottomOfArea);
path.closePath();
g.fill(path);
}
} | java | void closePath(
Graphics2D g, Path2D.Double path, double previousX, Rectangle2D bounds, double yTopMargin) {
if (path != null) {
double yBottomOfArea = getBounds().getY() + getBounds().getHeight() - yTopMargin;
path.lineTo(previousX, yBottomOfArea);
path.closePath();
g.fill(path);
}
} | [
"void",
"closePath",
"(",
"Graphics2D",
"g",
",",
"Path2D",
".",
"Double",
"path",
",",
"double",
"previousX",
",",
"Rectangle2D",
"bounds",
",",
"double",
"yTopMargin",
")",
"{",
"if",
"(",
"path",
"!=",
"null",
")",
"{",
"double",
"yBottomOfArea",
"=",
... | Closes a path for area charts if one is available. | [
"Closes",
"a",
"path",
"for",
"area",
"charts",
"if",
"one",
"is",
"available",
"."
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_.java#L66-L75 |
32,354 | knowm/XChart | xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java | SeriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle | public SeriesColorMarkerLineStyle getNextSeriesColorMarkerLineStyle() {
// 1. Color - cycle through colors one by one
if (colorCounter >= seriesColorList.length) {
colorCounter = 0;
strokeCounter++;
}
Color seriesColor = seriesColorList[colorCounter++];
// 2. Stroke - cycle through strokes one by one but only after a color cycle
if (strokeCounter >= seriesLineStyleList.length) {
strokeCounter = 0;
}
BasicStroke seriesLineStyle = seriesLineStyleList[strokeCounter];
// 3. Marker - cycle through markers one by one
if (markerCounter >= seriesMarkerList.length) {
markerCounter = 0;
}
Marker marker = seriesMarkerList[markerCounter++];
return new SeriesColorMarkerLineStyle(seriesColor, marker, seriesLineStyle);
} | java | public SeriesColorMarkerLineStyle getNextSeriesColorMarkerLineStyle() {
// 1. Color - cycle through colors one by one
if (colorCounter >= seriesColorList.length) {
colorCounter = 0;
strokeCounter++;
}
Color seriesColor = seriesColorList[colorCounter++];
// 2. Stroke - cycle through strokes one by one but only after a color cycle
if (strokeCounter >= seriesLineStyleList.length) {
strokeCounter = 0;
}
BasicStroke seriesLineStyle = seriesLineStyleList[strokeCounter];
// 3. Marker - cycle through markers one by one
if (markerCounter >= seriesMarkerList.length) {
markerCounter = 0;
}
Marker marker = seriesMarkerList[markerCounter++];
return new SeriesColorMarkerLineStyle(seriesColor, marker, seriesLineStyle);
} | [
"public",
"SeriesColorMarkerLineStyle",
"getNextSeriesColorMarkerLineStyle",
"(",
")",
"{",
"// 1. Color - cycle through colors one by one",
"if",
"(",
"colorCounter",
">=",
"seriesColorList",
".",
"length",
")",
"{",
"colorCounter",
"=",
"0",
";",
"strokeCounter",
"++",
... | Get the next ColorMarkerLineStyle
@return the next ColorMarkerLineStyle | [
"Get",
"the",
"next",
"ColorMarkerLineStyle"
] | 677a105753a855edf24782fab1bf1f5aec3e642b | https://github.com/knowm/XChart/blob/677a105753a855edf24782fab1bf1f5aec3e642b/xchart/src/main/java/org/knowm/xchart/internal/style/SeriesColorMarkerLineStyleCycler.java#L44-L66 |
32,355 | kevinsawicki/http-request | lib/src/main/java/com/github/kevinsawicki/http/HttpRequest.java | HttpRequest.arrayToList | private static List<Object> arrayToList(final Object array) {
if (array instanceof Object[])
return Arrays.asList((Object[]) array);
List<Object> result = new ArrayList<Object>();
// Arrays of the primitive types can't be cast to array of Object, so this:
if (array instanceof int[])
for (int value : (int[]) array) result.add(value);
else if (array instanceof boolean[])
for (boolean value : (boolean[]) array) result.add(value);
else if (array instanceof long[])
for (long value : (long[]) array) result.add(value);
else if (array instanceof float[])
for (float value : (float[]) array) result.add(value);
else if (array instanceof double[])
for (double value : (double[]) array) result.add(value);
else if (array instanceof short[])
for (short value : (short[]) array) result.add(value);
else if (array instanceof byte[])
for (byte value : (byte[]) array) result.add(value);
else if (array instanceof char[])
for (char value : (char[]) array) result.add(value);
return result;
} | java | private static List<Object> arrayToList(final Object array) {
if (array instanceof Object[])
return Arrays.asList((Object[]) array);
List<Object> result = new ArrayList<Object>();
// Arrays of the primitive types can't be cast to array of Object, so this:
if (array instanceof int[])
for (int value : (int[]) array) result.add(value);
else if (array instanceof boolean[])
for (boolean value : (boolean[]) array) result.add(value);
else if (array instanceof long[])
for (long value : (long[]) array) result.add(value);
else if (array instanceof float[])
for (float value : (float[]) array) result.add(value);
else if (array instanceof double[])
for (double value : (double[]) array) result.add(value);
else if (array instanceof short[])
for (short value : (short[]) array) result.add(value);
else if (array instanceof byte[])
for (byte value : (byte[]) array) result.add(value);
else if (array instanceof char[])
for (char value : (char[]) array) result.add(value);
return result;
} | [
"private",
"static",
"List",
"<",
"Object",
">",
"arrayToList",
"(",
"final",
"Object",
"array",
")",
"{",
"if",
"(",
"array",
"instanceof",
"Object",
"[",
"]",
")",
"return",
"Arrays",
".",
"asList",
"(",
"(",
"Object",
"[",
"]",
")",
"array",
")",
... | Represents array of any type as list of objects so we can easily iterate over it
@param array of elements
@return list with the same elements | [
"Represents",
"array",
"of",
"any",
"type",
"as",
"list",
"of",
"objects",
"so",
"we",
"can",
"easily",
"iterate",
"over",
"it"
] | 2d62a3e9da726942a93cf16b6e91c0187e6c0136 | https://github.com/kevinsawicki/http-request/blob/2d62a3e9da726942a93cf16b6e91c0187e6c0136/lib/src/main/java/com/github/kevinsawicki/http/HttpRequest.java#L835-L858 |
32,356 | kevinsawicki/http-request | lib/src/main/java/com/github/kevinsawicki/http/HttpRequest.java | HttpRequest.head | public static HttpRequest head(final CharSequence baseUrl,
final Map<?, ?> params, final boolean encode) {
String url = append(baseUrl, params);
return head(encode ? encode(url) : url);
} | java | public static HttpRequest head(final CharSequence baseUrl,
final Map<?, ?> params, final boolean encode) {
String url = append(baseUrl, params);
return head(encode ? encode(url) : url);
} | [
"public",
"static",
"HttpRequest",
"head",
"(",
"final",
"CharSequence",
"baseUrl",
",",
"final",
"Map",
"<",
"?",
",",
"?",
">",
"params",
",",
"final",
"boolean",
"encode",
")",
"{",
"String",
"url",
"=",
"append",
"(",
"baseUrl",
",",
"params",
")",
... | Start a 'HEAD' request to the given URL along with the query params
@param baseUrl
@param params
The query parameters to include as part of the baseUrl
@param encode
true to encode the full URL
@see #append(CharSequence, Map)
@see #encode(CharSequence)
@return request | [
"Start",
"a",
"HEAD",
"request",
"to",
"the",
"given",
"URL",
"along",
"with",
"the",
"query",
"params"
] | 2d62a3e9da726942a93cf16b6e91c0187e6c0136 | https://github.com/kevinsawicki/http-request/blob/2d62a3e9da726942a93cf16b6e91c0187e6c0136/lib/src/main/java/com/github/kevinsawicki/http/HttpRequest.java#L1264-L1268 |
32,357 | Baidu-AIP/java-sdk | src/main/java/com/baidu/aip/http/AipRequest.java | AipRequest.getBodyStr | public String getBodyStr() {
ArrayList<String> arr = new ArrayList<String>();
if (bodyFormat.equals(EBodyFormat.FORM_KV)) {
for (Map.Entry<String, Object> entry : body.entrySet()) {
if (entry.getValue() == null || entry.getValue().equals("")) {
arr.add(Util.uriEncode(entry.getKey(), true));
} else {
arr.add(String.format("%s=%s", Util.uriEncode(entry.getKey(), true),
Util.uriEncode(entry.getValue().toString(), true)));
}
}
return Util.mkString(arr.iterator(), '&');
}
else if (bodyFormat.equals(EBodyFormat.RAW_JSON)) {
JSONObject json = new JSONObject();
for (Map.Entry<String, Object> entry : body.entrySet()) {
json.put(entry.getKey(), entry.getValue());
}
return json.toString();
}
else if (bodyFormat.equals(EBodyFormat.RAW_JSON_ARRAY)) {
return (String) body.get("body");
}
return "";
} | java | public String getBodyStr() {
ArrayList<String> arr = new ArrayList<String>();
if (bodyFormat.equals(EBodyFormat.FORM_KV)) {
for (Map.Entry<String, Object> entry : body.entrySet()) {
if (entry.getValue() == null || entry.getValue().equals("")) {
arr.add(Util.uriEncode(entry.getKey(), true));
} else {
arr.add(String.format("%s=%s", Util.uriEncode(entry.getKey(), true),
Util.uriEncode(entry.getValue().toString(), true)));
}
}
return Util.mkString(arr.iterator(), '&');
}
else if (bodyFormat.equals(EBodyFormat.RAW_JSON)) {
JSONObject json = new JSONObject();
for (Map.Entry<String, Object> entry : body.entrySet()) {
json.put(entry.getKey(), entry.getValue());
}
return json.toString();
}
else if (bodyFormat.equals(EBodyFormat.RAW_JSON_ARRAY)) {
return (String) body.get("body");
}
return "";
} | [
"public",
"String",
"getBodyStr",
"(",
")",
"{",
"ArrayList",
"<",
"String",
">",
"arr",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"if",
"(",
"bodyFormat",
".",
"equals",
"(",
"EBodyFormat",
".",
"FORM_KV",
")",
")",
"{",
"for",
"("... | get body content depending on bodyFormat
@return body content as String | [
"get",
"body",
"content",
"depending",
"on",
"bodyFormat"
] | 16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90 | https://github.com/Baidu-AIP/java-sdk/blob/16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90/src/main/java/com/baidu/aip/http/AipRequest.java#L96-L120 |
32,358 | Baidu-AIP/java-sdk | src/main/java/com/baidu/aip/client/BaseClient.java | BaseClient.getAccessToken | protected synchronized void getAccessToken(AipClientConfiguration config) {
if (!needAuth()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("app[%s] no need to auth", this.appId));
}
return;
}
JSONObject res = DevAuth.oauth(aipKey, aipToken, config);
if (res == null) {
LOGGER.warn("oauth get null response");
return;
}
if (!res.isNull("access_token")) {
// openAPI认证成功
state.transfer(true);
accessToken = res.getString("access_token");
LOGGER.info("get access_token success. current state: " + state.toString());
Integer expireSec = res.getInt("expires_in");
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, expireSec);
expireDate = c;
// isBceKey.set(false);
// 验证接口权限
String[] scope = res.getString("scope").split(" ");
boolean hasRight = false;
for (String str : scope) {
if (AipClientConst.AI_ACCESS_RIGHT.contains(str)) {
// 权限验证通过
hasRight = true;
break;
}
}
state.transfer(hasRight);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("current state after check priviledge: " + state.toString());
}
}
else if (!res.isNull("error_code")) {
state.transfer(false);
LOGGER.warn("oauth get error, current state: " + state.toString());
}
} | java | protected synchronized void getAccessToken(AipClientConfiguration config) {
if (!needAuth()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("app[%s] no need to auth", this.appId));
}
return;
}
JSONObject res = DevAuth.oauth(aipKey, aipToken, config);
if (res == null) {
LOGGER.warn("oauth get null response");
return;
}
if (!res.isNull("access_token")) {
// openAPI认证成功
state.transfer(true);
accessToken = res.getString("access_token");
LOGGER.info("get access_token success. current state: " + state.toString());
Integer expireSec = res.getInt("expires_in");
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, expireSec);
expireDate = c;
// isBceKey.set(false);
// 验证接口权限
String[] scope = res.getString("scope").split(" ");
boolean hasRight = false;
for (String str : scope) {
if (AipClientConst.AI_ACCESS_RIGHT.contains(str)) {
// 权限验证通过
hasRight = true;
break;
}
}
state.transfer(hasRight);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("current state after check priviledge: " + state.toString());
}
}
else if (!res.isNull("error_code")) {
state.transfer(false);
LOGGER.warn("oauth get error, current state: " + state.toString());
}
} | [
"protected",
"synchronized",
"void",
"getAccessToken",
"(",
"AipClientConfiguration",
"config",
")",
"{",
"if",
"(",
"!",
"needAuth",
"(",
")",
")",
"{",
"if",
"(",
"LOGGER",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"String",... | get OAuth access token, synchronized function
@param config 网络连接设置 | [
"get",
"OAuth",
"access",
"token",
"synchronized",
"function"
] | 16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90 | https://github.com/Baidu-AIP/java-sdk/blob/16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90/src/main/java/com/baidu/aip/client/BaseClient.java#L182-L224 |
32,359 | Baidu-AIP/java-sdk | src/main/java/com/baidu/aip/client/BaseClient.java | BaseClient.requestServer | protected JSONObject requestServer(AipRequest request) {
// 请求API
AipResponse response = AipHttpClient.post(request);
String resData = response.getBodyStr();
Integer status = response.getStatus();
if (status.equals(200) && !resData.equals("")) {
try {
JSONObject res = new JSONObject(resData);
if (state.getState().equals(EAuthState.STATE_POSSIBLE_CLOUD_USER)) {
boolean cloudAuthState = res.isNull("error_code")
|| res.getInt("error_code") != AipClientConst.IAM_ERROR_CODE;
state.transfer(cloudAuthState);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("state after cloud auth: " + state.toString());
}
if (!cloudAuthState) {
return Util.getGeneralError(
AipClientConst.OPENAPI_NO_ACCESS_ERROR_CODE,
AipClientConst.OPENAPI_NO_ACCESS_ERROR_MSG);
}
}
return res;
} catch (JSONException e) {
return Util.getGeneralError(-1, resData);
}
}
else {
LOGGER.warn(String.format("call failed! response status: %d, data: %s", status, resData));
return AipError.NET_TIMEOUT_ERROR.toJsonResult();
}
} | java | protected JSONObject requestServer(AipRequest request) {
// 请求API
AipResponse response = AipHttpClient.post(request);
String resData = response.getBodyStr();
Integer status = response.getStatus();
if (status.equals(200) && !resData.equals("")) {
try {
JSONObject res = new JSONObject(resData);
if (state.getState().equals(EAuthState.STATE_POSSIBLE_CLOUD_USER)) {
boolean cloudAuthState = res.isNull("error_code")
|| res.getInt("error_code") != AipClientConst.IAM_ERROR_CODE;
state.transfer(cloudAuthState);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("state after cloud auth: " + state.toString());
}
if (!cloudAuthState) {
return Util.getGeneralError(
AipClientConst.OPENAPI_NO_ACCESS_ERROR_CODE,
AipClientConst.OPENAPI_NO_ACCESS_ERROR_MSG);
}
}
return res;
} catch (JSONException e) {
return Util.getGeneralError(-1, resData);
}
}
else {
LOGGER.warn(String.format("call failed! response status: %d, data: %s", status, resData));
return AipError.NET_TIMEOUT_ERROR.toJsonResult();
}
} | [
"protected",
"JSONObject",
"requestServer",
"(",
"AipRequest",
"request",
")",
"{",
"// 请求API",
"AipResponse",
"response",
"=",
"AipHttpClient",
".",
"post",
"(",
"request",
")",
";",
"String",
"resData",
"=",
"response",
".",
"getBodyStr",
"(",
")",
";",
"Int... | send request to server
@param request AipRequest object
@return JSONObject of server response | [
"send",
"request",
"to",
"server"
] | 16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90 | https://github.com/Baidu-AIP/java-sdk/blob/16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90/src/main/java/com/baidu/aip/client/BaseClient.java#L290-L321 |
32,360 | Baidu-AIP/java-sdk | src/main/java/com/baidu/aip/auth/DevAuth.java | DevAuth.oauth | public static JSONObject oauth(String apiKey, String secretKey, AipClientConfiguration config) {
try {
AipRequest request = new AipRequest();
request.setUri(new URI(AipClientConst.OAUTH_URL));
request.addBody("grant_type", "client_credentials");
request.addBody("client_id", apiKey);
request.addBody("client_secret", secretKey);
request.setConfig(config);
int statusCode = 500;
AipResponse response = null;
// add retry
int cnt = 0;
while (statusCode == 500 && cnt < 3) {
response = AipHttpClient.post(request);
statusCode = response.getStatus();
cnt++;
}
String res = response.getBodyStr();
if (res != null && !res.equals("")) {
return new JSONObject(res);
} else {
return Util.getGeneralError(statusCode, "Server response code: " + statusCode);
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
return Util.getGeneralError(-1, "unknown error");
} | java | public static JSONObject oauth(String apiKey, String secretKey, AipClientConfiguration config) {
try {
AipRequest request = new AipRequest();
request.setUri(new URI(AipClientConst.OAUTH_URL));
request.addBody("grant_type", "client_credentials");
request.addBody("client_id", apiKey);
request.addBody("client_secret", secretKey);
request.setConfig(config);
int statusCode = 500;
AipResponse response = null;
// add retry
int cnt = 0;
while (statusCode == 500 && cnt < 3) {
response = AipHttpClient.post(request);
statusCode = response.getStatus();
cnt++;
}
String res = response.getBodyStr();
if (res != null && !res.equals("")) {
return new JSONObject(res);
} else {
return Util.getGeneralError(statusCode, "Server response code: " + statusCode);
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
return Util.getGeneralError(-1, "unknown error");
} | [
"public",
"static",
"JSONObject",
"oauth",
"(",
"String",
"apiKey",
",",
"String",
"secretKey",
",",
"AipClientConfiguration",
"config",
")",
"{",
"try",
"{",
"AipRequest",
"request",
"=",
"new",
"AipRequest",
"(",
")",
";",
"request",
".",
"setUri",
"(",
"n... | get access_token from openapi
@param apiKey API key from console
@param secretKey Secret Key from console
@param config network config settings
@return JsonObject of response from OAuth server | [
"get",
"access_token",
"from",
"openapi"
] | 16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90 | https://github.com/Baidu-AIP/java-sdk/blob/16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90/src/main/java/com/baidu/aip/auth/DevAuth.java#L35-L62 |
32,361 | Baidu-AIP/java-sdk | src/main/java/com/baidu/aip/util/Base64Util.java | Base64Util.encode | public static String encode(byte[] from) {
StringBuilder to = new StringBuilder((int) (from.length * 1.34) + 3);
int num = 0;
char currentByte = 0;
for (int i = 0; i < from.length; i++) {
num = num % 8;
while (num < 8) {
switch (num) {
case 0:
currentByte = (char) (from[i] & lead6byte);
currentByte = (char) (currentByte >>> 2);
break;
case 2:
currentByte = (char) (from[i] & last6byte);
break;
case 4:
currentByte = (char) (from[i] & last4byte);
currentByte = (char) (currentByte << 2);
if ((i + 1) < from.length) {
currentByte |= (from[i + 1] & lead2byte) >>> 6;
}
break;
case 6:
currentByte = (char) (from[i] & last2byte);
currentByte = (char) (currentByte << 4);
if ((i + 1) < from.length) {
currentByte |= (from[i + 1] & lead4byte) >>> 4;
}
break;
default:
break;
}
to.append(encodeTable[currentByte]);
num += 6;
}
}
if (to.length() % 4 != 0) {
for (int i = 4 - to.length() % 4; i > 0; i--) {
to.append("=");
}
}
return to.toString();
} | java | public static String encode(byte[] from) {
StringBuilder to = new StringBuilder((int) (from.length * 1.34) + 3);
int num = 0;
char currentByte = 0;
for (int i = 0; i < from.length; i++) {
num = num % 8;
while (num < 8) {
switch (num) {
case 0:
currentByte = (char) (from[i] & lead6byte);
currentByte = (char) (currentByte >>> 2);
break;
case 2:
currentByte = (char) (from[i] & last6byte);
break;
case 4:
currentByte = (char) (from[i] & last4byte);
currentByte = (char) (currentByte << 2);
if ((i + 1) < from.length) {
currentByte |= (from[i + 1] & lead2byte) >>> 6;
}
break;
case 6:
currentByte = (char) (from[i] & last2byte);
currentByte = (char) (currentByte << 4);
if ((i + 1) < from.length) {
currentByte |= (from[i + 1] & lead4byte) >>> 4;
}
break;
default:
break;
}
to.append(encodeTable[currentByte]);
num += 6;
}
}
if (to.length() % 4 != 0) {
for (int i = 4 - to.length() % 4; i > 0; i--) {
to.append("=");
}
}
return to.toString();
} | [
"public",
"static",
"String",
"encode",
"(",
"byte",
"[",
"]",
"from",
")",
"{",
"StringBuilder",
"to",
"=",
"new",
"StringBuilder",
"(",
"(",
"int",
")",
"(",
"from",
".",
"length",
"*",
"1.34",
")",
"+",
"3",
")",
";",
"int",
"num",
"=",
"0",
"... | Base64 encoding.
@param from
The src data.
@return cryto_str | [
"Base64",
"encoding",
"."
] | 16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90 | https://github.com/Baidu-AIP/java-sdk/blob/16bb8b7bb8f9bbcb7c8af62d0a67a1e79eecad90/src/main/java/com/baidu/aip/util/Base64Util.java#L53-L95 |
32,362 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java | OnBindViewHolderListenerImpl.onBindViewHolder | @Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position, List<Object> payloads) {
Object tag = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tag instanceof FastAdapter) {
FastAdapter fastAdapter = ((FastAdapter) tag);
IItem item = fastAdapter.getItem(position);
if (item != null) {
item.bindView(viewHolder, payloads);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).bindView(item, payloads);
}
//set the R.id.fastadapter_item tag of this item to the item object (can be used when retrieving the view)
viewHolder.itemView.setTag(R.id.fastadapter_item, item);
}
}
} | java | @Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position, List<Object> payloads) {
Object tag = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tag instanceof FastAdapter) {
FastAdapter fastAdapter = ((FastAdapter) tag);
IItem item = fastAdapter.getItem(position);
if (item != null) {
item.bindView(viewHolder, payloads);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).bindView(item, payloads);
}
//set the R.id.fastadapter_item tag of this item to the item object (can be used when retrieving the view)
viewHolder.itemView.setTag(R.id.fastadapter_item, item);
}
}
} | [
"@",
"Override",
"public",
"void",
"onBindViewHolder",
"(",
"RecyclerView",
".",
"ViewHolder",
"viewHolder",
",",
"int",
"position",
",",
"List",
"<",
"Object",
">",
"payloads",
")",
"{",
"Object",
"tag",
"=",
"viewHolder",
".",
"itemView",
".",
"getTag",
"(... | is called in onBindViewHolder to bind the data on the ViewHolder
@param viewHolder the viewHolder for the type at this position
@param position the position of this viewHolder
@param payloads the payloads provided by the adapter | [
"is",
"called",
"in",
"onBindViewHolder",
"to",
"bind",
"the",
"data",
"on",
"the",
"ViewHolder"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L21-L36 |
32,363 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java | OnBindViewHolderListenerImpl.unBindViewHolder | @Override
public void unBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
IItem item = FastAdapter.getHolderAdapterItemTag(viewHolder);
if (item != null) {
item.unbindView(viewHolder);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).unbindView(item);
}
//remove set tag's
viewHolder.itemView.setTag(R.id.fastadapter_item, null);
viewHolder.itemView.setTag(R.id.fastadapter_item_adapter, null);
} else {
Log.e("FastAdapter", "The bindView method of this item should set the `Tag` on its itemView (https://github.com/mikepenz/FastAdapter/blob/develop/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java#L189)");
}
} | java | @Override
public void unBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
IItem item = FastAdapter.getHolderAdapterItemTag(viewHolder);
if (item != null) {
item.unbindView(viewHolder);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).unbindView(item);
}
//remove set tag's
viewHolder.itemView.setTag(R.id.fastadapter_item, null);
viewHolder.itemView.setTag(R.id.fastadapter_item_adapter, null);
} else {
Log.e("FastAdapter", "The bindView method of this item should set the `Tag` on its itemView (https://github.com/mikepenz/FastAdapter/blob/develop/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java#L189)");
}
} | [
"@",
"Override",
"public",
"void",
"unBindViewHolder",
"(",
"RecyclerView",
".",
"ViewHolder",
"viewHolder",
",",
"int",
"position",
")",
"{",
"IItem",
"item",
"=",
"FastAdapter",
".",
"getHolderAdapterItemTag",
"(",
"viewHolder",
")",
";",
"if",
"(",
"item",
... | is called in onViewRecycled to unbind the data on the ViewHolder
@param viewHolder the viewHolder for the type at this position
@param position the position of this viewHolder | [
"is",
"called",
"in",
"onViewRecycled",
"to",
"unbind",
"the",
"data",
"on",
"the",
"ViewHolder"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L44-L58 |
32,364 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java | OnBindViewHolderListenerImpl.onViewAttachedToWindow | @Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder viewHolder, int position) {
IItem item = FastAdapter.getHolderAdapterItem(viewHolder, position);
if (item != null) {
try {
item.attachToWindow(viewHolder);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).attachToWindow(item);
}
} catch (AbstractMethodError e) {
Log.e("FastAdapter", e.toString());
}
}
} | java | @Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder viewHolder, int position) {
IItem item = FastAdapter.getHolderAdapterItem(viewHolder, position);
if (item != null) {
try {
item.attachToWindow(viewHolder);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).attachToWindow(item);
}
} catch (AbstractMethodError e) {
Log.e("FastAdapter", e.toString());
}
}
} | [
"@",
"Override",
"public",
"void",
"onViewAttachedToWindow",
"(",
"RecyclerView",
".",
"ViewHolder",
"viewHolder",
",",
"int",
"position",
")",
"{",
"IItem",
"item",
"=",
"FastAdapter",
".",
"getHolderAdapterItem",
"(",
"viewHolder",
",",
"position",
")",
";",
"... | is called in onViewAttachedToWindow when the view is detached from the window
@param viewHolder the viewHolder for the type at this position
@param position the position of this viewHolder | [
"is",
"called",
"in",
"onViewAttachedToWindow",
"when",
"the",
"view",
"is",
"detached",
"from",
"the",
"window"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L66-L79 |
32,365 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java | OnBindViewHolderListenerImpl.onViewDetachedFromWindow | @Override
public void onViewDetachedFromWindow(RecyclerView.ViewHolder viewHolder, int position) {
IItem item = FastAdapter.getHolderAdapterItemTag(viewHolder);
if (item != null) {
item.detachFromWindow(viewHolder);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).detachFromWindow(item);
}
}
} | java | @Override
public void onViewDetachedFromWindow(RecyclerView.ViewHolder viewHolder, int position) {
IItem item = FastAdapter.getHolderAdapterItemTag(viewHolder);
if (item != null) {
item.detachFromWindow(viewHolder);
if (viewHolder instanceof FastAdapter.ViewHolder) {
((FastAdapter.ViewHolder) viewHolder).detachFromWindow(item);
}
}
} | [
"@",
"Override",
"public",
"void",
"onViewDetachedFromWindow",
"(",
"RecyclerView",
".",
"ViewHolder",
"viewHolder",
",",
"int",
"position",
")",
"{",
"IItem",
"item",
"=",
"FastAdapter",
".",
"getHolderAdapterItemTag",
"(",
"viewHolder",
")",
";",
"if",
"(",
"i... | is called in onViewDetachedFromWindow when the view is detached from the window
@param viewHolder the viewHolder for the type at this position
@param position the position of this viewHolder | [
"is",
"called",
"in",
"onViewDetachedFromWindow",
"when",
"the",
"view",
"is",
"detached",
"from",
"the",
"window"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L87-L96 |
32,366 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnCreateViewHolderListenerImpl.java | OnCreateViewHolderListenerImpl.onPreCreateViewHolder | @Override
public RecyclerView.ViewHolder onPreCreateViewHolder(FastAdapter<Item> fastAdapter, ViewGroup parent, int viewType) {
return fastAdapter.getTypeInstance(viewType).getViewHolder(parent);
} | java | @Override
public RecyclerView.ViewHolder onPreCreateViewHolder(FastAdapter<Item> fastAdapter, ViewGroup parent, int viewType) {
return fastAdapter.getTypeInstance(viewType).getViewHolder(parent);
} | [
"@",
"Override",
"public",
"RecyclerView",
".",
"ViewHolder",
"onPreCreateViewHolder",
"(",
"FastAdapter",
"<",
"Item",
">",
"fastAdapter",
",",
"ViewGroup",
"parent",
",",
"int",
"viewType",
")",
"{",
"return",
"fastAdapter",
".",
"getTypeInstance",
"(",
"viewTyp... | is called inside the onCreateViewHolder method and creates the viewHolder based on the provided viewTyp
@param parent the parent which will host the View
@param viewType the type of the ViewHolder we want to create
@return the generated ViewHolder based on the given viewType | [
"is",
"called",
"inside",
"the",
"onCreateViewHolder",
"method",
"and",
"creates",
"the",
"viewHolder",
"based",
"on",
"the",
"provided",
"viewTyp"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnCreateViewHolderListenerImpl.java#L21-L24 |
32,367 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnCreateViewHolderListenerImpl.java | OnCreateViewHolderListenerImpl.onPostCreateViewHolder | @Override
public RecyclerView.ViewHolder onPostCreateViewHolder(FastAdapter<Item> fastAdapter, RecyclerView.ViewHolder viewHolder) {
EventHookUtil.bind(viewHolder, fastAdapter.getEventHooks());
return viewHolder;
} | java | @Override
public RecyclerView.ViewHolder onPostCreateViewHolder(FastAdapter<Item> fastAdapter, RecyclerView.ViewHolder viewHolder) {
EventHookUtil.bind(viewHolder, fastAdapter.getEventHooks());
return viewHolder;
} | [
"@",
"Override",
"public",
"RecyclerView",
".",
"ViewHolder",
"onPostCreateViewHolder",
"(",
"FastAdapter",
"<",
"Item",
">",
"fastAdapter",
",",
"RecyclerView",
".",
"ViewHolder",
"viewHolder",
")",
"{",
"EventHookUtil",
".",
"bind",
"(",
"viewHolder",
",",
"fast... | is called after the viewHolder was created and the default listeners were added
@param viewHolder the created viewHolder after all listeners were set
@return the viewHolder given as param | [
"is",
"called",
"after",
"the",
"viewHolder",
"was",
"created",
"and",
"the",
"default",
"listeners",
"were",
"added"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnCreateViewHolderListenerImpl.java#L32-L36 |
32,368 | mikepenz/FastAdapter | app/src/main/java/com/mikepenz/fastadapter/app/helpers/CustomStickyRecyclerHeadersDecoration.java | CustomStickyRecyclerHeadersDecoration.setItemOffsetsForHeader | private void setItemOffsetsForHeader(Rect itemOffsets, View header, int orientation) {
mDimensionCalculator.initMargins(mTempRect, header);
if (orientation == LinearLayoutManager.VERTICAL) {
itemOffsets.top = header.getHeight() + mTempRect.top + mTempRect.bottom;
} else {
itemOffsets.left = header.getWidth() + mTempRect.left + mTempRect.right;
}
} | java | private void setItemOffsetsForHeader(Rect itemOffsets, View header, int orientation) {
mDimensionCalculator.initMargins(mTempRect, header);
if (orientation == LinearLayoutManager.VERTICAL) {
itemOffsets.top = header.getHeight() + mTempRect.top + mTempRect.bottom;
} else {
itemOffsets.left = header.getWidth() + mTempRect.left + mTempRect.right;
}
} | [
"private",
"void",
"setItemOffsetsForHeader",
"(",
"Rect",
"itemOffsets",
",",
"View",
"header",
",",
"int",
"orientation",
")",
"{",
"mDimensionCalculator",
".",
"initMargins",
"(",
"mTempRect",
",",
"header",
")",
";",
"if",
"(",
"orientation",
"==",
"LinearLa... | Sets the offsets for the first item in a section to make room for the header view
@param itemOffsets rectangle to define offsets for the item
@param header view used to calculate offset for the item
@param orientation used to calculate offset for the item | [
"Sets",
"the",
"offsets",
"for",
"the",
"first",
"item",
"in",
"a",
"section",
"to",
"make",
"room",
"for",
"the",
"header",
"view"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/app/src/main/java/com/mikepenz/fastadapter/app/helpers/CustomStickyRecyclerHeadersDecoration.java#L87-L94 |
32,369 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java | ItemFilter.withFilterPredicate | public ItemFilter<Model, Item> withFilterPredicate(IItemAdapter.Predicate<Item> filterPredicate) {
this.mFilterPredicate = filterPredicate;
return this;
} | java | public ItemFilter<Model, Item> withFilterPredicate(IItemAdapter.Predicate<Item> filterPredicate) {
this.mFilterPredicate = filterPredicate;
return this;
} | [
"public",
"ItemFilter",
"<",
"Model",
",",
"Item",
">",
"withFilterPredicate",
"(",
"IItemAdapter",
".",
"Predicate",
"<",
"Item",
">",
"filterPredicate",
")",
"{",
"this",
".",
"mFilterPredicate",
"=",
"filterPredicate",
";",
"return",
"this",
";",
"}"
] | define the predicate used to filter the list inside the ItemFilter
@param filterPredicate the predicate used to filter the list inside the ItemFilter
@return this | [
"define",
"the",
"predicate",
"used",
"to",
"filter",
"the",
"list",
"inside",
"the",
"ItemFilter"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java#L54-L57 |
32,370 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java | ItemFilter.getAdapterPosition | public int getAdapterPosition(long identifier) {
for (int i = 0, size = mOriginalItems.size(); i < size; i++) {
if (mOriginalItems.get(i).getIdentifier() == identifier) {
return i;
}
}
return -1;
} | java | public int getAdapterPosition(long identifier) {
for (int i = 0, size = mOriginalItems.size(); i < size; i++) {
if (mOriginalItems.get(i).getIdentifier() == identifier) {
return i;
}
}
return -1;
} | [
"public",
"int",
"getAdapterPosition",
"(",
"long",
"identifier",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
",",
"size",
"=",
"mOriginalItems",
".",
"size",
"(",
")",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"if",
"(",
"mOriginalItems",
"... | Searches for the given identifier and calculates its relative position
@param identifier the identifier of an item which is searched for
@return the relative position | [
"Searches",
"for",
"the",
"given",
"identifier",
"and",
"calculates",
"its",
"relative",
"position"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java#L184-L191 |
32,371 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java | ItemFilter.add | public ModelAdapter<?, Item> add(List<Item> items) {
if (mOriginalItems != null && items.size() > 0) {
if (mItemAdapter.isUseIdDistributor()) {
mItemAdapter.getIdDistributor().checkIds(items);
}
mOriginalItems.addAll(items);
publishResults(mConstraint, performFiltering(mConstraint));
return mItemAdapter;
} else {
return mItemAdapter.addInternal(items);
}
} | java | public ModelAdapter<?, Item> add(List<Item> items) {
if (mOriginalItems != null && items.size() > 0) {
if (mItemAdapter.isUseIdDistributor()) {
mItemAdapter.getIdDistributor().checkIds(items);
}
mOriginalItems.addAll(items);
publishResults(mConstraint, performFiltering(mConstraint));
return mItemAdapter;
} else {
return mItemAdapter.addInternal(items);
}
} | [
"public",
"ModelAdapter",
"<",
"?",
",",
"Item",
">",
"add",
"(",
"List",
"<",
"Item",
">",
"items",
")",
"{",
"if",
"(",
"mOriginalItems",
"!=",
"null",
"&&",
"items",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"if",
"(",
"mItemAdapter",
".",
"i... | add a list of items to the end of the existing items
will prior check if we are currently filtering
@param items the items to add | [
"add",
"a",
"list",
"of",
"items",
"to",
"the",
"end",
"of",
"the",
"existing",
"items",
"will",
"prior",
"check",
"if",
"we",
"are",
"currently",
"filtering"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java#L209-L220 |
32,372 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java | ItemFilter.clear | public ModelAdapter<?, Item> clear() {
if (mOriginalItems != null) {
mOriginalItems.clear();
publishResults(mConstraint, performFiltering(mConstraint));
return mItemAdapter;
} else {
return mItemAdapter.clear();
}
} | java | public ModelAdapter<?, Item> clear() {
if (mOriginalItems != null) {
mOriginalItems.clear();
publishResults(mConstraint, performFiltering(mConstraint));
return mItemAdapter;
} else {
return mItemAdapter.clear();
}
} | [
"public",
"ModelAdapter",
"<",
"?",
",",
"Item",
">",
"clear",
"(",
")",
"{",
"if",
"(",
"mOriginalItems",
"!=",
"null",
")",
"{",
"mOriginalItems",
".",
"clear",
"(",
")",
";",
"publishResults",
"(",
"mConstraint",
",",
"performFiltering",
"(",
"mConstrai... | removes all items of this adapter | [
"removes",
"all",
"items",
"of",
"this",
"adapter"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ItemFilter.java#L334-L342 |
32,373 | mikepenz/FastAdapter | library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/utilities/DragDropUtil.java | DragDropUtil.bindDragHandle | public static void bindDragHandle(final RecyclerView.ViewHolder holder, final IExtendedDraggable item) {
// if necessary, init the drag handle, which will start the drag when touched
if (item.getTouchHelper() != null && item.getDragView(holder) != null) {
item.getDragView(holder).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
if (item.isDraggable())
item.getTouchHelper().startDrag(holder);
}
return false;
}
});
}
} | java | public static void bindDragHandle(final RecyclerView.ViewHolder holder, final IExtendedDraggable item) {
// if necessary, init the drag handle, which will start the drag when touched
if (item.getTouchHelper() != null && item.getDragView(holder) != null) {
item.getDragView(holder).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
if (item.isDraggable())
item.getTouchHelper().startDrag(holder);
}
return false;
}
});
}
} | [
"public",
"static",
"void",
"bindDragHandle",
"(",
"final",
"RecyclerView",
".",
"ViewHolder",
"holder",
",",
"final",
"IExtendedDraggable",
"item",
")",
"{",
"// if necessary, init the drag handle, which will start the drag when touched",
"if",
"(",
"item",
".",
"getTouchH... | this functions binds the view's touch listener to start the drag via the touch helper...
@param holder the view holder
@param holder the item | [
"this",
"functions",
"binds",
"the",
"view",
"s",
"touch",
"listener",
"to",
"start",
"the",
"drag",
"via",
"the",
"touch",
"helper",
"..."
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/utilities/DragDropUtil.java#L23-L37 |
32,374 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/utils/EventHookUtil.java | EventHookUtil.bind | public static <Item extends IItem> void bind(RecyclerView.ViewHolder viewHolder, @Nullable final List<EventHook<Item>> eventHooks) {
if (eventHooks == null) {
return;
}
for (final EventHook<Item> event : eventHooks) {
View view = event.onBind(viewHolder);
if (view != null) {
attachToView(event, viewHolder, view);
}
List<? extends View> views = event.onBindMany(viewHolder);
if (views != null) {
for (View v : views) {
attachToView(event, viewHolder, v);
}
}
}
} | java | public static <Item extends IItem> void bind(RecyclerView.ViewHolder viewHolder, @Nullable final List<EventHook<Item>> eventHooks) {
if (eventHooks == null) {
return;
}
for (final EventHook<Item> event : eventHooks) {
View view = event.onBind(viewHolder);
if (view != null) {
attachToView(event, viewHolder, view);
}
List<? extends View> views = event.onBindMany(viewHolder);
if (views != null) {
for (View v : views) {
attachToView(event, viewHolder, v);
}
}
}
} | [
"public",
"static",
"<",
"Item",
"extends",
"IItem",
">",
"void",
"bind",
"(",
"RecyclerView",
".",
"ViewHolder",
"viewHolder",
",",
"@",
"Nullable",
"final",
"List",
"<",
"EventHook",
"<",
"Item",
">",
">",
"eventHooks",
")",
"{",
"if",
"(",
"eventHooks",... | binds the hooks to the viewHolder
@param viewHolder the viewHolder of the item | [
"binds",
"the",
"hooks",
"to",
"the",
"viewHolder"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/utils/EventHookUtil.java#L30-L47 |
32,375 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/utils/EventHookUtil.java | EventHookUtil.attachToView | public static <Item extends IItem> void attachToView(final EventHook<Item> event, final RecyclerView.ViewHolder viewHolder, View view) {
if (event instanceof ClickEventHook) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//get the adapter for this view
Object tagAdapter = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tagAdapter instanceof FastAdapter) {
FastAdapter<Item> adapter = (FastAdapter<Item>) tagAdapter;
//we get the adapterPosition from the viewHolder
int pos = adapter.getHolderAdapterPosition(viewHolder);
//make sure the click was done on a valid item
if (pos != RecyclerView.NO_POSITION) {
Item item = adapter.getItem(pos);
if (item != null) {
//we update our item with the changed property
((ClickEventHook<Item>) event).onClick(v, pos, adapter, item);
}
}
}
}
});
} else if (event instanceof LongClickEventHook) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//get the adapter for this view
Object tagAdapter = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tagAdapter instanceof FastAdapter) {
FastAdapter<Item> adapter = (FastAdapter<Item>) tagAdapter;
//we get the adapterPosition from the viewHolder
int pos = adapter.getHolderAdapterPosition(viewHolder);
//make sure the click was done on a valid item
if (pos != RecyclerView.NO_POSITION) {
Item item = adapter.getItem(pos);
if (item != null) {
//we update our item with the changed property
return ((LongClickEventHook<Item>) event).onLongClick(v, pos, adapter, item);
}
}
}
return false;
}
});
} else if (event instanceof TouchEventHook) {
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
//get the adapter for this view
Object tagAdapter = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tagAdapter instanceof FastAdapter) {
FastAdapter<Item> adapter = (FastAdapter<Item>) tagAdapter;
//we get the adapterPosition from the viewHolder
int pos = adapter.getHolderAdapterPosition(viewHolder);
//make sure the click was done on a valid item
if (pos != RecyclerView.NO_POSITION) {
Item item = adapter.getItem(pos);
if (item != null) {
//we update our item with the changed property
return ((TouchEventHook<Item>) event).onTouch(v, e, pos, adapter, item);
}
}
}
return false;
}
});
} else if (event instanceof CustomEventHook) {
//we trigger the event binding
((CustomEventHook<Item>) event).attachEvent(view, viewHolder);
}
} | java | public static <Item extends IItem> void attachToView(final EventHook<Item> event, final RecyclerView.ViewHolder viewHolder, View view) {
if (event instanceof ClickEventHook) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//get the adapter for this view
Object tagAdapter = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tagAdapter instanceof FastAdapter) {
FastAdapter<Item> adapter = (FastAdapter<Item>) tagAdapter;
//we get the adapterPosition from the viewHolder
int pos = adapter.getHolderAdapterPosition(viewHolder);
//make sure the click was done on a valid item
if (pos != RecyclerView.NO_POSITION) {
Item item = adapter.getItem(pos);
if (item != null) {
//we update our item with the changed property
((ClickEventHook<Item>) event).onClick(v, pos, adapter, item);
}
}
}
}
});
} else if (event instanceof LongClickEventHook) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//get the adapter for this view
Object tagAdapter = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tagAdapter instanceof FastAdapter) {
FastAdapter<Item> adapter = (FastAdapter<Item>) tagAdapter;
//we get the adapterPosition from the viewHolder
int pos = adapter.getHolderAdapterPosition(viewHolder);
//make sure the click was done on a valid item
if (pos != RecyclerView.NO_POSITION) {
Item item = adapter.getItem(pos);
if (item != null) {
//we update our item with the changed property
return ((LongClickEventHook<Item>) event).onLongClick(v, pos, adapter, item);
}
}
}
return false;
}
});
} else if (event instanceof TouchEventHook) {
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
//get the adapter for this view
Object tagAdapter = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter);
if (tagAdapter instanceof FastAdapter) {
FastAdapter<Item> adapter = (FastAdapter<Item>) tagAdapter;
//we get the adapterPosition from the viewHolder
int pos = adapter.getHolderAdapterPosition(viewHolder);
//make sure the click was done on a valid item
if (pos != RecyclerView.NO_POSITION) {
Item item = adapter.getItem(pos);
if (item != null) {
//we update our item with the changed property
return ((TouchEventHook<Item>) event).onTouch(v, e, pos, adapter, item);
}
}
}
return false;
}
});
} else if (event instanceof CustomEventHook) {
//we trigger the event binding
((CustomEventHook<Item>) event).attachEvent(view, viewHolder);
}
} | [
"public",
"static",
"<",
"Item",
"extends",
"IItem",
">",
"void",
"attachToView",
"(",
"final",
"EventHook",
"<",
"Item",
">",
"event",
",",
"final",
"RecyclerView",
".",
"ViewHolder",
"viewHolder",
",",
"View",
"view",
")",
"{",
"if",
"(",
"event",
"insta... | attaches the specific event to a view
@param event the event to attach
@param viewHolder the viewHolder containing this view
@param view the view to attach to | [
"attaches",
"the",
"specific",
"event",
"to",
"a",
"view"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/utils/EventHookUtil.java#L56-L126 |
32,376 | mikepenz/FastAdapter | library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/RangeSelectorHelper.java | RangeSelectorHelper.onLongClick | public boolean onLongClick(int index, boolean selectItem) {
if (mLastLongPressIndex == null) {
// we only consider long presses on not selected items
if (mFastAdapter.getAdapterItem(index).isSelectable()) {
mLastLongPressIndex = index;
// we select this item as well
if (selectItem)
mFastAdapter.select(index);
if (mActionModeHelper != null)
mActionModeHelper.checkActionMode(null); // works with null as well, as the ActionMode is active for sure!
return true;
}
} else if (mLastLongPressIndex != index) {
// select all items in the range between the two long clicks
selectRange(mLastLongPressIndex, index, true);
// reset the index
mLastLongPressIndex = null;
}
return false;
} | java | public boolean onLongClick(int index, boolean selectItem) {
if (mLastLongPressIndex == null) {
// we only consider long presses on not selected items
if (mFastAdapter.getAdapterItem(index).isSelectable()) {
mLastLongPressIndex = index;
// we select this item as well
if (selectItem)
mFastAdapter.select(index);
if (mActionModeHelper != null)
mActionModeHelper.checkActionMode(null); // works with null as well, as the ActionMode is active for sure!
return true;
}
} else if (mLastLongPressIndex != index) {
// select all items in the range between the two long clicks
selectRange(mLastLongPressIndex, index, true);
// reset the index
mLastLongPressIndex = null;
}
return false;
} | [
"public",
"boolean",
"onLongClick",
"(",
"int",
"index",
",",
"boolean",
"selectItem",
")",
"{",
"if",
"(",
"mLastLongPressIndex",
"==",
"null",
")",
"{",
"// we only consider long presses on not selected items",
"if",
"(",
"mFastAdapter",
".",
"getAdapterItem",
"(",
... | will take care to save the long pressed index
or to select all items in the range between the current long pressed item and the last long pressed item
@param index the index of the long pressed item
@param selectItem true, if the item at the index should be selected, false if this was already done outside of this helper or is not desired
@return true, if the long press was handled | [
"will",
"take",
"care",
"to",
"save",
"the",
"long",
"pressed",
"index",
"or",
"to",
"select",
"all",
"items",
"in",
"the",
"range",
"between",
"the",
"current",
"long",
"pressed",
"item",
"and",
"the",
"last",
"long",
"pressed",
"item"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/RangeSelectorHelper.java#L95-L114 |
32,377 | mikepenz/FastAdapter | library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/RangeSelectorHelper.java | RangeSelectorHelper.withSavedInstanceState | public RangeSelectorHelper withSavedInstanceState(Bundle savedInstanceState, String prefix) {
if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_LAST_LONG_PRESS + prefix))
mLastLongPressIndex = savedInstanceState.getInt(BUNDLE_LAST_LONG_PRESS + prefix);
return this;
} | java | public RangeSelectorHelper withSavedInstanceState(Bundle savedInstanceState, String prefix) {
if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_LAST_LONG_PRESS + prefix))
mLastLongPressIndex = savedInstanceState.getInt(BUNDLE_LAST_LONG_PRESS + prefix);
return this;
} | [
"public",
"RangeSelectorHelper",
"withSavedInstanceState",
"(",
"Bundle",
"savedInstanceState",
",",
"String",
"prefix",
")",
"{",
"if",
"(",
"savedInstanceState",
"!=",
"null",
"&&",
"savedInstanceState",
".",
"containsKey",
"(",
"BUNDLE_LAST_LONG_PRESS",
"+",
"prefix"... | restore the index of the last long pressed index
IMPORTANT! Call this method only after all items where added to the adapters again. Otherwise it may select wrong items!
@param savedInstanceState If the activity is being re-initialized after
previously being shut down then this Bundle contains the data it most
recently supplied in Note: Otherwise it is null.
@param prefix a prefix added to the savedInstance key so we can store multiple states
@return this | [
"restore",
"the",
"index",
"of",
"the",
"last",
"long",
"pressed",
"index",
"IMPORTANT!",
"Call",
"this",
"method",
"only",
"after",
"all",
"items",
"where",
"added",
"to",
"the",
"adapters",
"again",
".",
"Otherwise",
"it",
"may",
"select",
"wrong",
"items!... | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/RangeSelectorHelper.java#L214-L218 |
32,378 | mikepenz/FastAdapter | library/src/main/java/com/mikepenz/fastadapter/commons/utils/FastAdapterDiffUtil.java | FastAdapterDiffUtil.collapseIfPossible | private static void collapseIfPossible(FastAdapter fastAdapter) {
try {
Class c = Class.forName("com.mikepenz.fastadapter.expandable.ExpandableExtension");
if (c != null) {
IAdapterExtension extension = fastAdapter.getExtension(c);
if (extension != null) {
Method method = extension.getClass().getMethod("collapse");
method.invoke(extension);
}
}
} catch (Exception ignored) {
//
}
} | java | private static void collapseIfPossible(FastAdapter fastAdapter) {
try {
Class c = Class.forName("com.mikepenz.fastadapter.expandable.ExpandableExtension");
if (c != null) {
IAdapterExtension extension = fastAdapter.getExtension(c);
if (extension != null) {
Method method = extension.getClass().getMethod("collapse");
method.invoke(extension);
}
}
} catch (Exception ignored) {
//
}
} | [
"private",
"static",
"void",
"collapseIfPossible",
"(",
"FastAdapter",
"fastAdapter",
")",
"{",
"try",
"{",
"Class",
"c",
"=",
"Class",
".",
"forName",
"(",
"\"com.mikepenz.fastadapter.expandable.ExpandableExtension\"",
")",
";",
"if",
"(",
"c",
"!=",
"null",
")",... | Uses Reflection to collapse all items if this adapter uses expandable items
@param fastAdapter | [
"Uses",
"Reflection",
"to",
"collapse",
"all",
"items",
"if",
"this",
"adapter",
"uses",
"expandable",
"items"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library/src/main/java/com/mikepenz/fastadapter/commons/utils/FastAdapterDiffUtil.java#L85-L98 |
32,379 | mikepenz/FastAdapter | library/src/main/java/com/mikepenz/fastadapter/commons/adapters/AbstractWrapAdapter.java | AbstractWrapAdapter.getItemViewType | @Override
public int getItemViewType(int position) {
if (shouldInsertItemAtPosition(position)) {
return getItem(position).getType();
} else {
return mAdapter.getItemViewType(position - itemInsertedBeforeCount(position));
}
} | java | @Override
public int getItemViewType(int position) {
if (shouldInsertItemAtPosition(position)) {
return getItem(position).getType();
} else {
return mAdapter.getItemViewType(position - itemInsertedBeforeCount(position));
}
} | [
"@",
"Override",
"public",
"int",
"getItemViewType",
"(",
"int",
"position",
")",
"{",
"if",
"(",
"shouldInsertItemAtPosition",
"(",
"position",
")",
")",
"{",
"return",
"getItem",
"(",
"position",
")",
".",
"getType",
"(",
")",
";",
"}",
"else",
"{",
"r... | overwrite the getItemViewType to correctly return the value from the FastAdapter
@param position
@return | [
"overwrite",
"the",
"getItemViewType",
"to",
"correctly",
"return",
"the",
"value",
"from",
"the",
"FastAdapter"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library/src/main/java/com/mikepenz/fastadapter/commons/adapters/AbstractWrapAdapter.java#L95-L102 |
32,380 | mikepenz/FastAdapter | library/src/main/java/com/mikepenz/fastadapter/commons/adapters/AbstractWrapAdapter.java | AbstractWrapAdapter.getItemId | @Override
public long getItemId(int position) {
if (shouldInsertItemAtPosition(position)) {
return getItem(position).getIdentifier();
} else {
return mAdapter.getItemId(position - itemInsertedBeforeCount(position));
}
} | java | @Override
public long getItemId(int position) {
if (shouldInsertItemAtPosition(position)) {
return getItem(position).getIdentifier();
} else {
return mAdapter.getItemId(position - itemInsertedBeforeCount(position));
}
} | [
"@",
"Override",
"public",
"long",
"getItemId",
"(",
"int",
"position",
")",
"{",
"if",
"(",
"shouldInsertItemAtPosition",
"(",
"position",
")",
")",
"{",
"return",
"getItem",
"(",
"position",
")",
".",
"getIdentifier",
"(",
")",
";",
"}",
"else",
"{",
"... | overwrite the getItemId to correctly return the value from the FastAdapter
@param position
@return | [
"overwrite",
"the",
"getItemId",
"to",
"correctly",
"return",
"the",
"value",
"from",
"the",
"FastAdapter"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library/src/main/java/com/mikepenz/fastadapter/commons/adapters/AbstractWrapAdapter.java#L110-L117 |
32,381 | mikepenz/FastAdapter | library/src/main/java/com/mikepenz/fastadapter/commons/adapters/AbstractWrapAdapter.java | AbstractWrapAdapter.getItem | public Item getItem(int position) {
if (shouldInsertItemAtPosition(position)) {
return mItems.get(itemInsertedBeforeCount(position - 1));
}
return null;
} | java | public Item getItem(int position) {
if (shouldInsertItemAtPosition(position)) {
return mItems.get(itemInsertedBeforeCount(position - 1));
}
return null;
} | [
"public",
"Item",
"getItem",
"(",
"int",
"position",
")",
"{",
"if",
"(",
"shouldInsertItemAtPosition",
"(",
"position",
")",
")",
"{",
"return",
"mItems",
".",
"get",
"(",
"itemInsertedBeforeCount",
"(",
"position",
"-",
"1",
")",
")",
";",
"}",
"return",... | make sure we return the Item from the FastAdapter so we retrieve the item from all adapters
@param position
@return | [
"make",
"sure",
"we",
"return",
"the",
"Item",
"from",
"the",
"FastAdapter",
"so",
"we",
"retrieve",
"the",
"item",
"from",
"all",
"adapters"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library/src/main/java/com/mikepenz/fastadapter/commons/adapters/AbstractWrapAdapter.java#L132-L137 |
32,382 | mikepenz/FastAdapter | library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java | ExpandableExtension.getExpanded | public SparseIntArray getExpanded() {
SparseIntArray expandedItems = new SparseIntArray();
Item item;
for (int i = 0, size = mFastAdapter.getItemCount(); i < size; i++) {
item = mFastAdapter.getItem(i);
if (item instanceof IExpandable && ((IExpandable) item).isExpanded()) {
expandedItems.put(i, ((IExpandable) item).getSubItems().size());
}
}
return expandedItems;
} | java | public SparseIntArray getExpanded() {
SparseIntArray expandedItems = new SparseIntArray();
Item item;
for (int i = 0, size = mFastAdapter.getItemCount(); i < size; i++) {
item = mFastAdapter.getItem(i);
if (item instanceof IExpandable && ((IExpandable) item).isExpanded()) {
expandedItems.put(i, ((IExpandable) item).getSubItems().size());
}
}
return expandedItems;
} | [
"public",
"SparseIntArray",
"getExpanded",
"(",
")",
"{",
"SparseIntArray",
"expandedItems",
"=",
"new",
"SparseIntArray",
"(",
")",
";",
"Item",
"item",
";",
"for",
"(",
"int",
"i",
"=",
"0",
",",
"size",
"=",
"mFastAdapter",
".",
"getItemCount",
"(",
")"... | returns the expanded items this contains position and the count of items
which are expanded by this position
@return the expanded items | [
"returns",
"the",
"expanded",
"items",
"this",
"contains",
"position",
"and",
"the",
"count",
"of",
"items",
"which",
"are",
"expanded",
"by",
"this",
"position"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java#L208-L218 |
32,383 | mikepenz/FastAdapter | library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java | ExpandableExtension.toggleExpandable | public void toggleExpandable(int position) {
Item item = mFastAdapter.getItem(position);
if (item instanceof IExpandable && ((IExpandable) item).isExpanded()) {
collapse(position);
} else {
expand(position);
}
} | java | public void toggleExpandable(int position) {
Item item = mFastAdapter.getItem(position);
if (item instanceof IExpandable && ((IExpandable) item).isExpanded()) {
collapse(position);
} else {
expand(position);
}
} | [
"public",
"void",
"toggleExpandable",
"(",
"int",
"position",
")",
"{",
"Item",
"item",
"=",
"mFastAdapter",
".",
"getItem",
"(",
"position",
")",
";",
"if",
"(",
"item",
"instanceof",
"IExpandable",
"&&",
"(",
"(",
"IExpandable",
")",
"item",
")",
".",
... | toggles the expanded state of the given expandable item at the given position
@param position the global position | [
"toggles",
"the",
"expanded",
"state",
"of",
"the",
"given",
"expandable",
"item",
"at",
"the",
"given",
"position"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java#L309-L316 |
32,384 | mikepenz/FastAdapter | library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java | ExpandableExtension.collapse | public void collapse(boolean notifyItemChanged) {
int[] expandedItems = getExpandedItems();
for (int i = expandedItems.length - 1; i >= 0; i--) {
collapse(expandedItems[i], notifyItemChanged);
}
} | java | public void collapse(boolean notifyItemChanged) {
int[] expandedItems = getExpandedItems();
for (int i = expandedItems.length - 1; i >= 0; i--) {
collapse(expandedItems[i], notifyItemChanged);
}
} | [
"public",
"void",
"collapse",
"(",
"boolean",
"notifyItemChanged",
")",
"{",
"int",
"[",
"]",
"expandedItems",
"=",
"getExpandedItems",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"expandedItems",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",... | collapses all expanded items
@param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false | [
"collapses",
"all",
"expanded",
"items"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java#L330-L335 |
32,385 | mikepenz/FastAdapter | library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java | ExpandableExtension.expand | public void expand(boolean notifyItemChanged) {
int length = mFastAdapter.getItemCount();
for (int i = length - 1; i >= 0; i--) {
expand(i, notifyItemChanged);
}
} | java | public void expand(boolean notifyItemChanged) {
int length = mFastAdapter.getItemCount();
for (int i = length - 1; i >= 0; i--) {
expand(i, notifyItemChanged);
}
} | [
"public",
"void",
"expand",
"(",
"boolean",
"notifyItemChanged",
")",
"{",
"int",
"length",
"=",
"mFastAdapter",
".",
"getItemCount",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"ex... | expands all expandable items
@param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false | [
"expands",
"all",
"expandable",
"items"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java#L413-L418 |
32,386 | mikepenz/FastAdapter | library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java | ExpandableExtension.expand | public void expand(int position, boolean notifyItemChanged) {
Item item = mFastAdapter.getItem(position);
if (item != null && item instanceof IExpandable) {
IExpandable expandable = (IExpandable) item;
//if this item is not already expanded and has sub items we go on
if (!expandable.isExpanded() && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) {
IAdapter<Item> adapter = mFastAdapter.getAdapter(position);
if (adapter != null && adapter instanceof IItemAdapter) {
((IItemAdapter<?, Item>) adapter).addInternal(position + 1, expandable.getSubItems());
}
//remember that this item is now opened (not collapsed)
expandable.withIsExpanded(true);
//we need to notify to get the correct drawable if there is one showing the current state
if (notifyItemChanged) {
mFastAdapter.notifyItemChanged(position);
}
}
}
} | java | public void expand(int position, boolean notifyItemChanged) {
Item item = mFastAdapter.getItem(position);
if (item != null && item instanceof IExpandable) {
IExpandable expandable = (IExpandable) item;
//if this item is not already expanded and has sub items we go on
if (!expandable.isExpanded() && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) {
IAdapter<Item> adapter = mFastAdapter.getAdapter(position);
if (adapter != null && adapter instanceof IItemAdapter) {
((IItemAdapter<?, Item>) adapter).addInternal(position + 1, expandable.getSubItems());
}
//remember that this item is now opened (not collapsed)
expandable.withIsExpanded(true);
//we need to notify to get the correct drawable if there is one showing the current state
if (notifyItemChanged) {
mFastAdapter.notifyItemChanged(position);
}
}
}
} | [
"public",
"void",
"expand",
"(",
"int",
"position",
",",
"boolean",
"notifyItemChanged",
")",
"{",
"Item",
"item",
"=",
"mFastAdapter",
".",
"getItem",
"(",
"position",
")",
";",
"if",
"(",
"item",
"!=",
"null",
"&&",
"item",
"instanceof",
"IExpandable",
"... | opens the expandable item at the given position
@param position the global position
@param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false | [
"opens",
"the",
"expandable",
"item",
"at",
"the",
"given",
"position"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java#L436-L456 |
32,387 | mikepenz/FastAdapter | library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java | ExpandableExtension.getExpandedItemsCount | public int getExpandedItemsCount(int from, int position) {
int totalAddedItems = 0;
//first we find out how many items were added in total
//also counting subItems
Item tmp;
for (int i = from; i < position; i++) {
tmp = mFastAdapter.getItem(i);
if (tmp instanceof IExpandable) {
IExpandable tmpExpandable = ((IExpandable) tmp);
if (tmpExpandable.getSubItems() != null && tmpExpandable.isExpanded()) {
totalAddedItems = totalAddedItems + tmpExpandable.getSubItems().size();
}
}
}
return totalAddedItems;
} | java | public int getExpandedItemsCount(int from, int position) {
int totalAddedItems = 0;
//first we find out how many items were added in total
//also counting subItems
Item tmp;
for (int i = from; i < position; i++) {
tmp = mFastAdapter.getItem(i);
if (tmp instanceof IExpandable) {
IExpandable tmpExpandable = ((IExpandable) tmp);
if (tmpExpandable.getSubItems() != null && tmpExpandable.isExpanded()) {
totalAddedItems = totalAddedItems + tmpExpandable.getSubItems().size();
}
}
}
return totalAddedItems;
} | [
"public",
"int",
"getExpandedItemsCount",
"(",
"int",
"from",
",",
"int",
"position",
")",
"{",
"int",
"totalAddedItems",
"=",
"0",
";",
"//first we find out how many items were added in total",
"//also counting subItems",
"Item",
"tmp",
";",
"for",
"(",
"int",
"i",
... | calculates the count of expandable items before a given position
@param from the global start position you should pass here the count of items of the previous adapters (or 0 if you want to start from the beginning)
@param position the global position
@return the count of expandable items before a given position | [
"calculates",
"the",
"count",
"of",
"expandable",
"items",
"before",
"a",
"given",
"position"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java#L465-L480 |
32,388 | mikepenz/FastAdapter | library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java | ExpandableExtension.deselect | public void deselect() {
SelectExtension<Item> selectExtension = mFastAdapter.getExtension(SelectExtension.class);
if (selectExtension == null) {
return;
}
for (Item item : AdapterUtil.getAllItems(mFastAdapter)) {
selectExtension.deselect(item);
}
mFastAdapter.notifyDataSetChanged();
} | java | public void deselect() {
SelectExtension<Item> selectExtension = mFastAdapter.getExtension(SelectExtension.class);
if (selectExtension == null) {
return;
}
for (Item item : AdapterUtil.getAllItems(mFastAdapter)) {
selectExtension.deselect(item);
}
mFastAdapter.notifyDataSetChanged();
} | [
"public",
"void",
"deselect",
"(",
")",
"{",
"SelectExtension",
"<",
"Item",
">",
"selectExtension",
"=",
"mFastAdapter",
".",
"getExtension",
"(",
"SelectExtension",
".",
"class",
")",
";",
"if",
"(",
"selectExtension",
"==",
"null",
")",
"{",
"return",
";"... | deselects all selections | [
"deselects",
"all",
"selections"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.java#L485-L494 |
32,389 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java | AbstractItem.generateView | @Override
public View generateView(Context ctx) {
VH viewHolder = getViewHolder(createView(ctx, null));
//as we already know the type of our ViewHolder cast it to our type
bindView(viewHolder, Collections.EMPTY_LIST);
//return the bound view
return viewHolder.itemView;
} | java | @Override
public View generateView(Context ctx) {
VH viewHolder = getViewHolder(createView(ctx, null));
//as we already know the type of our ViewHolder cast it to our type
bindView(viewHolder, Collections.EMPTY_LIST);
//return the bound view
return viewHolder.itemView;
} | [
"@",
"Override",
"public",
"View",
"generateView",
"(",
"Context",
"ctx",
")",
"{",
"VH",
"viewHolder",
"=",
"getViewHolder",
"(",
"createView",
"(",
"ctx",
",",
"null",
")",
")",
";",
"//as we already know the type of our ViewHolder cast it to our type",
"bindView",
... | generates a view by the defined LayoutRes
@param ctx
@return | [
"generates",
"a",
"view",
"by",
"the",
"defined",
"LayoutRes"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java#L256-L265 |
32,390 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java | AbstractItem.getViewHolder | @Override
public VH getViewHolder(ViewGroup parent) {
return getViewHolder(createView(parent.getContext(), parent));
} | java | @Override
public VH getViewHolder(ViewGroup parent) {
return getViewHolder(createView(parent.getContext(), parent));
} | [
"@",
"Override",
"public",
"VH",
"getViewHolder",
"(",
"ViewGroup",
"parent",
")",
"{",
"return",
"getViewHolder",
"(",
"createView",
"(",
"parent",
".",
"getContext",
"(",
")",
",",
"parent",
")",
")",
";",
"}"
] | Generates a ViewHolder from this Item with the given parent
@param parent
@return | [
"Generates",
"a",
"ViewHolder",
"from",
"this",
"Item",
"with",
"the",
"given",
"parent"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java#L290-L293 |
32,391 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java | ModelAdapter.models | public static <Model, Item extends IItem> ModelAdapter<Model, Item> models(IInterceptor<Model, Item> interceptor) {
return new ModelAdapter<>(interceptor);
} | java | public static <Model, Item extends IItem> ModelAdapter<Model, Item> models(IInterceptor<Model, Item> interceptor) {
return new ModelAdapter<>(interceptor);
} | [
"public",
"static",
"<",
"Model",
",",
"Item",
"extends",
"IItem",
">",
"ModelAdapter",
"<",
"Model",
",",
"Item",
">",
"models",
"(",
"IInterceptor",
"<",
"Model",
",",
"Item",
">",
"interceptor",
")",
"{",
"return",
"new",
"ModelAdapter",
"<>",
"(",
"i... | static method to retrieve a new `ItemAdapter`
@return a new ItemAdapter | [
"static",
"method",
"to",
"retrieve",
"a",
"new",
"ItemAdapter"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java#L67-L69 |
32,392 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java | ModelAdapter.intercept | public List<Item> intercept(List<Model> models) {
List<Item> items = new ArrayList<>(models.size());
Item item;
for (Model model : models) {
item = intercept(model);
if (item == null) continue;
items.add(item);
}
return items;
} | java | public List<Item> intercept(List<Model> models) {
List<Item> items = new ArrayList<>(models.size());
Item item;
for (Model model : models) {
item = intercept(model);
if (item == null) continue;
items.add(item);
}
return items;
} | [
"public",
"List",
"<",
"Item",
">",
"intercept",
"(",
"List",
"<",
"Model",
">",
"models",
")",
"{",
"List",
"<",
"Item",
">",
"items",
"=",
"new",
"ArrayList",
"<>",
"(",
"models",
".",
"size",
"(",
")",
")",
";",
"Item",
"item",
";",
"for",
"("... | Generates a List of Item based on it's List of Model using the interceptor
@param models the List of Model which will be used to create the List of Item
@return the generated List of Item | [
"Generates",
"a",
"List",
"of",
"Item",
"based",
"on",
"it",
"s",
"List",
"of",
"Model",
"using",
"the",
"interceptor"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java#L110-L119 |
32,393 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java | ModelAdapter.withItemFilter | public ModelAdapter<Model, Item> withItemFilter(ItemFilter<Model, Item> itemFilter) {
this.mItemFilter = itemFilter;
return this;
} | java | public ModelAdapter<Model, Item> withItemFilter(ItemFilter<Model, Item> itemFilter) {
this.mItemFilter = itemFilter;
return this;
} | [
"public",
"ModelAdapter",
"<",
"Model",
",",
"Item",
">",
"withItemFilter",
"(",
"ItemFilter",
"<",
"Model",
",",
"Item",
">",
"itemFilter",
")",
"{",
"this",
".",
"mItemFilter",
"=",
"itemFilter",
";",
"return",
"this",
";",
"}"
] | allows you to define your own Filter implementation instead of the default `ItemFilter`
@param itemFilter the filter to use
@return this | [
"allows",
"you",
"to",
"define",
"your",
"own",
"Filter",
"implementation",
"instead",
"of",
"the",
"default",
"ItemFilter"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java#L171-L174 |
32,394 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java | ModelAdapter.getModels | public List<Model> getModels() {
ArrayList<Model> list = new ArrayList<>(mItems.size());
for (Item item : mItems.getItems()) {
if (mReverseInterceptor != null) {
list.add(mReverseInterceptor.intercept(item));
} else if (item instanceof IModelItem) {
list.add((Model) ((IModelItem) item).getModel());
} else {
throw new RuntimeException("to get the list of models, the item either needs to implement `IModelItem` or you have to provide a `reverseInterceptor`");
}
}
return list;
} | java | public List<Model> getModels() {
ArrayList<Model> list = new ArrayList<>(mItems.size());
for (Item item : mItems.getItems()) {
if (mReverseInterceptor != null) {
list.add(mReverseInterceptor.intercept(item));
} else if (item instanceof IModelItem) {
list.add((Model) ((IModelItem) item).getModel());
} else {
throw new RuntimeException("to get the list of models, the item either needs to implement `IModelItem` or you have to provide a `reverseInterceptor`");
}
}
return list;
} | [
"public",
"List",
"<",
"Model",
">",
"getModels",
"(",
")",
"{",
"ArrayList",
"<",
"Model",
">",
"list",
"=",
"new",
"ArrayList",
"<>",
"(",
"mItems",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Item",
"item",
":",
"mItems",
".",
"getItems",
"(",... | the ModelAdapter does not keep a list of input model's to get retrieve them a `reverseInterceptor` is required
usually it is used to get the `Model` from a `IModelItem`
@return a List of initial Model's | [
"the",
"ModelAdapter",
"does",
"not",
"keep",
"a",
"list",
"of",
"input",
"model",
"s",
"to",
"get",
"retrieve",
"them",
"a",
"reverseInterceptor",
"is",
"required",
"usually",
"it",
"is",
"used",
"to",
"get",
"the",
"Model",
"from",
"a",
"IModelItem"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java#L198-L210 |
32,395 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java | ModelAdapter.add | @SafeVarargs
public final ModelAdapter<Model, Item> add(Model... items) {
return add(asList(items));
} | java | @SafeVarargs
public final ModelAdapter<Model, Item> add(Model... items) {
return add(asList(items));
} | [
"@",
"SafeVarargs",
"public",
"final",
"ModelAdapter",
"<",
"Model",
",",
"Item",
">",
"add",
"(",
"Model",
"...",
"items",
")",
"{",
"return",
"add",
"(",
"asList",
"(",
"items",
")",
")",
";",
"}"
] | add an array of items to the end of the existing items
@param items the items to add | [
"add",
"an",
"array",
"of",
"items",
"to",
"the",
"end",
"of",
"the",
"existing",
"items"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java#L385-L388 |
32,396 | mikepenz/FastAdapter | library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java | ModelAdapter.add | public ModelAdapter<Model, Item> add(List<Model> list) {
List<Item> items = intercept(list);
return addInternal(items);
} | java | public ModelAdapter<Model, Item> add(List<Model> list) {
List<Item> items = intercept(list);
return addInternal(items);
} | [
"public",
"ModelAdapter",
"<",
"Model",
",",
"Item",
">",
"add",
"(",
"List",
"<",
"Model",
">",
"list",
")",
"{",
"List",
"<",
"Item",
">",
"items",
"=",
"intercept",
"(",
"list",
")",
";",
"return",
"addInternal",
"(",
"items",
")",
";",
"}"
] | add a list of items to the end of the existing items
@param list the items to add | [
"add",
"a",
"list",
"of",
"items",
"to",
"the",
"end",
"of",
"the",
"existing",
"items"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-core/src/main/java/com/mikepenz/fastadapter/adapters/ModelAdapter.java#L395-L398 |
32,397 | mikepenz/FastAdapter | library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/dialog/FastAdapterDialog.java | FastAdapterDialog.withOnClickListener | public FastAdapterDialog<Item> withOnClickListener(com.mikepenz.fastadapter.listeners.OnClickListener<Item> onClickListener) {
this.mFastAdapter.withOnClickListener(onClickListener);
return this;
} | java | public FastAdapterDialog<Item> withOnClickListener(com.mikepenz.fastadapter.listeners.OnClickListener<Item> onClickListener) {
this.mFastAdapter.withOnClickListener(onClickListener);
return this;
} | [
"public",
"FastAdapterDialog",
"<",
"Item",
">",
"withOnClickListener",
"(",
"com",
".",
"mikepenz",
".",
"fastadapter",
".",
"listeners",
".",
"OnClickListener",
"<",
"Item",
">",
"onClickListener",
")",
"{",
"this",
".",
"mFastAdapter",
".",
"withOnClickListener... | Define the OnClickListener which will be used for a single item
@param onClickListener the OnClickListener which will be used for a single item
@return this | [
"Define",
"the",
"OnClickListener",
"which",
"will",
"be",
"used",
"for",
"a",
"single",
"item"
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/dialog/FastAdapterDialog.java#L267-L270 |
32,398 | mikepenz/FastAdapter | app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.java | SortActivity.generateUnsortedList | private List<SimpleItem> generateUnsortedList() {
ArrayList<SimpleItem> result = new ArrayList<>(26);
for (int i = 0; i < 26; i++) {
result.add(makeItem(i));
}
Collections.shuffle(result);
return result;
} | java | private List<SimpleItem> generateUnsortedList() {
ArrayList<SimpleItem> result = new ArrayList<>(26);
for (int i = 0; i < 26; i++) {
result.add(makeItem(i));
}
Collections.shuffle(result);
return result;
} | [
"private",
"List",
"<",
"SimpleItem",
">",
"generateUnsortedList",
"(",
")",
"{",
"ArrayList",
"<",
"SimpleItem",
">",
"result",
"=",
"new",
"ArrayList",
"<>",
"(",
"26",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"26",
";",
"i",
"+... | Generates a simple list consisting of the letters of the alphabet, unordered on purpose.
@return The new list. | [
"Generates",
"a",
"simple",
"list",
"consisting",
"of",
"the",
"letters",
"of",
"the",
"alphabet",
"unordered",
"on",
"purpose",
"."
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.java#L210-L220 |
32,399 | mikepenz/FastAdapter | app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.java | SortActivity.makeItem | private SimpleItem makeItem(@IntRange(from = 0, to = 25) int position) {
SimpleItem result = new SimpleItem();
result.withName(ALPHABET[position]);
position++;
String description = "The " + (position);
if (position == 1 || position == 21) {
description += "st";
} else if (position == 2 || position == 22) {
description += "nd";
} else if (position == 3 || position == 23) {
description += "rd";
} else {
description += "th";
}
return result.withDescription(description + " letter in the alphabet");
} | java | private SimpleItem makeItem(@IntRange(from = 0, to = 25) int position) {
SimpleItem result = new SimpleItem();
result.withName(ALPHABET[position]);
position++;
String description = "The " + (position);
if (position == 1 || position == 21) {
description += "st";
} else if (position == 2 || position == 22) {
description += "nd";
} else if (position == 3 || position == 23) {
description += "rd";
} else {
description += "th";
}
return result.withDescription(description + " letter in the alphabet");
} | [
"private",
"SimpleItem",
"makeItem",
"(",
"@",
"IntRange",
"(",
"from",
"=",
"0",
",",
"to",
"=",
"25",
")",
"int",
"position",
")",
"{",
"SimpleItem",
"result",
"=",
"new",
"SimpleItem",
"(",
")",
";",
"result",
".",
"withName",
"(",
"ALPHABET",
"[",
... | Build a simple item with one letter of the alphabet.
@param position The position of the letter in the alphabet.
@return The new item. | [
"Build",
"a",
"simple",
"item",
"with",
"one",
"letter",
"of",
"the",
"alphabet",
"."
] | 3b2412abe001ba58422e0125846b704d4dba4ae9 | https://github.com/mikepenz/FastAdapter/blob/3b2412abe001ba58422e0125846b704d4dba4ae9/app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.java#L228-L248 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.