if let _ = detailInformation {
loadDetailInformation()
}
when optionals are killing yourself
int t;
if ((t > 1) && (t < 2))
{
errorString = errorBuffer;
return -1;
}
if (logger.isDebugEnabled()) {
logger.debug("process (FollettPojo) - start");
}
String dnum = StringUtil.toCapitalizedString(pojo.getDnum().toString());
pojo.setDnum(new String(dnum));
if (logger.isDebugEnabled()) {
logger.debug("process (FollettPojo) - middle ");
}
String rawI = StringUtil.toCapitalizedString(pojo.getRawInput().trim().toString());
pojo.setRawInput(new String(rawI));
if (logger.isDebugEnabled()) {
logger.debug("process (FollettPojo) - end ");
}
/* And you may ask what is this toCapitalizedString? Well here you go a separate class to boot */
public static String toCapitalizedString(String string){
StringBuilder strb = new StringBuilder();
if(string != null && string.trim().length() > 0
&& Character.isLetter(string.charAt(0))
&& Character.isLowerCase(string.charAt(0))){
strb.append(string.substring(0,1).toUpperCase()).append(string.substring(1));
return strb.toString();
}
return string;
}
SpringBatch this is the processor for each record...dnum example D00000000
function formatUpToANumberOfZeroesAfterFloatingPoint(number, numberOfZeroes, floatingPointSymbol) {
numberOfZeroes = (numberOfZeroes === undefined || numberOfZeroes < 0) ? 2 : numberOfZeroes;
floatingPointSymbol = floatingPointSymbol === undefined ? '.' : floatingPointSymbol;
let numberSplitByFloatingPoint = number.toString().split(floatingPointSymbol);
if (numberSplitByFloatingPoint.length !== 2)
return `${number}${floatingPointSymbol}${'0'.repeat(+numberOfZeroes)}`;
let numberAfterFloatingPoint = numberSplitByFloatingPoint[1].toString();
let formattedNumber = `${numberSplitByFloatingPoint[0]}`;
let numberAfterFloatingPointLength = numberAfterFloatingPoint.toString().length;
if (+numberOfZeroes > +numberAfterFloatingPointLength)
return `${formattedNumber}${floatingPointSymbol}${numberAfterFloatingPoint}${'0'.repeat(+numberOfZeroes - numberAfterFloatingPointLength)}`;
let countOfNumbersAfterFloatingPoint = numberAfterFloatingPointLength;
for (var i = numberAfterFloatingPointLength - 1; i >= 0; i--) {
if (+(numberAfterFloatingPoint[i]) !== 0 || +countOfNumbersAfterFloatingPoint === +numberOfZeroes) {
formattedNumber += `${floatingPointSymbol}${numberAfterFloatingPoint.substring(0, countOfNumbersAfterFloatingPoint)}`;
break;
}
countOfNumbersAfterFloatingPoint--;
}
return formattedNumber;
}
Well, a junior dev here. A cute female QA came to me with a request - "the field for the price already has precision up to 4 decimal places, but we don't like the 4 ugly zeroes, so if the number ends in zeroes, let it have only 2" - she said in the most innocent-like tone ever known to mankind. How easy I mumbled and accepted the task. As she was leaving she added - "oo almost forgot, we also would like it if all the data fields for the price that are shown in the tables also are formatted that way". As I was watching her better side, while she was getting reunited with her QA tribe, I got shivers down the spine. I had a bad feeling about that one, but I wasn't sure why yet. Suddenly as I was getting up to get a cup of coffe, it dawned on me - "this poor excuse for a project is using jqGrid for displaying the data". To wrap things up - I got a quadruple espresso with a shot of Jacky, developers best friend in a time of need, and came up with this piece of art. Enjoy :)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
O | O | O
-----------
O | O | O
-----------
O | O | O
*/
package tictactoe;
import java.util.Scanner;
public class TicTacToe {
/**
* @param args the command line arguments
* @throws java.lang.InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
Scanner input = new Scanner(System.in);
String a1 = "1";
String a2 = "2";
String a3 = "3";
String a4 = "4";
String a5 = "5";
String a6 = "6";
String a7 = "7";
String a8 = "8";
String a9 = "9";
int inO;
int inX = 0;
boolean winner = false;
PrintBoard(a1,a2,a3,a4,a5,a6,a7,a8,a9);
System.out.printf("How to play - wait for your turn and when it comes write the number of the field that you want to draw in (from 1 to 9)\n");
System.out.printf("Player O's turn: ");
inO = input.nextInt();
while (true) {
switch (inO) {
case 1:
if (a1 == "1") {
a1 = "O";
}
break;
case 2:
if (a2 == "2") {
a2 = "O";
}
break;
case 3:
if (a3 == "3") {
a3 = "O";
}
break;
case 4:
if (a4 == "4") {
a4 = "O";
}
break;
case 5:
if (a5 == "5") {
a5 = "O";
}
break;
case 6:
if (a6 == "6") {
a6 = "O";
}
break;
case 7:
if (a7 == "7") {
a7 = "O";
}
break;
case 8:
if (a8 == "8") {
a8 = "O";
}
break;
case 9:
if (a9 == "9") {
a9 = "O";
}
break;
default:
System.out.printf("An error occured. Please accept it politely and restart the game.");
break;
}
System.out.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
if (null != Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9))switch (Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9)) {
case "NONE":
if (a1 != "1" && a2 != "2" && a3 != "3" && a4 != "4" && a5 != "5" && a6 != "6" && a7 != "7" && a8 != "8" && a9 != "9") {
winner = true;
System.out.println("DRAW!");
Thread.sleep(3000);
break;
} else {
PrintBoard(a1,a2,a3,a4,a5,a6,a7,a8,a9);
System.out.printf("Player X's turn: ");
inX = input.nextInt();
break;
}
case "X":
winner = true;
System.out.println("X HAS WON!!!");
Thread.sleep(3000);
break;
case "O":
winner = true;
System.out.printf("O HAS WON!!!");
Thread.sleep(3000);
break;
default:
break;
}
if (winner) {
break;
}
switch (inX) {
case 1:
if (a1 == "1") {
a1 = "X";
}
break;
case 2:
if (a2 == "2") {
a2 = "X";
}
break;
case 3:
if (a3 == "3") {
a3 = "X";
}
break;
case 4:
if (a4 == "4") {
a4 = "X";
}
break;
case 5:
if (a5 == "5") {
a5 = "X";
}
break;
case 6:
if (a6 == "6") {
a6 = "X";
}
break;
case 7:
if (a7 == "7") {
a7 = "X";
}
break;
case 8:
if (a8 == "8") {
a8 = "X";
}
break;
case 9:
if (a9 == "9") {
a9 = "X";
}
break;
default:
System.out.printf("An error occured. Please accept it politely and restart the game.");
break;
}
System.out.printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
if (null != Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9))switch (Winners(a1,a2,a3,a4,a5,a6,a7,a8,a9)) {
case "NONE":
if (a1 != "1" && a2 != "2" && a3 != "3" && a4 != "4" && a5 != "5" && a6 != "6" && a7 != "7" && a8 != "8" && a9 != "9") {
winner = true;
System.out.println("DRAW!");
Thread.sleep(3000);
break;
} else {
PrintBoard(a1,a2,a3,a4,a5,a6,a7,a8,a9);
System.out.printf("Player O's turn: ");
inO = input.nextInt();
break;
}
case "X":
winner = true;
System.out.println("X HAS WON!!!");
Thread.sleep(3000);
break;
case "O":
winner = true;
System.out.println("O HAS WON!!!");
Thread.sleep(3000);
break;
default:
break;
}
if (winner) {
break;
}
}
}
public static void PrintBoard(String f1, String f2, String f3, String f4, String f5, String f6, String f7, String f8, String f9) {
System.out.printf(" %s | %s | %s \n",f1,f2,f3);
System.out.printf(" ----------- \n");
System.out.printf(" %s | %s | %s \n",f4,f5,f6);
System.out.printf(" ----------- \n");
System.out.printf(" %s | %s | %s \n",f7,f8,f9);
System.out.printf(" \n");
}
public static String Winners(String f1, String f2, String f3, String f4, String f5, String f6, String f7, String f8, String f9) {
if (f1 == f2 && f2 == f3 && f3 == "O") {
return "O";
} else if (f4 == f5 && f5 == f6 && f6 == "O") {
return "O";
} else if (f7 == f8 && f8 == f9 && f9 == "O") {
return "O";
} else if (f1 == f4 && f4 == f7 && f7 == "O") {
return "O";
} else if (f2 == f5 && f5 == f8 && f8 == "O") {
return "O";
} else if (f3 == f6 && f6 == f9 && f9 == "O") {
return "O";
} else if (f1 == f5 && f5 == f9 && f9 == "O") {
return "O";
} else if (f3 == f5 && f5 == f7 && f7 == "O") {
return "O";
} else if (f1 == f2 && f2 == f3 && f3 == "X") {
return "X";
} else if (f4 == f5 && f5 == f6 && f6 == "X") {
return "X";
} else if (f7 == f8 && f8 == f9 && f9 == "X") {
return "X";
} else if (f1 == f4 && f4 == f7 && f7 == "X") {
return "X";
} else if (f2 == f5 && f5 == f8 && f8 == "X") {
return "X";
} else if (f3 == f6 && f6 == f9 && f9 == "X") {
return "X";
} else if (f1 == f5 && f5 == f9 && f9 == "X") {
return "X";
} else if (f3 == f5 && f5 == f7 && f7 == "X") {
return "X";
} else {
return "NONE";
}
}
}
There are so many problems with this...
public boolean logout(String token)
{
LogedUser user = logedUsers.remove(token);
return (user != null) ? true : false;
}
var validAccountData = account.email != nil
validAccountData = account.firstName != nil
validAccountData = account.lastName != nil
if validAccountData {
return account
}
return nil
Proper validation
<?php
$now = time();
while ($now + 10 > time()) {
// Just chill...smoke a blunt
}
echo "Done.\n";
const errorHandler = () => {
throw new Error();
};
private boolean check_if_valid_login(Login login) {
boolean validLogin = false;
if (login.isValid(login)) {
validLogin = true;
}
if (!(login.isValid(login) == true)) {
validLogin = false;
}
return validLogin ? true : false;
}
Double value = item.getPrice() * loyaltyPointMultiplier;
String[] s = String.split(value.toString(), "\\.");
points = Integer.parseInt(s[0]);
if(Integer.parseInt(s[1]) > 0) {
points++;
}
return points;
Want to round up? Math.ceil() uses too little memory! Use this instead!
@Override
public void afterTextChanged(Editable s) {
switch (paymentType) {
case 0:
if (s.length() == 9) etPaymentAmount.requestFocus();
break;
case 1:
if (s.length() == 9) etPaymentAmount.requestFocus();
break;
}
}
$gallery = \common\models\UtVideogallery::find()->select(['ut_videogallery.VideogalleryID',
'ut_videogallery.Name_rus','ut_videogallery.TournamentID','ut_videogallery.MatchID', 'Slug',
'ut_videogallery.Date','COUNT(ut_video_to_gallery.VideoToGalleryID) count','ut_matches_videos.Data',
'm1.Data DataP'])
->leftJoin('ut_video_to_gallery','ut_video_to_gallery.VideogalleryID=ut_videogallery.VideogalleryID')
->leftJoin('ut_matches_videos','ut_matches_videos.VideoID=ut_video_to_gallery.VideoID')
->leftJoin('ut_matches_videos m1','m1.VideoID=ut_videogallery.PreviewID')
->where(['ut_videogallery.Active'=>1])
//->andWhere(['TournamentID'=>$list['selected']])
->groupBy('ut_videogallery.VideogalleryID')
->orderBy('ut_videogallery.Date DESC')
->limit(self::$countPerPage)
->asArray()->all();
foreach ($gallery as $key => $value) {
if($value['count']==0) unset($gallery[$key]);
}
foreach($gallery as $k=>$v){
if(isset($v['Data']))
$v['Data'] = str_replace('http:','https:',$v['Data']);
if(isset($v['DataP']))
$v['DataP'] = str_replace('http:','https:',$v['DataP']);
$gallery[$k]=$v;
}
$galleryCount = \common\models\UtVideogallery::find()->select(['ut_videogallery.VideogalleryID',
'ut_videogallery.Name_rus','ut_videogallery.TournamentID','ut_videogallery.MatchID',
'ut_videogallery.Date','COUNT(ut_video_to_gallery.VideoToGalleryID) count','ut_matches_videos.Data'])
->leftJoin('ut_video_to_gallery','ut_video_to_gallery.VideogalleryID=ut_videogallery.VideogalleryID')
->leftJoin('ut_matches_videos','ut_matches_videos.VideoID=ut_video_to_gallery.VideoID')
->leftJoin('ut_matches_videos m1','m1.VideoID=ut_videogallery.PreviewID')
->where(['ut_videogallery.Active'=>1])
//->andWhere(['TournamentID'=>$list['selected']])
->groupBy('ut_videogallery.VideogalleryID')
->orderBy('ut_videogallery.Date DESC')
->asArray()->all();
foreach ($galleryCount as $key => $value) {
if($value['count']==0) unset($galleryCount[$key]);
}
$pagination = new \yii\data\Pagination(
[
'totalCount' => count($galleryCount),
'pageSize' => self::$countPerPage,
]);
Picasso of PHP
try {
$order->addItem($item);
} catch (Exception $ex) {
throw $ex;
}