⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path.java

📁 基于MPEG 7 标准,符合未来语义网架构,很值得参考
💻 JAVA
字号:
/*
 * This file is part of Caliph & Emir.
 *
 * Caliph & Emir is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Caliph & Emir is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Caliph & Emir; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Copyright statement:
 * --------------------
 * (c) 2002-2005 by Mathias Lux (mathias@juggle.at)
 * http://www.juggle.at, http://caliph-emir.sourceforge.net
 */
package at.lux.fotoretrieval.lucene;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * Date: 25.03.2005
 * Time: 23:42:58
 *
 * @author Mathias Lux, mathias@juggle.at
 */
public class Path implements Comparable {
    LinkedList<String> nodes;
    LinkedList<String> relations;
    int length = 0;

    public Path(String start) {
        nodes = new LinkedList<String>();
        relations = new LinkedList<String>();
        nodes.add(start);
    }

    public boolean addRelation(String relation, String target) {
        boolean added = false;
        if (!nodes.contains(target)) {
            relations.add(relation);
            nodes.add(target);
            added = true;
        }
        if (added) length++;
        return added;
    }

    public int getLength() {
        return length;
    }

    public LinkedList<String> getNodes() {
        return nodes;
    }

    public LinkedList<String> getRelations() {
        return relations;
    }

    public String getEndPoint() {
        return nodes.getLast();
    }

    public Path clone() {
        Path returnPath = new Path(nodes.get(0));
        int count = 0;
        for (Iterator<String> iterator = nodes.iterator(); iterator.hasNext();) {
            String s = iterator.next();
            if (count > 0) {
                returnPath.getNodes().add(s);
            }
            count++;
        }
        for (Iterator<String> iterator = relations.iterator(); iterator.hasNext();) {
            String s = iterator.next();
            returnPath.getRelations().add(s);
        }
        return returnPath;
    }

    /**
     * Writes out the available paths ...
     * @return
     */
    public String toString() {
        StringBuilder sw = new StringBuilder(64);
        sw.append('[');
        // if the first is smaller then do not change the order
        if (nodes.getFirst().compareTo(nodes.getLast()) < 0) {
            for (int i = 0; i < nodes.size(); i++) {
                sw.append(nodes.get(i));
                if (i < nodes.size() - 1) {
                    sw.append(' ');
                    sw.append(relations.get(i));
                    sw.append(' ');
                }
            }
        } else { // switch order of nodes ..
            for (int i = nodes.size() - 1; i >= 0; i--) {
                sw.append(nodes.get(i));
                if (i > 0) {
                    sw.append(' ');
                    sw.append(Relation.invertRelationType(relations.get(i - 1)));
                    sw.append(' ');
                }
            }
        }
        sw.append(']');
        return sw.toString();
    }

    public int compareTo(Object o) {
        if (o instanceof Path) return toString().compareTo(((Path) o).toString());
        else return 0;
    }

    public boolean isTheSamePath(Path p) {
        if (toString().equals(p.toString())) return true;
        else return false;
    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -