use of java.util.SortedMap in project sonarqube by SonarSource.
the class SettingsMonitor method attributes.
@Override
public SortedMap<String, Object> attributes() {
PropertyDefinitions definitions = settings.getDefinitions();
ImmutableSortedMap.Builder<String, Object> builder = ImmutableSortedMap.naturalOrder();
for (Map.Entry<String, String> prop : settings.getProperties().entrySet()) {
String key = prop.getKey();
PropertyDefinition def = definitions.get(key);
if (def == null || def.type() != PropertyType.PASSWORD) {
builder.put(key, abbreviate(prop.getValue(), MAX_VALUE_LENGTH));
}
}
return builder.build();
}
use of java.util.SortedMap in project neo4j by neo4j.
the class NativeAllEntriesLabelScanReaderTest method assertRanges.
private static void assertRanges(AllEntriesLabelScanReader reader, Labels[] data) {
Iterator<NodeLabelRange> iterator = reader.iterator();
long highestRangeId = highestRangeId(data);
for (long rangeId = 0; rangeId <= highestRangeId; rangeId++) {
SortedMap<Long, List<Long>> /*labelIds*/
expected = rangeOf(data, rangeId);
if (expected != null) {
assertTrue("Was expecting range " + expected, iterator.hasNext());
NodeLabelRange range = iterator.next();
assertEquals(rangeId, range.id());
assertArrayEquals("Unexpected data in range " + rangeId, nodesOf(expected), range.nodes());
for (Map.Entry<Long, List<Long>> expectedEntry : expected.entrySet()) {
long[] labels = range.labels(expectedEntry.getKey());
assertArrayEquals(asArray(expectedEntry.getValue().iterator()), labels);
}
}
// else there was nothing in this range
}
assertFalse(iterator.hasNext());
}
use of java.util.SortedMap in project neo4j by neo4j.
the class FileNamesTest method shouldWorkCorrectlyOnReasonableDirectoryContents.
@Test
public void shouldWorkCorrectlyOnReasonableDirectoryContents() throws Exception {
// Given
// a raft log directory with just the expected files, without gaps
File base = new File("base");
FileNames fileNames = new FileNames(base);
FileSystemAbstraction fsa = mock(FileSystemAbstraction.class);
Log log = mock(Log.class);
List<File> filesPresent = new LinkedList<>();
int lower = 0;
int upper = 24;
// the files are added in reverse order, so we can verify that FileNames orders based on version
for (int i = upper; i >= lower; i--) {
filesPresent.add(fileNames.getForVersion(i));
}
when(fsa.listFiles(base)).thenReturn(filesPresent.toArray(new File[] {}));
// When
// asked for the contents of the directory
SortedMap<Long, File> allFiles = fileNames.getAllFiles(fsa, log);
// Then
// all the things we added above should be returned
assertEquals(upper - lower + 1, allFiles.size());
long currentVersion = lower;
for (Map.Entry<Long, File> longFileEntry : allFiles.entrySet()) {
assertEquals(currentVersion, longFileEntry.getKey().longValue());
assertEquals(fileNames.getForVersion(currentVersion), longFileEntry.getValue());
currentVersion++;
}
}
use of java.util.SortedMap in project hive by apache.
the class MockUtils method init.
static HBaseStore init(Configuration conf, HTableInterface htable, final SortedMap<String, Cell> rows) throws IOException {
((HiveConf) conf).setVar(ConfVars.METASTORE_EXPRESSION_PROXY_CLASS, NOOPProxy.class.getName());
Mockito.when(htable.get(Mockito.any(Get.class))).thenAnswer(new Answer<Result>() {
@Override
public Result answer(InvocationOnMock invocation) throws Throwable {
Get get = (Get) invocation.getArguments()[0];
Cell cell = rows.get(new String(get.getRow()));
if (cell == null) {
return new Result();
} else {
return Result.create(new Cell[] { cell });
}
}
});
Mockito.when(htable.get(Mockito.anyListOf(Get.class))).thenAnswer(new Answer<Result[]>() {
@Override
public Result[] answer(InvocationOnMock invocation) throws Throwable {
@SuppressWarnings("unchecked") List<Get> gets = (List<Get>) invocation.getArguments()[0];
Result[] results = new Result[gets.size()];
for (int i = 0; i < gets.size(); i++) {
Cell cell = rows.get(new String(gets.get(i).getRow()));
Result result;
if (cell == null) {
result = new Result();
} else {
result = Result.create(new Cell[] { cell });
}
results[i] = result;
}
return results;
}
});
Mockito.when(htable.getScanner(Mockito.any(Scan.class))).thenAnswer(new Answer<ResultScanner>() {
@Override
public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
Scan scan = (Scan) invocation.getArguments()[0];
List<Result> results = new ArrayList<Result>();
String start = new String(scan.getStartRow());
String stop = new String(scan.getStopRow());
SortedMap<String, Cell> sub = rows.subMap(start, stop);
for (Map.Entry<String, Cell> e : sub.entrySet()) {
results.add(Result.create(new Cell[] { e.getValue() }));
}
final Iterator<Result> iter = results.iterator();
return new ResultScanner() {
@Override
public Result next() throws IOException {
return null;
}
@Override
public Result[] next(int nbRows) throws IOException {
return new Result[0];
}
@Override
public void close() {
}
@Override
public Iterator<Result> iterator() {
return iter;
}
};
}
});
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Put put = (Put) invocation.getArguments()[0];
rows.put(new String(put.getRow()), put.getFamilyCellMap().firstEntry().getValue().get(0));
return null;
}
}).when(htable).put(Mockito.any(Put.class));
Mockito.when(htable.checkAndPut(Mockito.any(byte[].class), Mockito.any(byte[].class), Mockito.any(byte[].class), Mockito.any(byte[].class), Mockito.any(Put.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
// Always say it succeeded and overwrite
Put put = (Put) invocation.getArguments()[4];
rows.put(new String(put.getRow()), put.getFamilyCellMap().firstEntry().getValue().get(0));
return true;
}
});
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Delete del = (Delete) invocation.getArguments()[0];
rows.remove(new String(del.getRow()));
return null;
}
}).when(htable).delete(Mockito.any(Delete.class));
Mockito.when(htable.checkAndDelete(Mockito.any(byte[].class), Mockito.any(byte[].class), Mockito.any(byte[].class), Mockito.any(byte[].class), Mockito.any(Delete.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
// Always say it succeeded
Delete del = (Delete) invocation.getArguments()[4];
rows.remove(new String(del.getRow()));
return true;
}
});
// Mock connection
HBaseConnection hconn = Mockito.mock(HBaseConnection.class);
Mockito.when(hconn.getHBaseTable(Mockito.anyString())).thenReturn(htable);
HiveConf.setVar(conf, HiveConf.ConfVars.METASTORE_HBASE_CONNECTION_CLASS, HBaseReadWrite.TEST_CONN);
HBaseReadWrite.setTestConnection(hconn);
HBaseReadWrite.setConf(conf);
HBaseStore store = new HBaseStore();
store.setConf(conf);
return store;
}
use of java.util.SortedMap in project OpenClinica by OpenClinica.
the class SpreadsheetPreview method createGroupsMap.
public Map<Integer, Map<String, String>> createGroupsMap(HSSFWorkbook workbook) {
if (workbook == null || workbook.getNumberOfSheets() == 0) {
return new HashMap<Integer, Map<String, String>>();
}
HSSFSheet sheet;
HSSFRow row;
HSSFCell cell;
// static group headers for a CRF; TODO: change these so they are not
// static and hard-coded
String[] groupHeaders = { "group_label", "group_layout", "group_header", "group_sub_header", "group_repeat_number", "group_repeat_max", "group_repeat_array", "group_row_start_number" };
Map<String, String> rowCells = new HashMap<String, String>();
SortedMap<Integer, Map<String, String>> allRows = new TreeMap<Integer, Map<String, String>>();
String str = "";
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
sheet = workbook.getSheetAt(i);
str = workbook.getSheetName(i);
if (str.equalsIgnoreCase("Groups")) {
for (int j = 1; j < sheet.getPhysicalNumberOfRows(); j++) {
// time again.
if (j > 1)
rowCells = new HashMap<String, String>();
row = sheet.getRow(j);
for (int k = 0; k < groupHeaders.length; k++) {
cell = row.getCell((short) k);
if (groupHeaders[k].equalsIgnoreCase("group_header")) {
rowCells.put(groupHeaders[k], getCellValue(cell).replaceAll("<[^>]*>", ""));
} else {
}
}
allRows.put(j, rowCells);
}
// end inner for loop
}
// end if
}
// end outer for
return allRows;
}
Aggregations