Programming :: Equivalence Classes Based On Field Values And Multi-key Hashtable?
May 12, 2010
I've got a set of objects (all of the same type). I'm trying to think of a good way to divide it into equivalence classes, with equivalence of two objects defined as meaning a specified set of attributes are equal for both objects. More concretely, I've got:
- a Java class with around 50 fields
- a bunch of instances of the class
I want:
- to divide the instances into a few sets
- in each set, each instance has field 1 - field 5 equal to fields 1-5 of the other instances in the set.
The method I've come up with is to generate a hashcode for each instance based on the hashcodes of fields 1-5*, and map the hashcode to one of my sets. Ignoring problems with potential hashcode collisions (which I'm expecting to be too rare to worry about for now), does that sound reasonable? It seems simple enough, but I'm wondering if there's a simpler method I haven't thought of.
* I'll generate the hashcode using a method based on Eclipse's generic hashcode method, which looks like this:
Code:
public int hashCode() {
final int prime = 31;
int result = 1;
[code]....
View 5 Replies
ADVERTISEMENT
May 18, 2010
I've had a very colorful morning learning the innerparts of Linux's sort command, and have come across yet another issue that I can't seem to find an answer for in the documentation. I'm currently using -t, to indicate that my fields are split by the comma character, but I'm finding that in some of my files, the comma is used (between double-quotes) within values:
Jonathan Sampson,,foo@bar.com,0987654321
"Foobar CEO,","CEO,",ceo@foobar.com,,
How can I use a comma to terminate my fields, but ignore the occurences of it within values? Is this fairly simple, or do I need to re-export all of my data using a more-foreign field-terminator? (Unfortunately, I do not have any control over declaring a different terminator with this particular project).
View 2 Replies
View Related
Sep 1, 2010
In my file there are 2 fields separated by space.Sample content of file are as follows:56060 154242 053030 0Now i want to check second field of the file and if all values in second field are 0(zero) and send mail containing all contents of the file
View 3 Replies
View Related
Jul 27, 2010
I am splitting a file based on the values read from an input file. The below one is the script.
1)How do I add the header which is present in the original file to the new split files created?(For eg. pharmacyf conatins header as table column names. The new files created (ODS.POS.$pharmacyid.$tablename.$CURRENT_DATE.dat) are without the header).
2) Also the script is creating 0 byte files for the pharmacyids which are not available in the intial file? Can this be avoided?
for pharmacyf in *
do
tablename=`echo $pharmacyf |cut -f4 -d'.' `
while read pharmacyid
do
grep -w $pharmacyid $pharmacyf >> $OUT/ODS.POS.$pharmacyid.$tablename.$CURRENT_DATE.dat
done< inputfile
done
View 2 Replies
View Related
Mar 28, 2010
I'm trying to display fields from flat files where the first 8 fields are always the same. Fields 9 - n are varied but will contain specific patterns I'm after. I'm using this so far because "mySearch" is on each line I want to examine.
Code:
How would you pattern match and include 2 additional fields above field $9 but change field position from line to line?
View 12 Replies
View Related
Jan 8, 2010
How can print the, let's say 5nd field to the last field of every record (let's say we have 10 fields)?
I mean: I cant avoid to have to do:
print '{$5 $6 $7 $8 $9 $10}'
View 2 Replies
View Related
Apr 27, 2009
I am creating a game with random variables. In the game I have created a dialogue exchange to players. I have set up a table with various returns and I inserted {$fields} to represent various random variables. When I call on the requested fields, I only see the field text and my field names. Am I supposed to parse something and call it back another way?
ie: myfield is: "You have won {$random1} silver! <br />{$wi['gender'] majesty rewards you well." the code I am using to call that field is:
View 11 Replies
View Related
Feb 11, 2011
I want to select lines from FileA based on a key field in FileB.
egrep does this nicely:
"egrep -w '0132874|0132880|0100765' < " FileA
Suppose FileB consists of three lines:
0132874
0132880
0100765
Is there a way to code egrep to do the selection? I really like code which does not use explicit loops so my interest is to find a grep or egrep or sed (or some other) command to perform this function.
Neither file is sorted on the key field but they could be. There is no requirement to keep the files in their present order.We may assume that each key value in each file is unique.
View 2 Replies
View Related
Jan 18, 2011
I have a lot of files with thousands of rows and usually two columns of data. Column 1 is a coordinate, column 2 is a score. I want to delete rows that have a value in column 2 over, in this case, 50.
For example, here's a clip from a file:
2999898 39
2999899 40.9
2999900 42.7
2999901 44.7
2999902 46.7
2999903 48.9
2999904 51.1
2999905 53.3
2999906 55.7
I want the output to be this:
2999904 51.1
2999905 53.3
2999906 55.7
I know how to use sed for very basic things like deleting rows or ranges of rows but I can't figure out this ostensibly easy command.
View 6 Replies
View Related
Oct 28, 2010
I know the basic answer about how to create a class as ABC.But I don;'t know- - why I have to create a AbstractBaseClass. - In what situations it can be used.an example code base and not like a animal(base) and tiger(derived) relationship example.
View 2 Replies
View Related
Dec 14, 2010
i have a file : file.dat with following data
Code:
STORAGE PERCENTAGE FLAG:
/storage_01 64% 0
/storage_02 17% 1
/storage_03 10% 0
/storage_04 50% 1
I need to get the value of PERCENTAGE in a variable for a value of storage passed as variable i have tried the following without success like :
Code:
percentage='awk -vx="$defaultStorage" '{FS=OFS=" "}$1==x{print $2}1' file.dat
View 2 Replies
View Related
Apr 11, 2010
This is probably a really stupid thing to ask considering the development I'm doing (effectivly creating a virus scanner), but how do I link classes/cpp files?I have 3 applications/sections that I can compile/combine with a makefile, that's fine, but I need them to run 1, 2, 3 once the output from the makefile is done.Currently the only section to actually run is whichever I have "main" in and obviously if I put that into all three, they won't compile as one.I've been looking all over the place at all sorts, header files and such, but there is no mention of how toually do this although I'm sure it must be possible. I'm used to being able to do this in Java and I'm sure I've seen C++ applications do it, but not worked out how.I have 3x .cpp files which are combined into one using a makefile:
Code:
# Virus Scanner
scanner.out : ProgramList.o MD5Hash.o HazardCheck.o
[code]...
View 2 Replies
View Related
Feb 15, 2010
Is it possible to have a templated c++ stl container in another class without specifying the type prior to compile time? I haven't coded in c++ in a while and im at a total loss.
For example - Not real code. Just outlining the problem code...
View 1 Replies
View Related
Feb 4, 2010
facing a problem in declaring variables. i have a few classes like the one below...
Code:
#ifndef _FINANCE_H
#define_FINANCE_H
[code]....
View 1 Replies
View Related
Jan 6, 2011
I am fairly new to c++. There must be a better way to do the following?:- Say I have a base class, Pet. I have several child classes that extend from this, like Dog, Cat, Fish etc.
I have the following function, that returns a pointer to a new Pet:-
Code: Pet* addPetToVet()
{ //Do some stuff
return new Pet();
} This will return a pointer an instance of a pet object.
Now, if I want to interpret this pet as a dog or cat I have to do this:-
Code: Dog* dogA = static_cast<Dog*>(addPetToVet());
Cat* catA = static_cast<Cat*>(addPetToVet()); Is there a way around this? Casting seems lame. I cant write a function for each type of pet.
View 5 Replies
View Related
May 15, 2010
I'm new to Java.
I'm trying to use some dynamically loaded classes in my application.
The application doesn't know those classes , Just it try to load a class by name that its name came from input.
It doesn't know class (So I can't use casting) but just needs to call some methods of that class (every class should have that methods).
I thought about interfaces but I don't know how.
How can I call those methods?
View 1 Replies
View Related
Apr 18, 2011
Why are the 'defense' method calls actually using the 'offense' methods.Also, is there a way to remove the commented base classes for 'Player' so that the casting isn't necessary?
Code:
#include <iostream>
class Offense
[code]...
View 1 Replies
View Related
Feb 7, 2011
I'm trying to use awk to remove rows that are duplicates based on 3 fields, and I want to keep the on that has the higher value in another field. I'm working in C-Shell. For example the below is greped out of a larger data set to use in here as example:
Input (Field separator is a comma:
Code:
4180,-6999,MA,BARNSTABLE,BOURNE,1,1.7,1700,PM,1/26
4180,-6999,MA,BARNSTABLE,BOURNE,1,3.5,2025,PM,1/26
4180,-6999,MA,BARNSTABLE,BOURNE,1,1.0,1511,PM,1/26
4180,-6999,MA,BARNSTABLE,BOURNE,1,5.7,0540,AM,1/27
[Cpde]....
View 1 Replies
View Related
May 15, 2010
Does anyone know of an alsa based software multi-band (10 or more) graphic audio frequency equalizer that works with Suse 11.x? To be clear, I don't mean an equalizer within an audio or video player. One that can be used with any sound application, that works between the output of the player and the output plugs on a motherboard or sound card.
View 9 Replies
View Related
Sep 10, 2009
I want to validate a web form using PHP. I spent ages confusing myself with client side scripting and realised until I worked out it is not what I want. My problem is that now I am looking at PHP and everything is mixed up in my brain. I need to point out that PHP is very new to me! This is what I already have:
1 An html page with my form on it.
2 PHP page which emails the contents of the form to me.
The above works well. For the sake of clarity, here are my pages (cut down to the essentials where appropriate): My html form:
first name surname
Email
Home phone
Mobile
Work phone
I have read and understood your terms and conditions. My php script (regform.php)
$receiver = 'me@email'; $subject = 'New registration'; #$message = 'This is a new registration.'; $surname = $_POST['surname']; $firstname = $_POST['firstname']; $address = $_POST['address']; $email = $_POST['email']; $homeph = $_POST['homeph']; $mobileph = $_POST['mobileph']; $workph = $_POST['workph']; $time = $_POST['time']; #from here $oldaddress = $_POST['oldaddress']; $DOB = $_POST['DOB']; $elect = $_POST['elect']; $job = $_POST['job']; $salary = $_POST['salary']; $employer = $_POST['employer']; $benefit = $_POST['benefit']; $smoke = $_POST['smoke']; $claim = $_POST['claim']; $children = $_POST['children']; $children2 = $_POST['children2']; $pets = $_POST['pets']; $pets2 = $_POST['pets2']; $require = $_POST['require']; $terms = $_POST['terms']; $rooms = $_POST['rooms']; $body = "first name:$firstname
surname:$surname
DOB:$DOB
email:$email
home phone:$homeph
mobile phone:$mobileph
work phone:$workph
address:
$address
time at this address:$time
previous address:$oldaddress
electoral register:$elect
employment:$job
employer:$employer
salary:$salary
benefit claim:$benefit
future benefit:$claim
children:$children
ages:$children2
pets:$pet
pet type:$pets2
other requirements:$require
terms:$terms"; $headers = 'From: email' . "
" . 'Reply-To: email "
" . 'X-Mailer: PHP/' . phpversion(); mail($receiver, $subject, $body, $headers, "From: $firstname $surname
" . "Reply-To: $firstname $surname class="inlineimg" />;
You can see there are many more form fields than I have shown in my example html form above. What I want is that the following fields have to be filled:
1 mobileph
2 email
3 terms (checkbox)
I would like the user to be asked to fill the form in properly if any/all of the 3 fields have not been filled in. I imagine I need some php in the html page and some more in the php page. I am certainly not asking any one to do this for me but I am really confused. I have googled and copied and pasted and edited for 6 hours and I am lost. What I want is a very simple and clear example of the code needed. Sorry if I sound as if I can't search properly on Google: in this case I clearly can't!
View 2 Replies
View Related
Feb 12, 2010
how do i ask in a query for any numeric or string field? It may not have any meaning, but i need it to fill a toplink DataReadQuery in java....Something like " select * from table where table.fieldA='?'
View 2 Replies
View Related
Sep 30, 2010
I'm having a bit of a trouble getting a particular field replaced in a host list. I have a MasterHostList which has a comma delimiter for fields and a new line to separate servers.
server1,random,random,group1,random,random
server2,random,random,group1,random,random
I then have a file.list file with a grouping of server names. What I need is to search the MasterHostList and for each server that is in the file.list I need to change the fourth field from group1 to group2 without changing the order or position of anything in the MasterHostList. Obviously the above names are arbitrary.
Failed attempts have been: for SERVER in `cat file.list`; do sed /$SERVER/s/,group1,/,group2,/ MasterHostList MasterHostList.tmp && mv -f MasterHostList.tmp MasterHostList; done for SERVER in `cat file.list`;do awk 'BEGIN { FS=OFS="," } /^${SERVER}/ { $4 = "group2" } 1' ./MasterHostList MasterHostList.tmp && mv -f MasterHostList.tmp MasterHostList; done
Both of these would in various output tests find the correct lines, but it wouldn't change them all correctly.
View 3 Replies
View Related
Apr 5, 2010
I have a file with variable length lines containing fields separated by colons:
Code:
path/to/file0.c:4150:109:4151:142:4153:275
path/to/file1.c:4040:109
path/to/file2.c:4605:72:4606:109
path/to/file3.c:4380:54
The first field identifies the file name, the second is the search key, and the third is the line number of the file that the search key points to. Any subsequent fields are other key/line number pairs.
As an example, I can search for 4151 (key) from my bash script to identify the file I will have to access, but I also need to capture the line (142) as well, and I can't figure out how to do that using grep, awk or sed (or anything else).
View 2 Replies
View Related
Feb 18, 2011
If I have a MySQL field called, say, "Occupation", which contains "Java Programmer" in it, I would like it to come up when I search for "Java", so that I can get to the other fields in the table.
How do I do this?
View 2 Replies
View Related
Jul 1, 2011
In the MySQL database for one of my programming projects, I used a "YEAR(4)", because I wanted the column to contain four-digit year values. I discovered, though, that this type only allows values from 1901 to 2155, which is not workable as some year values are previous to the twentieth century. But I do not want a "DATE" type because the month and day are of no interest to me. What type should I convert to that would be the least radical change in data type, while giving more range?
View 1 Replies
View Related
Jan 28, 2010
The thing is that the command for sed resembles the following
[code]...
Now if I want to place another command like grep or cut in the address field how do I do it. Actually I don't know the line number. The user has to give it as an input. How shall I do that?
View 8 Replies
View Related
Jun 13, 2010
Is there a list somewhere that shows what programs for Fedora are the equivalence for Windows? I know that OpenOffice is the equivalence for Office but what else.
View 7 Replies
View Related
Apr 9, 2010
I am in the process of learning some scripting, however I am running into a roadblock in specifying a certain time format in the array. Ideally I would like to use Here are the lines of text that I am interrogating:
1123,3/25/2010,00:14 Thu,33229
1124,3/26/2010,13:30 Fri,33230
1125,3/27/2010,04:49 Sat,33231
[code]...
View 2 Replies
View Related
Jan 4, 2010
I am going to parse the Cisco voip CDR(Call Detail Records), please tell me the field format of the CDR files.
View 1 Replies
View Related
Sep 8, 2010
Using content proposal in helios, giving problem if u press tab. Below is the error. For recreation snippet is provided(taken from 2 sites) after error log.Only u need to press tab while proposal pop up is visible & then point mouse at client.
#################################ERROR LOG#############################
# A fatal error has been detected by the Java Runtime Environment:
#
[code]....
View 9 Replies
View Related