I'm dealing with a little bit issue when I try to compare two hashtables in J2ME.
This is the situation:
Fist, I've two hashtables:
parkingSlot(String SlotId, String Vehicle)
vehicles(vehicleID,"Available");
is it possible to find this?
parkingSlot
01 "Available"
02 XSD123
03 ASD423
04 "Available"
05 "Available"
vehicules
XSD123 "Available"
LAE212 "Available"
EDO987 "Available"
ADE934 "Available"
ASD423 "Available"
I need to get the car plates that exist in both hashtables. I tried using two iteration with Enumeration adding the values from the first hashtable and the keys from the second one to another hashtable or making a comparison between each one and I can't
Can someone give me a hand with this? ( I can attach my test code )
Finally I get the solution for this case: I add the content of the first Hashtable to a Vector and the I compared the Vector and the second hashtable deleting the data duplicated
Related
My client side code generates UUIDs and sends them to the server.
For example, '6ea140caa83b485f9c98ebaacfb536ce' would be a valid uuid4 to send back.
Is there any way to detect or prevent a user sending back a valid but "user generated" uuid4 like 'babebabebabe4abebabebabebabebabe'?
For example, one way to prevent a certain class of these would be looking at the number of occurrences of 0's and 1's in the binary representation of the number. This could work for a string like '00000000000040000000000000000000' but not for all strings.
It depends a little ...
there is no way to be entirely sure, but depending on the UUID version/subtype you are using there MIGHT be a way to detect at least some irregular values:
https://www.rfc-editor.org/rfc/rfc4122#section-4.1 defines the original version 1 of UUIDs, and a layout for the uuid fields ...
you could for example check if the version and variant fields are valid...
if your UUID generation actually uses Version 1 you could, in addition to the first test of version and variant, test if the timestamp is in a valid range ... for example, it might be unlikely that the UUID in question was generated in the year 1600 ... or in the future
so tests like there could be applied to check if the value actually makes sense, or is complete gibberish ... it can not protect you against someone thinking: ok ... lets analyze this and provide a manually choosen value that satisfies all conditions
No there is no way to distinguish user generated UUID's from randomly generated UUID's.
To start with, a user generated UUID may as well be partially random. But lets assume that it is not.
In that case you want to detect a pattern. However, although you give an example of a pattern, a pattern can be almost anything. For instance, the following byte array looks completely random, right?
40 09 21 fb 54 44 2d 18
But actually it is a nothing-up-my-sleeve number usually used within the cryptographic community: it's simply the encoding of Pi (in this case as a 64 bit floating point, as I was somewhat lazy).
There are certainly randomness tests, for instance FIPS random number tests. Those require a very high number of input to see if something fails or succeeds. Even then: it only shows that certain statistical properties have indeed been attained by a random number generator. The encoding of Pi might very well succeed.
And annoyingly, a random number generator is perfectly possible to generate bit strings that do not look random at all, if just by chance. The smaller the bit string the more chance of the random number generator generating something that doesn't look random at all. And UUID's are not all that big.
So yes, of course you can do some tests, but you can never be sure: you will have both false positives as false negatives.
I need to extract information from a COBOL program. I'm using the ANTLR grammar for COBOL. I need to extract group variables as a whole. I'm not able to extract this with ANTLR as the parser extracts every variable subdivision/group item as an individual element.
I need somehow to get the group items as a bunch. I'm new to COBOL, so I want to get an understanding of how the compiler understands which elements to include in a group, and where to stop.
EX:
01 EMPREC.
02 EEMPNAME.
10 FIRSTNAME PIC X(10)
10 LASTNAM PIC X(15)
07 SNO PIC X(15)
Is the above definition valid? Will the compiler include all elements(=>2 and <=49) after the first item (01 EMPREC), in the group EMPREC until it encounters another 01 or 77 ? Is this safe to assume?
Is the level information enough to derive what elements fall under a group?
Any pointers is appreciated.
I am the author of the COBOL ANTLR4 grammar you found in the ANTLR4 grammars project. The COBOL grammar generates only an Abstract Syntax Tree (AST).
In contrast, what you ask for is an Abstract Semantic Graph (ASG), which represents grouping of variables and in general relationships between AST elements.
Such an ASG is generated by the COBOL parser at my proleap-cobol-parser project. This project uses the mentioned COBOL grammar and resolves relationships between AST elements.
An example for parsing data description entries can be found in this unit test.
You actually had two questions:
"Is the [...] definition valid?" No it is not as you have no previous level 07. If you change the level of EEMPNAME to 07 or SNO to 02 it is valid. Group items may have a USAGE clause but no PICTURE.
This leads to the question "I want to get an understanding of how the compiler understands which elements to include in a group, and where to stop".
You need to store the level number together with the variable. If you want to know what is part of the group then you need to check this level and all below. If you want to check the complete level 02 group use only the variables with an higher level number below until you get to the next level 02 or a higher level (in this case 01), if you want the
Depending on your needs you additional need to check if the next variable with the same level has a REDEFINES in, in this case it belongs to the same group (storage-wise). Similar applies to level 66 (renames, doesn't have its own storage).
Level 88 has no storage either, it is just for validation entries depending on the parsing you want to do you can ignore them.
Important: level 88 does not create a sub-item, you can have multiple ones and a lower level number afterwards.
The level numbers that always defines a new item are 01, and with extensions 66, 77 and 78.
01 vargroup.
02 var-1 pic 9.
88 var-is-even values 0, 2, 4 6 8 .
88 var-is-not-even values 1 3 5 7 9.
88 var-is-big value 6 thru 9.
02 var-2 pic x.
01 new-var pic x.
77 other-var pic 9.
I suggest to read some COBOL sources and come up with a new question, if necessary. For example CBL_OC_DUMP.
I suspect you are going to need to put some additional code behind your ANTLR parser. If you tokenize each individual item, then keeping up with a stack of group items is somewhat easy. However, trying to grab the entire group item as a single production will be very hard.
Some of the challenges that ANTLR will not be up to are 1) group items can contain group items; 2) group items can redefine other items, or be redefined; 3) the little used, but very complicating level-66 renames clause.
If you treat each numbered data definition as a separate production, and maintain a stack, pushing for new items, popping once you have completed processing an item, and knowing that you have completed a group once you see the same level number again, your life will be easier.
It is quite a while now since I've done COBOL, but there are quite a lot of issues if my memory serves me correctly.
1) 01 levels always start in column 8.
2) When assigning subsiquent levels you are better off incrementing my +5
01 my-record.
05 my-name pic x(30) value spaces.
05 my-address1 pic x(40) value spaces.
3) 77 levels I thought are now obsolete since they are not an efficeint use of memory. Also when 77 levels are used they should always be defined at the start of the working storage section. Obviously record layouts are defined in file section unless using write from and read into?
4) If you are defining lots of new-var pic x. Don't use new 01 levels for each!
01 ws-flages.
05 ws_flag1 pic x value space.
05 ws_flag2 pic x value space.
etc.
For COBOL manuals try Stern & Stern.
Hope this helps!
I have looked a lot on the internet, couldn't find what I needed. I found either string to string, or md5, which doesn't return an int and so on.
So what I need is a bit of guidance on how I could encrypt a string into an int. The framework I am working on is used for a while so I cannot change that.
At some point, I have a UniqueID property which should be the ID of an entity, but that sometimes is null, therefore I cannot use it, so I need to use other two ID-s to create a unique id, to assign to my UniqueID, something like string.format("{0}-{1}", branchId, agentId), then encrypt this into int, assign it to UniqueID which gets sent to a whatever method, decrypt UniqueID back into a string, and split by "-" and get my two Ids. And to mention that I don't have any security worries. Grateful for your help.
What you're asking can't be done, in general. You have two numbers, each of which can range from 0 to 150,000. It takes 18 bits to represent 150,000. So it would take 36 bits to represent the two numbers. An int32 is 32 bits.
Unless you can exploit some special knowledge about the relationship between branches and agents (if there is any), then it will be impossible to squeeze those 36 bits into a 32 bit integer.
You could, however, create a lookup table that assigns a unique key to each branch-agent pair. A simple incrementing key. You could then build the pair (i.e. `142096-037854') and look up the id. Or, given the id, look up the branch/agent pair.
If there's a way to compress two 18 bit numbers into 32 bits, I sure don't know of it. If you can't be sure that the two ID's can be under 65536 (or one of them under 16384) then the best I can come up with is for you to change UniqueID to a long - then it's straight forward, no strings, just put AgentId into the first 32 bits and branchId into the last 32 bits.
I'm trying to store some time series data on the following column family:
create column family t_data with comparator=TimeUUIDType and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
I'm successfully inserting data this way:
data={datetime.datetime(2013, 3, 4, 17, 8, 57, 919671):'VALUE'}
key='row_id'
col_fam.insert(key,data)
As you can see, using a datetime object as the column name pycassa converts to a timeUUID object correctly.
[default#keyspace] get t_data[row_id];
=> (column=f36ad7be-84ed-11e2-af42-ef3ff4aa7c40, value=VALUE, timestamp=1362423749228331)
Sometimes, the application needs to update some data. The problem is that when I try to update that column, passing the same datetime object, pycassa creates a different UUID object (the time part is the same) so instead of updating the column, it creates another one.
[default#keyspace] get t_data[row_id];
=> (column=f36ad7be-84ed-11e2-af42-ef3ff4aa7c40, value=VALUE, timestamp=1362423749228331)
=> (column=**f36ad7be**-84ed-11e2-b2fa-a6d3e28fea13, value=VALUE, timestamp=1362424025433209)
The question is, how can I update TimeUUID based columns with pycassa passing the datetime object? or, if this is not the correct way to doing it, what is the recommended way?
Unless you do a read-modify-write you can't. UUIDs are by their nature unique. They exist to solve the problem of how to get unique IDs that sort in chronological order but at the same time avoid collisions for things that happen at exactly the same time.
So to update that column you need to first read it, so you can find its column key, change its value and write it back again.
It's not a particularly elegant solution. You should really avoid read-modify-write in Cassandra. Perhaps TimeUUID isn't the right type for your column keys? Or perhaps there's another way you can design your application to avoid having to go back and change things.
Without knowing what your query patterns look like I can't say exactly what you should do instead, but here are some suggestions that hopefully are relevant:
Don't update values, just write new values. If something was true at time T will always have been true for time T, even if it changes at time T + 1. When things change you write a new value with the time of the change and let the old values be. When you read the time line you resolve these conflics by picking the most recent value -- and since the values will be sorted in chronological order the most recent value will always be the last one. This is very similar to how Cassandra does things internally, and it's a very powerful pattern.
Don't worry that this will use up more disk space, or require some extra CPU when reading the time series, it will most likely be tiny in comparison with the read-modify-write complexity that you would otherwise have to implement.
There might be other ways to solve your problem, and if you give us some more details maybe we can come up with someting that fits better.
I need to name this structure:
struct NameNeeded
{
DateTime timestamp;
float value;
}
I will have arrays of this struct (a time-series).
I'd like a short and suggestive name. The data is financial (and Tick is not a good name).
The best one I can think of is DataPoint, but I feel that a better one exists :)
How would you name it?
Since you have a data value and an associated timestamp, the first thing that popped into my head was DataSample. I pictured a series of these, as if you were taking a digital sampling of an analog signal (the two values were like x- and y-coordinates on a graph).
My old scientist neurons are telling me that this is a Measurement. A measurement is an instrument reading associated with some context - time, position, experimental conditions, and so on.
The other metaphor that springs to mind is a Snapshot, or a moment in an evolving scene illuminated by a strobe light - an Instant, perhaps.
Given that we can't associate a specific concept with the float value structure member, only vague names such as "Value", "Number", "Float" or "Data" come to mind.
The DateTime timestamp member suggests to me that the name should have a time related suffix such as "When", "AtTime", "Instant" or "Moment"
So, combining these name fragments and you could have
ValueWhen
ValueAtInstant
NumberWhen
DataAtTime
etc.
When stuck on a naming problem, consulting a dictionary or thesaurus can sometimes help. It's pleasing to see well chosen type names, and gratifying to come up with them - good luck with your quest.
I would personally include "Float" in the name, to leave open the possibility of providing other time-stamped types. For example, you could provide a timestamped int or enum for analyst recommendation.
If you want the time-stamping to be implicit, consider "FloatValue." Making it implicit might be desirable if other attributes might someday join the timestamp (e.g., source of data, confidence level, or uncertainty).
If you want to be explicit, one possibility would be "RecordedFloat."