org.apache.commons.collections.bidimap.TreeBidiMap Java Examples

The following examples show how to use org.apache.commons.collections.bidimap.TreeBidiMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MuleSchemaProvider.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
private Map<String, String> parseSpringSchemas(String springSchemasContent) {
    BidiMap schemaUrlsAndFileNames = new TreeBidiMap();
    for (String line : springSchemasContent.split("\n")) {
        if (line != null && !line.startsWith("#") && line.contains("=")) {
            String url = line.substring(0, line.indexOf("=")).replaceAll("\\\\", "");
            String fileName = line.substring(line.indexOf("=") + 1);

            if (schemaUrlsAndFileNames.containsValue(fileName)) {
                if (url.contains("current")) { //Avoid duplicates and prefer URL with "current"
                    schemaUrlsAndFileNames.removeValue(fileName);
                    schemaUrlsAndFileNames.put(url, fileName);
                }
            } else {
                schemaUrlsAndFileNames.put(url, fileName);
            }
        }
    }
    return schemaUrlsAndFileNames;
}
 
Example #2
Source File: CommonsTest.java    From java-study with Apache License 2.0 5 votes vote down vote up
/**
 * 双向Map
 * 唯一的key和map,可以通过键或值来操作
 * 比如删除、查询等
 */
private static void bidimapTest(){
	BidiMap map=new TreeBidiMap();
	map.put(1, "a");
	map.put(2, "b");
	map.put(3, "c");
	System.out.println("map:"+map);	//map:{1=a, 2=b, 3=c}
	System.out.println("map.get():"+map.get(2)); //map.get():b
	System.out.println("map.getKey():"+map.getKey("a")); //map.getKey():1
	System.out.println("map.removeValue():"+map.removeValue("c")); //map.removeValue():3
	System.out.println("map:"+map);	//map:{1=a, 2=b}
}
 
Example #3
Source File: AnnotationSpans.java    From argument-reasoning-comprehension-task with Apache License 2.0 4 votes vote down vote up
public static AnnotationSpans extractAnnotationSpans(JCas jCas)
{
    BidiMap sentenceBeginIndexToCharacterIndex = new TreeBidiMap();
    BidiMap sentenceEndIndexToCharacterIndex = new TreeBidiMap();

    List<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class));
    for (int i = 0; i < sentences.size(); i++) {
        Sentence sentence = sentences.get(i);

        sentenceBeginIndexToCharacterIndex.put(i, sentence.getBegin());
        sentenceEndIndexToCharacterIndex.put(i, sentence.getEnd());
    }

    //        System.out.println(sentenceBeginIndexToCharacterIndex);
    //        System.out.println(sentenceEndIndexToCharacterIndex);

    AnnotationSpans annotationSpans = new AnnotationSpans(
            sentenceBeginIndexToCharacterIndex.size());

    Collection<ArgumentComponent> components = JCasUtil.select(jCas, ArgumentComponent.class);

    for (ArgumentComponent component : components) {
        if (!ArgumentUnitUtils.isImplicit(component)) {
            //            System.out.println("=====");
            //            System.out.println(component.getCoveredText());
            int relativeOffset = (int) sentenceBeginIndexToCharacterIndex
                    .getKey(component.getBegin());

            int endingSentenceIndex = (int) sentenceEndIndexToCharacterIndex
                    .getKey(component.getEnd());

            int length = endingSentenceIndex - relativeOffset + 1;

            String type = component.getType().getShortName();

            SingleAnnotationSpan singleAnnotationSpan = new SingleAnnotationSpan(type,
                    relativeOffset, length);

            annotationSpans.getAnnotationSpans().add(singleAnnotationSpan);
        }
    }

    return annotationSpans;
}