0

I encounter a difficult problem in java. I have two dataset or we can say that two arrays. They are x and y coordinates. Whenever this two co ordinates values are match they can extract whole data chunk. Then it again looking for matches. I include a picture with this question enter image description here

The blue line show the 1st data chunk

The black line show the 2nd data chunk

The red line show the 3rd data chunk.

I develop a algorithm for the problem

  1. Take two loop counter i and k and initialize i=0 and k=1.

    2.check if x[i] and y[i] is same with x[k] and y[k] then save x[i],y[i] to x[k],y[k] , increment both counter.

    3.If they are not same increment counter k with 1.

  2. if they are not same increment k with 1.

    5.If they are same increment counter i by 1 and set k=i+1.

    6.Then again check

    This is my algorithm. Now my problem is that how could I implement save data portion. Where should I save this chunk of data s. Also we should remember that the chunk are not always same in size. So I need some dynamic data structure.

    2ndly what is the technique to compare a pair of data with some other pair or data?

    So helpful suggestion of this two problem is most welcome.

    Thank you in advance.

Saswati
  • 192
  • 8
  • Possible duplicate of [Group a list of objects by an attribute : Java](https://stackoverflow.com/questions/21678430/group-a-list-of-objects-by-an-attribute-java) – derpirscher Aug 09 '18 at 18:01
  • No. there only one attribute matching required. My problem is like co ordinate matching. Two attribute matching required. How could I match a pair of data with a another pair of data? This is the uniqueness of this program. – Saswati Aug 09 '18 at 18:07
  • @Saswati I've already answered below what you've just marked-up bold - that example is for GPS coordinates, while for any other 2D coordinate system, it would work merely the same (just assume x/y instead of lat/lng - and ditch the limiter values of lat/lng). – Martin Zeitler Aug 09 '18 at 18:11
  • I guess you have some kind of data assigned to each coordinate pair. What do you want to do with that data, if coordinates match? What is the expected result of matching shown above? Instead of using single integer as hashmap key you can use your coordinate pair and then have all data chunks for a specific coordinate in one list. Just take those entities where the list contains at least two chunks and combine them as you need – derpirscher Aug 09 '18 at 18:19
  • accumulate Similar chunk of data in different different chunk and then plot them. plotting is not a big problem when the data chunk are present. – Saswati Aug 09 '18 at 18:23
  • Show some real input data and your expected output. Nobody can get that from your image. And show some code, what you tried to get your result – derpirscher Aug 09 '18 at 18:33
  • @MartinZeitler Try to implement my algorithm with code block. I share the link. This link not the same as this problem that I share here but a subpart. https://stackoverflow.com/questions/51787217/array-pairwise-matching-in-java-if-statement-through-error – Saswati Aug 10 '18 at 13:07

1 Answers1

0

Why to do not use OOP?

  • create DataChunk class with x and y properties
  • override equals method to compare x and y
  • convert your dataset(s) into list (e.g. ArrayList) of DataChunk objects then...

Your question is not quite clear - do you have two arrays with possible duplicate values? or just one with possibly repeated values?

depending on answer you can loop through first List and call second list contains method then if true you have your matched dataChunk and free to put it wherever you wan to.

If you have just one list then loop will be different to find second value. It is nothing than standard way to find duplicates in collection/array...

BTW use arrays in Java is clumsy and not a proper way to work with collections while Java has very powerful and improved Collections framework suited for almost all needs...

Vadim
  • 4,027
  • 2
  • 10
  • 26
  • The output will be [2.3 5.4,1.2 2.2, 3.3 4.4,5.5 6.6,2.3 4.4]-> 1st data chunk. [1.2 2.2,3.3 4.4,5.5 6.6,2.3 5.4,1.3 1.9,7.9 5.2,1.2 2.2]->2nd data chunk.[3.3 4.4,5.5 6.6,2.3 5.4,1.3 1.9,7.9 5.2,1.2 2.2,3.3 3.5,3.3 4.4]-> 3rd data chunk. How do I proceed? – Saswati Aug 10 '18 at 12:03
  • https://stackoverflow.com/questions/51787217/array-pairwise-matching-in-java-if-statement-through-error – Saswati Aug 10 '18 at 13:07