Tutorial by Examples: cases

Ruby uses the case keyword for switch statements. As per the Ruby Docs: Case statements consist of an optional condition, which is in the position of an argument to case, and zero or more when clauses. The first when clause to match the condition (or to evaluate to Boolean truth, if the condi...
To make all the characters in a String uppercase or lowercase: 2.2 let text = "AaBbCc" let uppercase = text.uppercaseString // "AABBCC" let lowercase = text.lowercaseString // "aabbcc" 3.0 let text = "AaBbCc" let uppercase = text.uppercased() // &qu...
The -CaseSensitive parameter enforces switch statements to perform exact, case-sensitive matching against conditions. Example: switch -CaseSensitive ('Condition') { 'condition' {'First Action'} 'Condition' {'Second Action'} 'conditioN' {'Third Action'} } Output: Second Act...
// *** Case sensitive with exact title match *** NSPredicate *filterByNameCS = [NSPredicate predicateWithFormat:@"self.title = %@",@"Tom and Jerry"]; NSLog(@"Filter By Name(CS) : %@",[array filteredArrayUsingPredicate:filterByNameCS]);
Incorrect usage: In the following snippet, the last match will never be used: let x = 4 match x with | 1 -> printfn "x is 1" | _ -> printfn "x is anything that wasn't listed above" | 4 -> printfn "x is 4" prints x is anything that wasn't listed abov...
For example, if you are sending an email to a customer after starting a task, it's best to immediately redirect the user to the next page while queuing the email to be sent in the background. This will speed up the load time for the next page, since sending an email can sometimes take several second...
You can test if a string matches several regular expressions using a switch statement. Example case "Ruby is #1!" when /\APython/ puts "Boooo." when /\ARuby/ puts "You are right." else puts "Sorry, I didn't understand that." end This w...
There is no revolution here, but angular constant can be useful specially when your application and/or team starts to grow ... or if you simply love writing beautiful code! Refactor code. Example with event's names. If you use a lot of events in your application, you have event's names a lit...
Extension methods can be used to "hide" processing of inelegant business rules that would otherwise require cluttering up a calling function with if/then statements. This is similar to and analogous to handling nulls with extension methods. For example, public static class CakeExtensions ...
This example shows the behaviour of getopt when the user input is uncommon: getopt.php var_dump( getopt("ab:c::", ["delta", "epsilon:", "zeta::"]) ); Shell command line $ php getopt.php -a -a -bbeta -b beta -cgamma --delta --epsilon --zeta --zeta=f...
In its simplest form supported by all versions of bash, case statement executes the case that matches the pattern. ;; operator breaks after the first match, if any. #!/bin/bash var=1 case $var in 1) echo "Antartica" ;; 2) echo "Brazil" ;; 3) echo "Cat&qu...
4.0 Since bash 4.0, a new operator ;& was introduced which provides fall through mechanism. #!/bin/bash var=1 case $var in 1) echo "Antartica" ;& 2) echo "Brazil" ;& 3) echo "Cat" ;& esac Outputs: Antartica Brazil Cat ...
ExecutorService ExecutorService executor = Executors.newFixedThreadPool(50); It is simple and easy to use. It hides low level details of ThreadPoolExecutor. I prefer this one when number of Callable/Runnable tasks are small in number and piling of tasks in unbounded queue does not increase m...
Executors returns different type of ThreadPools catering to specific need. public static ExecutorService newSingleThreadExecutor() Creates an Executor that uses a single worker thread operating off an unbounded queue There is a difference between newFixedThreadPool(1) and newSingleThreadE...
Case 1: While using in the place of method arguments. If a method requires an object of wrapper class as argument.Then interchangeably the argument can be passed a variable of the respective primitive type and vice versa. Example: int i; Integer j; void ex_method(Integer i)//Is a valid statem...
In a simple case statement, one value or variable is checked against multiple possible answers. The code below is an example of a simple case statement: SELECT CASE DATEPART(WEEKDAY, GETDATE()) WHEN 1 THEN 'Sunday' WHEN 2 THEN 'Monday' WHEN 3 THEN 'Tuesday' WHEN 4 THEN 'Wednes...
Using a CASE statement, conditionally display an expression in the column based on values found in another column, a.k.a. “my kingdom for an OR”. In the example, the result is obtained when the status of the transaction is Pending Fulfillment or Partially Fulfilled: CASE DECODE( {status}, 'Pending ...
In a saved search formula, the possible values of mainline are designed to be useful in an HTML context. When mainline is true, the value of {mainline} is the 1-character string * (asterisk). When mainline is false, the value of {mainline} is the 6-character string   (non-breaking space, HT...
We can have three cases to analyze an algorithm: Worst Case Average Case Best Case #include <stdio.h> // Linearly search x in arr[]. If x is present then return the index, // otherwise return -1 int search(int arr[], int n, int x) { int i; for (i=0; i<n; i...
Here are the steps to generate test skeleton for existing code: Open Eclipse, and choose the project you want to create test cases for In the Package Explorer, select the java class you want to generate the Junit test for Go to File -> New -> Junit Test Cases Change the Source folder to ...

Page 1 of 2