As you know for "AND" function you will get "True" if both inputs are true.
Edited by xxxxjayxxx, 19 April 2011 - 10:51 AM.
Edited by xxxxjayxxx, 19 April 2011 - 10:51 AM.
|
|
|
if (strLine.charAt(i) == '1') {
result1.set(i, true);
System.out.print([B][SIZE="4"][COLOR="purple"]i +": " +[/COLOR][/SIZE][/B] result1.get(i) + " ");
} else if (strLine.charAt(i) == '0') {
result1.set(i, false);
System.out.print([B][COLOR="purple"][SIZE="4"]i +": " +[/SIZE][/COLOR] [/B]result1.get(i) + " ");
}
1: false 3: true 4 false 1: false 2: true 4 true 5: falseAt set1, number 2 is missing, at set 2, number 3.
wim DC said:
if (strLine.charAt(i) == '1') {
result1.set(i, true);
System.out.print([B][SIZE="4"][COLOR="purple"]i +": " +[/COLOR][/SIZE][/B] result1.get(i) + " ");
} else if (strLine.charAt(i) == '0') {
result1.set(i, false);
System.out.print([B][COLOR="purple"][SIZE="4"]i +": " +[/SIZE][/COLOR] [/B]result1.get(i) + " ");
}
1: false 3: true 4 false 1: false 2: true 4 true 5: falseAt set1, number 2 is missing, at set 2, number 3.
strLine.replace(",", "");
wim DC said:
Edited by xxxxjayxxx, 19 April 2011 - 10:52 AM.
strLine.replace(",", "");
Should be:
strLine = strLine.replace(",", "");
wim DC said:
strLine.replace(",", "");
Should be:
strLine = strLine.replace(",", "");
result1.and(result2);
for (int i = 0; i < strLine.length(); i++) {
strLine.replace("false", "");
System.out.print(result1.get(i) + " ");
}
because the result will be store in result1 everytime I "AND" as a result result1 can't be reuse to "AND" with other input ?
100 010Will result in the bitset {true, false, false, false, true, false}
[B][SIZE="4"]int i=0;[/SIZE][/B]
while ((strLine = br1.readLine()) != null) {
for(char character : strLine.toCharArray() ) {
if( character == '1' ){
result1.set(i, true);
} else if( character == '0' ){
result1.set(i, false);
}
System.out.print(i + ": " + result1.get(i) + " ");
[B][SIZE="4"]i++;[/SIZE][/B]
}
}
100 010You will in the end, have 2 BitSets in an array, each containing 1 line:
Edited by xxxxjayxxx, 19 April 2011 - 10:53 AM.
BitSet[] bitSets = new BitSet[10]This creates an array of 10 BitSets. Now, because we don't know how many lines there will be, a normal array is not really the best solution here.
LinkedList<BitSet> bitSets = new LinkedList<BitSet>();You can add to it by doing:
BitSets.add( new BitSet() );And take out of it by doing
BitSet setNumber0 = BitSets.get(0);
[B][SIZE="4"]LinkedList<BitSet>[/SIZE][/B] result1 = new [SIZE="4"][B]LinkedList<BitSet>();[/B][/SIZE] [SIZE="4"][B]LinkedList<BitSet>[/B][/SIZE] result2 = new [B][SIZE="4"]LinkedList<BitSet>();[/SIZE][/B]
while ((strLine = br1.readLine()) != null) {
BitSet bitSet = new BitSet();
//In here, keep your code, but use "bitSet" instead of "result1"
result1.add(bitSet);
}
Next, you have this piece of code:
while ((strLine = br2.readLine()) != null) {
System.out.println();
strLine.replace(",", "");//.substring(strLine.indexOf(".")+5);
if (strLine.trim().startsWith("Name")) {
continue;
}
for (int i = 0; i < strLine.length(); i++) {
if (strLine.charAt(i) == '1') {
result2.set(i, true);
System.out.print(result2.get(i) + " ");
} else if (strLine.charAt(i) == '0') {
result2.set(i, false);
System.out.print(result2.get(i) + " ");
}
}
[B][COLOR="red"][SIZE="4"]System.out.println();
result1.and(result2);
for (int i = 0; i < strLine.length(); i++) {
strLine.replace("false", "");
System.out.print(result1.get(i) + " ");
}[/SIZE][/COLOR][/B]
}
I would suggest to not do the "AND" in there, but do it outside the loop. Just store it in a new BitSet, and add this bitSet to result2, like it's done for result1 in the code above.
for( int i=0 ; i<result1.size() ; i++){
BitSet bitSet1 = result1.get( i );
BitSet bitSet2 = result2.get( i );
bitSet1.and(bitSet2);
System.out.println();
for(int j=0 ; j<bitSet1.size() ; j++){
System.out.print( bitSet1.get( j ) + " ");
}
}
And that should be about it.
0 members, 1 guests, 0 anonymous users