{"id":476,"date":"2015-12-31T19:38:04","date_gmt":"2015-12-31T17:38:04","guid":{"rendered":"http:\/\/kra.lc\/blog\/?p=476"},"modified":"2016-01-04T22:14:40","modified_gmt":"2016-01-04T20:14:40","slug":"java-characters-class","status":"publish","type":"post","link":"https:\/\/kra.lc\/blog\/2015\/12\/java-characters-class\/","title":{"rendered":"Java Characters class"},"content":{"rendered":"<p>This is going to be my last post in <em>2015<\/em>, as New Year&#8217;s Eve quickly approaches. I also have to hurry up a little, as the raclette grill is already heating up. <strong>*jummy*<\/strong> ;-)<\/p>\n<p>Time for a little year-end review. This year has again been very successful for me. After finishing my Master&#8217;s Degree in Computer Science end of last year, I began working as a research associate at the University of Applied Sciences in Mannheim next to my main job. We made great progress and were able to release the <a href=\"http:\/\/www.gcat.bio\/\" target=\"_blank\">Genetic Code Anylsis Toolkit<\/a> just recently. Some of the code snippets of the past few days, have been part of the work done for the Genetic Code Analysis Toolkit. Other than that I mainly focussed on my primary workplace, where I was working hard towards a first release of the <a href=\"http:\/\/sapsupport.info\/onesupport\/onesupport-launchpad\/\" target=\"_blank\">SAP ONE Support Launchpad<\/a>. A lot more happened, but as our little <a href=\"https:\/\/kra.lc\/blog\/2015\/12\/java-thread-local-servlet-cookie-filter\/\">marathon<\/a> soon comes to an end, let&#8217;s get to the point of this post.<\/p>\n<p>There are a lot of <em>helper classes<\/em> in Java. Even in the core libraries you&#8217;ll find plenty of them. Classes such as <code>Arrays<\/code>, or the <code>Collections<\/code> class dealing with lists, sets and maps. One helper class I was missing out on, is a <strong><code>Characters<\/code> class<\/strong>!<\/p>\n<p><!--more--><\/p>\n<p>I often face the problem to have a <code>String<\/code> left or right trimmed for a certain character or a certain class of characters (e.g. whitespaces or new-line characters). Also other character based operations, such as finding the first occurrence of a character, or condensing multiple subsequent occurrences of a character into one, are commonly required. All of this can be achieved using the existing <code>String<\/code> methods and regular expressions, but for each character it&#8217;s again the same patterns to use and the same methods to call. Therefore I thought, why not creating a <code>Characters<\/code> helper class in Java, dealing with all of this?<\/p>\n<p>Said and done. Please find my neat little implementation of a <code>Characters<\/code> helper class on GitHub at <a href=\"https:\/\/github.com\/kristian\/characters\" target=\"_blank\"><strong>https:\/\/github.com\/kristian\/characters<\/strong><\/a>. With this dealing with characters becomes a walk in the park:<\/p>\n<pre class=\"syntax java\">\r\nCharacters.valueOf(&#039;X&#039;).trim(&#039;XXXHello WorldXXX&#039;);\r\nCharacters.WHITESPACE.condense(&#039;Foo  Bar  Baz&#039;);\r\n<\/pre>\n<p>I hope you had a great year 2015, best wishes for the New Year! <strong>See you in 2016.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is going to be my last post in 2015, as New Year&#8217;s Eve quickly approaches. I also have to hurry up a little, as the raclette grill is already heating up. *jummy* ;-) Time for a little year-end review. This year has again been very successful for me. After finishing my Master&#8217;s Degree in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[209,207,208,217,221,219,205,5,220,211,212,213,218,214,215,216,206,210],"class_list":["post-476","post","type-post","status-publish","format-standard","hentry","category-release","tag-char","tag-character","tag-chars","tag-condense","tag-find","tag-first-occurrence","tag-helper-class","tag-java","tag-last-occurrence","tag-left-trim","tag-lefttrim","tag-ltrim","tag-replace","tag-right-trim","tag-righttrim","tag-rtrim","tag-string","tag-trim"],"_links":{"self":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/comments?post=476"}],"version-history":[{"count":32,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts\/476\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts\/476\/revisions\/508"}],"wp:attachment":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/media?parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/categories?post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/tags?post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}