Skip to content

Commit

Permalink
More edits for Sonar style compliance, added null checks where approp…
Browse files Browse the repository at this point in the history
…riate and more JavaDocs, removed unnecessary exceptions in throws clauses
  • Loading branch information
ajs6f committed Apr 20, 2013
1 parent 00b050d commit e6b0627
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 63 deletions.
33 changes: 17 additions & 16 deletions fcrepo-kernel/src/main/java/org/fcrepo/Datastream.java
Expand Up @@ -2,6 +2,7 @@
package org.fcrepo;

import static com.google.common.base.Joiner.on;
import static com.google.common.base.Preconditions.checkArgument;
import static com.yammer.metrics.MetricRegistry.name;
import static org.fcrepo.services.PathService.getDatastreamJcrNodePath;
import static org.fcrepo.services.RepositoryService.metrics;
Expand All @@ -24,10 +25,6 @@
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.ValueFormatException;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;

import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.utils.ContentDigest;
Expand All @@ -46,19 +43,23 @@
*/
public class Datastream extends JcrTools implements FedoraJcrTypes {

private final static Logger logger = getLogger(Datastream.class);
private static final Logger logger = getLogger(Datastream.class);

final static Histogram contentSizeHistogram = metrics.histogram(name(
static final Histogram contentSizeHistogram = metrics.histogram(name(
Datastream.class, "content-size"));

Node node;
private Node node;

/**
* The JCR node for this datastream
* @param n an existing JCR node
* @param n an existing {@link Node}
*/
public Datastream(final Node n) {
super(false); // turn off debug logging
// turn off debug logging
super(false);
if (node != null) {
logger.debug("Supporting a Fedora Datastream with null backing Node!");
}
node = n;
}

Expand All @@ -83,6 +84,11 @@ public Datastream(final Session session, final String pid, final String dsId)
public Datastream(final Session session, final String dsPath)
throws RepositoryException {
super(false);
checkArgument(session != null,
"null cannot create a Fedora Datastream!");
checkArgument(dsPath != null,
"A Fedora Datastream cannot be created at null path!");

node = findOrCreateNode(session, dsPath, NT_FILE);
if (node.isNew()) {
node.addMixin(FEDORA_DATASTREAM);
Expand Down Expand Up @@ -123,6 +129,7 @@ public InputStream getContent() throws RepositoryException {
public void setContent(final InputStream content,
final String checksumType, final String checksum)
throws RepositoryException, InvalidChecksumException {

final Node contentNode =
findOrCreateChild(node, JCR_CONTENT, NT_RESOURCE);

Expand Down Expand Up @@ -301,15 +308,9 @@ public String getOwnerId() throws RepositoryException {
/**
* Set an administrative label for this object
* @param label
* @throws ValueFormatException
* @throws VersionException
* @throws LockException
* @throws ConstraintViolationException
* @throws RepositoryException
*/
public void setLabel(final String label) throws ValueFormatException,
VersionException, LockException, ConstraintViolationException,
RepositoryException {
public void setLabel(final String label) throws RepositoryException {
node.setProperty(DC_TITLE, label);
}

Expand Down
13 changes: 12 additions & 1 deletion fcrepo-kernel/src/main/java/org/fcrepo/FedoraObject.java
Expand Up @@ -2,6 +2,7 @@
package org.fcrepo;

import static com.google.common.base.Joiner.on;
import static com.google.common.base.Preconditions.checkArgument;
import static com.yammer.metrics.MetricRegistry.name;
import static org.fcrepo.services.RepositoryService.metrics;
import static org.fcrepo.services.ServiceHelpers.getObjectSize;
Expand All @@ -10,6 +11,7 @@
import static org.fcrepo.utils.FedoraTypesUtils.nodetype2name;
import static org.fcrepo.utils.FedoraTypesUtils.value2string;
import static org.modeshape.jcr.api.JcrConstants.NT_FOLDER;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Calendar;
import java.util.Collection;
Expand All @@ -21,6 +23,7 @@

import org.fcrepo.utils.FedoraJcrTypes;
import org.modeshape.jcr.api.JcrTools;
import org.slf4j.Logger;

import com.yammer.metrics.Timer;

Expand All @@ -33,10 +36,12 @@
*/
public class FedoraObject extends JcrTools implements FedoraJcrTypes {

static final Logger logger = getLogger(FedoraObject.class);

/**
* Timer for the time to create/initialize a FedoraObject
*/
final static Timer timer = metrics.timer(name(FedoraObject.class,
static final Timer timer = metrics.timer(name(FedoraObject.class,
"FedoraObject"));

private Node node;
Expand All @@ -46,6 +51,9 @@ public class FedoraObject extends JcrTools implements FedoraJcrTypes {
* @param n an existing JCR node to treat as an fcrepo object
*/
public FedoraObject(final Node n) {
if (node != null) {
logger.debug("Supporting a FedoraObject with null backing Node!");
}
node = n;
}

Expand All @@ -58,6 +66,9 @@ public FedoraObject(final Node n) {
public FedoraObject(final Session session, final String path)
throws RepositoryException {

checkArgument(session != null, "null cannot create a Fedora object!");
checkArgument(path != null, "Cannot create a Fedora object at null!");

final Timer.Context context = timer.time();

try {
Expand Down
Expand Up @@ -2,8 +2,9 @@
package org.fcrepo.exception;

/**
* Exception when the calculated digest does not match the stored digest
* Exception thrown when the calculated digest does not match the stored digest
*/

public class InvalidChecksumException extends Exception {

private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/
public class UUIDPidMinter extends BasePidMinter {

final static Timer timer = metrics.timer(name(UUIDPidMinter.class, "mint"));
static final Timer timer = metrics.timer(name(UUIDPidMinter.class, "mint"));

/**
* Mint a unique identifier as a UUID
Expand Down
@@ -1,6 +1,8 @@

package org.fcrepo.observer;

import static com.google.common.base.Preconditions.checkArgument;

import java.util.Map;

import javax.jcr.RepositoryException;
Expand All @@ -19,6 +21,7 @@ public class FedoraEvent implements Event {
private Event e;

public FedoraEvent(final Event e) {
checkArgument(e != null, "null cannot support a FedoraEvent!");
this.e = e;
}

Expand Down
Expand Up @@ -14,7 +14,7 @@ public class NOOPFilter implements EventFilter {
/**
* A no-op filter that passes every Event through.
* @param event
* @return
* @return true under all circumstances
*/
@Override
public boolean apply(final Event event) {
Expand Down
@@ -1,6 +1,7 @@

package org.fcrepo.services.functions;

import static com.google.common.base.Preconditions.checkArgument;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;

Expand All @@ -16,6 +17,7 @@ public class GetBinaryKey implements Function<Node, BinaryKey> {

@Override
public BinaryKey apply(final Node input) {
checkArgument(input != null, "null cannot have a Binarykey!");
try {
return ((BinaryValue) input.getNode(JCR_CONTENT).getProperty(
JCR_DATA).getBinary()).getKey();
Expand Down
@@ -1,6 +1,8 @@

package org.fcrepo.services.functions;

import static com.google.common.base.Preconditions.checkArgument;

import javax.jcr.Repository;

import org.modeshape.jcr.JcrRepository;
Expand All @@ -16,6 +18,7 @@ public class GetBinaryStore implements Function<Repository, BinaryStore> {
*/
@Override
public BinaryStore apply(final Repository input) {
checkArgument(input != null, "null cannot have a BinaryStore!");
try {
return ((JcrRepository) input).getConfiguration()
.getBinaryStorage().getBinaryStore();
Expand Down
@@ -1,6 +1,8 @@

package org.fcrepo.services.functions;

import static com.google.common.base.Preconditions.checkArgument;

import org.infinispan.Cache;
import org.infinispan.loaders.CacheLoaderManager;
import org.infinispan.loaders.CacheStore;
Expand All @@ -11,6 +13,7 @@ public class GetCacheStore implements Function<Cache<?, ?>, CacheStore> {

@Override
public CacheStore apply(final Cache<?, ?> input) {
checkArgument(input != null, "null cannot have a CacheStore!");
return input.getAdvancedCache().getComponentRegistry().getComponent(
CacheLoaderManager.class).getCacheStore();
}
Expand Down
Expand Up @@ -15,25 +15,22 @@
public class GetGoodFixityResults implements
Function<Collection<FixityResult>, Set<FixityResult>> {

private IsGoodFixity predicate = new IsGoodFixity();

public boolean isGood(final FixityResult input) {
return predicate.apply(input);
return isGoodFixity.apply(input);
}

@Override
public Set<FixityResult> apply(final Collection<FixityResult> input) {
return copyOf(filter(input, predicate));
return copyOf(filter(input, isGoodFixity));
}

static class IsGoodFixity implements Predicate<FixityResult> {

@Override
public boolean apply(final FixityResult input) {
return input.computedChecksum.equals(input.dsChecksum) &&
input.computedSize == input.dsSize;
}

}
static Predicate<FixityResult> isGoodFixity =
new Predicate<FixityResult>() {

@Override
public boolean apply(final FixityResult input) {
return input.computedChecksum.equals(input.dsChecksum) &&
input.computedSize == input.dsSize;
}
};
}

0 comments on commit e6b0627

Please sign in to comment.