Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
albertattard committed Feb 20, 2015
1 parent 6c0c4df commit 2b9f920
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
* limitations under the License.
* #L%
*/
package com.javacreed.examples.lang.part1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example1 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example1.class);

public static void main(final String[] args) {
final String a = "abcd";
final String b = "abcd";

Example1.LOGGER.debug("Same? {}", a == b);
}
}
package com.javacreed.examples.lang.part1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example1 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example1.class);

public static void main(final String[] args) {
final String a = "abcd";
final String b = "abcd";

Example1.LOGGER.debug("Same? {}", a == b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
* limitations under the License.
* #L%
*/
package com.javacreed.examples.lang.part1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example2 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example2.class);

public static void main(final String[] args) {
final String a = new String("abcd");
final String b = new String("abcd");

Example2.LOGGER.debug("Same? {}", a == b);
}
}
package com.javacreed.examples.lang.part1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example2 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example2.class);

public static void main(final String[] args) {
final String a = new String("abcd");
final String b = new String("abcd");

Example2.LOGGER.debug("Same? {}", a == b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
* limitations under the License.
* #L%
*/
package com.javacreed.examples.lang.part2;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example3 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example3.class);

public static void main(final String[] args) {
final String a = new String("abcd");
final String b = new String("abcd");

Example3.LOGGER.debug("Same? {}", a == b);
Example3.LOGGER.debug("Same intern? {}", a.intern() == b.intern());
}
}
package com.javacreed.examples.lang.part2;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example3 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example3.class);

public static void main(final String[] args) {
final String a = new String("abcd");
final String b = new String("abcd");

Example3.LOGGER.debug("Same? {}", a == b);
Example3.LOGGER.debug("Same intern? {}", a.intern() == b.intern());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
* limitations under the License.
* #L%
*/
package com.javacreed.examples.lang.part3;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example4 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example4.class);

public static void main(final String[] args) {
final int limit = 50000000;
final List<String> data = new ArrayList<>(limit);
for (int i = 0; i < limit; i++) {
data.add(new String("Sphinx of black quartz, judge my vow"));
}

Example4.LOGGER.debug("Done");
}
}
package com.javacreed.examples.lang.part3;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example4 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example4.class);

public static void main(final String[] args) {
final int limit = 50000000;
final List<String> data = new ArrayList<>(limit);
for (int i = 0; i < limit; i++) {
data.add(new String("Sphinx of black quartz, judge my vow"));
}

Example4.LOGGER.debug("Done");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
* limitations under the License.
* #L%
*/
package com.javacreed.examples.lang.part3;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example5 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example5.class);

public static void main(final String[] args) {
final int limit = 50000000;
final List<String> data = new ArrayList<>(limit);
for (int i = 0; i < limit; i++) {
data.add(new String("Sphinx of black quartz, judge my vow").intern());
}

Example5.LOGGER.debug("Done");
}
}
package com.javacreed.examples.lang.part3;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example5 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example5.class);

public static void main(final String[] args) {
final int limit = 50000000;
final List<String> data = new ArrayList<>(limit);
for (int i = 0; i < limit; i++) {
data.add(new String("Sphinx of black quartz, judge my vow").intern());
}

Example5.LOGGER.debug("Done");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@
* limitations under the License.
* #L%
*/
package com.javacreed.examples.lang.part3;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example6 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example6.class);

public static void main(final String[] args) {
final StringPool cache = new StringPool();

final int limit = 50000000;
final List<String> data = new ArrayList<>(limit);
for (int i = 0; i < limit; i++) {
data.add(cache.get(new String("Sphinx of black quartz, judge my vow")));
}

Example6.LOGGER.debug("Done");
}
}
package com.javacreed.examples.lang.part3;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Example6 {

private static final Logger LOGGER = LoggerFactory.getLogger(Example6.class);

public static void main(final String[] args) {
final StringPool cache = new StringPool();

final int limit = 50000000;
final List<String> data = new ArrayList<>(limit);
for (int i = 0; i < limit; i++) {
data.add(cache.get(new String("Sphinx of black quartz, judge my vow")));
}

Example6.LOGGER.debug("Done");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@
* limitations under the License.
* #L%
*/
package com.javacreed.examples.lang.part3;

import java.util.HashMap;
import java.util.Map;

public class StringPool {

private final Map<String, String> cache = new HashMap<>();

public String get(final String value) {
String cachedValue = cache.get(value);
if (cachedValue == null) {
cachedValue = value;
cache.put(value, value);
}
return cachedValue;
}
}
package com.javacreed.examples.lang.part3;

import java.util.HashMap;
import java.util.Map;

import net.jcip.annotations.NotThreadSafe;

@NotThreadSafe
public class StringPool {

private final Map<String, String> cache = new HashMap<>();

public String get(final String value) {
String cachedValue = cache.get(value);
if (cachedValue == null) {
cachedValue = value;
cache.put(value, value);
}
return cachedValue;
}
}

0 comments on commit 2b9f920

Please sign in to comment.