| 1 |
48e61813
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2024 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
|
|
// This file is part of Magic Cube. //
|
| 5 |
|
|
// //
|
| 6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
| 7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
| 8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 9 |
|
|
|
| 10 |
|
|
package org.distorted.objects;
|
| 11 |
|
|
|
| 12 |
|
|
import java.util.Arrays;
|
| 13 |
|
|
|
| 14 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 15 |
|
|
|
| 16 |
|
|
public class RubikObjectCategoriesAuthor extends RubikObjectCategories
|
| 17 |
|
|
{
|
| 18 |
|
|
private void buildSort(String[] data)
|
| 19 |
|
|
{
|
| 20 |
|
|
int numObjects = data.length;
|
| 21 |
|
|
String[] sorted = new String[numObjects];
|
| 22 |
|
|
System.arraycopy(data, 0, sorted, 0, numObjects);
|
| 23 |
|
|
|
| 24 |
|
|
Arrays.sort(sorted);
|
| 25 |
|
|
|
| 26 |
|
|
String[] categories = new String[numObjects];
|
| 27 |
|
|
int numCategories = 0;
|
| 28 |
|
|
|
| 29 |
|
|
for(int o=0; o<numObjects; o++)
|
| 30 |
|
|
if( o==0 || !sorted[o-1].equals(sorted[o]) )
|
| 31 |
|
|
{
|
| 32 |
|
|
categories[numCategories] = sorted[o];
|
| 33 |
|
|
numCategories++;
|
| 34 |
|
|
}
|
| 35 |
|
|
|
| 36 |
|
|
int lastChange = -1;
|
| 37 |
|
|
int curr = 0;
|
| 38 |
|
|
int[] numInCategory = new int[numCategories];
|
| 39 |
|
|
|
| 40 |
|
|
for(int o=0; o<numObjects; o++)
|
| 41 |
|
|
if( o==numObjects-1 || !sorted[o].equals(sorted[o+1]) )
|
| 42 |
|
|
{
|
| 43 |
|
|
numInCategory[curr] = o-lastChange;
|
| 44 |
|
|
curr++;
|
| 45 |
|
|
lastChange = o;
|
| 46 |
|
|
}
|
| 47 |
|
|
|
| 48 |
|
|
mObjectIndices = new int[numCategories][];
|
| 49 |
|
|
|
| 50 |
|
|
for(int c=0; c<numCategories; c++)
|
| 51 |
|
|
{
|
| 52 |
|
|
mObjectIndices[c] = new int[numInCategory[c]];
|
| 53 |
|
|
|
| 54 |
|
|
String cat = categories[c];
|
| 55 |
|
|
int index = 0;
|
| 56 |
|
|
|
| 57 |
|
|
for(int o=0; o<numObjects; o++)
|
| 58 |
|
|
if( data[o].equals(cat) ) mObjectIndices[c][index++] = o;
|
| 59 |
|
|
}
|
| 60 |
|
|
}
|
| 61 |
|
|
|
| 62 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 63 |
|
|
|
| 64 |
|
|
void buildIndices()
|
| 65 |
|
|
{
|
| 66 |
|
|
int numObjects = RubikObjectList.getNumObjects();
|
| 67 |
|
|
String[] auths = new String[numObjects];
|
| 68 |
|
|
|
| 69 |
|
|
for(int o=0; o<numObjects; o++)
|
| 70 |
|
|
{
|
| 71 |
|
|
RubikObject obj = RubikObjectList.getObject(o);
|
| 72 |
|
|
auths[o] = obj==null ? "" : obj.getAuthor();
|
| 73 |
|
|
}
|
| 74 |
|
|
|
| 75 |
|
|
buildSort(auths);
|
| 76 |
|
|
}
|
| 77 |
|
|
|
| 78 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 79 |
|
|
|
| 80 |
|
|
void buildTitle()
|
| 81 |
|
|
{
|
| 82 |
|
|
mTitles = new String[mNumCategories];
|
| 83 |
|
|
|
| 84 |
|
|
for(int t=0; t<mNumCategories; t++)
|
| 85 |
|
|
{
|
| 86 |
|
|
int obj = mObjectIndices[t][0];
|
| 87 |
|
|
RubikObject object = RubikObjectList.getObject(obj);
|
| 88 |
|
|
mTitles[t] = object==null ? "" : object.getAuthor();
|
| 89 |
|
|
}
|
| 90 |
|
|
}
|
| 91 |
|
|
}
|