Search in sources :

Example 36 with SortedMap

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();
}
Also used : PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) PropertyDefinition(org.sonar.api.config.PropertyDefinition)

Example 37 with SortedMap

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());
}
Also used : NodeLabelRange(org.neo4j.kernel.api.labelscan.NodeLabelRange) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) PrimitiveIntObjectMap(org.neo4j.collection.primitive.PrimitiveIntObjectMap) SortedMap(java.util.SortedMap)

Example 38 with SortedMap

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++;
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Log(org.neo4j.logging.Log) File(java.io.File) Map(java.util.Map) SortedMap(java.util.SortedMap) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 39 with SortedMap

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;
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Result(org.apache.hadoop.hbase.client.Result) Iterator(java.util.Iterator) HiveConf(org.apache.hadoop.hive.conf.HiveConf) ArrayList(java.util.ArrayList) List(java.util.List) Cell(org.apache.hadoop.hbase.Cell) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Get(org.apache.hadoop.hbase.client.Get) SortedMap(java.util.SortedMap) Scan(org.apache.hadoop.hbase.client.Scan)

Example 40 with SortedMap

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;
}
Also used : HashMap(java.util.HashMap) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

SortedMap (java.util.SortedMap)228 Map (java.util.Map)174 TreeMap (java.util.TreeMap)115 HashMap (java.util.HashMap)66 NavigableMap (java.util.NavigableMap)33 ArrayList (java.util.ArrayList)31 Iterator (java.util.Iterator)31 Test (org.junit.Test)25 ImmutableMap (com.google.common.collect.ImmutableMap)21 IOException (java.io.IOException)20 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 JASIExpr (org.matheclipse.core.convert.JASIExpr)16 IExpr (org.matheclipse.core.interfaces.IExpr)16 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)14 File (java.io.File)14 Entry (java.util.Map.Entry)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)12 LinkedHashMap (java.util.LinkedHashMap)11