
com.joanzapata.pdfview.util.ArrayUtils Maven / Gradle / Ivy
/**
* Copyright 2013 Joan Zapata
*
* This file is part of Android-pdfview.
*
* Android-pdfview is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Android-pdfview is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Android-pdfview. If not, see .
*/
package com.joanzapata.pdfview.util;
import java.util.ArrayList;
import java.util.List;
public class ArrayUtils {
private ArrayUtils() {
// Prevents instantiation
}
/** Transforms (0,1,2,2,3) to (0,1,2,3) */
public static int[] deleteDuplicatedPages(int[] pages) {
List result = new ArrayList();
int lastInt = -1;
for (Integer currentInt : pages) {
if (lastInt != currentInt) {
result.add(currentInt);
}
lastInt = currentInt;
}
int[] arrayResult = new int[result.size()];
for (int i = 0; i < result.size(); i++) {
arrayResult[i] = result.get(i);
}
return arrayResult;
}
/** Transforms (0, 4, 4, 6, 6, 6, 3) into (0, 1, 1, 2, 2, 2, 3) */
public static int[] calculateIndexesInDuplicateArray(int[] originalUserPages) {
int[] result = new int[originalUserPages.length];
if (originalUserPages.length == 0) {
return result;
}
int index = 0;
result[0] = originalUserPages[0];
for (int i = 1; i < originalUserPages.length; i++) {
if (originalUserPages[i] != originalUserPages[i - 1]) {
index++;
}
result[i] = index;
}
return result;
}
public static String arrayToString(int[] array) {
StringBuilder builder = new StringBuilder("[");
for (int i = 0; i < array.length; i++) {
builder.append(array[i]);
if (i != array.length - 1) {
builder.append(",");
}
}
builder.append("]");
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy