Java Code Examples for org.apache.commons.collections4.BidiMap#put()

The following examples show how to use org.apache.commons.collections4.BidiMap#put() . 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: InteractionAnalysisDetermineDirection.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
private static BidiMap<String, String> loadGte(String gtePath) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(gtePath), "UTF-8"));

		String line;

		BidiMap<String, String> gte = new DualHashBidiMap<String, String>();

		while ((line = reader.readLine()) != null) {
			String[] elements = StringUtils.split(line, '\t');
			if (elements.length != 2) {
				throw new RuntimeException("Error in GTE file line: " + line);
			}
			gte.put(elements[0], elements[1]);
		}

		return gte;
	}
 
Example 2
Source File: FunctionGraphFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static BidiMap<CodeBlock, FGVertex> createVertices(Function function,
		final FGController controller, TaskMonitor monitor) throws CancelledException {

	BidiMap<CodeBlock, FGVertex> vertices = new DualHashBidiMap<>();
	CodeBlockModel blockModel = new BasicBlockModel(controller.getProgram());

	AddressSetView addresses = function.getBody();
	CodeBlockIterator iterator = blockModel.getCodeBlocksContaining(addresses, monitor);
	monitor.initialize(addresses.getNumAddresses());

	for (; iterator.hasNext();) {
		CodeBlock codeBlock = iterator.next();

		FlowType flowType = codeBlock.getFlowType();
		boolean isEntry = isEntry(codeBlock);
		Address cbStart = codeBlock.getFirstStartAddress();
		if (cbStart.equals(function.getEntryPoint())) {
			isEntry = true;
		}

		FGVertex vertex =
			new ListingFunctionGraphVertex(controller, codeBlock, flowType, isEntry);
		vertices.put(codeBlock, vertex);

		long blockAddressCount = codeBlock.getNumAddresses();
		long currentProgress = monitor.getProgress();
		monitor.setProgress(currentProgress + blockAddressCount);
	}

	return vertices;
}
 
Example 3
Source File: JRCsvDataSource.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void assignColumnNames()
{
	BidiMap<Integer, String> indexColumns = new DualHashBidiMap<Integer, String>();
	for (int i = 0; i < crtRecordColumnValues.size(); i++)
	{
		String name = crtRecordColumnValues.get(i);
		
		Integer existingIdx = indexColumns.getKey(name);
		if (existingIdx == null)
		{
			//use the name from the file if possible
			indexColumns.put(i, name);
		}
		else
		{
			//the name is taken, force COLUMN_i for this column and recursively if COLUMN_x is already used
			Integer forceIndex = i;
			do
			{
				String indexName = INDEXED_COLUMN_PREFIX + forceIndex;
				Integer existingIndex = indexColumns.getKey(indexName);
				indexColumns.put(forceIndex, indexName);
				forceIndex = existingIndex;
			}
			while(forceIndex != null);
		}
	}
	
	this.columnNames = new LinkedHashMap<String, Integer>();
	for (int i = 0; i < crtRecordColumnValues.size(); i++)
	{
		String columnName = indexColumns.get(i);
		this.columnNames.put(columnName, i);
	}
}
 
Example 4
Source File: ApacheBidiMapTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    String[] englishWords = {"one", "two", "three","ball","snow"};
    String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};

    // Create Multiset
    BidiMap<String, String> biMap = new DualHashBidiMap();
    // Create Polish-English dictionary
    int i = 0;
    for(String englishWord: englishWords) {
        biMap.put(englishWord, russianWords[i]);
        i++;
    }

    // Print count words
    System.out.println(biMap); // Print "{ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}" - in random orders
    // Print unique words
    System.out.println(biMap.keySet());    // print "[ball, snow, one, two, three]"- in random orders
    System.out.println(biMap.values());    // print "[kula, snieg, jeden, dwa, trzy]" - in random orders

    // Print translate by words
    System.out.println("one = " + biMap.get("one"));    // print one = jeden
    System.out.println("two = " + biMap.get("two"));    // print two = dwa
    System.out.println("kula = " + biMap.getKey("kula"));    // print kula = ball
    System.out.println("snieg = " + biMap.getKey("snieg"));    // print snieg = snow
    System.out.println("empty = " + biMap.get("empty"));    // print empty = null

    // Print count word's pair
    System.out.println(biMap.size());    //print 5

}
 
Example 5
Source File: ApacheBidiMapTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    String[] englishWords = {"one", "two", "three","ball","snow"};
    String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};

    // Создаем Multiset
    BidiMap<String, String> biMap = new DualHashBidiMap();
    // создаем англо-польский словарь
    int i = 0;
    for(String englishWord: englishWords) {
        biMap.put(englishWord, russianWords[i]);
        i++;
    }

    // Выводим кол-вом вхождений слов
    System.out.println(biMap); // напечатает {ball=kula, snow=snieg, one=jeden, two=dwa, three=trzy}- в произвольном порядке
    // Выводим все уникальные слова
    System.out.println(biMap.keySet());    // напечатает [ball, snow, one, two, three]- в произвольном порядке
    System.out.println(biMap.values());    // напечатает [kula, snieg, jeden, dwa, trzy]- в произвольном порядке

    // Выводим перевод по каждому слову
    System.out.println("one = " + biMap.get("one"));    // напечатает one = jeden
    System.out.println("two = " + biMap.get("two"));    // напечатает two = dwa
    System.out.println("kula = " + biMap.getKey("kula"));    // напечатает kula = ball
    System.out.println("snieg = " + biMap.getKey("snieg"));    // напечатает snieg = snow
    System.out.println("empty = " + biMap.get("empty"));    // напечатает empty = null

    // Выводим общее количество переводов в словаре
    System.out.println(biMap.size());    //напечатает 5

}
 
Example 6
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenKeyValue_whenPut_thenAddEntryToMap() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    assertEquals(map.size(), 2);
}
 
Example 7
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenInverseBidiMap_thenInverseKeyValue() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    BidiMap<String, String> rMap = map.inverseBidiMap();
    assertTrue(rMap.containsKey("value1") && rMap.containsKey("value2"));
}
 
Example 8
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenValue_whenRemoveValue_thenRemoveMatchingMapEntry() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.removeValue("value2");
    assertFalse(map.containsKey("key2"));
}
 
Example 9
Source File: BidiMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenKeyValue_whenAddValue_thenReplaceFirstKey() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    map.put("key2", "value1");
    assertEquals(map.size(), 1);
    assertFalse(map.containsKey("key1"));
}
 
Example 10
Source File: MapUtilUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUsingBidiMap_shouldReturnKey() {
    BidiMap<String, String> capitalCountryMap = new DualHashBidiMap<String, String>();
    capitalCountryMap.put("Berlin", "Germany");
    capitalCountryMap.put("Cape Town", "South Africa");
    assertEquals("Berlin", capitalCountryMap.getKey("Germany"));
}
 
Example 11
Source File: MapUtilUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUsingBidiMapAddDuplicateValue_shouldRemoveOldEntry() {
    BidiMap<String, String> capitalCountryMap = new DualHashBidiMap<String, String>();
    capitalCountryMap.put("Berlin", "Germany");
    capitalCountryMap.put("Cape Town", "South Africa");
    capitalCountryMap.put("Pretoria", "South Africa");
    assertEquals("Pretoria", capitalCountryMap.getKey("South Africa"));
}
 
Example 12
Source File: DecompilerNestedLayout.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private BlockGraph buildCurrentFunctionGraph(Program program,
		VisualGraph<FGVertex, FGEdge> jungGraph, TaskMonitor taskMonitor)
		throws CancelledException {

	CodeBlockModel blockModel = new BasicBlockModel(program);
	AddressSetView addresses = function.getBody();
	CodeBlockIterator iterator = blockModel.getCodeBlocksContaining(addresses, taskMonitor);

	BlockGraph blockGraph = new BlockGraph();
	BidiMap<CodeBlock, PcodeBlock> bidiMap = new DualHashBidiMap<>();
	for (; iterator.hasNext();) {
		taskMonitor.checkCanceled();

		CodeBlock codeBlock = iterator.next();
		FGVertex vertex = getVertex(jungGraph, codeBlock.getMinAddress());
		if (vertex == null) {
			// this is unusual; can happen if the program is being changed while this is running
			continue;
		}

		PcodeBlock pcodeBlock = new BlockCopy(vertex, codeBlock.getMinAddress());
		bidiMap.put(codeBlock, pcodeBlock);
		blockGraph.addBlock(pcodeBlock);
	}

	for (CodeBlock block : bidiMap.keySet()) {
		taskMonitor.checkCanceled();

		CodeBlockReferenceIterator destinations = block.getDestinations(taskMonitor);
		while (destinations.hasNext()) {
			taskMonitor.checkCanceled();

			CodeBlockReference ref = destinations.next();
			// We only want control flow that is internal to the function. Make sure to
			// exclude the case where a function contains a (recursive) call to itself:
			// The reference would be between addresses internal to the function, but the
			// link doesn't represent internal flow. So we filter out ANY call reference.
			if (ref.getFlowType().isCall()) {
				continue;
			}
			CodeBlock destination = ref.getDestinationBlock();

			PcodeBlock sourcePcodeBlock = bidiMap.get(block);
			PcodeBlock destPcodeBlock = bidiMap.get(destination);
			if (destPcodeBlock == null) {
				continue;
			}

			blockGraph.addEdge(sourcePcodeBlock, destPcodeBlock);
		}
	}

	blockGraph.setIndices();
	return blockGraph;
}
 
Example 13
Source File: BidiMapUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenValue_whenGetKey_thenMappedKey() {
    BidiMap<String, String> map = new DualHashBidiMap<>();
    map.put("key1", "value1");
    assertEquals(map.getKey("value1"), "key1");
}