This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PrintTask { | |
| public static final String RESULT_SUCCESS = "SUCCESS_PRINT"; | |
| public static final String RESULT_FAILURE = "FAILURE_PRINT"; | |
| public static final String RESULT_TIMEOUT = "TIMEOUT_PRINT"; | |
| public static final String RESULT_NOTHING = "NOTHING_RESULT"; | |
| private String result = RESULT_NOTHING; | |
| public void getResult() throws PrintingException { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void handlePrinting(String text) { | |
| try { | |
| printText(text); | |
| } catch (PrintingException e) { | |
| // handle the exception and decide what to do | |
| // retry or show an error message and ... | |
| return; | |
| } | |
| // successful printing and ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public synchronized void printText(String text) throws PrintingException { | |
| PrintingListener printingListener = new PrintingListener() { | |
| @Override | |
| public void onSuccess(SuccessResult successResult) { | |
| } | |
| @Override | |
| public void onFailure(FailureResult failureResult) { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public synchronized void printText(String text) throws PrintingException { | |
| // communication with printer using API here | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getIntOr0 :: Maybe Int -> Int | |
| getIntOr0 = fromMaybe 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fromMaybe :: a -> Maybe a -> a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List | |
| import Data.Ord | |
| main :: IO () | |
| main = print $ desort [2,8,7,10,1,9,5,3,4,6] | |
| desort :: [Integer] -> [Integer] | |
| desort = reverse . sort -- better use: sortOn Data.Ord.Down |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| isPow2Even :: Integer -> Bool | |
| isPow2Even = even . pow2 --instead of: even $ pow2 a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| isPow2Even :: Integer -> Bool | |
| isPow2Even a = even $ pow2 a --or even (pow2 a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| main :: IO () | |
| main = print (pow2 3) -- or print $ pow2 3 |