All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cognitect.transit.impl.SymbolImpl Maven / Gradle / Ivy

Go to download

Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from Java.

There is a newer version: 1.0.371
Show newest version
// All rights reserved.
// Copyright (c) Cognitect, Inc.

package com.cognitect.transit.impl;

import com.cognitect.transit.Named;
import com.cognitect.transit.Symbol;

public class SymbolImpl implements Symbol, Comparable, Named {

    final String ns;
    final String name;
    String _str;

    public SymbolImpl(String nsname) {
        int i = nsname.indexOf('/');
        if(i == -1 || nsname.equals("/")) {
            ns = null;
            name = nsname.intern();
        } else {
            ns = nsname.substring(0, i);
            name = nsname.substring(i + 1);
        }
    }

    @Override
    public String toString() {
        if(_str == null){
            if(ns != null)
                _str = (ns + "/" + name).intern();
            else
                _str = name;
        }
        return _str;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getNamespace() {
        return ns;
    }

    @Override
    public String getValue() { return toString(); }

    @Override
    public boolean equals(Object o) {
        if(o == this)
            return true;

        if(o instanceof SymbolImpl && ((SymbolImpl)o).getValue().equals(getValue()))
            return true;
        else
            return false;
    }

    @Override
    public int hashCode() {
        return 19 * getValue().hashCode();
    }

    @Override
    public int compareTo(Symbol symbol) {
        return getValue().compareTo(((SymbolImpl)symbol).getValue());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy