Proteome Informatics Group > Java Proteomic Library
 

Recipe 1.3. Creating a sequence of symbols

Problem

You want to create a sequence of specific symbols and manipulate it.

Solution

Sequence of symbols take a generic argument that is the data type pointed out by symbols. In our example, a CardRankSymbol has integer values.

Specific builder is dealing with the instanciation

// create a sequence of 5 CardRankSymbols
SymbolSequenceImpl<Integer> openCards = 
	new SymbolSequenceImpl.Builder<Integer>("J2KTA",
		CardRankSymbol.getSymbolType()).build();

Then you can access to any symbol

Symbol<Integer> king = openCards.getSymbolAt(2);

and get the stored value

// get the instance of card manager (see this tutorial)
CardRankManager manager = CardRankManager.getInstance();

// get the value of the card
int kingRank = manager.lookUpDataFromSymbol(king);

Assert.assertEquals(12, kingRank);

Discussion

See Also