Java AtomicInteger getPrefixedTerm(String namespace, String localName)

Here you can find the source of getPrefixedTerm(String namespace, String localName)

Description

get Prefixed Term

License

Apache License

Declaration

public static String getPrefixedTerm(String namespace, String localName) 

Method Source Code

//package com.java2s;
/**/*  ww w .jav a2  s . com*/
 * Copyright 2014-2015 Ontology Engineering Group, Universidad Polit?cnica de Madrid, Spain
 * <p/>
 * 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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.
 *
 * @author Nandana Mihindukulasooriya
 * @since 1.0.0
 */

import com.google.common.collect.Maps;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    private static AtomicInteger counter = new AtomicInteger();
    public static Map<String, String> nsMap = Maps.newHashMap();

    public static String getPrefixedTerm(String namespace, String localName) {

        String prefix = nsMap.get(namespace);

        if (prefix == null) {
            prefix = "ns" + counter.getAndIncrement();
            nsMap.put(namespace, prefix);
        }

        return String.format("%s:%s", prefix, localName);

    }

    public static String getPrefixedTerm(String uri) {

        int i = uri.lastIndexOf('#');
        if (i == -1) {
            i = uri.lastIndexOf('/');
        }
        if (i == -1) {
            //TODO handle other URIs, do we really have to?
            throw new IllegalStateException("Unable to extract local name from '" + uri + "'");
        }

        String ns = uri.substring(0, i + 1);
        String localName = uri.substring(i + 1, uri.length());

        return getPrefixedTerm(ns, localName);

    }
}

Related

  1. getNextCounter(AtomicInteger counter)
  2. getNextId()
  3. getNextTempQueueName()
  4. getPortOffset()
  5. getPrefix(final String namespace, final Map namespacesPrefixesMap)
  6. getQueryCounters()
  7. getRandom()
  8. getRandomTenantId()
  9. getReply()