<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>non-academic guidance for computer science</title>
	<atom:link href="http://jiny-svet.cz/word/feed/" rel="self" type="application/rss+xml" />
	<link>http://jiny-svet.cz/word</link>
	<description>jan.cajthaml</description>
	<lastBuildDate>Fri, 06 Apr 2012 19:57:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>TCP protocol fast Java implementation</title>
		<link>http://jiny-svet.cz/word/2012/04/tcp-protocol-fast-java-implementation/</link>
		<comments>http://jiny-svet.cz/word/2012/04/tcp-protocol-fast-java-implementation/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 18:54:31 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[edit (nedokonceno)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=942</guid>
		<description><![CDATA[Theorem Wikipedia Licence Lorem Pouziti Lorem Kod Lorem Stazeni Lorem]]></description>
			<content:encoded><![CDATA[<h1>Theorem</h1>
<p><a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol">Wikipedia</a></p>
<h1>Licence</h1>
<p>Lorem</p>
<h1>Pouziti</h1>
<p>Lorem</p>
<h1>Kod</h1>
<p>Lorem</p>
<h1>Stazeni</h1>
<p>Lorem</p>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2012/04/tcp-protocol-fast-java-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playfair cipther</title>
		<link>http://jiny-svet.cz/word/2012/04/playfair-cipther/</link>
		<comments>http://jiny-svet.cz/word/2012/04/playfair-cipther/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 18:21:13 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[cryptography]]></category>
		<category><![CDATA[ČVUT]]></category>
		<category><![CDATA[edit (nedokonceno)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>
		<category><![CDATA[cipther]]></category>
		<category><![CDATA[learn java]]></category>
		<category><![CDATA[playfair]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=925</guid>
		<description><![CDATA[Playifair cipther implementation in Java]]></description>
			<content:encoded><![CDATA[<h1>Theorem</h1>
<h3>Introduction</h3>
<p>Although the Baron Playfair’s name is attached to one of the better-known classical ciphers, the baron’s friend, scientist Charles Wheatstone, actually devised the Playfair cipher. After its creation in 1854, the baron succesfully lobbied the Brittish government to adopt the cipher for official use, and thus got his name, and not Wheatstone’s, attached to the cipher.</p>
<p>The Playfair is a primitive—by modern reckoning—block cipher. Any new personal computer sold today can break a message encoded with it in a matter of seconds. That is, with the proper software, you could use such a computer to discover the original text without knowing the cipher key. Some skilled cryptogrophists and puzzle experts can even break it with nothing more than pen and paper.</p>
<p>Nonetheless, it uses some principles common to modern computer block ciphers. Understanding the Playfair will give you a beginning insight into modern cryptography—without all the complex mathematics and number theory.</p>
<h3>Preparatory Information</h3>
<p>To encode a message, you start by preparing your message, known as plaintext, in a specific way, and then transform form this prepared plaintext based upon an alphabet square—again, in a specific way. The alphabet square varies with your chosen keyword.</p>
<p>Decryption is essentially the reverse process.</p>
<p>For the purpose of this example, consider the following as the plaintext:</p>
<p>Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the government for a redress of grievances.</p>
<p>The words, &#8222;First Amendment,&#8220; will be used as the encryption key.</p>
<h3>Preparing the Plaintext</h3>
<p>The first step is to prepaire the plaintext. To do so, all letters are written uppercase, in pairs, and without punctuation. All Js are replaced with Is. This particular example contains no Js.</p>
<blockquote>
<pre>CO NG RE SS SH AL LM AK
EN OL AW RE SP EC TI NG
AN ES TA BL IS HM EN TO
FR EL IG IO NO RP RO HI
BI TI NG TH EF RE EE EX
ER CI SE TH ER EO FO RA
BR ID GI NG TH EF RE ED
OM OF SP EE CH OR OF TH
EP RE SS OR TH ER IG HT
OF TH EP EO PL EP EA CE
AB LY TO AS SE MB LE AN
DT OP ET IT IO NT HG OV
ER NM EN TF OR AR ED RE
SS OF GR IE VA NC ES</pre>
</blockquote>
<p>Next, double letters—if they occur in a pair—must be divided by an X or a Z. For example, freedom in this example becomes FREXEDOM. Because of the triple s between the first and second words, they are written as CONGRESXSZ SHALL. This rule for double letters reduces the number of visible patterns in the ciphertext.</p>
<p>Finally, if there are an odd number of letters, an extra letter chosen by the person writing the cipher is added to the end.</p>
<p>In its ready-to-encrypt form, the plaintext becomes:</p>
<blockquote>
<pre>CO NG RE SX SZ SH AL LM
MA KE NO LA WR ES PE CT
IN GA NE ST AB LI SH ME
NT OF RE LI GI ON OR PR
OH IB IT IN GT FR EX EZ
EX ER CI SE TH ER EO FO
RA BR RI DG IN GT HE FR
EX ED OM OF SP EX EC HO
RO FT HE PR ES SO RT HE
RI GH TO FT HE PE OP LE
PE AC EA BL YT OA SX SE
MB LE AN DT OP ET IT IO
NT HE GO VE RN ME NT FO
RA RE DR ES SO FG RI EV
AN CE SB</pre>
</blockquote>
<p>Notice that, for example, the seventh-from-the-end pair of Ss were not replaced with SXS; this is because previous modifications of double letters shifted everything in a way that they are no longer adjacent.</p>
<h3>Preparing the Key</h3>
<p>The alphabet square is a five-by-five grid. The key phrase is first written without repeating any letters. The remaining letters of the alphabet are filled in in order:</p>
<blockquote>
<pre>F I R S T
A M E N D
B C G H K
L O P Q U
V W X Y Z</pre>
</blockquote>
<p>Note the absence of a J, and that the last three leters of the key had already appeared in the previous ten.</p>
<p>The longer your key, the more secure your message will be—but remember that even the most secure Playfair cipher can be broken easily with the proper tools.</p>
<h3>Encryption</h3>
<p>Next comes the heart of the Playfair cipher: any pair of letters must both be in the same row, in the same column, or in different rows and columns; no other combinations are possible.</p>
<p>Each letter in a pair that is on the same row is replaced by the letter to the right. The letter to the right of the rightmost letter is the first letter in the same row—it &#8222;wraps&#8220; around without going to the next line. With this key, FI becomes IR; OQ becomes PU; KB becomes BC, and so on.</p>
<p>Similarly, letters in the same coumn are replace by the next letter below in the same column. IM becomes MC, GX becomes PR.</p>
<p>The hard one: when the letters are neither in the same row nor column, the substitution is based upon their intersection. Of great importance is preserving the order. Start with the first letter, and move across until it is lined up with the second letter; then start with the second, and move up or down until it is lined up with the first. GU becomes KP, *NOT* PK. YM becomes WN. DH becomes NK.</p>
<p>Remember: first move across (left or right), and then up or down.</p>
<p>Finally, perform this transformation for each pair of letters in the modified plaintext and remove the spaces:</p>
<blockquote>
<pre>OWEHEGRYTYNQBVOAEMGDMQVBXINRXGKI
SMBEDNTFBLOFNQENDSLIEGOFCRQMPIXE
QCFCRFSMKRISGRDXGRGEOMRNSKGEMPIL
FEGFSREKSMKRGNISGRNAWCLIRQGRMGCQ
IPIFGNXENRIQSFGNSRHKIUIFGNXGPQPA
XGMBNMLVZSLMRYRNACPAMDKDPQDRRFMW
DSGNCPXASEENDSILFEEGETNRIQRBSRAX
MDGMFH</pre>
</blockquote>
<p>The above is the final ciphertext. Were Playfair to be a perfect, unbreakable cipher—which it is not—it would be impossible to recover the original message without knowing the encryption key, &#8222;First Amendment.&#8220;</p>
<h3>Decryption</h3>
<p>To decrypt the message, simply reverse the entire process. Break the ciphertext into pairs of letters:</p>
<blockquote>
<pre>OW EH EG RY TY NQ BV OA
EM GD MQ VB XI NR XG KI
SM BE DN TF BL OF NQ EN
DS LI EG OF CR QM PI XE
QC FC RF SM KR IS GR DX
GR GE OM RN SK GE MP IL
FE GF SR EK SM KR GN IS
GR NA WC LI RQ GR MG CQ
IP IF GN XE NR IQ SF GN
SR HK IU IF GN XG PQ PA
XG MB NM LV ZS LM RY RN
AC PA MD KD PQ DR RF MW
DS GN CP XA SE EN DS IL
FE EG ET NR IQ RB SR AX
MD GM FH</pre>
</blockquote>
<p>Write down the alphabet square with the key:</p>
<blockquote>
<pre>F I R S T
A M E N D
B C G H K
L O P Q U
V W X Y Z</pre>
</blockquote>
<p>Transform the pairs of letters in the opposite direction from that used for encryption:</p>
<blockquote>
<pre>CO NG RE SX SZ SH AL LM
MA KE NO LA WR ES PE CT
IN GA NE ST AB LI SH ME
NT OF RE LI GI ON OR PR
OH IB IT IN GT FR EX EZ
EX ER CI SE TH ER EO FO
RA BR RI DG IN GT HE FR
EX ED OM OF SP EX EC HO
RO FT HE PR ES SO RT HE
RI GH TO FT HE PE OP LE
PE AC EA BL YT OA SX SE
MB LE AN DT OP ET IT IO
NT HE GO VE RN ME NT FO
RA RE DR ES SO FG RI EV
AN CE SB</pre>
</blockquote>
<p>This message is now readable, although removing the extra spaces and substitutions for double letters makes it more readable:</p>
<blockquote>
<pre>CONGRESS   SHALL  MAKE   NO  LAW
RESPECTING  AN ESTABLISHMENT  OF
RELIGION OR PROHIBITING THE FREE
EXERCISE  THEREOF  OR  ABRIDGING
THE FREEDOM OF  SPEECH OR OF THE
PRESS OR THE RIGHT OF THE PEOPLE
PEACEABLY  TO  ASSEMBLE  AND  TO
PETITION  THE  GOVERNMENT FOR  A
REDRESS OF GRIEVANCES</pre>
</blockquote>
<h3>Modern Comparisons</h3>
<p>Computer-run block ciphers work in a manner similar to Playfair’s: they break the original message into blocks of characters and apply a complex mathematical transformation, based upon the key, to each of those blocks.</p>
<p>Naturally, modern ciphers are not restriced to upper-case, no-punctuation, J-less messages. Any form of data that can be stored on a computer can be encrypted with a modern cipher.</p>
<p>A modern block cipher can be run in a mode similar to that of Playfair, where the same block (in Playfair, a pair of letters) always encrypts to the same bit of ciphertext: in our example, CO will always come out as OW. Indeed, many poorly-written encryption programs use just this technique, called Electronic Codebook, or ECB.</p>
<p>More sophisticated implementation of a cipher will use one of many other modes. The most common is called Cipher Feedback Mode, or CFB.</p>
<p>CFB starts by encrypting something other than your message, to get things started. This bit at the front of things is called an initialization vector, or IV. The IV need not be secret, but the same IV should never be re-used with the same encryption key.</p>
<p>First, encrypt the IV. Take the IV and combine it with the first block of the plaintext. With computers, this is done with a mathematical function called a binary XOR; a similar effect could be accomplished with Playfair by &#8222;adding&#8220; the two together: C + H = K; W + F = B. It is this value which is written to the ciphertext.</p>
<p>Next, take the result from the last step, encrypt it as normally, and add it to the next block from the plaintext. In this way, the encryption of each block depends upon the encryption of each preceeding block.</p>
<blockquote><p>Encrypt IV -&gt; XOR (add) result with first block of plaintext -&gt; write as ciphertext -&gt; encrypt from previous -&gt; XOR with next block of plaintext -&gt; write as ciphertext -&gt; repeat</p></blockquote>
<p>The example encoded with Playfair modified in this way, using an IV of &#8222;AB&#8220; might look thus:</p>
<blockquote>
<pre>OKHKBGVF…</pre>
</blockquote>
<p>This process greatly increases the security of the encryption system. When done with computers, the speed of the processing of the encryption is not significantly hindered.</p>
<h1>Example of usage</h1>
<pre class="brush:java">PLAYFAIR cipther = new PLAYFAIR();
String OT = "This is a 'secter message', do not read it";
String ST = "";
String KEY = "SECRET";
System.out.println("PLAYFAIR$ : open text : "+OT);
ST = cipther.encode(KEY,OT);
System.out.println("PLAYFAIR$ : encoded : "+ST);
OT = cipther.decode(KEY,ST);
System.out.println("PLAYFAIR$ : decoded : "+OT);</pre>
<h1>Licence</h1>
<p>Lorem</p>
<h1>The Code</h1>
<pre class="brush:java">class PLAYFAIR
{

	private final int w		= 5;
	private final int h		= 5;
	private char[][] matrix	= new char[w][h];

	// EXAMPLE
	// PASSWORD : LOREMIPSUMDOLOR -&gt; LOREMIPSUD
	//
	//   +-----+-----+-----+-----+-----+
	//   +&gt; L &lt;+&gt; O &lt;+&gt; R &lt;+&gt; E &lt;+&gt; M &lt;+
	//   +-----+-----+-----+-----+-----+
	//   +&gt; I &lt;+&gt; P &lt;+&gt; S &lt;+&gt; U &lt;+&gt; D &lt;+
	//   +-----+-----+-----+-----+-----+
	//   |  A  |  B  |  C  |  F  |  G  |
	//   +-----+-----+-----+-----+-----+
	//   |  H  |  K  |  N  |  Q  |  T  |
	//   +-----+-----+-----+-----+-----+
	//   |  V  |  W  |  X  |  Y  |  Z  |
	//   +-----+-----+-----+-----+-----+
	//

	public void setKey(String key)
	{
		if(key == null)
			key = "A";

		int nbIn = 0;

		char[] single	= new char[26];
		boolean[] done	= new boolean[26];
		char[] keyDigit	= key.toUpperCase().toCharArray();

		Loop1:for(char c : keyDigit)
		{
			char actual = c;
			actual = (actual == 'J')?'I':actual;

			int index = actual - 'A';
			if(done[index])
				continue Loop1;
			done[index] = true;
			single[nbIn++] = actual;
		}

		if(nbIn == 0)
		{
			single[nbIn++] = 'A';
			done[0] = true;
		}

		Loop2:for(char c = 'A'; c &lt;= 'Z'; c++)
		{
			if(c == 'J' || done[c - 'A'])
				continue Loop2;
			single[nbIn++] = c;
		}

		for(int x = 0; x &lt; w; x++)
			for(int y = 0; y &lt; h; y++)
				matrix[x][y] = single[x * w + y];

	}

	public String encode(String key,String OT)
	{

		if(OT == null)
			return "";

		this.setKey(key);

		char[] digit = OT.toUpperCase().toCharArray();
		java.util.ArrayList&lt;Pair&gt; list = new java.util.ArrayList&lt;Pair&gt;(10000);
		int index = 0;
		int i = 0;
		Pair lp = null;

		while(i &lt; digit.length)
		{

			digit[i] = (digit[i] == 'J')?'I':digit[i];

			if(index == 0)
			{
				lp = new Pair(digit[i++], true);
				list.add(lp);
				index = 1;
				continue;
			}

			lp.setCharacterAlternative((lp.left == digit[i])?'X':digit[i++]);

			index = 0;
		}

		if(index == 1)
			lp.setCharacterAlternative('X');

		return addSpaces(pairToString(list));
	}

	public String decode(String key,String ST)
	{
		if(ST == null)
			return "";

		this.setKey(key);
		char[] digit = ST.toUpperCase().toCharArray();
		StringBuilder sb = new StringBuilder(digit.length);
		java.util.ArrayList&lt;Pair&gt; aList = new java.util.ArrayList&lt;Pair&gt;(10000);

		for(int i = 0; i &lt; digit.length; i++)
			sb.append((digit[i] == 'J')?'I':digit[i]);

		digit = sb.toString().toCharArray();

		for(int i = 0; i &lt; digit.length; i += 2)
		{
			Pair lp = new Pair(digit[i], false);
			lp.setCharacterAlternative(digit[i+1]);
			aList.add(lp);
		}

		return pairToString(aList);
	}

	private String pairToString(ArrayList&lt;Pair&gt; list)
	{
		String result="";
		for(int i=0; i&lt;list.size(); result+=list.get(i++).getPair());
		return result;
	}

	//
	// AAAAABBBBBCCCCCDDDDDEEEEE -&gt; AAAAA BBBBB CCCCC DDDDD EEEEE
	//

	private String addSpaces(String sb)
	{
		String result = "";
		int i=0;
		int succ=0;
		String[] ar = sb.split("");

		for(String s : ar)
		{
			result+=s;
			if(i==5)
			{
				i=0;
				if(succ!=ar.length-1)
				result+=" ";
			}
			i++;
			succ++;
		}

		return result;
	}

	private class Pair
	{

		private char left;
		private Point point_left, point_right;
		private char[] character = new char[2];
		boolean inverse;

		private Pair(char left, boolean coding)
		{
			this.left		= left;
			this.inverse	= !coding;
			this.point_left	= position(left);
		}

		//	EXAMPLE
		//  _PASSWORD : PSI
		//  _OT : LOREM IPSUM
		//  _ST : RHXLA LSINT
		//
		//    +-------+-------+-------+-------+-------+
		//    | * P * | * S * | * I * |   A   |   B   |
		//    +-------+-------+-------+-------+-------+
		//    |   C   |   D   |   E   |   F   |   G   |
		//    +-------+-------+-------+-------+-------+
		//    |   H   |   K   |   L   |   M   |   N   |
		//    +-------+-------+-------+-------+-------+
		//    |   O   |   Q   |   R   |   T   |   U   |
		//    +-------+-------+-------+-------+-------+
		//    |   V   |   W   |   X   |   Y   |   Z   |
		//    +-------+-------+-------+-------+-------+
		//
		//   LO -&gt; ruleRectangle -&gt; RH
		//   RE -&gt; ruleColumn    -&gt; XL
		//   MI -&gt; ruleRectangle -&gt; AL
		//   PS -&gt; ruleRow       -&gt; SI
		//   UM -&gt; ruleRectangle -&gt; NT
		//

		private void setCharacterAlternative(char c)
		{
			point_right = position(c);

			if(point_left.x == point_right.x)
				ruleRow();
			else if(point_left.y == point_right.y)
				ruleColumn();
			else
				ruleRectangle();

			character[0] = matrix[point_left.x][point_left.y];
			character[1] = matrix[point_right.x][point_right.y];
		}

		//                              ^
		//                              |
		//                              |
		//
		//          +-------+-------+-------+-------+-------+
		//          |       |       |       |       |       |
		//          +-------+-------+-------+-------+-------+
		//          |       |   D   |       |   D   |       |
		//          +-------+-------+-------+-------+-------+
		//          |       | ///// |       | ##### |       |
		//          +-------+-------+-------+-------+-------+
		//          |       |   E   |       |   E   |       |
		//          +-------+-------+-------+-------+-------+
		//          |       |       |       |       |       |
		//          +-------+-------+-------+-------+-------+
		//
		//                              |
		//                              |
		//                              v

		private void ruleRow()
		{
			this.point_left.y	= inverse?((this.point_left.y &lt; 1)	? h-1 : this.point_left.y-1):((this.point_left.y+1)%h);
			this.point_right.y	= inverse?((this.point_right.y &lt; 1)	? h-1 : this.point_right.y-1):((this.point_right.y+1)%h);
		}

		//
		//          +-------+-------+-------+-------+-------+
		//          |       |       |       |       |       |
		//          +-------+-------+-------+-------+-------+
		//   &lt;----- |       |   D   | ///// |   E   |       | -----&gt;
		//          +-------+-------+-------+-------+-------+
		//          |       |       |       |       |       |
		//          +-------+-------+-------+-------+-------+
		//   &lt;----- |       |   D   | ##### |   E   |       | -----&gt;
		//          +-------+-------+-------+-------+-------+
		//          |       |       |       |       |       |
		//          +-------+-------+-------+-------+-------+
		//
		private void ruleColumn()
		{
			this.point_left.x	= inverse?((this.point_left.x &lt; 1)	?	w-1 : this.point_left.x-1):((this.point_left.x+1)%w);
			this.point_right.x	= inverse?((this.point_right.x &lt; 1)	?	w-1 : this.point_right.x-1):((this.point_right.x+1)%w);
		}

		//
		//          +-------+-------+-------+-------+-------+
		//          |       |       |       |       |       |
		//          +-------+-------+-------+-------+-------+
		//   +----&gt; |       |       |  E/D  | ///// |       | -----+
		//   |      +-------+-------+-------+-------+-------+      |
		//   |      |       |       |       |       |       |      |
		//   |      +-------+-------+-------+-------+-------+      |
		//   +----- |       |       | ##### |  E/D  |       | &lt;----+
		//          +-------+-------+-------+-------+-------+
		//          |       |       |       |       |       |
		//          +-------+-------+-------+-------+-------+
		//
		private void ruleRectangle()
		{
			int r			= point_left.y;
			point_left.y	= point_right.y;
			point_right.y	= r;
		}

		//
		//         ---- y ----&gt;
		// +-------+-------+-------+-------+-------+
		// | [0,0] | [1,0] | [2,0] | [3,0] | [4,0] |
		// +-------+-------+-------+-------+-------+  |
		// | [0,1] | [1,1] | [2,1] | [3,1] | [4,1] |  |
		// +-------+-------+-------+-------+-------+  x
		// | [0,2] | [1,2] | [2,2] | [3,2] | [4,2] |  |
		// +-------+-------+-------+-------+-------+  |
		// | [0,3] | [1,3] | [2,3] | [3,3] | [4,3] |  v
		// +-------+-------+-------+-------+-------+
		// | [0,4] | [1,4] | [2,4] | [3,4] | [4,4] |
		// +-------+-------+-------+-------+-------+
		//

		private Point position(char letter)
		{
			for(int x = 0; x &lt; 5; x++)
				for(int y = 0; y &lt; 5; y++)
					if(matrix[x][y] == letter)
						return new Point(x, y);

			throw new IllegalStateException("Pismeno " + letter + " neni v mrizce");
		}

		// EXAMPLE
		// _OT_CHAR : A
		// _ST_CHAR : G
		//
		// getPair -&gt; AG

		private String getPair() { return String.valueOf(character); }
	}

}</pre>
<h1>Download</h1>
<p>Lorem</p>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2012/04/playfair-cipther/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jcGraph &#8211; Java Compact Graph / Jan Cajthaml Graph</title>
		<link>http://jiny-svet.cz/word/2012/02/jcgraph-java-compact-graph-jan-cajthaml-graph/</link>
		<comments>http://jiny-svet.cz/word/2012/02/jcgraph-java-compact-graph-jan-cajthaml-graph/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 04:36:17 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[edit (nedokonceno)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[java graph]]></category>
		<category><![CDATA[java learn]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=919</guid>
		<description><![CDATA[Licence Lorem Ukázka jcGraph graph = new jcGraph(); jcGraphData data = new jcGraphData(); String[] thicks = {"a","b","c"}; graph.setHorizontalThicks(thicks); data.create("graphA"); data.create("graphB"); for(int i=0; i&#60;3; i++) { data.add("graphA", 0.2f*i); data.add("graphB", 0.1f*i); } graph.put(data); JPanel panel = new [...]]]></description>
			<content:encoded><![CDATA[<h1>Licence</h1>
<p>Lorem</p>
<h1>Ukázka</h1>
<pre class="brush:java">jcGraph graph = new jcGraph();
jcGraphData data = new jcGraphData();
String[] thicks = {"a","b","c"};
graph.setHorizontalThicks(thicks);
data.create("graphA");
data.create("graphB");

for(int i=0; i&lt;3; i++)
{
  data.add("graphA", 0.2f*i);
  data.add("graphB", 0.1f*i);
}

graph.put(data);

JPanel panel = new JPanel();
panel.add(graph);</pre>
<h1>Screenshot</h1>
<p><a href="http://jiny-svet.cz/word/wp-content/uploads/graph.png"><img class="alignnone size-full wp-image-920" title="graph" src="http://jiny-svet.cz/word/wp-content/uploads/graph.png" alt="" width="545" height="428" /></a></p>
<h1>Kód</h1>
<h2>Konstanty</h2>
<pre class="brush:java">package cajthamlConstants;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Paint;

public class Constants
{
	public static final Color FONT_COLOR = Color.white;
	public static final Paint THICK_COLOR = new Color(40,40,40);
	public static final Paint SHADE_W = new Color(255,255,255,10);
	public static final Paint SHADE_B = new Color(0,0,0,50);
	public static final Color BG_COLOR = new Color(30,30,30);
	public static final Paint BOX_COLOR = new Color(10,10,10);
	public static final Paint SLIDER_BG = new Color(20,20,20);
	public static final Paint SLIDER_FG = Color.white;
	public static final Paint SLIDER_FONT_COLOR = Color.black;
	public static final Paint SLIDER_FG_FOCUS = new Color(206,255,168);
}</pre>
<h2>Továrna</h2>
<pre class="brush:java">import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import java.util.Hashtable;
import java.util.LinkedList;
import javax.swing.JPanel;

import cajthamlConstants.Constants;

////////////////////////////////////////////////////////

public class jcGraph extends JPanel
{

	////////////////////////////////////////////////////////

	private static final long serialVersionUID = 1316232270722954338L;
	static int id = 0;
	boolean displayThicks = false;
	boolean displayLabels = false;
	int lineHeight = 10;
	static Hashtable&lt;Integer,jcGraphData&gt; graphs	= new Hashtable&lt;Integer,jcGraphData&gt;();
	Hashtable&lt;Integer,Paint&gt; _fcolors = new Hashtable&lt;Integer,Paint&gt;();
	Hashtable&lt;Integer,Paint&gt; _bcolors = new Hashtable&lt;Integer,Paint&gt;();
	String[] thicksH = {""};
	Paint _bg = new Color(0,0,0);
	Paint _cordsBg = new Color(255,255,255);
	int width = 10;
	int height = 100;
	int h = 1;
	int w = 1;
	int offset = 100;
	float amplitude = 1;
	Paint _shade = new Color(0,0,0,20);
	int thick = 2;

	////////////////////////////////////////////////////////

	public jcGraph()
	{
		setOpaque(false);

		_fcolors.put(0,new Color(224,27,106));
		_fcolors.put(1,new Color(27,142,224));
		_fcolors.put(2,new Color(139,224,27));
		_fcolors.put(3,new Color(200,200,200));

		_bcolors.put(0,new Color(224,27,106,30));
		_bcolors.put(1,new Color(27,142,224,30));
		_bcolors.put(2,new Color(139,224,27,30));
		_bcolors.put(3,new Color(200,200,200,30));
	}

	////////////////////////////////////////////////////////

	public void paint(Graphics g)
	{
		Graphics2D g2 = (Graphics2D)g;
		g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint (RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);

		int i=0;

		this.amplitude = graphs.get(0).getAmplitude();

		g.translate(offset/2, offset/2);

		w=getWidth()-offset;
		h=(int) (getHeight()-1.5f*offset);
		height=h;
		width=w/(thicksH.length-1);

		paintHorizontalThicks(g2);
		paintHVerticalThicks(g2);

		for(LinkedList&lt;Float&gt; data : graphs.get(0).iterator())
			drawGraph(g2,data,_fcolors.get(i),_bcolors.get(i++));

		g.translate(-offset/2, -offset/2);		

	}

	////////////////////////////////////////////////////////

	public void setHorizontalThicks(String[] thicks)
	{ this.thicksH=thicks; }

	////////////////////////////////////////////////////////

	private void paintHorizontalThicks(Graphics2D g)
	{

		g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND,30));

		for(int i=0; i&lt;thicksH.length; i++)
		{
			int x=i*width;
			int y=height+offset/4;
			g.setPaint(Constants.THICK_COLOR);
			g.drawLine(x,0,x,y-offset/4);
			g.setPaint(Constants.FONT_COLOR);
			g.drawString(thicksH[i], x-2,y+offset/4);
		}

	}

	////////////////////////////////////////////////////////

	private void paintHVerticalThicks(Graphics2D g)
	{
		g.setFont(new Font("Arial", Font.PLAIN, 20));
		g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND,30));

		int x=width*(this.thicksH.length-1);
		g.setPaint(Constants.THICK_COLOR);
		for(int i=0; i&lt;=this.height/this.lineHeight; i++)
		{
			int y=(height)-((i)*this.lineHeight);
			g.drawLine(0,y,x,y);
		}

		g.drawLine(0,0,width*(this.thicksH.length-1),0);
	}

	////////////////////////////////////////////////////////

	private void drawGraph(Graphics2D g, LinkedList&lt;Float&gt; data, Paint paintF, Paint paintB)
	{

		int x=0;

		GeneralPath body = new GeneralPath();

		body.moveTo(0,0);
		for(float y : data)
		{
			y/=amplitude;
			if(x==0)	body.moveTo(x*width, (h-y*height));
			else	body.lineTo(x*width, (h-y*height));
			x++;
		}

		GeneralPath b2 = (GeneralPath) body.clone();
		b2.lineTo(w,h);
		b2.lineTo(0,h);

		g.setStroke(new BasicStroke(this.thick, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND,30));

		Area area = new Area(new Rectangle2D.Float(0,0,w,h));
		area.intersect(new Area(b2));
		g.setPaint(paintB);
		g.fill(area);
		g.setPaint(paintF);
		g.draw(body);

	}

	////////////////////////////////////////////////////////

	public void put(jcGraphData a)
	{ graphs.put(id++, a); }

	public static jcGraphData getGraph()
	{
		return graphs.get(0);

	}

	////////////////////////////////////////////////////////

}

////////////////////////////////////////////////////////</pre>
<h2>Data</h2>
<pre class="brush:java">import java.util.Collection;
import java.util.Hashtable;
import java.util.LinkedList;

////////////////////////////////////////////////////////

public class jcGraphData
{

	////////////////////////////////////////////////////////

	private Hashtable&lt;String,LinkedList&lt;Float&gt;&gt; map = new Hashtable&lt;String,LinkedList&lt;Float&gt;&gt;(); 

	////////////////////////////////////////////////////////

	public void create(String title)
	{ this.map.put(title, new LinkedList&lt;Float&gt;()); }

	////////////////////////////////////////////////////////

	public void add(String title,float value)
	{ this.map.get(title).add(value); }

	////////////////////////////////////////////////////////

	public LinkedList&lt;Float&gt; get(String title)
	{ return this.map.get(title); }

	////////////////////////////////////////////////////////

	public void get(String title, int x)
	{ this.map.get(title).get(x); }

	////////////////////////////////////////////////////////

	public Collection&lt;LinkedList&lt;Float&gt;&gt; iterator()
	{ return this.map.values(); }

	////////////////////////////////////////////////////////

	public float getAmplitude()
	{
		float max=1;
		for(LinkedList&lt;Float&gt; data : iterator())
		{
			for(float cell : data)
				max=(max&lt;cell)?cell:max;

		}
		return max;
	}

	////////////////////////////////////////////////////////

	public void erase(String title)
	{ this.map.get(title).clear(); }

	////////////////////////////////////////////////////////

}

////////////////////////////////////////////////////////</pre>
<h1>Stažení</h1>
<p>Lorem</p>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2012/02/jcgraph-java-compact-graph-jan-cajthaml-graph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matrix Calculator</title>
		<link>http://jiny-svet.cz/word/2012/02/matrix-calculator/</link>
		<comments>http://jiny-svet.cz/word/2012/02/matrix-calculator/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 20:54:10 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[edit (nedokonceno)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=903</guid>
		<description><![CDATA[Matrix Calculator implementation in Java]]></description>
			<content:encoded><![CDATA[<h1>Ukázka použití</h1>
<h2>Operace mezi maticemi</h2>
<pre class="brush:java">		int n=10;
		int[][] matice = new int[n][n];

		for(int i=0; i&lt;n; i++)
			for(int j=0; j&lt;n; j++)
				matice[j][i]=1;

		Matrix&lt;NumberCore&gt; C = Factory.createMatrix(matice);
		Matrix&lt;NumberCore&gt; A = Factory.createMatrix(matice);
		Matrix&lt;NumberCore&gt; B = Factory.createMatrix(matice);
		B.neutral();

			C=B.plus(A);

		for(int i=1; i&lt;=n; i++)
		{
			for(int j=1; j&lt;=n; j++)
			{
				System.out.print("  "+C.getElement(j, i));
			}
			System.out.println();
		}

	}</pre>
<h2>Výstup</h2>
<table>
<tbody>
<tr>
<td><span style="color: #333333;"> 2 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
<td><span style="color: #333333;"> 1 </span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
<td><span style="color: #333333;"> 1</span></td>
</tr>
<tr>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 1</span></td>
<td><span style="color: #333333;"> 2</span></td>
</tr>
</tbody>
</table>
<h1>Dokumentace &amp; Licence</h1>
<p>Počítání matic v lineárním čase</p>
<h1>Nutná rozhraní</h1>
<h2>Entry</h2>
<pre class="brush:java">public interface Entry&lt;E&gt; extends DeepClonable&lt;E&gt;
{
	///////////////////////////////////////////////////////////////

	E times(E entry);
	E plus(E entry);
	E minus(E entry);
	void zero();
	void neutral();

	///////////////////////////////////////////////////////////////

}</pre>
<h2>DeepClone</h2>
<pre class="brush:java">public interface DeepClonable&lt;E&gt; extends Cloneable,java.io.Serializable
{
	///////////////////////////////////////////////////////////////

	public E duplicate();

	///////////////////////////////////////////////////////////////
}</pre>
<h1>Kód</h1>
<h2>Kernel</h2>
<h3>Factory</h3>
<pre class="brush:java">public class Factory
{
	///////////////////////////////////////////////////////////////

	public static Matrix&lt;NumberCore&gt; createMatrix(int[][] array)
	{
		NumberCore[][] result = new NumberCore[array.length][array[0].length];

		for(int y=0; y&lt; array.length; y++)
			for(int x=0; x&lt; array[y].length; x++)
				result[y][x]=new NumberCore(array[y][x]);

		return new Matrix&lt;NumberCore&gt;(result);
	}

	///////////////////////////////////////////////////////////////

}</pre>
<h3>HashTable</h3>
<pre class="brush:java">/////////////////////////////////////////////////////////////////////////////

class Pair&lt;K,V&gt;
{
    K key;
    V value;

    Pair(K k, V v){</pre>
<pre class="brush:java">        key = k;
        value = v;
    }

    public int hashCode()
    {
        return key.hashCode() + 3 * value.hashCode();
    }

	public boolean equals(Object other)
    {
        if (! (other instanceof Pair&lt;?,?&gt;)) return false;
        Pair&lt;?,?&gt; o = (Pair&lt;?,?&gt;) other;
        return key.equals(o.key) &amp;&amp; value.equals(o.value);
    }
}

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/** Trida DSAHashTable reprezentuje rozptylovaci tabulku se zřetězením (první varianta v učebnici). */
public class HashTable&lt;K,V&gt; implements Iterable&lt;Pair&lt;K,V&gt;&gt;
{

    private transient volatile int count = -1 ;
    private transient volatile int capacity = -1 ;
    private transient volatile int troubleshoot = -1 ;
    private transient volatile java.util.Set &lt; Pair &lt; K,V &gt; &gt; [ ] table ;

    /**Vytvori prazdnou instanci DSAHashTable, delka vnitrniho pole je nastavena na size. */

    @SuppressWarnings("unchecked")
	HashTable ( int capacity )
    {
		this.count = 0;
		this.capacity = capacity ;
		this.troubleshoot = capacity;

		this.table    = (java.util.Set&lt;Pair&lt;K, V&gt; &gt;[]) new java.util.Set&lt;?&gt;[capacity];
    	this.initCells ( this.table );
    }

/////////////////////////////////////////////////////////////////////////////

    /** Ulozi dvojici (key, value) do rozptylovaci tabulky.
     * Pokud uz v tabulce je jina dvojice se stejnym klicem,
     * je smazana.
     * Klic ani hodnota nesmi byt null.
     * Pokud by pocet dvojic v tabulce po vykonani put mel vzrust nad
     *  dvojnasobek delky vnitrniho pole, vnitrni pole zdvojnasobi.
     */
	void put ( K key , V value )
    {

		if ( value == null || key == null )
    	    return ;    	    	

		Pair&lt;K,V&gt; pair = new Pair&lt;K,V&gt; ( key , value ) ;

			remove(key);

    		int index = this.getIndexOf ( pair.key ) ;
    		table [ index ].add ( pair ) ;

    		count++;

        	if ( ! this.isBigEnough ( ) )
        		resize ( capacity &lt;&lt; 1 ) ;
    }

	/////////////////////////////////////////////////////////////////////////////
    /** Vrati hodnotu asociovanou s danym klicem nebo null, pokud dany klic v tabulce neni. */

	synchronized V get ( K key )
    {
		Pair&lt;K,V&gt; pair = this.getPair(key);
		if(pair==null) return null;
		return pair.value;
	}
/////////////////////////////////////////////////////////////////////////////

	private synchronized Pair&lt;K,V&gt; getPair ( K key )
    {
    	for ( Pair &lt; K,V &gt; e : this.table [ this.getIndexOf ( key ) ] )
    		if ( e . key . equals ( key ) )
    			return e;
    	return null ;
	}

/////////////////////////////////////////////////////////////////////////////

	private synchronized void initCells ( java.util.Set&lt;Pair&lt;K, V&gt;&gt;[] table )
	{

    		for ( int i = 0 ; i&lt;table.length ; i ++ )
        			table [ i ] = new GenericSet&lt;Pair&lt;K,V&gt;&gt;();	

	}

/////////////////////////////////////////////////////////////////////////////

    /** Smaze dvojici s danym klicem. Pokud v tabulce dany klic neni, nedela nic. */
	synchronized void remove ( K key )
    {
		int index = this.getIndexOf(key);
		Pair&lt;K,V&gt; pair= this.getPair(key);
		if(pair!=null)
		{
				this.table[index].remove(pair);
				this.count--;
				return;
		}

    }

/////////////////////////////////////////////////////////////////////////////
    /** Vrati vnitrni pole. */
	java.util.Set&lt;Pair&lt;K,V&gt;&gt;[] getArray()
    {
		//OK
		return this.table ;
    }

/////////////////////////////////////////////////////////////////////////////
    /** Pro dany klic vrati index v poli. */
    int getIndexOf ( K key )
    {
    	//OK
		return key.hashCode ( ) % troubleshoot ;
    }

/////////////////////////////////////////////////////////////////////////////
    /** Pokud je pocet prvku mensi nebo roven dvojnasobku delky vnitrniho pole, vrati true, jinak vrati false. */
    private boolean isBigEnough()
    {
    	//OK
    	return this.count &lt;= this.capacity &lt;&lt; 1 ;
    }

/////////////////////////////////////////////////////////////////////////////
    /** Zmeni delku vnitrniho pole a zkopiruje do nej vsechny dvojice. */
    @SuppressWarnings("unchecked")
	synchronized void resize ( int size )
    {
    	//OK
    	java.util.Set &lt; Pair &lt; K,V &gt; &gt; [ ] temp = (java.util.Set&lt;Pair&lt;K, V&gt; &gt;[]) new java.util.Set&lt;?&gt;[size];
		this.initCells ( temp ) ;
		this.troubleshoot = size;
		for ( Pair&lt;K, V&gt; p : this )
		{
			int index = this.getIndexOf ( p.key ) ;
			temp [ index ].add ( p ) ;
		}
		this.capacity = size;
		this.table = temp;
	}

	/////////////////////////////////////////////////////////////////////////////
    /** Vrati iterator pres vsechny dvojice v tabulce. */
    public java.util.Iterator &lt; Pair &lt; K,V &gt; &gt;  iterator ( )
    {
    	java.util.Set&lt; Pair &lt; K,V &gt;&gt; c = new GenericSet&lt; Pair &lt; K,V &gt;&gt;();
    		for ( int i = 0 ; i &lt; this.capacity ; i ++ )
        			for( Pair &lt; K,V &gt; p : table [ i ] )
        				c.add ( p ) ;	

    	return c.iterator();

    }

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

    private class GenericSet&lt;G&gt; extends java.util.HashSet&lt;G&gt;
    {
		private static final long serialVersionUID = -1093311608282332682L;
    }

    public int getSize()
    {
    	return this.count;
    }
}</pre>
<p>&nbsp;</p>
<h3>NumberCore</h3>
<pre class="brush:java">public class NumberCore implements Entry&lt;NumberCore&gt;
{

	///////////////////////////////////////////////////////////////

	private java.math.BigInteger value;

	///////////////////////////////////////////////////////////////

	public NumberCore(int value)
	{ this.value = new java.math.BigInteger(String.valueOf(value)); }

	///////////////////////////////////////////////////////////////

	private NumberCore(java.math.BigInteger value)
	{ this.value = value; }

	///////////////////////////////////////////////////////////////

	public synchronized NumberCore minus(NumberCore entry)
	{ return new NumberCore(this.value.min(entry.value)); }

	///////////////////////////////////////////////////////////////

	public synchronized NumberCore plus(NumberCore entry)
	{ return new NumberCore(this.value.add(entry.value)); }

	///////////////////////////////////////////////////////////////

	public synchronized NumberCore times(NumberCore entry)
	{ return new NumberCore(this.value.multiply(entry.value)); }

	///////////////////////////////////////////////////////////////

	public String toString()
	{ return this.value.toString(); }

	///////////////////////////////////////////////////////////////

	public NumberCore duplicate()
	{ return new NumberCore(this.value); }

	///////////////////////////////////////////////////////////////

	public void neutral()
	{ this.value=java.math.BigInteger.ONE; }

	///////////////////////////////////////////////////////////////

	public void zero()
	{ this.value=java.math.BigInteger.ZERO; }

	///////////////////////////////////////////////////////////////

}</pre>
<h3>Matrix</h3>
<pre class="brush:java">public class Matrix&lt;E extends Entry&lt;E&gt;&gt; implements Entry&lt;Matrix&lt;E&gt;&gt;
{
	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	private int size;
	private HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt; data;

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public Matrix ( E[][] array )
    { 

    		if( array==null ) return;

			size = array.length;
			this.data = new HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt;(size);

			for(int i=1; i&lt;=size ; i++)
			{
				this.data.put(i, new HashTable&lt;Integer,E&gt;(size));
				for(int j=1; j&lt;=size; j++)
				{
					this.data.get(i).put(j, array[j-1][i-1]);
				}
			}

    		///////////////////////////////////////////////////////

    }

	private Matrix ( HashTable&lt;Integer, HashTable&lt;Integer, E&gt;&gt; array )
    { 

    		if( array==null ) return;

			size = array.getSize();
			this.data=array;

    		///////////////////////////////////////////////////////

    }

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public synchronized E getElement( int x , int y )
	{

		return this.data.get(y).get(x);

	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public int getSize()
	{
		return this.size;
	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////	

	public synchronized Matrix&lt;E&gt; minus(Matrix&lt;E&gt; other)
	{
	HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt; array = new HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt;(size);

		for(int i=1; i&lt;=size ; i++)
		{
			array.put(i, new HashTable&lt;Integer,E&gt;(size));
			for(int j=1; j&lt;=size; j++)
			{
				array.get(i).put(j, this.getElement(i,j).minus(other.getElement(i, j)));
			}
		}

		return new Matrix&lt;E&gt;(array);
	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public synchronized Matrix&lt;E&gt; plus(Matrix&lt;E&gt; other)
	{
		HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt; array = new HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt;(size);

		for(int i=1; i&lt;=size ; i++)
		{
			array.put(i, new HashTable&lt;Integer,E&gt;(size));
			for(int j=1; j&lt;=size; j++)
			{
				array.get(i).put(j, this.getElement(i,j).plus(other.getElement(i, j)));
			}
		}

		return new Matrix&lt;E&gt;(array);

	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public synchronized Matrix&lt;E&gt; times(Matrix&lt;E&gt; other)
	{
	HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt; array = new HashTable&lt;Integer,HashTable&lt;Integer,E&gt;&gt;(size);

		for(int i = 1; i &lt;= size; i++)
		{
			array.put(i, new HashTable&lt;Integer,E&gt;(size));
		    for(int j = 1; j &lt;= size; j++) {

		    	E el = this.getElement(j, i).duplicate();
		    	el.zero();

		        for(int s = 1; s&lt;=other.size; s++)
		        {
		        	el=el.plus((this.getElement(s, i).times(other.getElement(j, s))));
		        }
		        array.get(i).put(j,el);

		        }
		    }

		return new Matrix&lt;E&gt;(array);
	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public Matrix&lt;E&gt; duplicate()
	{
		return new Matrix&lt;E&gt;(this.data);
	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public void neutral()
	{

		for(int i=1; i&lt;=size ; i++)
			for(int j=1; j&lt;=size; j++)
			{
				if(i==j)
					this.getElement(i, j).neutral();
				else
					this.getElement(i, j).zero();
			}

	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	public void zero()
	{
		for(int i=1; i&lt;=size ; i++)
			for(int j=1; j&lt;=size; j++)
					this.getElement(i, j).zero();
	}

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////</pre>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2012/02/matrix-calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSA java implementation</title>
		<link>http://jiny-svet.cz/word/2012/01/rsa-java-implementation/</link>
		<comments>http://jiny-svet.cz/word/2012/01/rsa-java-implementation/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 18:00:12 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[cryptography]]></category>
		<category><![CDATA[edit (nedokonceno)]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[learn java]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[rsa implementation]]></category>
		<category><![CDATA[rsa java]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=886</guid>
		<description><![CDATA[RSA Crypt/encrypt/brute in java generic]]></description>
			<content:encoded><![CDATA[<h1>Použití</h1>
<p>Například:</p>
<pre class="brush:java">public class Test
{
	public static void main(String[] args)
	{</pre>
<pre class="brush:java">		Message message = new Message(123);

		System.out.println("message: "+message);

		RSA&lt;Pair,Message&gt; rsa = new RSA&lt;Pair,Message&gt;();
		Pair publicKey = new Pair(3233,17);
		Pair privateKey = new Pair(3233,2753);

		System.out.println("\nCrypting with public key");
		message=rsa.encrypt(publicKey, message);
		System.out.println("crypted: "+message);

		System.out.println("\nEncrypting with private key");
		message=rsa.decrypt(privateKey, message);
		System.out.println("result: "+message);

		System.out.println("\nCrypting with public key");
		message=rsa.encrypt(publicKey, message);
		System.out.println("crypted: "+message);

		System.out.println("\nEncrypting with brute force");
		message=rsa.brute(publicKey, message);
		System.out.println("result: "+message);
	}
}</pre>
<h1 class="brush:java">Dokumentace &amp; Licence</h1>
<h2>Potřebná rozhraní</h2>
<pre class="brush:java">public interface Crypt &lt;K,M&gt;
{
	M encrypt ( K key , M message ) ;
	M decrypt ( K key , M message ) ;
	M brute   ( K key , M message ) ;
}</pre>
<h2>Potřebné objekty</h2>
<pre class="brush:java">public class Pair
{
	private int modulo;
	private int key;

	Pair(int modulo, int key)
	{
		this.modulo=modulo;
		this.key=key;
	}

	public int getModulo()
	{
		return modulo;
	}

	public int getKey()
	{
		return key;
	}

}

public class Message
{
	private int value=0;
	Message(int value)
	{
	this.value=value;
	}

	int getValue()
	{
		return this.value;
	}
	void setValue(int value)
	{
		this.value=value;
	}

	public String toString()
	{
		return String.valueOf(this.value);
	}

}</pre>
<h1>Kód</h1>
<h2>Implementace</h2>
<pre class="brush:java">public class RSA&lt;K extends Pair,M extends Message&gt; implements Crypt&lt;K,M&gt;
{

	////////////////////////////////////////////////////////////////

	public M decrypt(K key, M msg)
	{
		return this.decrypt(key.getModulo(), key.getKey(), msg);
	}

	////////////////////////////////////////////////////////////////

	public M encrypt(K key, M msg)
	{
		msg.setValue(this.exponent(msg.getValue(), key.getKey(),key.getModulo()));
		return msg;
	}

	////////////////////////////////////////////////////////////////

	private M decrypt(int modulo, int key, M msg)
	{
		msg.setValue(this.exponent(msg.getValue(),key,modulo));
		return msg;
	}

	////////////////////////////////////////////////////////////////

	private int exponent(int number, int exponent,int modulo)
	{
		    long x=1;
		    long y=number;
		    while(exponent &gt; 0)
		    {
		        if(exponent%2 == 1)
		            x=(x*y)%modulo;
		        y = (y*y)%modulo;
		        exponent /= 2;
		    }
		    return (int) x%modulo;

	}

	////////////////////////////////////////////////////////////////

	public M brute(K key, M message)
	{
		int n = key.getModulo();
		int p = this.root(n);
		return this.decrypt(
				key.getModulo(),
				this.inversion(key.getKey(),(p-1)*(n/p-1)),
				message);
	}

	////////////////////////////////////////////////////////////////

	private int inversion(int number, int modulo)
	{
		int i = modulo, v = 0, d = 1;
		while (number&gt;0)
			 {
			  int t = i/number, x = number;
			  number = i % x;
			  i = x;
			  x = d;
			  d = v - t*x;
			  v = x;
			 }
			 v %= modulo;
			 if (v&lt;0) v = (v+modulo)%modulo;
			 return v;

	}

	////////////////////////////////////////////////////////////////

	private int root ( int n )
	{

		boolean search = true ;
		int p=0;

		while(search)
		{
			float a = n/++p;
			int b = (int)a;
			if(p==n || ((a==b) &amp;&amp; this.isPrime(b) &amp;&amp; (p*a)==n))
				search=false;
		}

		return p;

	}

	////////////////////////////////////////////////////////////////

	private boolean isPrime(int num)
	{
		 int i;
		 for (i=2; i &lt; num ;i++ )
			 if((num%i)==0) return false;
		 return (i == num);
	}

	////////////////////////////////////////////////////////////////

}

////////////////////////////////////////////////////////////////</pre>
<pre class="brush:java"></pre>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2012/01/rsa-java-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP SQL API</title>
		<link>http://jiny-svet.cz/word/2011/12/php-sql/</link>
		<comments>http://jiny-svet.cz/word/2011/12/php-sql/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 03:47:58 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutoring]]></category>
		<category><![CDATA[php API]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[sql API]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=882</guid>
		<description><![CDATA[PHP API for execution SQL scripts pure javascript]]></description>
			<content:encoded><![CDATA[PHP API for execution SQL scripts pure javascript]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2011/12/php-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery RSA cryptosystem</title>
		<link>http://jiny-svet.cz/word/2011/12/jquery-rsa-cryptosystem/</link>
		<comments>http://jiny-svet.cz/word/2011/12/jquery-rsa-cryptosystem/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 06:59:49 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[edit (nedokonceno)]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=879</guid>
		<description><![CDATA[jQuery script for RSA cryptography]]></description>
			<content:encoded><![CDATA[jQuery script for RSA cryptography]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2011/12/jquery-rsa-cryptosystem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic Strassen Matrix Multiplication</title>
		<link>http://jiny-svet.cz/word/2011/11/generic-merge-sort/</link>
		<comments>http://jiny-svet.cz/word/2011/11/generic-merge-sort/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 21:51:16 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[edit (nedokonceno)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>
		<category><![CDATA[learn java]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[strassen multiplication]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=868</guid>
		<description><![CDATA[Použití Lorem ipsum Dokumentace &#38; Licence Licence Lorem ipsum Dokumentace Rozhrani Entry reprezentuje objekt se kterym lze delat matematicke operace scitani/nasobeni/odcitani. interface Entry &#60; E &#62; { E times ( E entry ) ; E [...]]]></description>
			<content:encoded><![CDATA[<h1>Použití</h1>
<p>Lorem ipsum</p>
<h1>Dokumentace &amp; Licence</h1>
<h2>Licence</h2>
<p>Lorem ipsum</p>
<h2>Dokumentace</h2>
<p>Rozhrani Entry reprezentuje objekt se kterym lze delat matematicke operace scitani/nasobeni/odcitani.</p>
<pre class="brush:java">interface Entry &lt; E &gt;
{
  E times ( E entry ) ;
  E plus ( E entry ) ;
  E minus ( E entry ) ;
}</pre>
<p>Rozhrani Matrix reprezentuje ctvercovou matici, jejiz rozmer je mocnina dvojky.</p>
<pre class="brush:java">interface Matrix &lt; E &gt; extends Entry &lt; Matrix &lt; E &gt; &gt;
{
    // Vrati rozmer matice.
    int getSize();
    // Vrati prvek na indexu n, m (1 &lt;= n &lt;= getSize(), 1 &lt;= m &lt;= getSize()).
    E getElement(int n, int m);
    // Vrati levou horni podmatici.
    Matrix&lt;E&gt; getTopLeftSubmatrix();
    // Vrati pravou horni podmatici.
    public Matrix&lt;E&gt; getTopRightSubmatrix();
    // Vrati levou dolni podmatici.
    public Matrix&lt;E&gt; getBottomLeftSubmatrix();
    // Vrati pravou dolni podmatici.
    public Matrix&lt;E&gt; getBottomRightSubmatrix();
    // Vrati soucet matic this a other
    public Matrix&lt;E&gt; plus(Matrix&lt;E&gt; other);
    // Vrati rozdil matic this a other
    public Matrix&lt;E&gt; minus(Matrix&lt;E&gt; other);
    // Vrati soucin matic this a other
    public Matrix&lt;E&gt; times(Matrix&lt;E&gt; other);
}</pre>
<h1>Kód</h1>
<pre class="brush:java">class GenericMatrix &lt; E extends Entry &lt; E &gt; &gt; implements Matrix &lt; E &gt;
{

  ///////////////////////////////////////////////////////////////

  private Matrix &lt; E &gt; top_left = null;
  private Matrix &lt; E &gt; top_right = null;
  private Matrix &lt; E &gt; bottom_left = null;
  private Matrix &lt; E &gt; bottom_right = null;

  ///////////////////////////////////////////////////////////////

  private int size;
  private int center;
  private E value;

  ///////////////////////////////////////////////////////////////

  public GenericMatrix ( E [][] contents )
  {

    if( contents==null ) return;
    size = contents.length;
    center = size/2;

    if( contents.length==1 )
    {
      value = contents[0][0];
      top_left     = this;
      top_right    = this;
      bottom_left  = this;
      bottom_right = this;
      return;
     }

     E[][] A11 = (E[][]) new Object[center][center];

     for(int i=0; i&lt;center ; i++)
       for(int j=0; j&lt;center ; j++)
         A11[i][j]=contents[i][j];

     E[][] A12 = (E[][]) new Object[center][center];

     for(int i=0; i&lt;center ; i++)
       for(int j=center; j&lt;size ; j++)
         A12[i][j-center]=contents[i][j];

     E[][] A21 = (E[][]) new Object[center][center];

     for(int i=center; i&lt;size ; i++)
       for(int j=0; j&lt;center ; j++)
         A21[i-center][j]=contents[i][j];

     E[][] A22 = (E[][]) new Object[center][center];

     for(int i=center; i&lt;size ; i++)
       for(int j=center; j&lt;size ; j++)
         A22[i-center][j-center]=contents[i][j];

     top_left     =  new GenericMatrix&lt;E&gt; ( A11 );
     top_right    =  new GenericMatrix&lt;E&gt; ( A12 );
     bottom_left  =  new GenericMatrix&lt;E&gt; ( A21 );
     bottom_right =  new GenericMatrix&lt;E&gt; ( A22 );

    }

	///////////////////////////////////////////////////////////////

  public E getElement( int y , int x )
  {

    if( size==1 ) return value;

    if(y&gt;center)
    {
      if( x&gt;center )
        return bottom_right.getElement( y-center , x-center );
        return bottom_left.getElement( y-center , x);
    }
    else
    {
      if( x&gt;center )
        return top_right.getElement( y , x-center );
	return top_left.getElement( y , x );
    }

  }

	///////////////////////////////////////////////////////////////

  public int getSize()
  {
    return this.size;
  }

	///////////////////////////////////////////////////////////////

  public Matrix&lt;E&gt; minus(Matrix&lt;E&gt; other)
  {

    E[][] array = (E[][]) new Object[other.getSize()][other.getSize()];

    for(int i=0; i&lt;size ; i++)
      for(int j=0; j&lt;size; j++)
        array[i][j] = this.getElement(i+1,j+1).minus(other.getElement(i+1, j+1));

    return new GenericMatrix&lt;E&gt;(array);

  }

	///////////////////////////////////////////////////////////////

  public Matrix&lt;E&gt; plus(Matrix&lt;E&gt; other)
  {

    E[][] array = (E[][]) new Object[other.getSize()][other.getSize()];

    for(int i=0; i&lt;size ; i++)
      for(int j=0; j&lt;size; j++)
        array[i][j] = this.getElement(i+1,j+1).plus(other.getElement(i+1, j+1));

    return new GenericMatrix&lt;E&gt;(array);

  }

	///////////////////////////////////////////////////////////////

  public Matrix&lt;E&gt; times(Matrix&lt;E&gt; other)
  {

    E [][] result = (E[][]) new Object[other.getSize()][other.getSize()];	

    if(this.getSize() == 1)
    {
      result[0][0] = this.getElement(0,0).times(other.getElement(0,0));
      return new GenericMatrix&lt;E&gt;(result);
    }

    Matrix&lt;E&gt; A11 = this.getTopLeftSubmatrix();
    Matrix&lt;E&gt; A12 = this.getTopRightSubmatrix();
    Matrix&lt;E&gt; A21 = this.getBottomLeftSubmatrix();
    Matrix&lt;E&gt; A22 = this.getBottomRightSubmatrix();

    Matrix&lt;E&gt; B11 = other.getTopLeftSubmatrix();
    Matrix&lt;E&gt; B12 = other.getTopRightSubmatrix();
    Matrix&lt;E&gt; B21 = other.getBottomLeftSubmatrix();
    Matrix&lt;E&gt; B22 = other.getBottomRightSubmatrix();

    Matrix&lt;E&gt; P1 = (A11.plus(A22)).times(B11.plus(B22));
    Matrix&lt;E&gt; P2 = (A21.plus(A22)).times(B11);
    Matrix&lt;E&gt; P3 = A11.times(B12.minus(B22));
    Matrix&lt;E&gt; P4 = A22.times(B21.minus(B11));
    Matrix&lt;E&gt; P5 = (A11.plus(A12)).times(B22);
    Matrix&lt;E&gt; P6 = (A21.minus(A11)).times(B11.plus(B12));
    Matrix&lt;E&gt; P7 = (A12.minus(A22)).times(B21.plus(B22));

    Matrix&lt;E&gt; C11 = P7.plus((P1.plus(P4)).minus(P5));
    Matrix&lt;E&gt; C12 = P3.plus(P5);
    Matrix&lt;E&gt; C21 = P2.plus(P4);
    Matrix&lt;E&gt; C22 = ((P1.plus(P3)).minus(P2)).plus(P6);

    GenericMatrix&lt;E&gt; res = new GenericMatrix&lt;E&gt;(result);
    res.putTree(C11,C12,C21,C22);
    return res;

  }

	///////////////////////////////////////////////////////////////

  private void putTree(Matrix&lt;E&gt; C11, Matrix&lt;E&gt; C12, Matrix&lt;E&gt; C21, Matrix&lt;E&gt; C22)
  {
    this.top_left=C11;
    this.top_right=C12;
    this.bottom_left=C21;
    this.bottom_right=C22;

  }

	///////////////////////////////////////////////////////////////

  public Matrix&lt;E&gt; getBottomLeftSubmatrix()
  {
    return bottom_left;
  }

	///////////////////////////////////////////////////////////////

  public Matrix&lt;E&gt; getBottomRightSubmatrix()
  {
    return bottom_right;
  }

	///////////////////////////////////////////////////////////////

  public Matrix&lt;E&gt; getTopLeftSubmatrix()
  {
    return top_left;
  }

	///////////////////////////////////////////////////////////////

  public Matrix&lt;E&gt; getTopRightSubmatrix()
  {
    return top_right;
  }

	///////////////////////////////////////////////////////////////

}</pre>
<h2>Download</h2>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2011/11/generic-merge-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generic SET</title>
		<link>http://jiny-svet.cz/word/2011/11/generic-set/</link>
		<comments>http://jiny-svet.cz/word/2011/11/generic-set/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 18:18:51 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[ČVUT]]></category>
		<category><![CDATA[edit (nedokonceno)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=849</guid>
		<description><![CDATA[Generic Set for Java]]></description>
			<content:encoded><![CDATA[<h1>Abstrakt</h1>
<p>Použití například</p>
<pre class="brush:java">Set&lt;String&gt; set = new GenericSet&lt;String&gt;() ;

for ( String T : set )
  System.out.println ( T ) ;</pre>
<h1>Dokumentace &amp; Licence</h1>
<p>&nbsp;</p>
<h1>Kód</h1>
<pre class="brush:java">class GenericSet&lt;P&gt; implements java.util.Set&lt;P&gt;,Iterable&lt;P&gt;
{

/////////////////////////////////////////////////////////////////////////////

  private Node head ;
  private int count ;

/////////////////////////////////////////////////////////////////////////////

  public GenericSet()
  {
    clear();
    this.count = 0;
  }

/////////////////////////////////////////////////////////////////////////////

  private int size()
  {
    return this.count;
  }

/////////////////////////////////////////////////////////////////////////////

  public boolean add(P o)
  {
    Node temp = new Node(o);
    Node current = head;
    while(current.getNext() != null)
      current = current.getNext();

    current.setNext(temp);
    this.count++;
    return true;
  }

/////////////////////////////////////////////////////////////////////////////

  public boolean remove ( Object o )
  {
    Node current = head;
    while(current.getNext() != null &amp;&amp; current.getNext().getData()!=o)
      current = current.getNext();
    current.setNext(current.getNext().getNext());
    this.count--;
    return true;
  }

/////////////////////////////////////////////////////////////////////////////

  public boolean addAll(java.util.Collection&lt;? extends P&gt; c) { return false; }

/////////////////////////////////////////////////////////////////////////////

  public void clear()
  {
    head = new Node(null);
  }

/////////////////////////////////////////////////////////////////////////////

  public boolean contains(Object o)
  {
    for(P n : this) if(n.equals(o)) return true;    
    return false;
  }

/////////////////////////////////////////////////////////////////////////////

  public boolean containsAll(java.util.Collection&lt;?&gt; c) { return false; }

/////////////////////////////////////////////////////////////////////////////

  public boolean isEmpty() { return this.size()==0; }

/////////////////////////////////////////////////////////////////////////////

  public java.util.Iterator&lt;P&gt; iterator() { return new GenericIterator(); }

/////////////////////////////////////////////////////////////////////////////

  public boolean removeAll(java.util.Collection&lt;?&gt; c) { return false; }

/////////////////////////////////////////////////////////////////////////////

  public boolean retainAll(java.util.Collection&lt;?&gt; c) { return false; }

/////////////////////////////////////////////////////////////////////////////

  public Object[] toArray() { return null; }

/////////////////////////////////////////////////////////////////////////////

  public &lt;T&gt; T[] toArray(T[] a) { return null; }

/////////////////////////////////////////////////////////////////////////////

  private class GenericIterator implements java.util.Iterator&lt;P&gt;
  {
    Node cur = head;
    public boolean hasNext() { return cur.next!=null; }
    public P next() { return (cur=cur.next).getData(); }
    public void remove() { }
  }

/////////////////////////////////////////////////////////////////////////////

  private class Node
  {
    Node next;
    P data;
    public Node(P _data) { next = null; data = _data; }
    public P getData() { return data; }
    public Node getNext() { return next; }
    public void setNext(Node _next) { next = _next; }
  }

/////////////////////////////////////////////////////////////////////////////

}</pre>
<p>&nbsp;</p>
<h2>Download</h2>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2011/11/generic-set/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashing</title>
		<link>http://jiny-svet.cz/word/2011/11/hashing/</link>
		<comments>http://jiny-svet.cz/word/2011/11/hashing/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 19:34:52 +0000</pubDate>
		<dc:creator>jancajthaml</dc:creator>
				<category><![CDATA[ČVUT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[Tutoring]]></category>

		<guid isPermaLink="false">http://jiny-svet.cz/word/?p=846</guid>
		<description><![CDATA[http://www.javamex.com/tutorials/collections/hashing_intro.shtml]]></description>
			<content:encoded><![CDATA[<p>http://www.javamex.com/tutorials/collections/hashing_intro.shtml</p>
]]></content:encoded>
			<wfw:commentRss>http://jiny-svet.cz/word/2011/11/hashing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

