org.antlr.v4.testgen.LinesStringMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of runtime-testsuite Show documentation
Show all versions of runtime-testsuite Show documentation
A collection of tests for ANTLR 4 Runtime libraries.
/*
* Copyright (c) 2012 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD-3-Clause license that
* can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.testgen;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
/**
*
* @author Sam Harwell
*/
public class LinesStringMap extends AbstractMap {
@Override
public Object get(Object key) {
if (key instanceof String) {
String str = (String)key;
if (str.isEmpty()) {
return Collections.singletonList(str);
}
ArrayList result = new ArrayList();
int startIndex = 0;
while (startIndex < str.length()) {
int endIndex = str.indexOf('\n', startIndex);
if (endIndex < 0) {
result.add(str.substring(startIndex));
break;
}
result.add(str.substring(startIndex, endIndex + 1));
startIndex = endIndex + 1;
}
return result;
}
return super.get(key);
}
@Override
public boolean containsKey(Object key) {
return key instanceof String;
}
@Override
public Set> entrySet() {
return Collections.emptySet();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy