com.github.fritaly.graphml4j.datastructure.Edge.java Source code

Java tutorial

Introduction

Here is the source code for com.github.fritaly.graphml4j.datastructure.Edge.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 com.github.fritaly.graphml4j.datastructure;

import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public final class Edge {

    private final Node source, target;

    private final String id;

    private final Object data;

    Edge(String id, Node source, Node target, Object data) {
        // the associated data can be null
        Validate.notNull(id, "The given edge id is null");
        Validate.notNull(source, "The given source node is null");
        Validate.notNull(target, "The given target node is null");

        this.id = id;
        this.source = source;
        this.target = target;
        this.data = data;
    }

    public Object getData() {
        return data;
    }

    public boolean hasData() {
        return (data != null);
    }

    public String getId() {
        return id;
    }

    public Node getSource() {
        return source;
    }

    public Node getTarget() {
        return target;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", id).append("source", source)
                .append("target", target).toString();
    }
}