All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.utils.repositories.Vector_boolean Maven / Gradle / Ivy

There is a newer version: 7.15.25
Show newest version
/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * Vector_boolean.java
 * ---------------
 */
package org.jpedal.utils.repositories;

import java.io.Serializable;

/**
 * Provides the functionality/convenience of a Vector for boolean
 * 

* Much faster because not synchronized and no cast * Does not double in size each time */ public class Vector_boolean implements Serializable { //how much we resize each time - will be doubled up to 160 int increment_size = 1000; //current max size int max_size = 250; //holds the data private boolean[] items = new boolean[max_size]; protected static int incrementSize(int increment_size) { if (increment_size < 8000) { increment_size *= 4; } else if (increment_size < 16000) { increment_size *= 2; } else { increment_size += 2000; } return increment_size; } //set size public Vector_boolean(final int number) { max_size = number; items = new boolean[max_size]; } /////////////////////////////////// /** * extract underlying data * @return boolean[] */ public final boolean[] get() { return items; } /////////////////////////////////// /** * set an element * @param new_name boolean to set * @param id id of boolean */ public final void setElementAt(final boolean new_name, final int id) { if (id >= max_size) { checkSize(id); } items[id] = new_name; } /** * get element at * @param id id of boolean * @return boolean */ public final boolean elementAt(final int id) { if (id >= max_size) { return false; } else { return items[id]; } } /** * check the size of the array and increase if needed */ private void checkSize(final int i) { if (i >= max_size) { final int old_size = max_size; max_size += increment_size; //allow for it not creating space if (max_size <= i) { max_size = i + increment_size + 2; } final boolean[] temp = items; items = new boolean[max_size]; System.arraycopy(temp, 0, items, 0, old_size); increment_size = incrementSize(increment_size); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy