org.sitemap4j.sitemapindex.SiteMapLocation.java Source code

Java tutorial

Introduction

Here is the source code for org.sitemap4j.sitemapindex.SiteMapLocation.java

Source

/*
 * Copyright (C) 2012 Nicolas A. Brard-Nault
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sitemap4j.sitemapindex;

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

import java.net.URI;

import org.joda.time.DateTime;
import org.sitemap4j.value.AbstractValueObject;

import com.google.common.base.Optional;

public class SiteMapLocation extends AbstractValueObject {
    final private URI location;
    final private Optional<DateTime> lastModificationTime;

    public SiteMapLocation(final URI location, final DateTime lastModificationTime) {
        checkNotNull(location);

        this.location = location;

        if (lastModificationTime != null) {
            this.lastModificationTime = Optional.of(lastModificationTime);
        } else {
            this.lastModificationTime = Optional.absent();
        }
    }

    public SiteMapLocation(final URI location) {
        this(location, null);
    }

    public URI getLocationUri() {
        return location;
    }

    public boolean hasLastModificationTime() {
        return lastModificationTime.isPresent();
    }

    public DateTime getLastModificationTime() {
        return lastModificationTime.get();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder().append("(Site map location, URI: ").append(location);

        if (hasLastModificationTime()) {
            builder.append(" , last modification: ").append(lastModificationTime);
        }

        return builder.append(")").toString();
    }

    static public SiteMapLocation create(final URI location, final DateTime lastModificationTime) {
        return new SiteMapLocation(location, lastModificationTime);
    }

    public static SiteMapLocation create(final URI location) {
        return new SiteMapLocation(location);
    }
}