LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Sponsors
  • Mirrors
  • Logos
  • Contact us
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Thu Oct 26 02:48:58 CEST 2006
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/06/10 26:02:48

    Added: jop/java/target/src/jdk11/java/util Calendar.java Date.java
    EmptyStackException.java Enumeration.java
    Hashtable.java Iterator.java
    NoSuchElementException.java Random.java Stack.java
    TimeZone.java Vector.java
    Log:
    merge with Nelsons JDK and split into three source directories


    Revision Changes Path
    1.1 jop/java/target/src/jdk11/java/util/Calendar.java

    http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Calendar.java?rev=1.1&content-type=text/x-cvsweb-markup

    Index: Calendar.java
    ===================================================================
    /* Calendar.java --
    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.

    This file is part of GNU Classpath.

    GNU Classpath 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 2, or (at your option)
    any later version.

    GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301 USA.

    Linking this library statically or dynamically with other modules is
    making a combined work based on this library. Thus, the terms and
    conditions of the GNU General Public License cover the whole
    combination.

    As a special exception, the copyright holders of this library give you
    permission to link this library with independent modules to produce an
    executable, regardless of the license terms of these independent
    modules, and to copy and distribute the resulting executable under
    terms of your choice, provided that you also meet, for each linked
    independent module, the terms and conditions of the license of that
    module. An independent module is a module which is not derived from
    or based on this library. If you modify this library, you may extend
    this exception to your version of the library, but you are not
    obligated to do so. If you do not wish to do so, delete this
    exception statement from your version. */

    package java.util;


    /**
    * This class is an abstract base class for Calendars, which can be used to
    * convert between <code>Date</code> objects and a set of integer fields which
    * represent <code>YEAR</code>, <code>MONTH</code>, <code>DAY</code>,
    * etc. The <code>Date</code> object represents a time in milliseconds since
    * the Epoch. <br>
    *
    * This class is locale sensitive. To get the Object matching the current locale
    * you can use <code>getInstance</code>. You can even provide a locale or a
    * timezone. <code>getInstance</code> returns currently a
    * <code>GregorianCalendar</code> for the current date. <br>
    *
    * If you want to convert a date from the Year, Month, Day, DayOfWeek, etc.
    * Representation to a <code>Date</code>-Object, you can create a new
    * Calendar with <code>getInstance()</code>, <code>clear()</code> all
    * fields, <code>set(int,int)</code> the fields you need and convert it with
    * <code>getTime()</code>. <br>
    *
    * If you want to convert a <code>Date</code>-object to the Calendar
    * representation, create a new Calendar, assign the <code>Date</code>-Object
    * with <code>setTime()</code>, and read the fields with
    * <code>get(int)</code>. <br>
    *
    * When computing the date from time fields, it may happen, that there are
    * either two few fields set, or some fields are inconsistent. This cases will
    * handled in a calendar specific way. Missing fields are replaced by the fields
    * of the epoch: 1970 January 1 00:00. <br>
    *
    * To understand, how the day of year is computed out of the fields look at the
    * following table. It is traversed from top to bottom, and for the first line
    * all fields are set, that line is used to compute the day. <br>
    *
    *
    * <pre>
    * month + day_of_month
    * month + week_of_month + day_of_week
    * month + day_of_week_of_month + day_of_week
    * day_of_year
    * day_of_week + week_of_year
    * </pre>
    *
    * The hour_of_day-field takes precedence over the ampm and hour_of_ampm fields.
    * <br>
    *
    * <STRONG>Note:</STRONG> This can differ for non-Gregorian calendar. <br> * * To convert a calendar to a human readable form and vice versa, use the * <code>java.text.DateFormat</code> class. <br> * * Other useful things you can do with an calendar, is <code>roll</code>ing * fields (that means increase/decrease a specific field by one, propagating * overflows), or <code>add</code>ing/substracting a fixed amount to a field. * * @see Date * @see GregorianCalendar * @see TimeZone * @see java.text.DateFormat */ public abstract class Calendar { /** * Constant representing the era time field. */ public static final int ERA = 0; /** * Constant representing the year time field. */ public static final int YEAR = 1; /** * Constant representing the month time field. This field should contain one * of the JANUARY,...,DECEMBER constants below. */ public static final int MONTH = 2; /** * Constant representing the week of the year field. * * @see #setFirstDayOfWeek(int) */ public static final int WEEK_OF_YEAR = 3; /** * Constant representing the week of the month time field. * * @see #setFirstDayOfWeek(int) */ public static final int WEEK_OF_MONTH = 4; /** * Constant representing the day time field, synonym for DAY_OF_MONTH. */ public static final int DATE = 5; /** * Constant representing the day time field. */ public static final int DAY_OF_MONTH = 5; /** * Constant representing the day of year time field. This is 1 for the first * day in month. */ public static final int DAY_OF_YEAR = 6; /** * Constant representing the day of week time field. This field should * contain one of the SUNDAY,...,SATURDAY constants below. */ public static final int DAY_OF_WEEK = 7; /** * Constant representing the day-of-week-in-month field. For instance this * field contains 2 for the second thursday in a month. If you give a * negative number here, the day will count from the end of the month. */ public static final int DAY_OF_WEEK_IN_MONTH = 8; /** * Constant representing the part of the day for 12-hour clock. This should * be one of AM or PM. */ public static final int AM_PM = 9; /** * Constant representing the hour time field for 12-hour clock. */ public static final int HOUR = 10; /** * Constant representing the hour of day time field for 24-hour clock. */ public static final int HOUR_OF_DAY = 11; /** * Constant representing the minute of hour time field. */ public static final int MINUTE = 12; /** * Constant representing the second time field. */ public static final int SECOND = 13; /** * Constant representing the millisecond time field. */ public static final int MILLISECOND = 14; /** * Constant representing the time zone offset time field for the time given * in the other fields. It is measured in milliseconds. The default is the * offset of the time zone. */ public static final int ZONE_OFFSET = 15; /** * Constant representing the daylight saving time offset in milliseconds. * The default is the value given by the time zone. */ public static final int DST_OFFSET = 16; /** * Number of time fields. */ public static final int FIELD_COUNT = 17; /** * Constant representing Sunday. */ public static final int SUNDAY = 1; /** * Constant representing Monday. */ public static final int MONDAY = 2; /** * Constant representing Tuesday. */ public static final int TUESDAY = 3; /** * Constant representing Wednesday. */ public static final int WEDNESDAY = 4; /** * Constant representing Thursday. */ public static final int THURSDAY = 5; /** * Constant representing Friday. */ public static final int FRIDAY = 6; /** * Constant representing Saturday. */ public static final int SATURDAY = 7; /** * Constant representing January. */ public static final int JANUARY = 0; /** * Constant representing February. */ public static final int FEBRUARY = 1; /** * Constant representing March. */ public static final int MARCH = 2; /** * Constant representing April. */ public static final int APRIL = 3; /** * Constant representing May. */ public static final int MAY = 4; /** * Constant representing June. */ public static final int JUNE = 5; /** * Constant representing July. */ public static final int JULY = 6; /** * Constant representing August. */ public static final int AUGUST = 7; /** * Constant representing September. */ public static final int SEPTEMBER = 8; /** * Constant representing October. */ public static final int OCTOBER = 9; /** * Constant representing November. */ public static final int NOVEMBER = 10; /** * Constant representing December. */ public static final int DECEMBER = 11; /** * Constant representing Undecimber. This is an artificial name useful for * lunar calendars. */ public static final int UNDECIMBER = 12; /** * Useful constant for 12-hour clock. */ public static final int AM = 0; /** * Useful constant for 12-hour clock. */ public static final int PM = 1; /** * The time fields. The array is indexed by the constants YEAR to * DST_OFFSET. * * @serial */ protected int[] fields = new int[FIELD_COUNT]; /** * The flags which tell if the fields above have a value. * * @serial */ protected boolean[] isSet = new boolean[FIELD_COUNT]; /** * The time in milliseconds since the epoch. * * @serial */ protected long time; /** * Tells if the above field has a valid value. * * @serial */ protected boolean isTimeSet; /** * Tells if the fields have a valid value. This superseeds the isSet array. * * @serial */ protected boolean areFieldsSet; /** * The time zone of this calendar. Used by sub classes to do UTC / local * time conversion. Sub classes can access this field with getTimeZone(). * * @serial */ private TimeZone zone; /** * Specifies if the date/time interpretation should be lenient. If the flag * is set, a date such as "February 30, 1996" will be treated as the 29th * day after the February 1. If this flag is false, such dates will cause an * exception. * * @serial */ private boolean lenient; /** * Sets what the first day of week is. This is used for WEEK_OF_MONTH and * WEEK_OF_YEAR fields. * * @serial */ private int firstDayOfWeek; /** * Sets how many days are required in the first week of the year. If the * first day of the year should be the first week you should set this value * to 1. If the first week must be a full week, set it to 7. * * @serial */ private int minimalDaysInFirstWeek; /** * Is set to true if DST_OFFSET is explicitly set. In that case it's value * overrides the value computed from the current time and the timezone. */ private boolean explicitDSTOffset = false; /** * Constructs a new Calendar with the default time zone and the default * locale. */ protected Calendar() { this(TimeZone.getDefault()); } /** * Constructs a new Calendar with the given time zone and the given locale. * * @param zone * a time zone. * @param locale * a locale. */ protected Calendar(TimeZone zone) { this.zone = zone; lenient = true; minimalDaysInFirstWeek = 1; firstDayOfWeek = 1; clear(); } /** * Compares the given calendar with this. * * @param o * the object to that we should compare. * @return true, if the given object is a calendar, and this calendar * represents a bigger time than the calendar o. * @exception ClassCastException * if o is not an calendar. * @since JDK1.2 you don't need to override this method */ public boolean after(Object o) { return getTimeInMillis() > ((Calendar) o).getTimeInMillis(); } /** * Compares the given calendar with this. * * @param o * the object to that we should compare. * @return true, if the given object is a calendar, and this calendar * represents a smaller time than the calendar o. * @exception ClassCastException * if o is not an calendar. * @since JDK1.2 you don't need to override this method */ public boolean before(Object o) { return getTimeInMillis() < ((Calendar) o).getTimeInMillis(); } /** * Converts the milliseconds since the epoch UTC (<code>time</code>) to * time fields (<code>fields</code>). Override this method if you write * your own Calendar. */ protected abstract void computeFields(); /** * Converts the time field values (<code>fields</code>) to milliseconds * since the epoch UTC (<code>time</code>). Override this method if you * write your own Calendar. */ public boolean equals(Object o) { if (!(o instanceof Calendar)) return false; Calendar cal = (Calendar) o; if (getTimeInMillis() == ((Calendar) o).getTimeInMillis() && cal.getFirstDayOfWeek() == getFirstDayOfWeek() && cal.isLenient() == isLenient() && cal.getMinimalDaysInFirstWeek() == getMinimalDaysInFirstWeek()) { TimeZone self = getTimeZone(); TimeZone oth = cal.getTimeZone(); return self == null ? oth == null : self.equals(oth); } return false; } /** * Gets the value of the specified field. They are recomputed if they are * invalid. * * @param field * the time field. One of the time field constants. * @return the value of the specified field * @throws ArrayIndexOutOfBoundsException * if the field is outside the valid range. The value of field * must be >= 0 and <= <code>FIELD_COUNT</code>. * @specnote Not final since JDK 1.4 */ public int get(int field) { // If the requested field is invalid, force all fields to be recomputed. if (!isSet[field]) areFieldsSet = false; return fields[field]; } /** * Creates a calendar representing the actual time, using the default time * zone and locale. */ public static synchronized Calendar getInstance() { // TODO: not implemented return null; } /** * Creates a calendar representing the actual time, using the given time * zone and the default locale. * * @param zone * a time zone. */ public static synchronized Calendar getInstance(TimeZone zone) { // TODO: not implemented return null; } /** * Converts the time represented by this object to a <code>Date</code>-Object. * * @return the Date. */ public final Date getTime() { return new Date(time); } /** * Returns the time represented by this Calendar. * * @return the time in milliseconds since the epoch. * @specnote This was made public in 1.4. */ public long getTimeInMillis() { return time; } /** * Gets the time zone of this calendar * * @return the current time zone. */ public TimeZone getTimeZone() { return zone; } /** * Sets the time field with the given value. This does invalidate the time * in milliseconds. * * @param field * the time field. One of the time field constants * @param value * the value to be set. * @throws ArrayIndexOutOfBoundsException * if field is outside the valid range. The value of field must * be >= 0 and <= <code>FIELD_COUNT</code>. * @specnote Not final since JDK 1.4 */ public void set(int field, int value) { if (isTimeSet) for (int i = 0; i < FIELD_COUNT; i++) isSet[i] = false; isTimeSet = false; fields[field] = value; isSet[field] = true; // The five valid date patterns, in order of priority // 1 YEAR + MONTH + DAY_OF_MONTH // 2 YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK // 3 YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK // 4 YEAR + DAY_OF_YEAR // 5 YEAR + DAY_OF_WEEK + WEEK_OF_YEAR switch (field) { case MONTH: // pattern 1,2 or 3 isSet[DAY_OF_YEAR] = false; isSet[WEEK_OF_YEAR] = false; break; case DAY_OF_MONTH: // pattern 1 isSet[YEAR] = true; isSet[MONTH] = true; isSet[WEEK_OF_MONTH] = true; isSet[DAY_OF_WEEK] = false; isSet[DAY_OF_WEEK_IN_MONTH] = false; isSet[DAY_OF_YEAR] = false; isSet[WEEK_OF_YEAR] = false; break; case WEEK_OF_MONTH: // pattern 2 if (!isSet[DAY_OF_WEEK]) fields[DAY_OF_WEEK] = getFirstDayOfWeek(); isSet[YEAR] = true; isSet[MONTH] = true; isSet[DAY_OF_WEEK] = true; isSet[DAY_OF_MONTH] = false; isSet[DAY_OF_WEEK_IN_MONTH] = false; isSet[DAY_OF_YEAR] = false; isSet[WEEK_OF_YEAR] = false; break; case DAY_OF_WEEK_IN_MONTH: // pattern 3 if (!isSet[DAY_OF_WEEK]) fields[DAY_OF_WEEK] = getFirstDayOfWeek(); isSet[YEAR] = true; isSet[MONTH] = true; isSet[DAY_OF_WEEK] = true; isSet[DAY_OF_YEAR] = false; isSet[DAY_OF_MONTH] = false; isSet[WEEK_OF_MONTH] = false; isSet[WEEK_OF_YEAR] = false; break; case DAY_OF_YEAR: // pattern 4 isSet[YEAR] = true; isSet[MONTH] = false; isSet[WEEK_OF_MONTH] = false; isSet[DAY_OF_MONTH] = false; isSet[DAY_OF_WEEK] = false; isSet[WEEK_OF_YEAR] = false; isSet[DAY_OF_WEEK_IN_MONTH] = false; break; case WEEK_OF_YEAR: // pattern 5 if (!isSet[DAY_OF_WEEK]) fields[DAY_OF_WEEK] = getFirstDayOfWeek(); isSet[YEAR] = true; isSet[DAY_OF_WEEK] = true; isSet[MONTH] = false; isSet[DAY_OF_MONTH] = false; isSet[WEEK_OF_MONTH] = false; isSet[DAY_OF_YEAR] = false; isSet[DAY_OF_WEEK_IN_MONTH] = false; break; case AM_PM: isSet[HOUR] = true; isSet[HOUR_OF_DAY] = false; break; case HOUR_OF_DAY: isSet[AM_PM] = false; isSet[HOUR] = false; break; case HOUR: isSet[AM_PM] = true; isSet[HOUR_OF_DAY] = false; break; case DST_OFFSET: explicitDSTOffset = true; } // May have crossed over a DST boundary. if (!explicitDSTOffset && (field != DST_OFFSET && field != ZONE_OFFSET)) isSet[DST_OFFSET] = false; } /** * Sets this Calendar's time to the given Date. All time fields * are invalidated by this method. */ public final void setTime(Date date) { setTimeInMillis(date.getTime()); } /** * Sets this Calendar's time to the given Time. All time fields are * invalidated by this method. * * @param time * the time in milliseconds since the epoch * @specnote This was made public in 1.4. */ public void setTimeInMillis(long time) { clear(); this.time = time; isTimeSet = true; computeFields(); } /** * Sets the time zone to the specified value. * * @param zone * the new time zone */ public void setTimeZone(TimeZone zone) { this.zone = zone; } private void clear() { isTimeSet = false; areFieldsSet = false; int zoneOffs = zone.getRawOffset(); int[] tempFields = { 1, 1970, JANUARY, 1, 1, 1, 1, THURSDAY, 1, AM, 0, 0, 0, 0, 0, zoneOffs, 0 }; fields = tempFields; for (int i = 0; i < FIELD_COUNT; i++) isSet[i] = false; } /** * Gets what the first day of week is. This is used for WEEK_OF_MONTH and * WEEK_OF_YEAR fields. * * @return the first day of week. One of SUNDAY to SATURDAY. */ private int getFirstDayOfWeek() { return firstDayOfWeek; } /** * Tells if the date/time interpretation is lenient. * * @return true, if the date should be interpreted linient, false if it * should be interpreted strict. */ private boolean isLenient() { return lenient; } /** * Gets how many days are required in the first week of the year. * * @return the minimal days required in the first week. * @see #setMinimalDaysInFirstWeek */ public int getMinimalDaysInFirstWeek() { return minimalDaysInFirstWeek; } } 1.1 jop/java/target/src/jdk11/java/util/Date.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Date.java?rev=1.1&content-type=text/x-cvsweb-markup Index: Date.java =================================================================== /* java.util.Date Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /** * <p> * This class represents a specific time in milliseconds since the epoch. The * epoch is 1970, January 1 00:00:00.0000 UTC. * </p> * <p> * <code>Date</code> is intended to reflect universal time coordinate (UTC), * but this depends on the underlying host environment. Most operating systems * don't handle the leap second, which occurs about once every year or so. The * leap second is added to the last minute of the day on either the 30th of June * or the 31st of December, creating a minute 61 seconds in length. * </p> * <p> * The representations of the date fields are as follows: * <ul> * <li> Years are specified as the difference between the year and 1900. Thus, * the final year used is equal to 1900 + y, where y is the input value. </li> * <li> Months are represented using zero-based indexing, making 0 January and * 11 December. </li> * <li> Dates are represented with the usual values of 1 through to 31. </li> * <li> Hours are represented in the twenty-four hour clock, with integer values * from 0 to 23. 12am is 0, and 12pm is 12. </li> * <li> Minutes are again as usual, with values from 0 to 59. </li> * <li> Seconds are represented with the values 0 through to 61, with 60 and 61 * being leap seconds (as per the ISO C standard). </li> * </ul> * </p> * <p> * Prior to JDK 1.1, this class was the sole class handling date and time * related functionality. However, this particular solution was not amenable to * internationalization. The new <code>Calendar</code> class should now be * used to handle dates and times, with <code>Date</code> being used only for * values in milliseconds since the epoch. The <code>Calendar</code> class, * and its concrete implementations, handle the interpretation of these values * into minutes, hours, days, months and years. The formatting and parsing of * dates is left to the <code>DateFormat</code> class, which is able to handle * the different types of date format which occur in different locales. * </p> * * @see Calendar * @see GregorianCalendar * @see java.text.DateFormat * @author Jochen Hoenicke * @author Per Bothner (bothner@c...) * @author Andrew John Hughes (gnu_andrew@m...) */ public class Date { /** * The time in milliseconds since the epoch. */ private transient long time; /** * An array of week names used to map names to integer values. */ private static final String[] weekNames = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; /** * An array of month names used to map names to integer values. */ private static final String[] monthNames = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; /** * Creates a new Date Object representing the current time. */ public Date() { time = System.currentTimeMillis(); } /** * Creates a new Date Object representing the given time. * * @param time * the time in milliseconds since the epoch. */ public Date(long time) { this.time = time; } /** * Compares two dates for equality. * * @param obj * the object to compare. * @return true, if obj is a Date object and the time represented by obj is * exactly the same as the time represented by this object. */ public boolean equals(Object obj) { return (obj instanceof Date && time == ((Date) obj).time); } /** * Gets the time represented by this object. * * @return the time in milliseconds since the epoch. */ public long getTime() { return time; } /** * Computes the hash code of this <code>Date</code> as the XOR of the most * significant and the least significant 32 bits of the 64 bit milliseconds * value. * * @return the hash code. */ public int hashCode() { return (int) time ^ (int) (time >>> 32); } /** * Sets the time which this object should represent. * * @param time * the time in milliseconds since the epoch. */ public void setTime(long time) { this.time = time; } /** * <p> * Returns a string representation of this date using the following date * format: * </p> * <p> * <code>day mon dd hh:mm:ss zz yyyy</code> * </p> * <p> * where the fields used here are: * <ul> * <li> <code>day</code> -- the day of the week (Sunday through to * Saturday). </li> * <li> <code>mon</code> -- the month (Jan to Dec). </li> * <li> <code>dd</code> -- the day of the month as two decimal digits (01 * to 31). </li> * <li> <code>hh</code> -- the hour of the day as two decimal digits in * 24-hour clock notation (01 to 23). </li> * <li> <code>mm</code> -- the minute of the day as two decimal digits (01 * to 59). </li> * <li> <code>ss</code> -- the second of the day as two decimal digits (01 * to 61). </li> * <li> <code>zz</code> -- the time zone information if available. The * possible time zones used include the abbreviations recognised by * <code>parse()</code> (e.g. GMT, CET, etc.) and may reflect the fact * that daylight savings time is in effect. The empty string is used if * there is no time zone information. </li> * <li> <code>yyyy</code> -- the year as four decimal digits. </li> * </ul> * <p> * The <code>DateFormat</code> class should now be preferred over using * this method. * </p> * * @return A string of the form 'day mon dd hh:mm:ss zz yyyy' * @see #parse(String) * @see DateFormat */ public String toString() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); String day = "0" + cal.get(Calendar.DATE); String hour = "0" + cal.get(Calendar.HOUR_OF_DAY); String min = "0" + cal.get(Calendar.MINUTE); String sec = "0" + cal.get(Calendar.SECOND); String year = "000" + cal.get(Calendar.YEAR); return weekNames[cal.get(Calendar.DAY_OF_WEEK) - 1] + " " + monthNames[cal.get(Calendar.MONTH)] + " " + day.substring(day.length() - 2) + " " + hour.substring(hour.length() - 2) + ":" + min.substring(min.length() - 2) + ":" + sec.substring(sec.length() - 2) + " " + year.substring(year.length() - 4); } } 1.1 jop/java/target/src/jdk11/java/util/EmptyStackException.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/EmptyStackException.java?rev=1.1&content-type=text/x-cvsweb-markup Index: EmptyStackException.java =================================================================== /* EmptyStackException.java -- Attempt to pop from an empty stack Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /* * Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 "The * Java Language Specification", ISBN 0-201-63451-1 plus online API docs for JDK * 1.2 beta from http://www.javasoft.com. */ /** * This exception is thrown by the Stack class when an attempt is made to pop or * otherwise access elements from an empty stack. * * @author Warren Levy (warrenl@c...) * @author Eric Blake (ebb9@e...) * @see Stack * @since 1.0 * @status updated to 1.4 */ public class EmptyStackException extends RuntimeException { /** * Compatible with JDK 1.0. */ private static final long serialVersionUID = 5084686378493302095L; /** * Constructs an EmptyStackException with no detail message. */ public EmptyStackException() { } } 1.1 jop/java/target/src/jdk11/java/util/Enumeration.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Enumeration.java?rev=1.1&content-type=text/x-cvsweb-markup Index: Enumeration.java =================================================================== /* Enumeration.java -- Interface for enumerating lists of objects Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 * "The Java Language Specification", ISBN 0-201-63451-1. * Status: Believed complete and correct */ /** * Interface for lists of objects that can be returned in sequence. Successive * objects are obtained by the nextElement method. * <p> * As of Java 1.2, the Iterator interface provides the same functionality, but * with shorter method names and a new optional method to remove items from the * list. If writing for 1.2, consider using Iterator instead. Enumerations over * the new collections classes, for use with legacy APIs that require them, can * be obtained by the enumeration method in class Collections. * * @author Warren Levy (warrenl@c...) * @author Eric Blake (ebb9@e...) * @see Iterator * @see Hashtable * @see Vector * @since 1.0 * @status updated to 1.4 */ public interface Enumeration { /** * Tests whether there are elements remaining in the enumeration. * * @return true if there is at least one more element in the enumeration, * that is, if the next call to nextElement will not throw a * NoSuchElementException. */ boolean hasMoreElements(); /** * Obtain the next element in the enumeration. * * @return the next element in the enumeration * @throws NoSuchElementException if there are no more elements */ Object nextElement(); } 1.1 jop/java/target/src/jdk11/java/util/Hashtable.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Hashtable.java?rev=1.1&content-type=text/x-cvsweb-markup Index: Hashtable.java =================================================================== /* Hashtable.java -- a class providing a basic hashtable data structure, mapping Object --> Object Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; // NOTE: This implementation is very similar to that of HashMap. If you fix // a bug in here, chances are you should make a similar change to the HashMap // code. /** * A class which implements a hashtable data structure. * <p> * * This implementation of Hashtable uses a hash-bucket approach. That is: linear * probing and rehashing is avoided; instead, each hashed value maps to a simple * linked-list which, in the best case, only has one node. Assuming a large * enough table, low enough load factor, and / or well implemented hashCode() * methods, Hashtable should provide O(1) insertion, deletion, and searching of * keys. Hashtable is O(n) in the worst case for all of these (if all keys hash * to the same bucket). * <p> * * This is a JDK-1.2 compliant implementation of Hashtable. As such, it belongs, * partially, to the Collections framework (in that it implements Map). For * backwards compatibility, it inherits from the obsolete and utterly useless * Dictionary class. * <p> * * Being a hybrid of old and new, Hashtable has methods which provide redundant * capability, but with subtle and even crucial differences. For example, one * can iterate over various aspects of a Hashtable with either an Iterator * (which is the JDK-1.2 way of doing things) or with an Enumeration. The latter * can end up in an undefined state if the Hashtable changes while the * Enumeration is open. * <p> * * Unlike HashMap, Hashtable does not accept `null' as a key value. Also, all * accesses are synchronized: in a single thread environment, this is expensive, * but in a multi-thread environment, this saves you the effort of extra * synchronization. However, the old-style enumerators are not synchronized, * because they can lead to unspecified behavior even if they were synchronized. * You have been warned. * <p> * * The iterators are <i>fail-fast</i>, meaning that any structural * modification, except for <code>remove()</code> called on the iterator * itself, cause the iterator to throw a * <code>ConcurrentModificationException</code> rather than exhibit * non-deterministic behavior. * * @author Jon Zeppieri * @author Warren Levy * @author Bryce McKinlay * @author Eric Blake (ebb9@e...) * @see HashMap * @see TreeMap * @see IdentityHashMap * @see LinkedHashMap * @since 1.0 * @status updated to 1.4 */ public class Hashtable { // WARNING: Hashtable is a CORE class in the bootstrap cycle. See the // comments in vm/reference/java/lang/Runtime for implications of this fact. /** * Default number of buckets. This is the value the JDK 1.3 uses. Some early * documentation specified this value as 101. That is incorrect. */ private static final int DEFAULT_CAPACITY = 11; /** * Array containing the actual key-value mappings. */ // Package visible for use by nested classes. transient HashEntry[] buckets; /** * Counts the number of modifications this Hashtable has undergone, used by * Iterators to know when to throw ConcurrentModificationExceptions. */ // Package visible for use by nested classes. transient int modCount; /** * The size of this Hashtable: denotes the number of key-value pairs. */ // Package visible for use by nested classes. transient int size; private int threshold = 0; /** * Class to represent an entry in the hash table. Holds a single key-value * pair. A Hashtable Entry is identical to a HashMap Entry, except that * `null' is not allowed for keys and values. */ private static final class HashEntry { /** The next entry in the linked list. */ HashEntry next; Object key; Object value; /** * Simple constructor. * * @param key * the key, already guaranteed non-null * @param value * the value, already guaranteed non-null */ HashEntry(Object key, Object value) { this.key = key; this.value = value; } /** * Resets the value. * * @param newVal * the new value * @return the prior value * @throws NullPointerException * if <code>newVal</code> is null */ public Object setValue(Object newVal) { if (newVal == null) throw new NullPointerException(); Object r = value; value = newVal; return r; } } /** * Construct a new Hashtable with the default capacity (11) and the default * load factor (0.75). */ public Hashtable() { this(DEFAULT_CAPACITY); } /** * Construct a new Hashtable with a specific inital capacity and default * load factor of 0.75. * * @param initialCapacity * the initial capacity of this Hashtable (&gt;= 0) * @throws IllegalArgumentException * if (initialCapacity &lt; 0) */ public Hashtable(int initialCapacity) { if (initialCapacity < 0) throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity); if (initialCapacity == 0) initialCapacity = 1; buckets = new HashEntry[initialCapacity]; } /** * Clears the hashtable so it has no keys. This is O(1). */ public synchronized void clear() { // TODO: if (size > 0) { modCount++; for (int i = buckets.length - 1; i >= 0; i--) { buckets[i] = null; } size = 0; } } /** * Returns true if this Hashtable contains a value <code>o</code>, such * that <code>o.equals(value)</code>. This is the same as * <code>containsValue()</code>, and is O(n). * <p> * * @param value * the value to search for in this Hashtable * @return true if at least one key maps to the value * @throws NullPointerException * if <code>value</code> is null * @see #containsValue(Object) * @see #containsKey(Object) */ public synchronized boolean contains(Object value) { if (value == null) { throw new NullPointerException(); } for (int i = buckets.length - 1; i >= 0; i--) { HashEntry e = buckets[i]; while (e != null) { // MARITN: if uncomment this, the path of execution changes // System.out.println("Debugmsg 3"); if (e.value.equals(value)) { return true; } e = e.next; } } return false; } /** * Returns true if the supplied object <code>equals()</code> a key in this * Hashtable. * * @param key * the key to search for in this Hashtable * @return true if the key is in the table * @throws NullPointerException * if key is null * @see #containsValue(Object) */ public synchronized boolean containsKey(Object key) { int idx = hash(key); HashEntry e = buckets[idx]; while (e != null) { if (e.key.equals(key)) return true; e = e.next; } return false; } /** * Return an enumeration of the values of this table. There's no point in * synchronizing this, as you have already been warned that the enumeration * is not specified to be thread-safe. * * @return the values * @see #keys() * @see #values() */ public Enumeration elements() { return new ValueEnumerator(); } /** * Return the value in this Hashtable associated with the supplied key, or * <code>null</code> if the key maps to nothing. * * @param key * the key for which to fetch an associated value * @return what the key maps to, if present * @throws NullPointerException * if key is null * @see #put(Object, Object) * @see #containsKey(Object) */ public synchronized Object get(Object key) { int idx = hash(key); HashEntry e = buckets[idx]; while (e != null) { if (e.key.equals(key)) return e.value; e = e.next; } return null; } /** * Returns true if there are no key-value mappings currently in this table. * * @return <code>size() == 0</code> */ public synchronized boolean isEmpty() { return size == 0; } /** * Return an enumeration of the keys of this table. There's no point in * synchronizing this, as you have already been warned that the enumeration * is not specified to be thread-safe. * * @return the keys * @see #elements() * @see #keySet() */ public Enumeration keys() { return new KeyEnumerator(); } /** * Puts the supplied value into the Map, mapped by the supplied key. Neither * parameter may be null. The value may be retrieved by any object which * <code>equals()</code> this key. * * @param key * the key used to locate the value * @param value * the value to be stored in the table * @return the prior mapping of the key, or null if there was none * @throws NullPointerException * if key or value is null * @see #get(Object) * @see Object#equals(Object) */ public synchronized Object put(Object key, Object value) { int idx = hash(key); HashEntry e = buckets[idx]; // Check if value is null since it is not permitted. if (value == null) throw new NullPointerException(); while (e != null) { if (e.key.equals(key)) { // Bypass e.setValue, since we already know value is non-null. Object r = e.value; e.value = value; return r; } else { e = e.next; } } // At this point, we know we need to add a new entry. modCount++; if (++size > threshold) { rehash(); // Need a new hash value to suit the bigger table. idx = hash(key); } e = new HashEntry(key, value); e.next = buckets[idx]; buckets[idx] = e; return null; } /** * Increases the size of the Hashtable and rehashes all keys to new array * indices; this is called when the addition of a new value would cause * size() &gt; threshold. Note that the existing Entry objects are reused in * the new hash table. * <p> * * This is not specified, but the new size is twice the current size plus * one; this number is not always prime, unfortunately. This implementation * is not synchronized, as it is only invoked from synchronized methods. */ protected void rehash() { HashEntry[] oldBuckets = buckets; int newcapacity = (buckets.length * 2) + 1; threshold = newcapacity; buckets = new HashEntry[newcapacity]; for (int i = oldBuckets.length - 1; i >= 0; i--) { HashEntry e = oldBuckets[i]; while (e != null) { int idx = hash(e.key); HashEntry dest = buckets[idx]; if (dest != null) { HashEntry next = dest.next; while (next != null) { dest = next; next = dest.next; } dest.next = e; } else { buckets[idx] = e; } HashEntry next = e.next; e.next = null; e = next; } } } /** * Removes from the table and returns the value which is mapped by the * supplied key. If the key maps to nothing, then the table remains * unchanged, and <code>null</code> is returned. * * @param key * the key used to locate the value to remove * @return whatever the key mapped to, if present */ public synchronized Object remove(Object key) { int idx = hash(key); HashEntry e = buckets[idx]; HashEntry last = null; while (e != null) { if (e.key.equals(key)) { modCount++; if (last == null) buckets[idx] = e.next; else last.next = e.next; size--; return e.value; } last = e; e = e.next; } return null; } /** * Returns the number of key-value mappings currently in this hashtable. * * @return the size */ public synchronized int size() { return size; } /** * Converts this Hashtable to a String, surrounded by braces, and with * key/value pairs listed with an equals sign between, separated by a comma * and space. For example, <code>"{a=1, b=2}"</code>. * <p> * * NOTE: if the <code>toString()</code> method of any key or value throws * an exception, this will fail for the same reason. * * @return the string representation */ public synchronized String toString() { // Since we are already synchronized, and entrySet().iterator() // would repeatedly re-lock/release the monitor, we directly use the // unsynchronized EntryIterator instead. Iterator entries = new EntryIterator(); StringBuffer r = new StringBuffer("{\r\n"); for (int pos = size; pos > 0; pos--) { Object obj = new Object(); r.append(obj); if (pos > 1) r.append(", "); r.append("\r\n"); } r.append("}"); return r.toString(); } /** * Helper method that returns an index in the buckets array for `key' based * on its hashCode(). * * @param key * the key * @return the bucket number * @throws NullPointerException * if key is null */ private int hash(Object key) { // Note: Inline Math.abs here, for less method overhead, and to avoid // a bootstrap dependency, since Math relies on native methods. int hash = key.hashCode() % buckets.length; return hash < 0 ? -hash : hash; } /** * Returns the hashCode for this Hashtable. As specified by Map, this is the * sum of the hashCodes of all of its Map.Entry objects * * @return the sum of the hashcodes of the entries * @since 1.2 */ public synchronized int hashCode() { // Since we are already synchronized, and entrySet().iterator() // would repeatedly re-lock/release the monitor, we directly use the // unsynchronized EntryIterator instead. Iterator itr = new EntryIterator(); int hashcode = 0; for (int pos = size; pos > 0; pos--) hashcode += itr.next().hashCode(); return hashcode; } /** * Enumeration view of the entries in this Hashtable, providing sequential * access to its elements. * * <b>NOTE</b>: Enumeration is not safe if new elements are put in the * table as this could cause a rehash and we'd completely lose our place. * Even without a rehash, it is undetermined if a new element added would * appear in the enumeration. The spec says nothing about this, but the * "Java Class Libraries" book implies that modifications to the hashtable * during enumeration causes indeterminate results. Don't do it! * * @author Jon Zeppieri * @author Fridjof Siebert */ private class EntryEnumerator implements Enumeration { /** The number of elements remaining to be returned by next(). */ int count = size; /** Current index in the physical hash table. */ int idx = buckets.length; /** * Entry which will be returned by the next nextElement() call. It is * set if we are iterating through a bucket with multiple entries, or * null if we must look in the next bucket. */ HashEntry next; /** * Construct the enumeration. */ EntryEnumerator() { // Nothing to do here. } /** * Checks whether more elements remain in the enumeration. * * @return true if nextElement() will not fail. */ public boolean hasMoreElements() { return count > 0; } /** * Returns the next element. * * @return the next element * @throws NoSuchElementException * if there is none. */ public Object nextElement() { if (count == 0) throw new NoSuchElementException("Hashtable Enumerator"); count--; HashEntry e = next; while (e == null) if (idx <= 0) return null; else e = buckets[--idx]; next = e.next; return e; } } // class EntryEnumerator /** * Enumeration view of this Hashtable, providing sequential access to its * values. * * <b>NOTE</b>: Enumeration is not safe if new elements are put in the * table as this could cause a rehash and we'd completely lose our place. * Even without a rehash, it is undetermined if a new element added would * appear in the enumeration. The spec says nothing about this, but the * "Java Class Libraries" book implies that modifications to the hashtable * during enumeration causes indeterminate results. Don't do it! * * @author Jon Zeppieri * @author Fridjof Siebert */ private final class ValueEnumerator extends EntryEnumerator { /** * Returns the next element. * * @return the next element * @throws NoSuchElementException * if there is none. */ public Object nextElement() { HashEntry entry = (HashEntry) super.nextElement(); Object retVal = null; if (entry != null) retVal = entry.value; return retVal; } } // class ValueEnumerator /** * Enumeration view of this Hashtable, providing sequential access to its * elements. * * <b>NOTE</b>: Enumeration is not safe if new elements are put in the * table as this could cause a rehash and we'd completely lose our place. * Even without a rehash, it is undetermined if a new element added would * appear in the enumeration. The spec says nothing about this, but the * "Java Class Libraries" book implies that modifications to the hashtable * during enumeration causes indeterminate results. Don't do it! * * @author Jon Zeppieri * @author Fridjof Siebert */ private final class KeyEnumerator extends EntryEnumerator { /** * Returns the next element. * * @return the next element * @throws NoSuchElementException * if there is none. */ public Object nextElement() { HashEntry entry = (HashEntry) super.nextElement(); Object retVal = null; if (entry != null) retVal = entry.key; return retVal; } } // class KeyEnumerator /** * A class which implements the Iterator interface and is used for iterating * over Hashtables. This implementation iterates entries. Subclasses are * used to iterate key and values. It also allows the removal of elements, * as per the Javasoft spec. Note that it is not synchronized; this is a * performance enhancer since it is never exposed externally and is only * used within synchronized blocks above. * * @author Jon Zeppieri * @author Fridjof Siebert */ private class EntryIterator implements Iterator { /** * The number of modifications to the backing Hashtable that we know * about. */ int knownMod = modCount; /** The number of elements remaining to be returned by next(). */ int count = size; /** Current index in the physical hash table. */ int idx = buckets.length; /** The last Entry returned by a next() call. */ HashEntry last; /** * The next entry that should be returned by next(). It is set to * something if we're iterating through a bucket that contains multiple * linked entries. It is null if next() needs to find a new bucket. */ HashEntry next; /** * Construct a new EtryIterator */ EntryIterator() { } /** * Returns true if the Iterator has more elements. * * @return true if there are more elements */ public boolean hasNext() { return count > 0; } /** * Returns the next element in the Iterator's sequential view. * * @return the next element * @throws ConcurrentModificationException * if the hashtable was modified * @throws NoSuchElementException * if there is none */ public Object next() { if (knownMod != modCount) // TODO: throw new ConcurrentModificationException(); if (count == 0) // TODO: throw new NoSuchElementException(); count--; HashEntry e = next; while (e == null) if (idx <= 0) return null; else e = buckets[--idx]; next = e.next; last = e; return e; } /** * Removes from the backing Hashtable the last element which was fetched * with the <code>next()</code> method. * * @throws ConcurrentModificationException * if the hashtable was modified * @throws IllegalStateException * if called when there is no last element */ public void remove() { if (knownMod != modCount) // TODO: throw new Exception(); if (last == null) // TODO: throw new Exception(); Hashtable.this.remove(last.key); last = null; knownMod++; } } // class EntryIterator } // class Hashtable 1.1 jop/java/target/src/jdk11/java/util/Iterator.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Iterator.java?rev=1.1&content-type=text/x-cvsweb-markup Index: Iterator.java =================================================================== /* Iterator.java -- Interface for iterating over collections Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /** * An object which iterates over a collection. An Iterator is used to return * the items once only, in sequence, by successive calls to the next method. * It is also possible to remove elements from the underlying collection by * using the optional remove method. Iterator is intended as a replacement * for the Enumeration interface of previous versions of Java, which did not * have the remove method and had less conveniently named methods. * * @author Original author unknown * @author Eric Blake (ebb9@e...) * @see Collection * @see ListIterator * @see Enumeration * @since 1.2 * @status updated to 1.4 */ public interface Iterator { /** * Tests whether there are elements remaining in the collection. In other * words, calling <code>next()</code> will not throw an exception. * * @return true if there is at least one more element in the collection */ boolean hasNext(); /** * Obtain the next element in the collection. * * @return the next element in the collection * @throws NoSuchElementException if there are no more elements */ Object next(); /** * Remove from the underlying collection the last element returned by next * (optional operation). This method can be called only once after each * call to <code>next()</code>. It does not affect what will be returned * by subsequent calls to next. * * @throws IllegalStateException if next has not yet been called or remove * has already been called since the last call to next. * @throws UnsupportedOperationException if this Iterator does not support * the remove operation. */ void remove(); } 1.1 jop/java/target/src/jdk11/java/util/NoSuchElementException.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/NoSuchElementException.java?rev=1.1&content-type=text/x-cvsweb-markup Index: NoSuchElementException.java =================================================================== /* NoSuchElementException.java -- Attempt to access element that does not exist Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 * "The Java Language Specification", ISBN 0-201-63451-1 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. */ /** * Exception thrown when an attempt is made to access an element that does not * exist. This exception is thrown by the Enumeration, Iterator and * ListIterator classes if the nextElement, next or previous method goes * beyond the end of the list of elements that are being accessed. It is also * thrown by Vector and Stack when attempting to access the first or last * element of an empty collection. * * @author Warren Levy (warrenl@c...) * @author Eric Blake (ebb9@e...) * @see Enumeration * @see Iterator * @see ListIterator * @see Enumeration#nextElement() * @see Iterator#next() * @see ListIterator#previous() * @since 1.0 * @status updated to 1.4 */ public class NoSuchElementException extends RuntimeException { /** * Compatible with JDK 1.0. */ private static final long serialVersionUID = 6769829250639411880L; /** * Constructs a NoSuchElementException with no detail message. */ public NoSuchElementException() { } /** * Constructs a NoSuchElementException with a detail message. * * @param detail the detail message for the exception */ public NoSuchElementException(String detail) { super(detail); } } 1.1 jop/java/target/src/jdk11/java/util/Random.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Random.java?rev=1.1&content-type=text/x-cvsweb-markup Index: Random.java =================================================================== /* Random.java -- a pseudo-random number generator Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /** * This class generates pseudorandom numbers. It uses the same algorithm as the * original JDK-class, so that your programs behave exactly the same way, if * started with the same seed. * * The algorithm is described in <em>The Art of Computer Programming, * Volume 2</em> * by Donald Knuth in Section 3.2.1. It is a 48-bit seed, linear congruential * formula. * * If two instances of this class are created with the same seed and the same * calls to these classes are made, they behave exactly the same way. This * should be even true for foreign implementations (like this), so every port * must use the same algorithm as described here. * * If you want to implement your own pseudorandom algorithm, you should extend * this class and overload the <code>next()</code> and * <code>setSeed(long)</code> method. In that case the above paragraph doesn't * apply to you. * * This class shouldn't be used for security sensitive purposes (like generating * passwords or encryption keys. See <code>SecureRandom</code> in package * <code>java.security</code> for this purpose. * * For simple random doubles between 0.0 and 1.0, you may consider using * Math.random instead. * * @see java.security.SecureRandom * @see Math#random() * @author Jochen Hoenicke * @author Eric Blake (ebb9@e...) * @status updated to 1.4 */ public class Random { /** * True if the next nextGaussian is available. This is used by nextGaussian, * which generates two gaussian numbers by one call, and returns the second * on the second call. * * @serial whether nextNextGaussian is available * @see #nextGaussian() * @see #nextNextGaussian */ private boolean haveNextNextGaussian; /** * The next nextGaussian, when available. This is used by nextGaussian, * which generates two gaussian numbers by one call, and returns the second * on the second call. * * @serial the second gaussian of a pair * @see #nextGaussian() * @see #haveNextNextGaussian */ private double nextNextGaussian; /** * The seed. This is the number set by setSeed and which is used in next. * * @serial the internal state of this generator * @see #next(int) */ private long seed; /** * Compatible with JDK 1.0+. */ private static final long serialVersionUID = 3905348978240129619L; /** * Creates a new pseudorandom number generator. The seed is initialized to * the current time, as if by * <code>setSeed(System.currentTimeMillis());</code>. * * @see System#currentTimeMillis() */ public Random() { this(System.currentTimeMillis()); } /** * Creates a new pseudorandom number generator, starting with the specified * seed, using <code>setSeed(seed);</code>. * * @param seed * the initial seed */ public Random(long seed) { setSeed(seed); } /** * Sets the seed for this pseudorandom number generator. As described above, * two instances of the same random class, starting with the same seed, * should produce the same results, if the same methods are called. The * implementation for java.util.Random is: * * <pre> * public synchronized void setSeed(long seed) { * this.seed = (seed &circ; 0x5DEECE66DL) &amp; ((1L &lt;&lt; 48) - 1); * haveNextNextGaussian = false; * } * </pre> * * @param seed * the new seed */ public synchronized void setSeed(long seed) { this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1); haveNextNextGaussian = false; } /** * Generates the next pseudorandom number. This returns an int value whose * <code>bits</code> low order bits are independent chosen random bits (0 * and 1 are equally likely). The implementation for java.util.Random is: * * <pre> * protected synchronized int next(int bits) { * seed = (seed * 0x5DEECE66DL + 0xBL) &amp; ((1L &lt;&lt; 48) - 1); * return (int) (seed &gt;&gt;&gt; (48 - bits)); * } * </pre> * * @param bits * the number of random bits to generate, in the range 1..32 * @return the next pseudorandom value * @since 1.1 */ protected synchronized int next(int bits) { seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1); return (int) (seed >>> (48 - bits)); } /** * Generates the next pseudorandom number. This returns an int value whose * 32 bits are independent chosen random bits (0 and 1 are equally likely). * The implementation for java.util.Random is: * * <pre> * public int nextInt() { * return next(32); * } * </pre> * * @return the next pseudorandom value */ public int nextInt() { return next(32); } /** * Generates the next pseudorandom long number. All bits of this long are * independently chosen and 0 and 1 have equal likelihood. The * implementation for java.util.Random is: * * <pre> * public long nextLong() { * return ((long) next(32) &lt;&lt; 32) + next(32); * } * </pre> * * @return the next pseudorandom value */ public long nextLong() { return ((long) next(32) << 32) + next(32); } } 1.1 jop/java/target/src/jdk11/java/util/Stack.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Stack.java?rev=1.1&content-type=text/x-cvsweb-markup Index: Stack.java =================================================================== /* Stack.java - Class that provides a Last In First Out (LIFO) datatype, known more commonly as a Stack Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /* * Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 "The * Java Language Specification", ISBN 0-201-63451-1 plus online API docs for JDK * 1.2 beta from http://www.javasoft.com. Status: Believed complete and correct * * /** Stack provides a Last In First Out (LIFO) data type, commonly known as a * Stack. Stack itself extends Vector and provides the additional methods for * stack manipulation (push, pop, peek). You can also seek for the 1-based * position of an element on the stack. * * @author Warren Levy (warrenl@c...) @author Eric Blake * (ebb9@e...) * * @see List * @see AbstractList * @see LinkedList * @since 1.0 @status updated to 1.4 */ public class Stack extends Vector { // We could use Vector methods internally for the following methods, // but have used Vector fields directly for efficiency (i.e. this // often reduces out duplicate bounds checking). /** * Compatible with JDK 1.0+. */ // private static final long serialVersionUID = 1224463164541339165L; /** * This constructor creates a new Stack, initially empty */ public Stack() { } /** * Pushes an Object onto the top of the stack. This method is effectively * the same as addElement(item). * * @param item * the Object to push onto the stack * @return the Object pushed onto the stack * @see Vector#addElement(Object) */ public Object push(Object item) { // When growing the Stack, use the Vector routines in case more // memory is needed. // Note: spec indicates that this method *always* returns obj passed in! addElement(item); return item; } /** * Pops an item from the stack and returns it. The item popped is removed * from the Stack. * * @return the Object popped from the stack * @throws EmptyStackException * if the stack is empty */ public synchronized Object pop() { if (elementCount == 0) throw new EmptyStackException(); modCount++; Object obj = elementData[--elementCount]; // Set topmost element to null to assist the gc in cleanup. elementData[elementCount] = null; return obj; } /** * Returns the top Object on the stack without removing it. * * @return the top Object on the stack * @throws EmptyStackException * if the stack is empty */ public synchronized Object peek() { if (elementCount == 0) throw new EmptyStackException(); return elementData[elementCount - 1]; } /** * Tests if the stack is empty. * * @return true if the stack contains no items, false otherwise */ public synchronized boolean empty() { return elementCount == 0; } /** * Returns the position of an Object on the stack, with the top most Object * being at position 1, and each Object deeper in the stack at depth + 1. * * @param o * The object to search for * @return The 1 based depth of the Object, or -1 if the Object is not on * the stack */ public synchronized int search(Object o) { int i = elementCount; while (--i >= 0) if (elementData[i].equals(o)) return elementCount - i; return -1; } } 1.1 jop/java/target/src/jdk11/java/util/TimeZone.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/TimeZone.java?rev=1.1&content-type=text/x-cvsweb-markup Index: TimeZone.java =================================================================== /* java.util.TimeZone Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /** * This class represents a time zone offset and handles daylight savings. * * You can get the default time zone with <code>getDefault</code>. This * represents the time zone where program is running. * * Another way to create a time zone is <code>getTimeZone</code>, where you * can give an identifier as parameter. For instance, the identifier of the * Central European Time zone is "CET". * * With the <code>getAvailableIDs</code> method, you can get all the supported * time zone identifiers. * * @see Calendar * @see SimpleTimeZone * @author Jochen Hoenicke */ public abstract class TimeZone { /** * Constant used to indicate that a short timezone abbreviation should be * returned, such as "EST" */ public static final int SHORT = 0; /** * Constant used to indicate that a long timezone name should be returned, * such as "Eastern Standard Time". */ public static final int LONG = 1; /** * The time zone identifier, e.g. PST. */ private String ID; /** * The default time zone, as returned by getDefault. */ private static TimeZone defaultZone0; public TimeZone() { } /** * Gets all available IDs. * * @return An array of all supported IDs. */ public static String[] getAvailableIDs() { String[] jopId = new String[1]; jopId[0] = "joptimezone"; return jopId; } /** * Returns the time zone under which the host is running. This can be * changed with setDefault. * * @return A clone of the current default time zone for this host. * @see #setDefault */ public static TimeZone getDefault() { return defaultZone0; } /** * Gets the identifier of this time zone. For instance, PST for Pacific * Standard Time. * * @returns the ID of this time zone. */ public String getID() { return ID; } /** * Gets the time zone offset, for current date, modified in case of daylight * savings. This is the offset to add to UTC to get the local time. * * @param era * the era of the given date * @param year * the year of the given date * @param month * the month of the given date, 0 for January. * @param day * the day of month * @param dayOfWeek * the day of week * @param milliseconds * the millis in the day (in local standard time) * @return the time zone offset in milliseconds. */ public abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds); /** * Gets the time zone offset, ignoring daylight savings. This is the offset * to add to UTC to get the local time. * * @return the time zone offset in milliseconds. */ public abstract int getRawOffset(); /** * Gets the TimeZone for the given ID. * * @param ID * the time zone identifier. * @return The time zone for the identifier or GMT, if no such time zone * exists. */ // FIXME: XXX: JCL indicates this and other methods are synchronized. public static TimeZone getTimeZone(String ID) { return defaultZone0; } /** * Returns true, if this time zone uses Daylight Savings Time. */ public abstract boolean useDaylightTime(); } 1.1 jop/java/target/src/jdk11/java/util/Vector.java http://www.opencores.org/cvsweb.shtml/jop/java/target/src/jdk11/java/util/Vector.java?rev=1.1&content-type=text/x-cvsweb-markup Index: Vector.java =================================================================== /* Vector.java -- Class that provides growable arrays. Copyright (C) 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath 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 2, or (at your option) any later version. GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package java.util; /** * The <code>Vector</code> classes implements growable arrays of Objects. You * can access elements in a Vector with an index, just as you can in a built in * array, but Vectors can grow and shrink to accommodate more or fewer objects. * <p> * * Vectors try to mantain efficiency in growing by having a * <code>capacityIncrement</code> that can be specified at instantiation. When * a Vector can no longer hold a new Object, it grows by the amount in * <code>capacityIncrement</code>. If this value is 0, the vector doubles in * size. * <p> * * Vector implements the JDK 1.2 List interface, and is therefore a fully * compliant Collection object. The iterators are fail-fast - if external code * structurally modifies the vector, any operation on the iterator will then * throw a {@link ConcurrentModificationException}. The Vector class is fully * synchronized, but the iterators are not. So, when iterating over a vector, be * sure to synchronize on the vector itself. If you don't want the expense of * synchronization, use ArrayList instead. On the other hand, the Enumeration of * elements() is not thread-safe, nor is it fail-fast; so it can lead to * undefined behavior even in a single thread if you modify the vector during * iteration. * <p> * * Note: Some methods, especially those specified by List, specify throwing * {@link IndexOutOfBoundsException}, but it is easier to implement by throwing * the subclass {@link ArrayIndexOutOfBoundsException}. Others directly specify * this subclass. * * @author Scott G. Miller * @author Bryce McKinlay * @author Eric Blake (ebb9@e...) * @see Collection * @see List * @see ArrayList * @see LinkedList * @since 1.0 * @status updated to 1.4 */ public class Vector { /** * The internal array used to hold members of a Vector. The elements are in * positions 0 through elementCount - 1, and all remaining slots are null. * * @serial the elements */ protected Object[] elementData; /** * The number of elements currently in the vector, also returned by * {@link #size}. * * @serial the size */ protected int elementCount; /** * The amount the Vector's internal array should be increased in size when a * new element is added that exceeds the current size of the array, or when * {@link #ensureCapacity} is called. If &lt;= 0, the vector just doubles in * size. * * @serial the amount to grow the vector by */ protected int capacityIncrement; /** * A count of the number of structural modifications that have been made to * the list (that is, insertions and removals). */ protected int modCount; /** * Constructs an empty vector with an initial size of 10, and a capacity * increment of 0 */ public Vector() { this(10, 0); } /** * Constructs a Vector with the initial capacity and capacity increment * specified. * * @param initialCapacity * the initial size of the Vector's internal array * @param capacityIncrement * the amount the internal array should be increased by when * necessary, 0 to double the size * @throws IllegalArgumentException * if initialCapacity &lt; 0 */ public Vector(int initialCapacity, int capacityIncrement) { if (initialCapacity < 0) throw new IllegalArgumentException(); elementData = new Object[initialCapacity]; this.capacityIncrement = capacityIncrement; modCount = 0; } /** * Constructs a Vector with the initial capacity specified, and a capacity * increment of 0 (double in size). * * @param initialCapacity * the initial size of the Vector's internal array * @throws IllegalArgumentException * if initialCapacity &lt; 0 */ public Vector(int initialCapacity) { this(initialCapacity, 0); } /** * Adds an element to the Vector at the end of the Vector. The vector is * increased by ensureCapacity(size() + 1) if needed. * * @param obj * the object to add to the Vector */ public synchronized void addElement(Object obj) { if (elementCount == elementData.length) ensureCapacity(elementCount + 1); modCount++; elementData[elementCount++] = obj; } /** * Returns the size of the internal data array (not the amount of elements * contained in the Vector). * * @return capacity of the internal data array */ public synchronized int capacity() { return elementData.length; } /** * Returns true when <code>elem</code> is contained in this Vector. * * @param elem * the element to check * @return true if the object is contained in this Vector, false otherwise */ public boolean contains(Object elem) { return indexOf(elem, 0) >= 0; } /** * Copies the contents of the Vector into the provided array. If the array * is too small to fit all the elements in the Vector, an * {@link IndexOutOfBoundsException} is thrown without modifying the array. * Old elements in the array are overwritten by the new elements. * * @param a * target array for the copy * @throws IndexOutOfBoundsException * the array is not large enough * @throws NullPointerException * the array is null * @see #toArray(Object[]) */ public synchronized void copyInto(Object[] a) { System.arraycopy(elementData, 0, a, 0, elementCount); } /** * Returns the Object stored at <code>index</code>. * * @param index * the index of the Object to retrieve * @return the object at <code>index</code> * @throws ArrayIndexOutOfBoundsException * index &lt; 0 || index &gt;= size() * @see #get(int) */ public synchronized Object elementAt(int index) { checkBoundExclusive(index); return elementData[index]; } /** * Returns an Enumeration of the elements of this Vector. The enumeration * visits the elements in increasing index order, but is NOT thread-safe. * * @return an Enumeration * @see #iterator() */ // No need to synchronize as the Enumeration is not thread-safe! public Enumeration elements() { return new Enumeration() { private int i = 0; public boolean hasMoreElements() { return i < elementCount; } public Object nextElement() { if (i >= elementCount) throw new NoSuchElementException(); return elementData[i++]; } }; } /** * Ensures that <code>minCapacity</code> elements can fit within this * Vector. If <code>elementData</code> is too small, it is expanded as * follows: If the <code>elementCount + capacityIncrement</code> is * adequate, that is the new size. If <code>capacityIncrement</code> is * non-zero, the candidate size is double the current. If that is not * enough, the new size is <code>minCapacity</code>. * * @param minCapacity * the desired minimum capacity, negative values ignored */ public synchronized void ensureCapacity(int minCapacity) { if (elementData.length >= minCapacity) return; int newCapacity; if (capacityIncrement <= 0) newCapacity = elementData.length * 2; else newCapacity = elementData.length + capacityIncrement; // TODO: any way to omit this new? Object[] newArray = new Object[Math.max(newCapacity, minCapacity)]; System.arraycopy(elementData, 0, newArray, 0, elementCount); elementData = newArray; } /** * Returns the first element (index 0) in the Vector. * * @return the first Object in the Vector * @throws NoSuchElementException * the Vector is empty */ public synchronized Object firstElement() { if (elementCount == 0) throw new NoSuchElementException(); return elementData[0]; } /** * Returns the first occurrence of <code>elem</code> in the Vector, or -1 * if <code>elem</code> is not found. * * @param elem * the object to search for * @return the index of the first occurrence, or -1 if not found */ public int indexOf(Object elem) { return indexOf(elem, 0); } /** * Searches the vector starting at <code>index</code> for object * <code>elem</code> and returns the index of the first occurrence of this * Object. If the object is not found, or index is larger than the size of * the vector, -1 is returned. * * @param e * the Object to search for * @param index * start searching at this index * @return the index of the next occurrence, or -1 if it is not found * @throws IndexOutOfBoundsException * if index &lt; 0 */ public synchronized int indexOf(Object e, int index) { for (int i = index; i < elementCount; i++) if (elementData[i].equals(e)) return i; return -1; } /** * Inserts a new element into the Vector at <code>index</code>. Any * elements at or greater than index are shifted up one position. * * @param obj * the object to insert * @param index * the index at which the object is inserted * @throws ArrayIndexOutOfBoundsException * index &lt; 0 || index &gt; size() * @see #add(int, Object) */ public synchronized void insertElementAt(Object obj, int index) { checkBoundInclusive(index); if (elementCount == elementData.length) ensureCapacity(elementCount + 1); modCount++; System.arraycopy(elementData, index, elementData, index + 1, elementCount - index); elementCount++; elementData[index] = obj; } /** * Returns true if this Vector is empty, false otherwise * * @return true if the Vector is empty, false otherwise */ public synchronized boolean isEmpty() { return elementCount == 0; } /** * Returns the last element in the Vector. * * @return the last Object in the Vector * @throws NoSuchElementException * the Vector is empty */ public synchronized Object lastElement() { if (elementCount == 0) throw new NoSuchElementException(); return elementData[elementCount - 1]; } /** * Returns the last index of <code>elem</code> within this Vector, or -1 * if the object is not within the Vector. * * @param elem * the object to search for * @return the last index of the object, or -1 if not found */ public int lastIndexOf(Object elem) { return lastIndexOf(elem, elementCount - 1); } /** * Returns the index of the first occurrence of <code>elem</code>, when * searching backwards from <code>index</code>. If the object does not * occur in this Vector, or index is less than 0, -1 is returned. * * @param e * the object to search for * @param index * the index to start searching in reverse from * @return the index of the Object if found, -1 otherwise * @throws IndexOutOfBoundsException * if index &gt;= size() */ public synchronized int lastIndexOf(Object e, int index) { checkBoundExclusive(index); for (int i = index; i >= 0; i--) if (elementData[i].equals(e)) return i; return -1; } /** * Removes all elements from the Vector. Note that this does not resize the * internal data array. * * @see #clear() */ public synchronized void removeAllElements() { if (elementCount == 0) return; modCount++; // Arrays.fill(elementData, 0, elementCount, null); // TODO: memory leaks of course for JOP for (int i = 0; i < elementCount; i++) { elementData[i] = null; } elementCount = 0; } /** * Removes the first (the lowestindex) occurance of the given object from * the Vector. If such a remove was performed (the object was found), true * is returned. If there was no such object, false is returned. * * @param obj * the object to remove from the Vector * @return true if the Object was in the Vector, false otherwise * @see #remove(Object) */ public synchronized boolean removeElement(Object obj) { int idx = indexOf(obj, 0); if (idx >= 0) { remove(idx); return true; } return false; } /** * Removes the element at <code>index</code>, and shifts all elements at * positions greater than index to their index - 1. * * @param index * the index of the element to remove * @throws ArrayIndexOutOfBoundsException * index &lt; 0 || index &gt;= size(); * @see #remove(int) */ public void removeElementAt(int index) { remove(index); } /** * Changes the element at <code>index</code> to be <code>obj</code> * * @param obj * the object to store * @param index * the position in the Vector to store the object * @throws ArrayIndexOutOfBoundsException * the index is out of range * @see #set(int, Object) */ public void setElementAt(Object obj, int index) { set(index, obj); } /** * Returns the number of elements stored in this Vector. * * @return the number of elements in this Vector */ public synchronized int size() { return elementCount; } /** * Explicitly sets the size of the vector (but not necessarily the size of * the internal data array). If the new size is smaller than the old one, * old values that don't fit are lost. If the new size is larger than the * old one, the vector is padded with null entries. * * @param newSize * The new size of the internal array * @throws ArrayIndexOutOfBoundsException * if the new size is negative */ public synchronized void setSize(int newSize) { // Don't bother checking for the case where size() == the capacity of // the // vector since that is a much less likely case; it's more efficient to // not do the check