File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes key with combinations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "key with combinations" Watch "key with combinations" New topic
Author

key with combinations

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
I want to create keys with different combinations.
Let's say i have two params(a, b), then the keys would be like this:
a||
|b|
a|b|

If i have 3 params(a,b,c), then the keys would be like this:
a|b|c|
a|||
a||c|
a|b||
|b|c|
|b||
||c|

Could anyone please guide me that when the code know how many params, it will return me keys with the valid combination?

Amit Bhargava
Greenhorn

Joined: May 20, 2011
Posts: 20
If I'm getting this correctly, given a set of arguments, you put | after each param.
After this you remove one or more original params from the string in order to get the keys.
The keys then have to be returned in an array/vector.

Firstly, do you need to have two separate params (a&b) in the first example? If you have an array, will that suffice?
Once you have an input array, the steps may become a lot clearer.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jacob Sonia wrote:I want to create keys with different combinations.
Let's say i have two params(a, b), then the keys would be like this:
a||
|b|
a|b|

That looks a lot like


If i have 3 params(a,b,c), then the keys would be like this:
a|b|c|
a|||
a||c|
a|b||
|b|c|
|b||
||c|


And that looks a lot like


That's a HUGE hint, by the way.
Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
Hi,

My concern is that i could have anything in a like 23 and in b like 12333. I want to pass a key already made like this 12|123|123| and when for a and b(the combinations i am looking for), i want the program to append it and create combinations like this:

12|123|123|a||
12|123|123||b|
.....


How is this possible, i am not able to think through it fully.

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11295
    
  16

I don't understand what you are trying to do exactly. you have an existing key, like 12|123|123|. Now you are saying you are adding two new fields/pieces, like 'a' and 'b'?

so you will pass a string in, and return an array of strings. Your method will use Jeff's HUGE HINT to generate all the possible things you want to add on. Then you can create a bunch of new Strings by concatenating the passed in string with all the new ones you create.

or have we completely misunderstood what you are trying to do?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
hi,

yes i will pass a string to a method and let's say two more params

inputString(String input, String param1, String param2)

the output of this method would be
String input | String param1 | |
String input | | String param2|
String input |||

Appreciate any inputs on this.

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11295
    
  16

Jacob Sonia wrote:hi,
the output of this method would be
String input | String param1 | |
String input | | String param2|
String input |||

Why not
String input | String param1 | String param2 |

Why is that one left off?

I'll re-iterate what I said before. There are two pieces. your method needs to build all the possible pieces that can be added on, like this:
|||
param1||
||param2|
|param1|param2|

and then, for each one, it needs to append it onto the end of 'input'.

Note that you probably don't want a method signature of "inputString(String input, String param1, String param2) ". If you did it that way, you'd need a new method every time you wanted to add another param...

inputString(String input, String param1, String param2, String param3)
inputString(String input, String param1, String param2, String param3, String param4)
inputString(String input, String param1, String param2, String param3, String param4, String param5)
etc...

you probably want

inputString(String input, String [] pieces)

Then you write your method to process the pieces array.
Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
Hi Fred,

Yes you are right and thanks for the tips, but i am still not sure how to implement it. Any tips would be great.

Thanks
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11295
    
  16

ok...it works better around here if you

  • ask specific questions
  • post your code so far
  • tell us what you expect your code to do
  • tell us what your code does

  • Generic questions like "I need help" or "show me how to do this project" are generally met with silence. Right now, it looks like you have put zero effort into doing this. If you have put in zero effort, why do you expect anyone else to put in any more effort?

    You've been given several suggestions throughout this thread, and only come back with "yeah, I need help writing this code".

    My first suggestion would be to try writing SOMETHING...ANYTHING...to at least get started.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: key with combinations