From: <lh...@us...> - 2008-09-08 11:37:44
|
Revision: 157 http://tinytim.svn.sourceforge.net/tinytim/?rev=157&view=rev Author: lheuer Date: 2008-09-08 11:37:54 +0000 (Mon, 08 Sep 2008) Log Message: ----------- * Simplified Literal factory methods * DatatypeAwareConstruct uses createDecimal / createInteger directly Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-09-05 12:01:41 UTC (rev 156) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-09-08 11:37:54 UTC (rev 157) @@ -92,7 +92,7 @@ */ public void setValue(BigDecimal value) { Check.valueNotNull(this, value); - setLiteral(Literal.create(value)); + setLiteral(Literal.createDecimal(value)); } /* (non-Javadoc) @@ -100,7 +100,7 @@ */ public void setValue(BigInteger value) { Check.valueNotNull(this, value); - setLiteral(Literal.create(value)); + setLiteral(Literal.createInteger(value)); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-09-05 12:01:41 UTC (rev 156) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-09-08 11:37:54 UTC (rev 157) @@ -94,6 +94,15 @@ } + private static synchronized <L extends ILiteral> L _registerIfAbsent(final WeakObjectRegistry<L> registry, final L lit) { + final L existing = registry.get(lit); + if (existing != null) { + return existing; + } + registry.add(lit); + return lit; + } + public static synchronized ILiteral create(final String value, final Locator datatype) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); @@ -113,33 +122,13 @@ if (XSD.INTEGER.equals(datatype)) { return createInteger(value); } - ILiteral literal = new Literal(value, datatype); - ILiteral existing = _OTHERS.get(literal); - if (existing != null) { - return existing; - } - _OTHERS.add(literal); - return literal; + return _registerIfAbsent(_OTHERS, new Literal(value, datatype)); } public static synchronized ILiteral create(String value) { - ILiteral literal = new Literal(value, XSD.STRING); - ILiteral existing = _STRINGS.get(literal); - if (existing != null) { - return existing; - } - _STRINGS.add(literal); - return literal; + return _registerIfAbsent(_STRINGS, new Literal(value, XSD.STRING)); } - public static ILiteral create(BigDecimal value) { - return createDecimal(value); - } - - public static ILiteral create(BigInteger value) { - return createInteger(value); - } - public static ILiteral create(float value) { return create(value, XSD.FLOAT); } @@ -171,65 +160,35 @@ if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - IRI iri = new IRI(value); - IRI existing = _IRIS.get(iri); - if (existing != null) { - return existing; - } - _IRIS.add(iri); - return iri; + return _registerIfAbsent(_IRIS, new IRI(value)); } public static synchronized ILiteral createDecimal(String value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - ILiteral lit = new DecimalLiteral(value); - ILiteral existing = _OTHERS.get(lit); - if (existing != null) { - return existing; - } - _OTHERS.add(lit); - return lit; + return _registerIfAbsent(_OTHERS, new DecimalLiteral(value)); } public static synchronized ILiteral createDecimal(BigDecimal value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - ILiteral lit = new DecimalLiteral(value); - ILiteral existing = _OTHERS.get(lit); - if (existing != null) { - return existing; - } - _OTHERS.add(lit); - return lit; + return _registerIfAbsent(_OTHERS, new DecimalLiteral(value)); } public static synchronized ILiteral createInteger(String value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - ILiteral lit = new IntegerLiteral(value); - ILiteral existing = _OTHERS.get(lit); - if (existing != null) { - return existing; - } - _OTHERS.add(lit); - return lit; + return _registerIfAbsent(_OTHERS, new IntegerLiteral(value)); } public static synchronized ILiteral createInteger(BigInteger value) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - ILiteral lit = new IntegerLiteral(value); - ILiteral existing = _OTHERS.get(lit); - if (existing != null) { - return existing; - } - _OTHERS.add(lit); - return lit; + return _registerIfAbsent(_OTHERS, new IntegerLiteral(value)); } public BigDecimal decimalValue() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |