提交 b3c1eef2 编写于 作者: 檀越@新空间's avatar 檀越@新空间 🐭

fix:添加重写

上级 8f686982
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EasyCodeTableSetting">
<option name="tableInfoMap">
<map>
<entry key="default.dim_org_store_info">
<value>
<TableInfoDTO>
<option name="fullColumn">
<list>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeKey" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeLno" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeLno2" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeShortName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeIsnewFlag" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeFlag" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeStatus" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="wholeStoreStatus" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeBrandFlag" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="affiliationNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="affiliationName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandCode" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandCname" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandEname" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandNameShort" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandDetailNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandDetailCode" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandDetailEname" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandDetailCname" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandDetailOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandDetailStatus" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="brandDetailStatusName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="regionNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="regionName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="regionOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryNo1" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryName1" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryOrder1" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryNo2" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryName2" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryOrder2" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryNo3" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryName3" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeCategoryOrder3" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelNo1" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelName1" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelOrder1" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelNo2" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelName2" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelOrder2" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelNo3" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelName3" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelOrder3" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalProvinceNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalProvinceName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalProvinceOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCityNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCityName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCityOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCountyNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCountyName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCountyOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeLatitude" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeLongitude" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storePictureUrl" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeTypeNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeTypeName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeTypeOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelTypeNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelTypeName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelTypeOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeFormNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeFormName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeFormOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storageWhsNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storageWhsName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeLevelNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeLevelName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeLevelOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="staffNumber" />
<option name="type" value="java.lang.Double" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeArea" />
<option name="type" value="java.lang.Double" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="businessArea" />
<option name="type" value="java.lang.Double" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="projectArea" />
<option name="type" value="java.lang.Double" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeSalDate" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="telnoCol" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="mobilePhone" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="contactCol" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="cmanAddress" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="propertyCoopTypeNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="propertyCoopTypeName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="propertyCoopTermsNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="propertyCoopTermsName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCityLevelNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="normalCityLevelName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="atraStoreLevelNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="atraStoreLevelName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="atraStoreLevelOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="floorNumber" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="contractArea" />
<option name="type" value="java.lang.Double" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="mdmCmpAreaNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="mdmCmpAreaName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="isUnsaleeNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="isUnsaleeName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="isUnsaleeOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="cityTemZoneNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="cityTemZoneName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="cityTemZoneOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelDtlNo" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelDtlName" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="storeChannelDtlOrder" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="salType" />
<option name="type" value="java.lang.Integer" />
</ColumnInfoDTO>
<ColumnInfoDTO>
<option name="custom" value="false" />
<option name="ext" value="{}" />
<option name="name" value="etlTime" />
<option name="type" value="java.lang.String" />
</ColumnInfoDTO>
</list>
</option>
<option name="name" value="DimOrgStoreInfo" />
<option name="preName" value="" />
<option name="saveModelName" value="deepexi-dsc-belle-operate-provider" />
<option name="savePackageName" value="" />
<option name="savePath" value="./deepexi-dsc-belle-operate-provider/src/main/java" />
<option name="templateGroupName" value="Default" />
</TableInfoDTO>
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="false" level="BLOCKER" enabled_by_default="false" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="date" />
</inspection_tool>
<inspection_tool class="WrongPackageStatement" enabled="false" level="ERROR" enabled_by_default="false" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/classes1.iml" filepath="$PROJECT_DIR$/classes1.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<!--
Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides the classes necessary to create an applet and the classes an applet
uses to communicate with its applet context.
<p>
The applet framework involves two
entities: the <i>applet</i> and the <i>applet context</i>. An applet is an
embeddable window (see the Panel class) with a few extra methods that the applet
context can use to initialize, start, and stop the applet.
<p>
The applet context is an application that is responsible for loading and running
applets. For example, the applet context could be a Web browser or an applet
development environment.
<p>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.0
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides classes for color spaces. It contains an
implementation of a color space based on the International Color
Consortium (ICC) Profile Format Specification, Version 3.4, August 15,
1997. It also contains color profiles based on the ICC Profile Format
Specification.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides interfaces and classes for transferring data
between and within applications. It defines the notion of a
"transferable" object, which is an object capable of being
transferred between or within applications. An object identifies
itself as being transferable by implementing the Transferable
interface.
<p>
It also provides a clipboard mechanism, which is an object that
temporarily holds a transferable object that can be transferred
between or within an application. The clipboard is typically used
for copy and paste operations. Although it is possible to create
a clipboard to use within an application, most applications will
use the system clipboard to ensure the data can be transferred
across applications running on the platform.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Drag and Drop is a direct manipulation gesture found in many Graphical
User Interface systems that provides a mechanism to transfer
information between two entities logically associated with presentation
elements in the GUI. Normally driven by a physical gesture of a
human user using an appropriate input device, Drag and Drop provides both
a mechanism to enable continuous feedback regarding the
possible outcome of any subsequent data transfer to the user during
navigation over the presentation elements in the GUI, and the facilities
to provide for any subsequent data negotiation and transfer.
<P>
This package defines the classes and interfaces necessary to perform Drag
and Drop operations in Java. It
defines classes for the drag-source and the drop-target, as well as
events for transferring the data being dragged. This package also provides
a means for giving visual feedback to the user throughout the
duration of the Drag and Drop operation.
<P>
A typical Drag and Drop operation can be decomposed into the following
states (not entirely sequentially):
<UL>
<LI>A <code>DragSource</code> comes into existence,
associated with some presentation
element (<code>Component</code>) in the GUI, to initiate a Drag and Drop of
some potentially <code>Transferable</code> data.
<br><br>
<LI>1 or more <code>DropTarget</code>(s) come into/go out of
existence, associated
with presentation elements in the GUI (Components), potentially
capable of consuming <code>Transferable</code> data types.
<br><br>
<LI> A <code>DragGestureRecognizer</code> is
obtained from the <code>DragSource</code> and is
associated with a <code>Component</code> in order
to track and identify any Drag
initiating gesture by the user over the <code>Component</code>.
<br><br>
<LI> A user makes a Drag gesture over the <code>Component</code>,
which the registered
<code>DragGestureRecognizer</code> detects, and notifies its
<code>DragGestureListener</code> of.
<P>
Note: Although this API consistently refers to the stimulus for a
drag and drop operation being a physical gesture by a human user, this
does not preclude a programmatically driven DnD operation given the
appropriate implementation of a <code>DragSource</code>. This package
contains the abstract class <code>MouseDragGestureRecognizer</code> for
recognizing mouse device gestures. Other abstract subclasses may be
provided by the platform to support other input devices or
particular <code>Component</code> class semantics.
<br><br>
<LI> The <code>DragGestureListener</code> causes the
<code>DragSource</code> to initiate the Drag
and Drop operation on behalf of the user, perhaps animating the
GUI Cursor and/or rendering an <code>Image</code> of the item(s) that are the
subject of the operation.
<br><br>
<LI> As the user gestures navigate over <code>Component</code>(s)
in the GUI with
associated <code>DropTarget</code>(s), the <code>DragSource</code>
receives notifications in order
to provide "Drag Over" feedback effects, and the <code>DropTarget</code>(s)
receive notifications in order to provide "Drag Under" feedback effects
based upon the operation(s) supported and the data type(s) involved.
</UL>
<P>
The gesture itself moves a logical cursor across the GUI hierarchy,
intersecting the geometry of GUI Component(s), possibly resulting in
the logical "Drag" cursor entering, crossing, and subsequently
leaving <code>Component</code>(s) and associated <code>DropTarget</code>(s).
<P>
The <code>DragSource</code> object manifests "Drag Over" feedback to the user, in the typical case by animating the GUI <code>Cursor</code> associated with the
logical cursor.
<P>
<code>DropTarget</code> objects manifest "Drag Under" feedback to the user, in
the typical case, by rendering animations into their associated GUI
<code>Component</code>(s) under the GUI Cursor.
<P>
The determination of the feedback effects, and the ultimate success
or failure of the data transfer, should one occur, is parameterized
as follows:
<UL>
<LI> By the transfer "operation" selected by the user, and supported by
both the <code>DragSource</code> and <code>DropTarget</code>: Copy, Move or Reference(link).
<br><br>
<LI> By the intersection of the set of data types provided by the
<code>DragSource</code> and the set of data types comprehensible by the
<code>DropTarget</code>.
<br><br>
<LI>When the user terminates the drag operation, normally resulting in a
successful Drop, both the <code>DragSource</code> and <code>DropTarget</code>
receive
notifications that include, and result in the type negotiation and
transfer of, the information associated with the <code>DragSource</code> via a
<code>Transferable</code> object.
</UL>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides for interfacing with the underlying window system
in order to access its platform-dependent drag-and-drop facilities.
This package is only used by AWT toolkit developers.
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
</body>
</html>
<!--
Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body bgcolor=white>
<h1 align=center>AWT Threading Issues</h1>
<a name="ListenersThreads"></a>
<h2>Listeners and threads</h2>
Unless otherwise noted all AWT listeners are notified on the event
dispatch thread. It is safe to remove/add listeners from any thread
during dispatching, but the changes only effect subsequent notification.
<br>For example, if a key listeners is added from another key listener, the
newly added listener is only notified on subsequent key events.
<a name="Autoshutdown"></a>
<h2>Auto-shutdown</h2>
According to
<cite>The Java&trade; Virtual Machine Specification</cite>,
sections 2.17.9 and 2.19,
the Java virtual machine (JVM) initially starts up with a single non-daemon
thread, which typically calls the <code>main</code> method of some class.
The virtual machine terminates all its activity and exits when
one of two things happens:
<ul>
<li> All the threads that are not daemon threads terminate.
<li> Some thread invokes the <code>exit</code> method of class
<code>Runtime</code> or class <code>System</code>, and the exit
operation is permitted by the security manager.
</ul>
<p>
This implies that if an application doesn't start any threads itself,
the JVM will exit as soon as <code>main</code> terminates.
This is not the case, however, for a simple application
that creates and displays a <code>java.awt.Frame</code>:
<pre>
public static void main(String[] args) {
Frame frame = new Frame();
frame.setVisible(true);
}
</pre>
The reason is that AWT encapsulates asynchronous event dispatch
machinery to process events AWT or Swing components can fire. The
exact behavior of this machinery is implementation-dependent. In
particular, it can start non-daemon helper threads for its internal
purposes. In fact, these are the threads that prevent the example
above from exiting. The only restrictions imposed on the behavior of
this machinery are as follows:
<ul>
<li> <a href="../EventQueue.html#isDispatchThread()"><code>EventQueue.isDispatchThread</code></a>
returns <code>true</code> if and only if the calling thread is the
event dispatch thread started by the machinery;
<li> <code>AWTEvents</code> which were actually enqueued to a
particular <code>EventQueue</code> (note that events being
posted to the <code>EventQueue</code> can be coalesced) are
dispatched:
<ul>
<li> Sequentially.
<dl><dd> That is, it is not permitted that several events from
this queue are dispatched simultaneously. </dd></dl>
<li> In the same order as they are enqueued.
<dl><dd> That is, if <code>AWTEvent</code>&nbsp;A is enqueued
to the <code>EventQueue</code> before
<code>AWTEvent</code>&nbsp;B then event B will not be
dispatched before event A.</dd></dl>
</ul>
<li> There is at least one alive non-daemon thread while there is at
least one displayable AWT or Swing component within the
application (see
<a href="../Component.html#isDisplayable()"><code>Component.isDisplayable</code></a>).
</ul>
The implications of the third restriction are as follows:
<ul>
<li> The JVM will exit if some thread invokes the <code>exit</code>
method of class <code>Runtime</code> or class <code>System</code>
regardless of the presence of displayable components;
<li> Even if the application terminates all non-daemon threads it
started, the JVM will not exit while there is at least one
displayable component.
</ul>
It depends on the implementation if and when the non-daemon helper
threads are terminated once all components are made undisplayable.
The implementation-specific details are given below.
<h3>
Implementation-dependent behavior.
</h3>
Prior to 1.4, the helper threads were never terminated.
<p>
Starting with 1.4, the behavior has changed as a result of the fix for
<a href="http://bugs.sun.com/view_bug.do?bug_id=4030718">
4030718</a>. With the current implementation, AWT terminates all its
helper threads allowing the application to exit cleanly when the
following three conditions are true:
<ul>
<li> There are no displayable AWT or Swing components.
<li> There are no native events in the native event queue.
<li> There are no AWT events in java EventQueues.
</ul>
Therefore, a stand-alone AWT application that wishes to exit
cleanly without calling <code>System.exit</code> must:
<ul>
<li> Make sure that all AWT or Swing components are made
undisplayable when the application finishes. This can be done
by calling
<a href="../Window.html#dispose()"><code>Window.dispose</code></a>
on all top-level <code>Windows</code>. See
<a href="../Frame.html#getFrames()"><code>Frame.getFrames</code></a>.
<li> Make sure that no method of AWT event listeners registered by
the application with any AWT or Swing component can run into an
infinite loop or hang indefinitely. For example, an AWT listener
method triggered by some AWT event can post a new AWT event of
the same type to the <code>EventQueue</code>.
The argument is that methods
of AWT event listeners are typically executed on helper
threads.
</ul>
Note, that while an application following these recommendations will
exit cleanly under normal conditions, it is not guaranteed that it
will exit cleanly in all cases. Two examples:
<ul>
<li> Other packages can create displayable components for internal
needs and never make them undisplayable. See
<a href="http://bugs.sun.com/view_bug.do?bug_id=4515058">
4515058</a>,
<a href="http://bugs.sun.com/view_bug.do?bug_id=4671025">
4671025</a>, and
<a href="http://bugs.sun.com/view_bug.do?bug_id=4465537">
4465537</a>.
<li> Both Microsoft Windows and X11 allow an application to send native
events to windows that belong to another application. With this
feature it is possible to write a malicious program that will
continuously send events to all available windows preventing
any AWT application from exiting cleanly.
</ul>
On the other hand, if you require the JVM to continue running even after
the application has made all components undisplayable you should start a
non-daemon thread that blocks forever.
<pre>
<...>
Runnable r = new Runnable() {
public void run() {
Object o = new Object();
try {
synchronized (o) {
o.wait();
}
} catch (InterruptedException ie) {
}
}
};
Thread t = new Thread(r);
t.setDaemon(false);
t.start();
<...>
</pre>
<cite>The Java&trade; Virtual Machine Specification</cite>
guarantees
that the JVM doesn't exit until this thread terminates.
</body>
</html>
<!--
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body bgcolor=white>
<h1 align=center>AWT Desktop Properties</h1>
The following refers to standard AWT desktop properties that
may be obtained via the
<a href="../Toolkit.html#getDesktopProperty(java.lang.String)">
<code>Toolkit.getDesktopProperty</code></a> method.
<p>
Each desktop property is named by a unique string, which
is the "name" of that property.
<p>
Desktop properties supported by the AWT but not documented
elsewhere - typically because there is no suitable
method or class - are documented here.
<p>
Desktop properties documented elsewhere are those which are
tightly coupled with a method or class which documents them.
<p>
Since desktop properties abstract an underlying platform
setting, they may not be available in environments that do
not support them. In the event that a desktop property is
unavailable for any reason, the implementation will return
<code>null</code>.
<p>
The following table summarizes the desktop properties documented
here, and their value types.
<br><br>
<table align="center" border="0" cellspacing="0" cellpadding="2"
summary="Standard AWT Desktop Properties">
<tr bgcolor="#ccccff">
<th valign="TOP" align="LEFT">Property Name</th>
<th valign="TOP" align="LEFT">Value Type</th>
<th valign="TOP" align="LEFT">Summary Description</th>
</tr>
<tr>
<td valign="TOP"><A href="#awt.font.desktophints">awt.font.desktophints</A></td>
<td valign="TOP"><a href="../../util/Map.html">java.util.Map</a></td>
<td valign="TOP">Font smoothing (text antialiasing) settings.</td>
</tr>
<tr>
<td valign="TOP"><A href="#sun.awt.enableExtraMouseButtons">sun.awt.enableExtraMouseButtons</A></td>
<td valign="TOP"><a href="../../lang/Boolean.html">java.lang.Boolean</a></td>
<td valign="TOP">Controls if mouse events from extra buttons are to be generated or not</td>
</tr>
</table>
<h2>Desktop Font Rendering Hints</h2>
<b>Desktop Property: <A name="awt.font.desktophints">"awt.font.desktophints"</A></b>
<p>
Modern desktops support various forms of text antialiasing (font smoothing).
<p>
These are applied by platform-specific heavyweight components.
However an application may want to render text using the same text
antialiasing on a drawing surface or lightweight (non-platform) component using
<a href="../Graphics2D.html"> <code>Graphics2D</code></a> methods.
This is particularly important when creating
<a href="../../../javax/swing/JComponent.html"> Swing components</a> which
are required to appear consistent with native desktop components or other
Swing components.
<h3>Basic Usage</h3>
The standard desktop property named
<b>"awt.font.desktophints"</b>
can be used to obtain the rendering hints that best match the desktop settings.
The return value is a
<a href="../../util/Map.html"> Map</a> of
<a href="../RenderingHints.html"> <code>RenderingHints</code></a> which
can be directly applied to a <code>Graphics2D</code>.
<p>
It is a <code>Map</code> as more than one hint may be needed.
If non-null this can be directly applied to the <code>Graphics2D</code>.
<pre><code>
Toolkit tk = Toolkit.getDefaultToolkit();
Map map = (Map)(tk.getDesktopProperty("awt.font.desktophints"));
if (map != null) {
graphics2D.addRenderingHints(map);
}
</code></pre>
<h3>Advanced Usage Tips</h3>
<h4>Listening for changes</h4>
<p>
An application can listen for changes in the property
using a <a href="../../beans/PropertyChangeListener.html">
<code>PropertyChangeListener</code></a> :
<pre><code>
tk.addPropertyChangeListener("awt.font.desktophints", pcl);
</code></pre>
Listening for changes is recommended as users can, on rare occasions,
reconfigure a desktop environment whilst applications are running
in a way that may affect the selection of these hints, and furthermore
many desktop environments support dynamic reconfiguration of these
running applications to conform to the new settings.
<p>
There is no direct way to discover if dynamic reconfiguration
is expected of running applications but the default assumption
should be that it is expected, since most modern desktop environments
do provide this capability.
<h4>Text Measurement</h4>
<p>
Text always needs to be measured using the same
<a href="../font/FontRenderContext.html"> <code>FontRenderContext</code></a>
as used for rendering. The text anti-aliasing hint is a component of
the <code>FontRenderContext</code>.
A <a href="../FontMetrics.html"> <code>FontMetrics</code></a>
obtained from the <code>Graphics</code> object on which the hint
has been set will measure text appropriately.
This is not a unique requirement for clients that specify this hint
directly, since the value of the <code>FontRenderContext</code> should
never be assumed, so is discussed here principally as a reminder.
<h4>Saving and restoring Graphics State</h4>
<p>
Sometimes an application may need to apply these hints on a shared
Graphics only temporarily, restoring the previous values after they
have been applied to text rendering operations.
The following sample code shows one way to do this.
<pre><code>
/**
* Get rendering hints from a Graphics instance.
* "hintsToSave" is a Map of RenderingHint key-values.
* For each hint key present in that map, the value of that
* hint is obtained from the Graphics and stored as the value
* for the key in savedHints.
*/
RenderingHints getRenderingHints(Graphics2D g2d,
RenderingHints hintsToSave,
RenderingHints savedHints) {
if (savedHints == null) {
savedHints = new RenderingHints(null);
} else {
savedHints.clear();
}
if (hintsToSave.size() == 0) {
return savedHints;
}
/* RenderingHints.keySet() returns Set&lt;Object&gt; */
for (Object o : hintsToSave.keySet()) {
RenderingHints.Key key = (RenderingHints.Key)o;
Object value = g2d.getRenderingHint(key);
savedHints.put(key, value);
}
return savedHints;
}
Toolkit tk = Toolkit.getDefaultToolkit();
Map map = (Map)(tk.getDesktopProperty("awt.font.desktophints"));
Map oldHints;
if (map != null) {
oldHints = getRenderingHints(graphic2D, map, null);
graphics2D.addRenderingHints(map);
..
graphics2D.addRenderingHints(oldHints);
}
</code></pre>
<h3>Details</h3>
<ul>
<li>The return value will always be null or a <code>Map</code>
<br><br>
<li>If the return value is null, then no desktop properties are available,
and dynamic updates will not be available. This is a typical behaviour if
the JDK does not recognise the desktop environment, or it is one which
has no such settings. The <b>Headless</b> toolkit is one such example.
Therefore it is important to test against null before using the map.
<br><br>
<li>If non-null the value will be a <code>Map</code> of
<code>RenderingHints</code> such that every key is an instance of
<code>RenderingHints.Key</code> and the value is a legal value for that key.
<br><br>
<li>The map may contain the default value for a hint. This is
needed in the event there is a previously a non-default value for the hint
set on the <code>Graphics2D</code>. If the map did not contain
the default value, then <code>addRenderingHints(Map)</code> would leave
the previous hint which may not correspond to the desktop setting.
<p>
An application can use <code>setRenderingHints(Map)</code> to reinitialise
all hints, but this would affect unrelated hints too.
<br><br>
<li>A multi-screen desktop may support per-screen device settings in which
case the returned value is for the default screen of the desktop.
An application may want to use the settings for the screen on
which they will be applied.
The per-screen device hints may be obtained by per-device property names
which are constructed as the String concatenation
<pre><code>
"awt.font.desktophints" + "." + GraphicsDevice.getIDstring();
</code></pre>
<p>
An application can also listen for changes on these properties.
<p>
However this is an extremely unlikely configuration, so to help
ease of development, if only a single, desktop-wide setting is supported,
then querying each of these per-device settings will return null.
So to determine if there are per-device settings it is sufficient to
determine that there is a non-null return for any screen device using
the per-device property name.
</ul>
<h2>Mouse Functionality</h2>
<b>Desktop Property: <A name="sun.awt.enableExtraMouseButtons">"sun.awt.enableExtraMouseButtons"</A></b>
<p>
This property determines if events from extra mouse buttons (if they are exist and are
enabled by the underlying operating system) are allowed to be processed and posted into
{@code EventQueue}.
<br>
The value could be changed by passing "sun.awt.enableExtraMouseButtons"
property value into java before application starts. This could be done with the following command:
<pre>
java -Dsun.awt.enableExtraMouseButtons=false Application
</pre>
Once set on application startup, it is impossible to change this value after.
<br>
Current value could also be queried using getDesktopProperty("sun.awt.enableExtraMouseButtons")
method.
<br>
If the property is set to {@code true} then
<ul>
<li> it is still legal to create {@code MouseEvent} objects with
standard buttons and, if the mouse has more
then three buttons, it is also legal to use buttons from the range started
from 0 up to {@link java.awt.MouseInfo#getNumberOfButtons() getNumberOfButtons()}.
<li> it is legal to use standard button masks when using {@code Robot.mousePress()}
and {@code Robot.mouseRelease()} methods and, if the mouse has more then three buttons,
it is also legal to use masks for existing extended mouse buttons.
That way, if there are more then three buttons on the mouse then it is allowed to
use button masks corresponding to the buttons
in the range from 1 up to {@link java.awt.MouseInfo#getNumberOfButtons() getNumberOfButtons()}
</ul>
<br>
If the property is set to {@code false} then
<ul>
<li> it is legal to create {@code MouseEvent} objects with standard buttons
only: {@code NOBUTTON}, {@code BUTTON1}, {@code BUTTON2} and
{@code BUTTON3}
<li> it is legal to use standard button masks only:
{@code InputEvent.BUTTON1_DOWN_MASK}, {@code InputEvent.BUTTON2_DOWN_MASK},
{@code InputEvent.BUTTON3_DOWN_MASK}
</ul>
This property should be used when there is no need in listening mouse events fired as a result of
activity with extra mouse button.
By default this property is set to {@code true}.
</body>
</html>
<!--
Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>The AWT Focus Subsystem</title>
</head>
<body bgcolor="white">
<h1 align=center>The AWT Focus Subsystem</h1>
<p>
Prior to Java 2 Standard Edition, JDK 1.4, the AWT focus subsystem
was inadequate. It suffered from major design and API problems,
as well as over a hundred open bugs. Many of these bugs were caused by
platform inconsistencies, or incompatibilities between the native
focus system for heavyweights and the Java focus system for
lightweights.
<p>
The single worst problem with the AWT focus implementation was the
inability to query for the currently focused Component. Not only was
there no API for such a query, but also, because of an insufficient
architecture, such information was not even maintained by the code.
<p>
Almost as bad was the inability of lightweight children of a Window
(not a Frame or a Dialog) to receive keyboard input. This problem
existed because Windows never received <code>WINDOW_ACTIVATED</code>
events and thus could never be activated, and only active Windows
could contain focused Components.
<p>
In addition, many developers noted that the APIs for FocusEvent and
WindowEvent were insufficient because they did not provide a way for
determining the "opposite" Component involved in the focus or
activation change. For example, when a Component received a FOCUS_LOST
event, it had no way of knowing which Component was gaining
focus. Since Microsoft Windows provides this functionality for free,
developers migrating from Microsoft Windows C/C++ or Visual Basic to
Java had been frustrated by the omission.
<p>
To address these and other deficiencies, we have designed a new focus
model for the AWT in JDK 1.4. The primary design changes were the
construction of a new centralized KeyboardFocusManager class, and a
lightweight focus architecture. The amount of focus-related,
platform-dependent code has been minimized and replaced by fully
pluggable and extensible public APIs in the AWT. While we have
attempted to remain backward compatible with the existing
implementation, we were forced to make minor incompatible changes in
order to reach an elegant and workable conclusion. We anticipate that
these incompatibilities will have only a trivial impact on existing
applications.
<p>
This document is a formal specification both of the new APIs and of
existing APIs which remain relevant in the new model. Combined with
the javadoc for focus-related classes and methods, this document
should enable developers to create substantial AWT and Swing
applications with a focus behavior that is customized yet consistent
across platforms. This document has the following sections:
<ul>
<li><a href=#Overview>Overview of KeyboardFocusManager</a>
<li><a href=#BrowserContexts>KeyboardFocusManager and Browser Contexts</a>
<li><a href=#KeyEventDispatcher>KeyEventDispatcher</a>
<li><a href=#FocusEventAndWindowEvent>FocusEvent and WindowEvent</a>
<li><a href=#EventDelivery>Event Delivery</a>
<li><a href=#OppositeComponents>Opposite Components and Windows</a>
<li><a href=#TemporaryFocusEvents>Temporary FocusEvents</a>
<li><a href=#FocusTraversal>Focus Traversal</a>
<li><a href=#FocusTraversalPolicy>Focus Traversal Policy</a>
<li><a href=#FocusTraversalPolicyProviders>Focus Traversal Policy Providers</a>
<li><a href=#ProgrammaticTraversal>Programmatic Traversal</a>
<li><a href=#Focusability>Focusability</a>
<li><a href=#FocusableWindows>Focusable Windows</a>
<li><a href=#RequestingFocus>Requesting Focus</a>
<li><a href=#FocusAndPropertyChangeListener>Focus and PropertyChangeListener</a>
<li><a href=#FocusAndVetoableChangeListener>Focus and VetoableChangeListener</a>
<li><a href=#ZOrder>Z-Order</a>
<li><a href=#ReplacingDefaultKeyboardFocusManager>Replacing DefaultKeyboardFocusManager</a>
<li><a href=#Incompatibilities>Incompatibilities with Previous Releases</a>
</ul>
<a name="Overview"></a>
<h3>Overview of KeyboardFocusManager</h3>
<p>
The focus model is centralized around a single class,
KeyboardFocusManager, that provides a set of APIs for client code to
inquire about the current focus state, initiate focus changes, and
replace default focus event dispatching with a custom dispatcher.
Clients can inquire about the focus state directly, or can register a
PropertyChangeListener that will receive PropertyChangeEvents when a
change to the focus state occurs.
<p>
KeyboardFocusManager introduces the following main concepts and their
terminology:
<ol>
<li>The "focus owner" -- the Component which typically receives
keyboard input.
<li>The "permanent focus owner" -- the last Component to receive
focus permanently. The "focus owner" and the "permanent focus
owner" are equivalent unless a temporary focus change is
currently in effect. In such a situation, the "permanent focus
owner" will again be the "focus owner" when the temporary focus
change ends.
<li>The "focused Window" -- the Window which contains the "focus
owner".
<li>The "active Window" -- the Frame or Dialog that is either the
"focused Window", or the first Frame or Dialog that is an owner
of the "focused Window".
<li>"Focus traversal" -- the user's ability to change the "focus
owner" without moving the cursor. Typically, this is done using
the keyboard (for example, by using the TAB key), or an
equivalent device in an accessible environment. Client code can
also initiate traversal programmatically. Normal focus traversal
can be either "forward" to the "next" Component, or "backward" to
the "previous" Component.
<li>"Focus traversal cycle" -- a portion of the Component hierarchy,
such that normal focus traversal "forward" (or "backward") will
traverse through all of the Components in the focus cycle, but no
other Components. This cycle provides a mapping from an arbitrary
Component in the cycle to its "next" (forward traversal) and
"previous" (backward traversal) Components.
<li>"Traversable Component" -- Component that is in the focus traversal
cycle.
<li>"Non-traversable Component" -- Component that is not in the focus
traversal cycle. Note that a non-traversable Component can nevertheless
be focused in other way (e.g. by direct focus request).
<li>"Focus cycle root" -- Container that is the root of the Component
hierarchy for a particular "focus traversal cycle". When the
"focus owner" is a Component inside a particular cycle, normal
forward and backward focus traversal cannot move the "focus
owner" above the focus cycle root in the Component hierarchy.
Instead, two additional traversal operations, "up cycle" and
"down cycle", are defined to allow keyboard and programmatic
navigation up and down the focus traversal cycle hierarchy. </li>
<li>"Focus traversal policy provider" - Container which has
"FocusTraversalPolicyProvider" property as true. This Container will
be used to acquire focus traversal policy. This container doesn't
define new focus cycle but only modifies the order by which its
children are traversed "forward" and "backward". Focus traversal
policy provider can be set using
<code>setFocusTraversalPolicyProvider</code> on the Container.
</ol>
<p>
Every Window and JInternalFrame is, by default, a "focus cycle
root". If it's the only focus cycle root, then all of its
focusable descendants should be in its focus cycle, and its focus
traversal policy should enforce that they are by making sure that
all will be reached during normal forward (or backward)
traversal. If, on the other hand, the Window or JInternalFrame
has descendants that are also focus cycle roots, then each such
descendant is a member of two focus cycles: the one that it is
the root of, and the one of its nearest focus-cycle-root
ancestor. In order to traverse the focusable components belonging
to the focus cycle of such a "descendant" focus cycle root, one
first traverses (forward or backward) to reach the descendant,
and then uses the "down cycle" operation to reach, in turn, its
descendants.
<p>
Here is an example:<br> <img src="FocusCycle.gif" align=middle
alt="Three groups as described below: ABCF BDE and DGH. "><br>
<p>Assume the following:
<ul>
<li><b>A</b> is a <code>Window</code>, which means that it
must be a focus cycle root.
<li><b>B</b> and <b>D</b> are <code>Container</code>s that
are focus cycle roots.
<li><b>C</b> is a <code>Container</code> that is not a focus cycle root.
<li><b>G</b>, <b>H</b>, <b>E</b>, and <b>F</b> are all
<code>Component</code>s.
</ul>
There are a total of three focus cycle roots in this example:
<ol>
<li><b>A</b> is a root, and <b>A</b>, <b>B</b>, <b>C</b>,
and <b>F</b> are members of <b>A</b>'s cycle.
<li><b>B</b> is a root, and <b>B</b>, <b>D</b>, and
<b>E</b> are members of <b>B</b>'s cycle.
<li><b>D</b> is a root, and <b>D</b>, <b>G</b>,
and <b>H</b> are members of <b>D</b>'s cycle.
</ol>
Windows are the only Containers which, by default, are focus cycle
roots.
<code>KeyboardFocusManager</code> is an abstract class. AWT provides a default
implementation in the <code>DefaultKeyboardFocusManager</code> class.
<a name="BrowserContexts"></a>
<h3>KeyboardFocusManager and Browser Contexts</h3>
<p>
Some browsers partition applets in different code bases into separate
contexts, and establish walls between these contexts. Each thread and
each Component is associated with a particular context and cannot
interfere with threads or access Components in other contexts. In such
a scenario, there will be one KeyboardFocusManager per context. Other
browsers place all applets into the same context, implying that there
will be only a single, global KeyboardFocusManager for all
applets. This behavior is implementation-dependent. Consult your
browser's documentation for more information. No matter how many
contexts there may be, however, there can never be more than one focus
owner, focused Window, or active Window, per ClassLoader.
<a name="KeyEventDispatcher"></a>
<h3>KeyEventDispatcher and KeyEventPostProcessor</h3>
<p>
While the user's KeyEvents should generally be delivered to the focus
owner, there are rare cases where this is not desirable. An input
method is an example of a specialized Component that should receive
KeyEvents even though its associated text Component is and should
remain the focus owner.
<p>
A KeyEventDispatcher is a lightweight interface that allows client
code to pre-listen to all KeyEvents in a particular context. Instances
of classes that implement the interface and are registered with the
current KeyboardFocusManager will receive KeyEvents before they are
dispatched to the focus owner, allowing the KeyEventDispatcher to
retarget the event, consume it, dispatch it itself, or make other
changes.
<p>
For consistency, KeyboardFocusManager itself is a
KeyEventDispatcher. By default, the current KeyboardFocusManager will
be the sink for all KeyEvents not dispatched by the registered
KeyEventDispatchers. The current KeyboardFocusManager cannot be
completely deregistered as a KeyEventDispatcher. However, if a
KeyEventDispatcher reports that it dispatched the KeyEvent, regardless
of whether it actually did so, the KeyboardFocusManager will take no
further action with regard to the KeyEvent. (While it is possible for
client code to register the current KeyboardFocusManager as a
KeyEventDispatcher one or more times, there is no obvious reason why
this would be necessary, and therefore it is not recommended.)
<p>
Client-code may also post-listen to KeyEvents in a particular context
using the KeyEventPostProcessor interface. KeyEventPostProcessors
registered with the current KeyboardFocusManager will receive
KeyEvents after the KeyEvents have been dispatched to and handled by
the focus owner. The KeyEventPostProcessors will also receive
KeyEvents that would have been otherwise discarded because no
Component in the application currently owns the focus. This will allow
applications to implement features that require global KeyEvent post-
handling, such as menu shortcuts.
<p>
Like KeyEventDispatcher, KeyboardFocusManager also implements
KeyEventPostProcessor, and similar restrictions apply to its use in
that capacity.
<a name="FocusEventAndWindowEvent"></a>
<h3>FocusEvent and WindowEvent</h3>
<p>
The AWT defines the following six event types central to the focus
model in two different <code>java.awt.event</code> classes:
<ol>
<li><code>WindowEvent.WINDOW_ACTIVATED</code>: This event is
dispatched to a Frame or Dialog (but never a Window which
is not a Frame or Dialog) when it becomes the active Window.
<li><code>WindowEvent.WINDOW_GAINED_FOCUS</code>: This event is
dispatched to a Window when it becomes the focused Window.
Only focusable Windows can receive this event.
<li><code>FocusEvent.FOCUS_GAINED</code>: This event is dispatched
to a Component when it becomes the focus owner. Only focusable
Components can receive this event.
<li><code>FocusEvent.FOCUS_LOST</code>: This event is dispatched
to a Component when it is no longer the focus owner.
<li><code>WindowEvent.WINDOW_LOST_FOCUS</code>: This event is
dispatched to a Window when it is no longer the focused Window.
<li><code>WindowEvent.WINDOW_DEACTIVATED</code>: This event is
dispatched to a Frame or Dialog (but never a Window which is
not a Frame or Dialog) when it is no longer the active Window.
</ol>
<a name="EventDelivery"></a>
<h3>Event Delivery</h3>
<p>
If the focus is not in java application and the user clicks on a focusable
child Component<b>a</b> of an inactive Frame <b>b</b>, the following events
will be dispatched and handled in order:
<ol>
<li><b>b</b> will receive a <code>WINDOW_ACTIVATED</code> event.
<li>Next, <b>b</b> will receive a <code>WINDOW_GAINED_FOCUS</code> event.
<li>Finally, <b>a</b> will receive a <code>FOCUS_GAINED</code> event.
</ol>
If the user later clicks on a focusable child Component <b>c</b> of another
Frame <b>d</b>, the following events will be dispatched and handled in
order:
<ol>
<li><b>a</b> will receive a <code>FOCUS_LOST</code> event.
<li><b>b</b> will receive a <code>WINDOW_LOST_FOCUS</code> event.
<li><b>b</b> will receive a <code>WINDOW_DEACTIVATED</code> event.
<li><b>d</b> will receive a <code>WINDOW_ACTIVATED</code> event.
<li><b>d</b> will receive a <code>WINDOW_GAINED_FOCUS</code> event.
<li><b>c</b> will receive a <code>FOCUS_GAINED</code> event.
</ol>
Note that each event will be fully handled before the next event is
dispatched. This restriction will be enforced even if the Components
are in different contexts and are handled on different event
dispatching threads.
<p>
In addition, each event type will be dispatched in 1-to-1
correspondence with its opposite event type. For example, if a
Component receives a <code>FOCUS_GAINED</code> event, under no
circumstances can it ever receive another <code>FOCUS_GAINED</code>
event without an intervening <code>FOCUS_LOST</code> event.
<p>
Finally, it is important to note that these events are delivered for
informational purposes only. It is impossible, for example, to prevent
the delivery of a pending <code>FOCUS_GAINED</code> event by requesting
focus back to the Component losing focus while handling the preceding
<code>FOCUS_LOST</code> event. While client code may make such a request,
the pending <code>FOCUS_GAINED</code> will still be delivered,
followed later by the events transferring focus back to the original
focus owner.
<p>
If it is absolutely necessary to suppress the <code>FOCUS_GAINED</code> event,
client code can install a <code>VetoableChangeListener</code> which
rejects the focus change. See <a href="#FocusAndVetoableChangeListener">Focus
and VetoableChangeListener</a>.
<a name="OppositeComponents"></a>
<h3>Opposite Components and Windows</h3>
<p>
Each event includes information about the "opposite" Component or
Window involved in the focus or activation change. For example, for a
<code>FOCUS_GAINED</code> event, the opposite Component is the Component
that lost focus. If the focus or activation change occurs with a native
application, with a Java application in a different VM or context, or
with no other Component, then the opposite Component or Window is
null. This information is accessible using
<code>FocusEvent.getOppositeComponent</code> or
<code>WindowEvent.getOppositeWindow</code>.
<p>
On some platforms, it is not possible to discern the opposite
Component or Window when the focus or activation change occurs between
two different heavyweight Components. In these cases, the opposite
Component or Window may be set to null on some platforms, and to a
valid non-null value on other platforms. However, for a focus change
between two lightweight Components which share the same heavyweight
Container, the opposite Component will always be set correctly. Thus,
a pure Swing application can ignore this platform restriction when
using the opposite Component of a focus change that occurred within a
top-level Window.
<a name="TemporaryFocusEvents"></a>
<h3>Temporary FocusEvents</h3>
<p>
<code>FOCUS_GAINED</code> and <code>FOCUS_LOST</code> events are
marked as either temporary or permanent.
<p>
Temporary <code>FOCUS_LOST</code> events are sent when a Component is
losing the focus, but will regain the focus shortly. These events
can be useful when focus changes are used as triggers for validation
of data. For instance, a text Component may want to commit its
contents when the user begins interacting with another Component,
and can accomplish this by responding to <code>FOCUS_LOST</code> events.
However, if the <code>FocusEvent</code> received is temporary,
the commit should not be done, since the text field will be receiving
the focus again shortly.
<p>
A permanent focus transfer typically occurs as the result of a user
clicking on a selectable, heavyweight Component, focus traversal with
the keyboard or an equivalent input device, or from a call to
<code>requestFocus()</code> or <code>requestFocusInWindow()</code>.
<p>
A temporary focus transfer typically occurs as the result of showing a
Menu or PopupMenu, clicking or dragging a Scrollbar, moving a Window
by dragging the title bar, or making another Window the focused
Window. Note that on some platforms, these actions may not generate
any FocusEvents at all. On others, temporary focus transfers will
occur.
<p>
When a Component receives a temporary <code>FOCUS_LOST</code> event,
the event's opposite Component (if any) may receive a temporary
<code>FOCUS_GAINED</code> event, but could also receive a permanent
<code>FOCUS_GAINED</code> event. Showing a Menu or PopupMenu, or
clicking or dragging a Scrollbar, should generate a temporary
<code>FOCUS_GAINED</code> event. Changing the focused Window,
however, will yield a permanent <code>FOCUS_GAINED</code> event
for the new focus owner.
<p>
The Component class includes variants of <code>requestFocus</code> and
<code>requestFocusInWindow</code> which take a desired temporary state as a
parameter. However, because specifying an arbitrary temporary state
may not be implementable on all native windowing systems, correct
behavior for this method can be guaranteed only for lightweight
Components. This method is not intended for general use, but exists
instead as a hook for lightweight Component libraries, such as Swing.
<a name="FocusTraversal"></a>
<h3>Focus Traversal</h3>
<p>
Each Component defines its own Set of focus traversal keys for a given
focus traversal operation. Components support separate Sets of keys
for forward and backward traversal, and also for traversal up one
focus traversal cycle. Containers which are focus cycle roots also
support a Set of keys for traversal down one focus traversal cycle. If
a Set is not explicitly defined for a Component, that Component
recursively inherits a Set from its parent, and ultimately from a
context-wide default set on the current <code>KeyboardFocusManager</code>.
<p>
Using the <code>AWTKeyStroke</code> API, client code can specify
on which of two specific KeyEvents, <code>KEY_PRESSED</code> or
<code>KEY_RELEASED</code>, the focus traversal operation will occur.
Regardless of which KeyEvent is specified, however, all KeyEvents
related to the focus traversal key, including the associated
<code>KEY_TYPED</code> event, will be consumed, and will not be
dispatched to any Component. It is a runtime error to specify a
<code>KEY_TYPED</code> event as mapping to a focus traversal operation,
or to map the same event to multiple focus traversal operations for any
particular Component or for a <code>KeyboardFocusManager</code>'s defaults.
<p>
The default focus traversal keys are implementation-dependent. Sun
recommends that the all implementations for a particular native
platform use the same keys. For Windows and Unix, the recommendations
are:
<ul>
<li>traverse forward to the next Component:
<br><i>TextAreas</i>: <code>CTRL-TAB</code> on <code>KEY_PRESSED</code>
<br><i>All others</i>: <code>TAB</code> on <code>KEY_PRESSED</code> and
<code>CTRL-TAB</code> on <code>KEY_PRESSED</code>
<li>traverse backward to the previous Component:
<br><i>TextAreas</i>: <code>CTRL-SHIFT-TAB</code> on
<code>KEY_PRESSED</code>
<br><i>All others</i>: <code>SHIFT-TAB</code> on <code>KEY_PRESSED</code>
and <code>CTRL-SHIFT-TAB</code> on
<code>KEY_PRESSED</code>
<li>traverse up one focus traversal cycle : &lt;none&gt;
<li>traverse down one focus traversal cycle : &lt;none&gt;
</ul>
<p>
Components can enable and disable all of their focus traversal keys en
masse using <code>Component.setFocusTraversalKeysEnabled</code>. When focus
traversal keys are disabled, the Component receives all KeyEvents for
those keys. When focus traversal keys are enabled, the Component never
receives KeyEvents for traversal keys; instead, the KeyEvents are
automatically mapped to focus traversal operations.
<p>
For normal forward and backward traversal, the AWT focus
implementation determines which Component to focus next based on the
<a href=#FocusTraversalPolicy><code>FocusTraversalPolicy</code></a> of
the focus owner's focus cycle root or focus traversal policy provider. If the
focus owner is a focus cycle root, then it may be ambiguous as to which
Components represent the next and previous Components to focus during
normal focus traversal. Thus, the current
<code>KeyboardFocusManager</code> maintains a reference to the
"current" focus cycle root, which is global across all contexts. The
current focus cycle root is used to resolve the ambiguity.
<p>
For up-cycle traversal, the focus owner is set to the current focus
owner's focus cycle root, and the current focus cycle root is set to
the new focus owner's focus cycle root. If, however, the current focus
owner's focus cycle root is a top-level window, then the focus owner
is set to the focus cycle root's default component to focus, and the
current focus cycle root is unchanged.
<p>
For down-cycle traversal, if the current focus owner is a focus cycle
root, then the focus owner is set to the current focus owner's default
component to focus, and the current focus cycle root is set to the
current focus owner. If the current focus owner is not a focus cycle
root, then no focus traversal operation occurs.
<a name="FocusTraversalPolicy"></a>
<h3>FocusTraversalPolicy</h3>
<p>
A <code>FocusTraversalPolicy</code> defines the order in which Components within
a particular focus cycle root or focus traversal policy provider are
traversed. Instances of <code>FocusTraversalPolicy</code> can be shared across
Containers, allowing those Containers to implement the same traversal policy.
FocusTraversalPolicies do not need to be reinitialized when the
focus-traversal-cycle hierarchy changes.
<p>
Each <code>FocusTraversalPolicy</code> must define the following
five algorithms:
<ol>
<li>Given a focus cycle root and a Component <b>a</b> in that cycle, the
next Component after <b>a</b>.
<li>Given a focus cycle root and a Component <b>a</b> in that cycle, the
previous Component before <b>a</b>.
<li>Given a focus cycle root, the "first" Component in that cycle.
The "first" Component is the Component to focus when traversal
wraps in the forward direction.
<li>Given a focus cycle root, the "last" Component in that cycle.
The "last" Component is the Component to focus when traversal
wraps in the reverse direction.
<li>Given a focus cycle root, the "default" Component in that cycle.
The "default" Component will be the first to receive focus when
traversing down into a new focus traversal cycle. This may be the
same as the "first" Component, but need not be.
</ol>
<p>
A <code>FocusTraversalPolicy</code> may optionally provide an
algorithm for the following:
<blockquote>
Given a Window, the "initial" Component in that Window. The initial
Component will be the first to receive focus when the Window is
first made visible. By default, this is the same as the "default"
Component.
</blockquote>
In addition, Swing provides a subclass of <code>FocusTraversalPolicy</code>,
<code>InternalFrameFocusTraversalPolicy</code>, which allows developers
to provide an algorithm for the following:
<blockquote>
Given a <code>JInternalFrame</code>, the "initial" Component in that
<code>JInternalFrame</code>. The initial Component is the first to
receive focus when the <code>JInternalFrame</code> is first selected.
By default, this is the same as the <code>JInternalFrame</code>'s
default Component to focus.
</blockquote>
A <code>FocusTraversalPolicy</code> is installed on a Container using
Container.<code>setFocusTraversalPolicy</code>. If a policy is not explicitly
set, then a Container inherits its policy from its nearest focus-cycle-root
ancestor. Top-levels initialize their focus traversal policies using the context
default policy. The context default policy is established by using
KeyboardFocusManager. <code>setDefaultFocusTraversalPolicy</code>.
<p>
AWT provides two standard <code>FocusTraversalPolicy</code>
implementations for use by client code.
<ol>
<li><code>ContainerOrderFocusTraversalPolicy</code>: Iterates across the
Components in a focus traversal cycle in the order they were added
to their Containers. Each Component is tested for fitness using the
accept(Component) method. By default, a Component is fit only if it
is visible, displayable, enabled, and focusable.
<li>By default, ContainerOrderFocusTraversalPolicy implicitly transfers
focus down-cycle. That is, during normal forward focus traversal,
the Component traversed after a focus cycle root will be the
focus-cycle-root's default Component to focus, regardless of whether
the focus cycle root is a traversable or non-traversable Container
(see the pic.1,2 below). Such behavior provides backward compatibility
with applications designed without the concepts of up- and down-cycle
traversal.
<li><code>DefaultFocusTraversalPolicy</code>: A subclass of
<code>ContainerOrderFocusTraversalPolicy</code> which redefines
the fitness test. If client code has explicitly set the
focusability of a Component by either overriding
<code>Component.isFocusTraversable()</code> or
<code>Component.isFocusable()</code>, or by calling
<code>Component.setFocusable(boolean)</code>, then a
<code>DefaultFocusTraversalPolicy</code> behaves exactly
like a <code>ContainerOrderFocusTraversalPolicy</code>. If,
however, the Component is relying on default focusability, then a
<code>DefaultFocusTraversalPolicy</code> will reject all
Components with non-focusable peers.
<br>
The focusability of a peer is implementation-dependent. Sun
recommends that all implementations for a particular native platform
construct peers with the same focusability. The recommendations for
Windows and Unix are that Canvases, Labels, Panels, Scrollbars,
ScrollPanes, Windows, and lightweight Components have non-focusable
peers, and all other Components have focusable peers. These
recommendations are used in the Sun AWT implementations. Note that
the focusability of a Component's peer is different from, and does
not impact, the focusability of the Component itself.
</ol>
<p>
Swing provides two additional, standard FocusTraversalPolicy
implementations for use by client code. Each implementation is an
InternalFrameFocusTraversalPolicy.
<ol>
<li>SortingFocusTraversalPolicy: Determines traversal order by
sorting the Components of a focus traversal cycle based on a given
Comparator. Each Component is tested for fitness using the
accept(Component) method. By default, a Component is fit only if it
is visible, displayable, enabled, and focusable.
<li>By default, SortingFocusTraversalPolicy implicitly transfers focus
down-cycle. That is, during normal forward focus traversal, the
Component traversed after a focus cycle root will be the
focus-cycle-root's default Component to focus, regardless of
whether the focus cycle root is a traversable or non-traversable
Container (see the pic.1,2 below). Such behavior provides backward
compatibility with applications designed without the concepts of
up- and down-cycle traversal.
<li>LayoutFocusTraversalPolicy: A subclass of
SortingFocusTraversalPolicy which sorts Components based on their
size, position, and orientation. Based on their size and position,
Components are roughly categorized into rows and columns. For a
Container with horizontal orientation, columns run left-to-right or
right-to-left, and rows run top-to-bottom. For a Container with
vertical orientation, columns run top-to-bottom and rows run
left-to-right or right-to-left. All columns in a row are fully
traversed before proceeding to the next row.
<br>
In addition, the fitness test is extended to exclude JComponents
that have or inherit empty InputMaps.
</ol>
<p>
The figure below shows an implicit focus transfer:
<br><img src="ImplicitFocusTransfer.gif" align=middle alt="Implicit focus transfer."><br>
Assume the following:
<ul>
<li><b>A</b>, <b>B</b> and <b>C</b> are components in some window (a container)
<li><b>R</b> is a container in the window and it is a parent of <b>B</b> and <b>C</b>.
Besides, <b>R</b> is a focus cycle root.
<li><b>B</b> is the default component in the focul traversal cycle of <b>R</b>
<li><b>R</b> is a traversable Container in the pic.1, and it is a non-traversable
Container in the pic.2.
<li>In such a case a forward traversal will look as follows:
<ul>
<li> pic.1 : <b>A</b> -> <b>R</b> -> <b>B</b> -> <b>C</b>
<li> pic.2 : <b>A</b> -> <b>B</b> -> <b>C</b>
</ul>
</ul>
<p>
Swing applications, or mixed Swing/AWT applications, that use one of
the standard look and feels, or any other look and feel derived from
BasicLookAndFeel, will use LayoutFocusTraversalPolicy for all
Containers by default.
<p>
All other applications, including pure AWT applications, will use
<code>DefaultFocusTraversalPolicy</code> by default.
<a name="FocusTraversalPolicyProviders"></a>
<h3>Focus Traversal Policy Providers</h3>
<p>
A Container that isn't a focus cycle root has an option to provide a
FocusTraversalPolicy of its own. To do so, one needs to set Container's focus
traversal policy provider property to <code>true</code> with the call to
<blockquote>
<code>Container.setFocusTraversalPolicyProvider(boolean)</code>
</blockquote>
To determine whether a Container is a focus traversal policy provider, the
following method should be used:
<blockquote>
<code>Container.isFocusTraversalPolicyProvider()</code>
</blockquote>
If focus traversal policy provider property is set on a focus cycle root, it
isn't considered a focus traversal policy provider and behaves just like any
other focus cycle root.
<p>
The main difference between focus cycle roots and focus traversal policy
providers is that the latter allow focus to enter and leave them just as all other
Containers. However, children inside focus traversal policy provider are
traversed in the order determined by provider's FocusTraversalPolicy. In order
to enable focus traversal policy providers to behave this way,
FocusTraversalPolicies treat them in the following manner:
<ul>
<li> Focus traversal policy providers can be passed to FocusTraversalPolicy
methods instead of focus cycle roots.
<li> When calculating next or previous Component in
<code>FocusTraversalPolicy.getComponentAfter</code> or
<code>FocusTraversalPolicy.getComponentBefore</code>,
<ul>
<li>if a Component is a child of a focus traversal policy provider,
the next and previous for this Component are determined using this
focus traversal policy provider's FocusTraversalPolicy. However,
in order for focus to leave the provider, the following rules are
applied:
<ul>
<li> if at some point the <code>next</code> found Component is
the <code>first</code> Component of focus traversal policy
provider, the Component after the focus traversal policy
provider is returned
<li> if at some point the <code>previous</code> found Component is
the <code>last</code> Component of focus traversal policy
provider, the Component before the focus traversal policy
provider is returned
</ul>
<li> When calculating the next Component in
<code>FocusTraversalPolicy.getComponentAfter</code>,
<ul>
<li> if an obtained Component is a non-traversable Container and
it is a focus traversal policy provider, then the default Component
of that provider is returned
<li> if the Component passed to the <code>FocusTraversalPolicy.getComponentAfter</code>
method is a traversable Container and it is a focus
traversal policy provider, then the default Component of this provider
is returned
</ul>
<li> When calculating the previous Component in
<code>FocusTraversalPolicy.getComponentBefore</code>,
<ul>
<li> if an obtained Component is a Container (traversable or
non-traversable) and it is a focus traversal policy provider, then
the last Component of that provider is returned
</ul>
</ul>
<li> When calculating the first Component in FocusTraversalPolicy.getFirstComponent,
<ul>
<li> if an obtained Component is a non-traversable Container and it is a focus
traversal policy provider, then the default Component of that provider is
returned
<li> if an obtained Component is a traversable Container and it is a focus traversal
policy provider, then that Container itself is returned
</ul>
<li> When calculating the last Component in FocusTraversalPolicy.getLastComponent,
<ul>
<li> if an obtained Component is a Container (traversable or non-traversable)
and it is a focus traversal policy provider, then the last Component of
that provider is returned
</ul>
</ul>
<a name="ProgrammaticTraversal"></a>
<h3>Programmatic Traversal</h3>
<p>
In addition to user-initiated focus traversal, client code can
initiate a focus traversal operation programmatically. To client code,
programmatic traversals are indistinguishable from user-initiated
traversals. The preferred way to initiate a programmatic traversal is
to use one of the following methods on <code>KeyboardFocusManager</code>:
<ul>
<li><code>KeyboardFocusManager.focusNextComponent()</code>
<li><code>KeyboardFocusManager.focusPreviousComponent()</code>
<li><code>KeyboardFocusManager.upFocusCycle()</code>
<li><code>KeyboardFocusManager.downFocusCycle()</code>
</ul>
<p>
Each of these methods initiates the traversal operation with the
current focus owner. If there is currently no focus owner, then no
traversal operation occurs. In addition, if the focus owner is not a
focus cycle root, then downFocusCycle() performs no traversal
operation.
<p>
<code>KeyboardFocusManager</code> also supports the following variants
of these methods:
<ul>
<li><code>KeyboardFocusManager.focusNextComponent(Component)</code>
<li><code>KeyboardFocusManager.focusPreviousComponent(Component)</code>
<li><code>KeyboardFocusManager.upFocusCycle(Component)</code>
<li><code>KeyboardFocusManager.downFocusCycle(Container)</code>
</ul>
Each of these methods initiates the traversal operation with the
specified Component rather than the focus owner. That is, the
traversal occurs as though the specified Component is the focus owner,
though it need not be.
<p>
Alternate, but equivalent, APIs are defined on the Component and
Container classes themselves:
<ul>
<li><code>Component.transferFocus()</code>
<li><code>Component.transferFocusBackward()</code>
<li><code>Component.transferFocusUpCycle()</code>
<li><code>Container.transferFocusDownCycle()</code>
</ul>
As with the <code>KeyboardFocusManager</code> variants, each of these methods
initiates the traversal operation as though the Component is the focus
owner, though it need not be.
<p>
Also note that hiding or disabling the focus owner, directly or
indirectly via an ancestor, or making the focus owner non-displayable
or non-focusable, initiates an automatic, forward focus traversal.
While hiding any ancestor, lightweight or heavyweight, will always
indirectly hide its children, only disabling a heavyweight ancestor
will disable its children. Thus, disabling a lightweight ancestor of
the focus owner does not automatically initiate a focus traversal.
<p>
If client code initiates a focus traversal, and there is no other
Component to focus, then the focus owner remains unchanged. If client
code initiates an automatic focus traversal by hiding the focus owner,
directly or indirectly, or by making the focus owner non-displayable or
non-focusable, and there is no other Component to focus, then the
global focus owner is cleared. If client code initiates an automatic
focus traversal by disabling the focus owner, directly or indirectly,
and there is no other Component to focus, then the focus owner remains
unchanged.
<a name="Focusability"></a>
<h3>Focusability</h3>
<p>
A focusable Component can become the focus owner ("focusability") and
participates in keyboard focus traversal ("focus traversability") with
a FocusTraversalPolicy. There is no separation of these two concepts;
a Component must either be both focusable and focus traversable, or
neither.
A Component expresses this state via the isFocusable() method. By
default, all Components return true from this method. Client code can
change this default by calling Component.setFocusable(boolean).
<a name="FocusableWindows"></a>
<h3>Focusable Windows</h3>
<p>
To support palette windows and input methods, client code can prevent
a Window from becoming the focused Window. By transitivity, this
prevents the Window or any of its descendants from becoming the focus
owner. Non-focusable Windows may still own Windows that are
focusable. By default, every Frame and Dialog is focusable. Every
Window which is not a Frame or Dialog, but whose nearest owning Frame
or Dialog is showing on the screen, and which has at least one
Component in its focus traversal cycle, is also focusable by
default. To make a Window non-focusable, use
Window.setFocusableWindowState(false).
<p>
If a Window is non-focusable, this restriction is enforced when the
<code>KeyboardFocusManager</code> sees a <code>WINDOW_GAINED_FOCUS</code>
event for the Window. At this point, the focus change is rejected and
focus is reset to a different Window. The rejection recovery scheme
is the same as if a <code>VetoableChangeListener</code> rejected the
focus change. See <a href="#FocusAndVetoableChangeListener">Focus
and VetoableChangeListener</a>.
<p>
Because the new focus implementation requires that KeyEvents intended
for a Window or its descendants be proxied through a child of the
Window's owner, and because this proxy must be mapped on X11 in order
to receive events, a Window whose nearest owning Frame or Dialog is
not showing could never receive KeyEvents on X11. To support this
restriction, we have made a distinction between a Window's "window
focusability" and its "window focusability state". A Window's
focusability state is combined with the showing state of the Window's
nearest owning Frame or Dialog to determine the Window's focusability.
By default, all Windows have a focusability state of true. Setting a
Window's focusability state to false ensures that it will not become
the focused Window regardless of the showing state of its nearest
owning Frame or Dialog.
<p>
Swing allows applications to create JWindows with null owners. Swing
constructs all such JWindows so that they are owned by a private,
hidden Frame. Because the showing state of this Frame will always be
false, a JWindow constructed will a null owner can never be the
focused Window, even if it has a Window focusability state of true.
<p>
If the focused Window is made non-focusable, then the AWT will attempt
to focus the most recently focused Component of the Window's
owner. The Window's owner will thus become the new focused Window. If
the Window's owner is also a non-focusable Window, then the focus
change request will proceed up the ownership hierarchy recursively.
Since not all platforms support cross-Window focus changes (see
<a href=#RequestingFocus>Requesting Focus</a>), it is possible that
all such focus change requests will fail. In this case, the global
focus owner will be cleared and the focused Window will remain unchanged.
<a name="RequestingFocus"></a>
<h3>Requesting Focus</h3>
<p>
A Component can request that it become the focus owner by calling
<code>Component.requestFocus()</code>. This initiates a permanent
focus transfer to the Component only if the Component is displayable,
focusable, visible and all of its ancestors (with the exception of the
top-level Window) are visible. The request will be immediately denied if
any of these conditions is not met. A disabled Component may be
the focus owner; however, in this case, all KeyEvents will be discarded.
<p>
The request will also be denied if the Component's top-level Window is
not the focused Window and the platform does not support requesting
focus across Windows. If the request is denied for this reason, the
request is remembered and will be granted when the Window is later
focused by the user. Otherwise, the focus change request changes the
focused Window as well.
<p>
There is no way to determine synchronously whether a focus change
request has been granted. Instead, client code must install a
FocusListener on the Component and watch for the delivery of a
<code>FOCUS_GAINED</code> event. Client code must not assume that
the Component is the focus owner until it receives this event.
The event may or may not be delivered before <code>requestFocus()</code>
returns. Developers must not assume one behavior or the other.
<p>
The AWT supports type-ahead if all focus change requests are made on
the EventDispatchThread. If client code requests a focus change, and
the AWT determines that this request might be granted by the native
windowing system, then the AWT will notify the current
KeyboardFocusManager that is should enqueue all KeyEvents with a
timestamp later than the that of the event currently being handled.
These KeyEvents will not be dispatched until the new Component becomes
the focus owner. The AWT will cancel the delayed dispatching request
if the focus change does not succeed at the native level, if the
Component's peer is disposed, or if the focus change is vetoed by a
VetoableChangeListener. KeyboardFocusManagers are not required to
support type-ahead if a focus change request is made from a thread
other than the EventDispatchThread.
<p>
Because <code>Component.requestFocus()</code> cannot be implemented
consistently across platforms, developers are encouraged to use
<code>Component.requestFocusInWindow()</code> instead. This method
denies cross-Window focus transfers on all platforms automatically.
By eliminating the only platform-specific element of the focus transfer,
this method achieves consistent cross-platform behavior.
<p>
In addition, <code>requestFocusInWindow()</code> returns a boolean value.
If 'false' is returned, the request is guaranteed to fail. If 'true' is
returned, the request will succeed unless it is vetoed, or an
extraordinary event, such as disposal of the Component's peer, occurs
before the request can be granted by the native windowing
system. Again, while a return value of 'true' indicates that the
request is likely to succeed, developers must never assume that this
Component is the focus owner until this Component receives a
<code>FOCUS_GAINED</code> event.
<p>
If client code wants no Component in the application to be the focus
owner, it can call the method <code>KeyboardFocusManager</code>.
<code>clearGlobalFocusOwner()</code> on the current
<code>KeyboardFocusManager</code>. If there exists a focus owner
when this method is called, the focus owner will receive a permanent
<code>FOCUS_LOST</code> event. After this point, the AWT
focus implementation will discard all KeyEvents until the user or
client code explicitly sets focus to a Component.
<p>
The Component class also supports variants of <code>requestFocus</code> and
<code>requestFocusInWindow</code> that allow client code to specify
a temporary state.
See <a href="#TemporaryFocusEvents">Temporary FocusEvents</a>
<a name="FocusAndPropertyChangeListener"></a>
<h3>Focus and PropertyChangeListener</h3>
<p>
Client code can listen to changes in context-wide focus state, or to
changes in focus-related state in Components, via
PropertyChangeListeners.
<p>
The <code>KeyboardFocusManager</code> supports the following properties:
<ol>
<li><code>focusOwner</code>: the focus owner
<li><code>focusedWindow</code>: the focused Window
<li><code>activeWindow</code>: the active Window
<li><code>defaultFocusTraversalPolicy</code>: the default focus
traversal policy
<li><code>forwardDefaultFocusTraversalKeys</code>: the Set of default
<code>FORWARD_TRAVERSAL_KEYS</code>
<li><code>backwardDefaultFocusTraversalKeys</code>: the Set of default
<code>BACKWARD_TRAVERSAL_KEYS</code>
<li><code>upCycleDefaultFocusTraversalKeys</code>: the Set of default
<code>UP_CYCLE_TRAVERSAL_KEYS</code>
<li><code>downCycleDefaultFocusTraversalKeys</code>: the Set of default
<code>DOWN_CYCLE_TRAVERSAL_KEYS</code>
<li><code>currentFocusCycleRoot</code>: the current focus cycle root
</ol>
<p>
A <code>PropertyChangeListener</code> installed on the current
<code>KeyboardFocusManager</code> will only see these changes within
the <code>KeyboardFocusManager</code>'s context, even though the
focus owner, focused Window, active Window, and current focus cycle
root comprise the global focus state shared by all contexts.
We believe this is less intrusive than requiring client code to pass
a security check before installing a <code>PropertyChangeListener</code>.
<p>
Component supports the following focus-related properties:
<ol>
<li><code>focusable</code>: the Component's focusability
<li><code>focusTraversalKeysEnabled</code>: the Component's
focus traversal keys enabled state
<li><code>forwardFocusTraversalKeys</code>: the Component's Set of
<code>FORWARD_TRAVERSAL_KEYS</code>
<li><code>backwardFocusTraversalKeys</code>: the Component's Set of
<code>BACKWARD_TRAVERSAL_KEYS</code>
<li><code>upCycleFocusTraversalKeys</code>: the Component's Set of
<code>UP_CYCLE_TRAVERSAL_KEYS</code>
</ol>
<p>
In addition to the Component properties, Container supports the
following focus-related properties:
<ol>
<li><code>downCycleFocusTraversalKeys</code>: the Container's Set of
<code>DOWN_CYCLE_TRAVERSAL_KEYS</code>
<li><code>focusTraversalPolicy</code>: the Container's focus
traversal policy
<li><code>focusCycleRoot</code>: the Container's focus-cycle-root state
</ol>
<p>
In addition to the Container properties, Window supports the following
focus-related property:
<ol>
<li><code>focusableWindow</code>: the Window's focusable Window state
</ol>
<p>
Also note that a <code>PropertyChangeListener</code> installed on a
Window will never see a <code>PropertyChangeEvent</code> for the
<code>focusCycleRoot</code> property.
A Window is always a focus cycle root; this property cannot change.
<p>
<a name="FocusAndVetoableChangeListener"></a>
<h3>Focus and VetoableChangeListener</h3>
<p>
The <code>KeyboardFocusManager</code> also supports
<code>VetoableChangeListener</code>s for the following properties:
<ol>
<li>"focusOwner": the focus owner
<li>"focusedWindow": the focused Window
<li>"activeWindow": the active Window
</ol>
If a VetoableChangeListener vetoes a focus or activation change by
throwing a PropertyVetoException, the change is aborted. Any
VetoableChangeListeners which had already approved the change will
asynchronously receive PropertyChangeEvents indicating a reversion of
state to the previous value.
<p>
VetoableChangeListeners are notified of the state change before the
change is reflected in the KeyboardFocusManager. Conversely,
PropertyChangeListeners are notified after the change is reflected.
It follows that all VetoableChangeListeners will be notified before
any PropertyChangeListener.
<p>
VetoableChangeListeners must be idempotent, and must veto both loss
and gain events for a particular focus change (e.g., both
<code>FOCUS_LOST</code> and <code>FOCUS_GAINED</code>). For example,
if a <code>VetoableChangeListener</code> vetoes a <code>FOCUS_LOST</code>
event, a <code>KeyboardFocusManager</code> is not required to search the
<code>EventQueue</code> and remove the associated pending
<code>FOCUS_GAINED</code> event. Instead, the
<code>KeyboardFocusManager</code> is free to attempt to
dispatch this event and it is the responsibility of the
<code>VetoableChangeListener</code> to veto it as well. In addition,
during processing of the <code>FOCUS_GAINED</code> event, the
<code>KeyboardFocusManager</code> may attempt to resync the global
focus state by synthesizing another <code>FOCUS_LOST</code> event.
This event must be vetoed just as the first <code>FOCUS_LOST</code> event was.
<p>
A <code>KeyboardFocusManager</code> may not hold any locks while
notifying <code>PropertyChangeListener</code>s of a state change.
This requirement is relaxed for <code>VetoableChangeListeners</code>,
however. Therefore, client-definied <code>VetoableChangeListener</code>s
should avoid acquiring additional locks inside
<code>vetoableChange(PropertyChangeEvent)</code> as this may lead to deadlock.
If a focus or activation change is rejected, the KeyboardFocusManager
will initiate rejection recovery as follows:
<ul>
<li>If a focused or active Window change was rejected, then the
focused or active Window will be reset to the Window which was
previously the focused or active Window. If there is no such
Window, then the <code>KeyboardFocusManager</code> will clear
the global focus owner.
<li>If a focus owner change was rejected, then the focus owner will be
reset to the Component which was previously the focus owner. If
that is not possible, then it will be reset to the next Component
in the focus traversal cycle after the previous focus owner. If
that is also not possible, then the <code>KeyboardFocusManager</code>
will clear the global focus owner.
</ul>
<code>VetoableChangeListener</code>s must be careful to avoid vetoing focus
changes initiated as a result of veto rejection recovery. Failure
to anticipate this situation could lead to an infinite cycle of
vetoed focus changes and recovery attempts.
<a name="ZOrder"></a>
<h3>Z-Order</h3>
<p>
On some native windowing systems, the Z-order of a Window can affect
its focused or active (if applicable) state. On Microsoft Windows, the
top-most Window is naturally the focused Window as well. However, on
Solaris, many window managers use a point-to-focus model that ignores
Z-order in determining the focused Window.
When focusing or activating Windows, the AWT adheres to the UI
requirements of the native platform. Therefore, the focus behavior of
Z-order-related methods such as:
<ul>
<li><code>Window.toFront()</code>
<li><code>Window.toBack()</code>
<li><code>Window.show()</code>
<li><code>Window.hide()</code>
<li><code>Window.setVisible(boolean)</code>
<li><code>Window.dispose()</code>
<li><code>Frame.setState(int)</code>
</ul>
is platform-dependent. In JDK 1.4, the behavior of these methods on
Microsoft Windows and Solaris is as follows:
<ul>
<li><code>Window.toFront()</code>:<br>
<b>Microsoft Windows</b>: The Window is moved to front, if possible.
While we will always be able to move this Window in front of other
Windows in the same VM, Windows 98 and Windows 2000 do not allow an
application to bring any of its windows to the front unless one
of that application's windows is already in the foreground. In
this case, Windows will instead flash the Window's icon in the
taskbar. If the Window is moved to the front, it will be made
the focused and (if applicable) active Window.
<br>
<b>Solaris</b>: The Window is moved to front. In a point-to-focus
window manager, the Window will become the focused Window if it
is the top-most Window underneath the cursor. In a click-to-focus
window manager, the focused Window will remain unchanged.
<li><code>Window.toBack()</code>:<br>
<b>Microsoft Windows</b>: The Window is moved to back. Note however
that Microsoft Windows insists that an owned Window always be in
front of all of its recursive owners. Thus, after the completion of
this operation, the Window may not be the lowest Java Window in the
Z-order. If the Window, or any of its owners, was the focused Window,
then the focused Window is reset to the top-most Window in the VM.
<br>
<b>Solaris</b>: The Window is moved to back. Like Microsoft Windows,
some window managers insist than an owned Window always be in front
of all of its recursive owners. Thus, after the completion of this
operation, the Window may not be the lowest Java Window in the
Z-order. If the Window was the focused Window, it will lose
focus in a point-to-focus window manager if it is no longer the
top-most Window under the cursor. In a click-to-focus window
manager, the focused Window will remain unchanged.
<li><code>Window.show()/Window.setVisible(true)/Frame.setState(NORMAL)</code>:<br>
<b>Microsoft Windows</b>: The Window is moved to front and becomes the focused
Window.
<br>
<b>Solaris</b>: The Window is moved to front. In a point-to-focus focus
window manager, the Window will be focused if it is now the
top-most Window under the cursor. In a click-to-focus window
manager, the Window will become the focused Window.
<li><code>Window.hide()/Window.setVisible(false)/Window.dispose()/
Frame.setState(ICONIFIED)</code>:<br>
<b>Microsoft Windows</b>: If the Window was the focused Window, the focused
Window is reset to a window chosen by the OS, or to no window. The
window may be in a native application, or a Java application in
another VM.
<br>
<b>Solaris</b>: If the Window was the focused Window, in a point-to-
focus window manager, the top-most Window under the cursor will
become the focused Window. In a click-to-focus window manager,
the focused Window is reset to a window chosen by the window
manager. The window may be in a native application, or a Java
application in another VM.
</ul>
<a name="ReplacingDefaultKeyboardFocusManager"></a>
<h3>Replacing DefaultKeyboardFocusManager</h3>
<p>
<code>KeyboardFocusManager</code>s are pluggable at the browser context
level. Client code can subclass <code>KeyboardFocusManager</code> or
<code>DefaultKeyboardFocusManager</code> to modify the way that WindowEvents
related to focus, FocusEvents, and KeyEvents are handled and
dispatched, and to examine and modify the global focus state. A custom
<code>KeyboardFocusManager</code> can also reject focus changes at a more
fundamental level then a FocusListener or WindowListener ever could.
<p>
While giving a developer ultimate control over the focus model,
replacing the entire <code>KeyboardFocusManager</code> is a difficult process
requiring a thorough understanding of the peer focus layer.
Fortunately, most applications do not need this much control.
Developers are encouraged to use KeyEventDispatchers,
KeyEventPostProcessors, FocusTraversalPolicies,
VetoableChangeListeners, and other concepts discussed in this document
before resorting to a full replacement of the <code>KeyboardFocusManager</code>.
<p>
First note that, because unhindered access to Components in other
contexts represents a security hole, the SecurityManager must grant a
new permission, "replaceKeyboardFocusManager", before client code is
permitted to replace the <code>KeyboardFocusManager</code> with an arbitrary
subclass instance. Because of the security check, replacing the
<code>KeyboardFocusManager</code> is not an option for applications that will be
deployed in environments with a SecurityManager, such as applets in a
browser.
<p>
Once installed, a <code>KeyboardFocusManager</code> instance has
access to the global focus state via a set of protected functions.
The <code>KeyboardFocusManager</code> can only call these functions
if it is installed in the calling thread's context. This ensures
that malicious code cannot circumvent the security check in
<code>KeyboardFocusManager.setCurrentFocusManager</code>.
A <code>KeyboardFocusManager</code> should always work with
the global focus state instead of the context focus state.
Failure to do this will lead to incorrect behavior of the
<code>KeyboardFocusManager</code>.
<p>
The primary responsibility of a <code>KeyboardFocusManager</code>
is the dispatch of the following events:
<ul>
<li>all <code>KeyEvent</code>s
<li>all <code>FocusEvent</code>s
<li><code>WindowEvent.WINDOW_GAINED_FOCUS</code>
<li><code>WindowEvent.WINDOW_LOST_FOCUS</code>
<li><code>WindowEvent.WINDOW_ACTIVATED</code>
<li><code>WindowEvent.WINDOW_DEACTIVATED</code>
</ul>
The peer layer will provide the <code>KeyboardFocusManager</code>
with all of the above events except <code>WINDOW_ACTIVATED</code>
and <code>WINDOW_DEACTIVATED</code>. The <code>KeyboardFocusManager</code>
must synthesize <code>WINDOW_ACTIVATED</code> and
<code>WINDOW_DEACTIVATED</code> events when appropriate and target them
accordingly.
<p>
The <code>KeyboardFocusManager</code> may need to retarget the events
provided by the peer layer to its own notion of the focus owner or
focused Window:
<ul>
<li>A KeyEvent must be retargeted to the focus owner. Because the peer
layer is unaware of any lightweight Components, KeyEvents will
arrive from the peer layer targeted to the focus owner's
heavyweight Container, not the focus owner.
<li>A <code>FOCUS_LOST</code> event must be retargeted to the focus
owner. Again, this is necessary because the peer layer is
unaware of lightweight Components.
<li>A <code>WINDOW_LOST_FOCUS</code> event must be retargeted to
the focused Window. The implementation of the Window class
may cause the native focused Window to differ from the Java
focused Window.
</ul>
<p>
A <code>KeyboardFocusManager</code> must ensure proper event ordering,
and a 1-to-1 correspondence between an event and its opposite event type.
The peer layer does not make any of these guarantees. For example, it is
possible for the peer layer to send a <code>FOCUS_GAINED</code>
event before a <code>WINDOW_GAINED_FOCUS</code> event.
The <code>KeyboardFocusManager</code> is responsible for
ensuring that the <code>WINDOW_GAINED_FOCUS</code> event is dispatched
before the <code>FOCUS_GAINED</code> event.
<p>
Before redispatching an event via <code>KeyboardFocusManager</code>.
<code>redispatchEvent</code>, a <code>KeyboardFocusManager</code>
must attempt to update the global focus state. Typically, this
is done using one of the <code>KeyboardFocusManager.setGlobal*</code>
methods; however, an implementation is free to implement its own methods.
After attempting an update, the <code>KeyboardFocusManager</code>
must verify that the global focus state change
was not rejected. A rejection is detected when a call to the
corresponding <code>getGlobal*</code> method returns a value different than the
value just set. Rejections occur in three standard cases:
<ul>
<li>If the <code>KeyboardFocusManager</code> attempts
to set the global focus owner to a non-focusable Component.
<li>If the <code>KeyboardFocusManager</code> attempts
to set the global focused Window to a non-focusable Window.
<li>If the change is rejected by an installed
<code>VetoableChangeListener</code>.
</ul>
<p>
Client-defined implementations of <code>KeyboardFocusManager</code>
can adjust the set of focus transfers which are rejected by overriding the
accessor and mutator methods for the global focus state.
<p>
If a request to change the global focus state is rejected, the
<code>KeyboardFocusManager</code> must discard the event which prompted
the focus change request. The Component to which the event was targeted
must not receive the event.
<p>
The <code>KeyboardFocusManager</code> is also expected to initiate rejection
recovery as outlined in <a href="#FocusAndVetoableChangeListener">Focus
and VetoableChangeListener</a>.
<p>
Finally, a KeyboardFocusManager must handle the following set of
special cases:
<ul>
<li>When handling a <code>WINDOW_GAINED_FOCUS</code> event, the
<code>KeyboardFocusManager</code> must set focus to the
appropriate child Component of the Window. If a child
Component of the Window previously requested focus,
but the focus change was rejected because the platform
does not support cross-Window focus change requests,
then focus should be set to that child Component.
Otherwise, if the Window has never been focused, focus should be
set to the Window's initial Component to focus. If the Window was
previously focused, focus should be set to the Window's most
recent focus owner.
<li>The <code>KeyboardFocusManager</code> must ensure that the
opposite Component or Window are as accurate as the native
windowing platform permits. For example, the
<code>KeyboardFocusManager</code> may need to
retarget the opposite Component to a lightweight child of the
heavyweight initially specified by the peer layer.
<br>
If the peer layer states that the opposite Component or Window is
<code>null</code>, it is acceptable for the
<code>KeyboardFocusManager</code> to propagate
this value. <code>null</code> indicates that it is highly
probably that no other Component or Window was involved
in the focus or activation change. Because of platform
limitations, this computation may be
subject to a heuristic and could be incorrect. Nevertheless, this
heuristic will be the best possible guess which the peer layer
could make.
<li>Focus and activation changes in which a Component or Window loses
focus or activation to itself must be discarded.
<li>Events posted by the peer layer claiming that the active Window
has lost focus to the focused Window must be discarded. The peer
implementation of the Window class may generate these spurious
events.
</ul>
<a name="Incompatibilities"></a>
<h3>Incompatibilities with Previous Releases</h3>
<p><b>Cross-platform changes:</b>
<ol>
<li>The default focus traversability for all Components is now
'true'. Previously, some Components (in particular, all
lightweights), had a default focus traversability of 'false'. Note
that despite this change, however, the
<code>DefaultFocusTraversalPolicy</code> for all AWT Containers
will preserve the traversal order of previous releases.
<li>A request to focus a non-focus traversable (i.e., non-focusable)
Component will be denied. Previously, such requests were granted.
<li><code>Window.toFront()</code> and <code>Window.toBack()</code>
now perform no operation if the Window is not visible.
Previously, the behavior was platform-dependent.
<li>KeyListeners installed on <code>Component</code>s
will no longer see <code>KeyEvent</code>s that map to focus
traversal operations, and
<code>Component.handleEvent()</code> will no longer be invoked
for such events. Previously, AWT Components saw these events
and had an opportunity to consume them before AWT
initiated focus traversal. Code that requires this
functionality should instead disable focus traversal keys on
its <code>Component</code>s and handle focus traversal
itself. Alternately, the code can use an
<code>AWTEventListener</code> or
<code>KeyEventDispatcher</code> to pre-listen to all
<code>KeyEvent</code>s.
</ol>
<p><b>Changes specific to Microsoft Windows:</b>
<ol>
<li><code>Window.toBack()</code> changes the focused Window to
the top-most Window after the Z-order change.
<li><code>requestFocus()</code> now allows cross-Window focus
change requests in all cases. Previously, requests were granted
for heavyweights, but denied for lightweights.
</ol>
</body>
</html>
<!--
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>The AWT Modality</title>
</head>
<body bgcolor="white">
<h1 align="center">The AWT Modality</h1>
<p>
This document, together with the API documentation for modality-related
classes (such as <code>java.awt.Dialog</code>), briefly describes the new
modality features and how to use them. It contains the following sections:
</p><ul>
<li><a href="#Definitions">Definitions</a></li>
<li><a href="#ModalityTypes">Modality types</a></li>
<li><a href="#ShowHideBlocking">Show/hide blocking</a></li>
<li><a href="#ModalExclusion">Modal exclusion</a></li>
<li><a href="#Related">Related AWT features</a></li>
<li><a href="#Security">Security</a></li>
<li><a href="#PlatformSupport">Platform support</a></li>
<li><a href="#Compatibility">Compatibility</a></li>
<li><a href="#Examples">Examples</a></li>
</ul>
<a name="Definitions"></a>
<h3>Definitions</h3>
<p>
<u>Document</u> - a window without an owner that, together with
all its child hierarchy, may be operated on as a single self-contained
document.
Every window belongs to some document &mdash; its root can be found as
the closest ancestor window without an owner.
</p><p>
<a name="ModalBlocked"></a>
<u>Modal blocked window</u> - a window, that:
</p><ul>
<li>doesn't receive any user input events
</li><li>doesn't receive input focus
</li><li>keeps its Z-order below the modal dialog that blocks it
</li></ul>
<blockquote>
<hr>
<b>Warning!</b> Some window managers allow users to change the window
Z-order in an arbitrary way &mdash; in that case the last requirement
may not be met.
<hr>
</blockquote>
<p>
<u>Modal dialog</u> - a dialog that blocks some windows while it is
visible. The blocked windows are determined according to the dialog's
scope of blocking.
</p><p>
<u>Modal excluded window</u> - a window that stays unblocked
while the modal dialog is visible. If a window is modal excluded
then all its owned windows and child components are also excluded.
</p><p>
<u>Scope of blocking (SB)</u> - the set of windows (instances of
<code>java.awt.Window</code> and all derived classes) that are blocked by
the modal dialog while it is visible.
</p><p>
<blockquote><hr>
<b>Note</b>: Everywhere in this document the notion of "window" is equal
to a top-level window in the Java programming language &mdash; in other words
an instance of <code>java.awt.Window</code> or any descendant class.
<hr></blockquote>
<a name="ModalityTypes"></a>
<h3>Modality types</h3>
<p>
There are four supported modality types :
</p><ul>
<li>toolkit
</li><li>application
</li><li>document
</li><li>modeless
</li></ul>
A dialog is, by default, modeless. A modal dialog is, by default,
application-modal.
<p>
</p><ol>
<li><u>Modeless dialogs</u><br>
A modeless dialog doesn't block any windows while visible.
</li><li><u>Document-modal dialogs</u><br>
A document-modal dialog blocks all windows from the same
document except those from its child hierarchy. The document root
is determined as the closest ancestor window without an
owner.
</li><li><u>Application-modal dialogs</u><br>
An application-modal dialog blocks all windows from the same
application except for those from its child hierarchy.
If there are several applets launched in a browser, they can be
treated either as separate applications or a single application.
This behavior is implementation-dependent.
</li><li><u>Toolkit-modal dialogs</u><br>
A toolkit-modal dialog blocks all windows that run in the same
toolkit except those from its child hierarchy. If there
are several applets launched all of them run with the same toolkit,
so a toolkit-modal dialog shown from an applet may affect other
applets and all windows of the browser instance which embeds the
Java runtime environment for this toolkit.
See the security section below.
</li></ol>
<p>
Modality priority is arranged by the strength of blocking: modeless,
document-modal, application-modal and toolkit-modal. This arrangement
is used when determining what dialog should remain unblocked if two
are visible and block each other. It naturally reflects the nesting
of a dialog's scope of blocking (SB): a modeless dialog has an empty SB,
a document-modal dialog's SB is complete in some applications,
and all the applications are run in one toolkit. </p><p>
Notes about owners:
</p><ul>
<li>Creating a document-modal dialog without an owner:<br>
Since <code>Dialog</code> is a class derived from
<code>Window</code>, a <code>Dialog</code> instance automatically
becomes the root of the document if it has no owner. Thus, if
such a dialog is document-modal, its scope of blocking is empty
and it behaves the same way as a modeless dialog.
</li><li>Creating an application-modal or toolkit-modal dialog with an
owner:<br>
The scope of blocking for an application- or toolkit-modal
dialog, as opposed to a document-modal dialog, doesn't depend on
its owner. Thus, in this case the only thing that the owner
affects is the Z-order: the dialog always stays on top of its owner.
</li></ul>
<p>
<blockquote><hr>
<b>Implementation note</b>: Changing the modality type for a visible
dialog may have no effect until it is hidden and then shown again.
<hr></blockquote>
<a name="ShowHideBlocking"></a>
<h3>Show/hide blocking</h3>
<p>
<u>Showing the window or modeless dialog: "F"</u><br>
All the visible modal dialogs are looked through &mdash; if F is from the SB
of one of them, it becomes blocked by it. If there are several such
dialogs, the first shown is used. If no such dialogs exist, F remains
unblocked.
</p><p>
<u>Showing the modal dialog: "M"</u><br>
When modal dialog M is shown, all the visible windows fall into one of
three distinct groups:
<ul>
<li>Blockers of M (modal dialogs that block M and
either are in M's child hierarchy, or are not blocked by M, or have
a greater mode of modality, or block some other blocker of M)
<li>Blocked by M (windows from M's SB that are not blockers and are
not in child hierarchy of any blocker)
<li>All other windows (windows or modeless
dialogs outside M's SB and modal dialogs outside M's SB that do not
block M).
</ul>
<p>
After the modal dialog M is shown, it becomes blocked by the first shown
dialog from the first group (if there are any), all the windows from the
second one become blocked by M, and all the windows from the third group
remain untouched.
</p><p>
<u>In typical cases</u>, when no child dialogs are shown before their owners,
this rule can be simplified. (The following, simplified case, may
leave out some details).
</p><p>
<u>Showing the document-modal dialog: "M"</u><br>
All the visible application- and toolkit-modal dialogs are looked
through &mdash; if M is from the SB of one of them,
it becomes blocked by it. If there are several such dialogs,
the first shown is used. If no such dialogs exist, M remains unblocked.
</p><p>
<u>Showing the application-modal dialog: "M"</u><br>
All the visible toolkit-modal dialogs are looked through &mdash;
if M is from the SB of one of them, it becomes blocked by it.
If there are several such dialogs, the first shown is used.
If no such dialogs exist, M remains unblocked.
</p><p>
<u>Showing the toolkit-modal dialog: "M"</u><br>
M remains unblocked.
</p><p>
<!-- <center> -->
</p>
<table border="1">
<caption>The Standard Blocking Matrix</caption>
<tbody><tr align="center">
<td align="center">current/shown</td>
<td align="center">frame &amp; modeless</td>
<td align="center">document</td>
<td align="center">application</td>
<td align="center">toolkit</td>
</tr>
<tr align="center">
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
</tr>
<tr align="center">
<td align="center">document</td>
<td align="center">blocked</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
</tr>
<tr align="center">
<td align="center">application</td>
<td align="center">blocked</td>
<td align="center">blocked</td>
<td align="center">-</td>
<td align="center">-</td>
</tr>
<tr align="center">
<td align="center">toolkit</td>
<td align="center">blocked</td>
<td align="center">blocked</td>
<td align="center">blocked</td>
<td align="center">-</td>
</tr>
</tbody></table>
<!-- </center> -->
<p>
After the modal dialog is shown, all the windows from its SB are blocked,
except those that block this modal dialog.
</p><p>
<u>Hiding the window or modeless dialog: "F"</u><br>
If F was blocked by any modal dialog M, it becomes unblocked and is
removed from M's blocked windows list.
</p><p>
<u>Hiding the modal dialog: "M"</u><br>
If M was blocked by any other modal dialog, for example, "N",
it becomes unblocked and
is removed from N's blocked windows list. Then, all the windows and dialogs
blocked by M become unblocked, and after that the same checks
(as in Showing the modal dialog: "M")
are performed for each of them in the order they were initially shown.
<a name="ModalExclusion"></a>
</p><h3>Modal exclusion</h3>
<p>
There are two modal exclusion types introduced as of JDK 6
</p><ul>
<li>Exclusion from blocking of toolkit-modal dialogs
</li><li>Exclusion from blocking of application-modal dialogs
</li></ul>
By default, a window's modal exclusion property is turned off.
<p>
</p><ol>
<li><u>Application-modal exclusion</u><br>
If a window is application-modal excluded, it is not blocked by any
application-modal dialogs. Also, it is not blocked by document-modal
dialogs from outside of its child hierarchy.
</li><li><u>Toolkit-modal exclusion</u><br>
If a window is toolkit-modal excluded, it is not blocked
by any application- or toolkit-modal dialogs. Also, it is not
blocked by document-modal dialogs from outside of their child hierarchy.
</li></ol>
<p>
<blockquote>
<hr>
<b>Implementation note</b>: Changing the modal exclusion type for a visible window
may have no effect until it is hidden and then shown again.
</blockquote>
<a name="Related"></a>
<h3>Related AWT features</h3>
<p>
<u>Always-On-Top</u><br>
When a modal dialog that is not always-on-top blocks an always-on-top window,
their relative Z-order is unspecified and platform-dependent.
</p>
<p>
<u>The <code>toFront()</code> and <code>toBack()</code> methods</u><br>
A modal dialog should always be above all its blocked windows. Thus, if a blocked
window is brought to the front, its blocking dialog, if any, is also brought to the
front and remains above the blocked window. Likewise, if a modal dialog is sent to
the back, all of its blocked windows are sent to the back to keep them below the
blocking dialog.
</p>
<p>
<u>Minimizing, maximizing and closing blocked windows</u><br>
When a modal dialog blocks a window, the user may not be able to maximize or
minimize the blocked window&mdash; however, the actual behavior is unspecified
and platform-dependent. In any case, the user can't close the blocked window
interactively&mdash; but it can be closed programmatically by calling the
<code>setVisible(false)</code> or <code>dispose()</code> methods on the blocked
window.
</p>
<p>
<u>Blocked windows activations</u><br>
When the user selects a blocked window, it may be brought to the front, along
with the blocking modal dialog which would then become the active window&mdash;
however, the actual behavior is unspecified and platform-dependent.
</p>
<p>
<u>Hiding a modal dialog</u><br>
When the modal dialog that currently has focus is hidden, it is unspecified
and platform-dependent, which other window will become the active window.
Any of the following may become the active window:
<ol>
<li>The owner of the modal dialog - if the owner is unblocked.
</li><li>The <code>Window</code>, which was active before this modal dialog gained
focus - if the owner of the modal dialog is absent or is blocked.
</li></ol>
If the modal dialog to be hidden does not have focus, the active window remains
unchanged.
<a name="Security"></a>
<h3>Security</h3>
<p>
A special <code>AWTPermission</code>, <code>"toolkitModality"</code>,
is required to show toolkit-modal
dialogs. This would prevent, for example, blocking a browser or
Java Web Start (JWS) by modal dialogs shown from applets.
</p><p>
The same permission is required to exclude a window from toolkit modality.
This would prevent, for example, a dialog shown from an applet not to be
blocked by a browser's or JWS's modal dialog.
<a name="PlatformSupport"></a>
</p><h3>Platform support</h3>
<p>
Two <code>java.awt.Toolkit</code> methods allow you to check whether
the current platform supports specific modality features:
</p><ul>
<li><code>isModalityTypeSupported(modalityType)</code><br>
Returns whether the specified modality type is supported on
the current platform.
If mode "M" is not supported and a dialog is set to M-modal,
it behaves as modeless.
</li>
<li><code>isModalExclusionTypeSupported(modalExclusionType)</code><br>
Returns whether the given modal exclusion type is supported on
the current platform. If exclusion type "E" is not supported
and a window is marked as E-excluded, this has no effect.
</li></ul>
<a name="Compatibility"></a>
<h3>Compatibility</h3>
<p>
The default modality type is application-modal. It is used by the API
calls: <code>Dialog.setModal(true)</code>,
<code>Dialog(owner, true)</code>, etc. Prior to JDK 6
the default type was toolkit-modal,
but the only distinction between application- and toolkit-modality is for
applets and applications launched from Java Web Start.
<a name="Examples"></a>
</p><h3>Examples</h3>
<table border="0">
<tbody><tr>
<td align="left" >
<ol>
<li>Frame "F" is shown<br>
<li>Document-modal dialog "D<sub>i</sub>" is shown<br>
<li>F becomes blocked by D<sub>i</sub> &mdash; it's in the same document<br>
<li>Document-modal dialog "D<sub>ii</sub>" is shown<br>
<li>D<sub>i</sub> becomes blocked by D<sub>ii</sub> &mdash; it's in the
same document<br>
</ol>
<br>
</td>
<td align="center">
<img src="modal-example1.gif">
<br>
</td>
</tr>
<tr>
<td align="left">
<ol>
<li>Frame "F" is shown<br>
<li>Document-modal dialog "D<sub>i</sub>" is shown<br>
<li>F becomes blocked by D<sub>i</sub> &mdash; it's in the same document<br>
<li>Document-modal dialog "D<sub>ii</sub>" is shown<br>
<li>D<sub>i</sub> becomes blocked by D<sub>ii</sub> &mdash;
it's in the same document<br>
<li>D<sub>i</sub> is hidden<br>
<li>F becomes blocked by D<sub>ii</sub> &mdash; it's in the same document<br>
</ol>
<br>
</td>
<td align="center">
<img src="modal-example2.gif">
<br>
</td>
</tr>
<tr>
<td align="left">
<ol>
<li>Frame "F" is shown<br>
<li>Toolkit-modal dialog "D<sub>i</sub>" is created, but not shown<br>
<li>Document-modal dialog "D<sub>ii</sub>" is shown<br>
<li>F becomes blocked by D<sub>ii</sub> &mdash; it's in the same document<br>
<li>Application-modal dialog "D<sub>iii</sub>" is shown<br>
<li>D<sub>ii</sub> becomes blocked by D<sub>iii</sub> &mdash;
it's in the same application<br>
<li>D<sub>i</sub> is shown<br>
<li>D<sub>i</sub> becomes blocked by D<sub>ii</sub> &mdash; it's its owner<br>
<li>D<sub>iii</sub> remains unblocked &mdash; it blocks D<sub>ii</sub> and
D<sub>ii</sub> blocks D<sub>i</sub><br>
</ol>
<br>
</td>
<td align="center">
<img src="modal-example3.gif">
<br>
</td>
</tr>
<tr>
<td align="left">
<ol>
<li>Frame "F" is shown<br>
<li>Toolkit-modal dialog "D<sub>i</sub>" is created, but not shown<br>
<li>Document-modal dialog "D<sub>ii</sub>" is shown<br>
<li>F becomes blocked by D<sub>ii</sub> &mdash; it's in the same document<br>
<li>Application-modal dialog "D<sub>iii</sub>" is shown<br>
<li>D<sub>ii</sub> becomes blocked by D<sub>iii</sub> &mdash; it's in the
same application<br>
<li>D<sub>i</sub> is shown<br>
<li>D<sub>iii</sub> becomes blocked by D<sub>i</sub> &mdash; D<sub>i</sub>
is not blocked<br>
<li>D<sub>i</sub> remains unblocked<br>
</ol>
<br>
</td>
<td align="center">
<img src="modal-example4.gif">
<br>
</td>
</tr>
</tbody></table>
</body></html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides interfaces and classes for dealing with different
types of events fired by AWT components. See the java.awt.AWTEvent
class for details on the AWT event model. Events are fired by event
sources. An event listener registers with an event source to receive
notifications about the events of a particular type. This package
defines events and event listeners, as well as event listener
adapters, which are convenience classes to make easier the process of
writing event listeners.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides classes and interface relating to fonts. It
contains support for representing Type 1, Type 1 Multiple Master
fonts, OpenType fonts, and TrueType fonts.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides the Java 2D classes for defining and performing operations
on objects related to two-dimensional geometry. Some important features
of the package include:
<ul>
<li>classes for manipulating geometry, such as AffineTransform and
the PathIterator interface which is implemented by all Shape objects.
<li>classes that implement the Shape interface, such as
CubicCurve2D, Ellipse2D, Line2D, Rectangle2D, and GeneralShape.
<li>the Area class which provides mechanisms for add (union), subtract,
intersect, and exclusiveOR operations on other Shape objects.
</ul>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME=GENERATOR CONTENT="Claris Home Page 2.0">
<X-SAS-WINDOW TOP=42 BOTTOM=589 LEFT=4 RIGHT=534>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<P>Provides classes and interfaces for the input method framework.
This package enables text editing components to receive text input
through input methods. Input methods are software components that let
the user enter text in ways other than simple typing on a keyboard.
They are commonly used to enter Japanese, Chinese, or Korean -
languages using thousands of different characters - on keyboards with
far fewer keys. However, the framework also supports input methods
for other languages and the use of entirely different input
mechanisms, such as handwriting or speech recognition.</P>
<H2>Package Specification</H2>
<UL>
<LI><B><A HREF="{@docRoot}/../technotes/guides/imf/spec.html">Input Method
Framework Specification</A></B>
<LI><B><A HREF="{@docRoot}/../technotes/guides/imf/api-reference.html">Input
Method Client API Reference</A></B>
</UL>
<H2>Related Documentation</H2>
<P>For overviews, tutorials, examples, guides, and tool
documentation, please see:</P>
<UL>
<LI><B><A HREF="{@docRoot}/../technotes/guides/imf/overview.html">Input Method
Framework Overview</A></B>
<LI><B><A HREF="{@docRoot}/../technotes/guides/imf/api-tutorial.html">Input
Method Client API Tutorial</A></B>
</UL>
@since 1.2
</BODY>
</HTML>
<!--
Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--This file created 7/22/1999 11:47 by Claris Home Page version 2.0-->
<HTML>
<HEAD>
<TITLE>Package java.awt.im.spi Description</TITLE>
<META NAME=GENERATOR CONTENT="Claris Home Page 2.0">
<X-SAS-WINDOW TOP=51 BOTTOM=592 LEFT=171 RIGHT=701>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<P>Provides interfaces that enable the development of input methods
that can be used with any Java runtime environment. Input methods are
software components that let the user enter text in ways other than
simple typing on a keyboard. They are commonly used to enter
Japanese, Chinese, or Korean - languages using thousands of different
characters - on keyboards with far fewer keys. However, this package
also allows the development of input methods for other languages and
the use of entirely different input mechanisms, such as handwriting
recognition.</P>
<H2><A NAME="package_specification"></A>Package Specification</H2>
<UL>
<LI><B><A HREF="../../../../../technotes/guides/imf/spec.html">Input Method
Framework Specification</A></B>
<LI><B><A HREF="../../../../../technotes/guides/imf/spi-reference.html">Input
Method Engine SPI Reference</A></B>
</UL>
<H4><A NAME="Packaging"></A>Packaging Input Methods</H4>
<P>Input methods are packaged as installed extensions, as specified
by the <A HREF="../../../../../technotes/guides/extensions/index.html">Extension
Mechanism</A>. The main JAR file of an input method must contain the
file:</P>
<PRE> META-INF/services/java.awt.im.spi.InputMethodDescriptor</PRE>
<P>The file should contain a list of fully-qualified class names, one
per line, of classes implementing the
<CODE>java.awt.im.spi.InputMethodDescriptor</CODE> interface. Space
and tab characters surrounding each name, as well as blank lines, are
ignored. The comment character is <CODE>'#'</CODE>
(<CODE>\u0023</CODE>); on each line all characters following the
first comment character are ignored. The file must be encoded in
UTF-8.</P>
<P>For example, if the fully-qualified name of the class that
implements <CODE>java.awt.im.spi.InputMethodDesciptor</CODE> for the
<EM>Foo</EM> input method is
<CODE>com.sun.ime.FooInputMethodDescriptor</CODE>, the file
<CODE>META-INF/services/java.awt.im.spi.InputMethodDescriptor</CODE>
contains a line:</P>
<PRE> com.sun.ime.FooInputMethodDescriptor</PRE>
<P>The input method must also provide at least two classes: one class
implementing the <CODE>java.awt.im.spi.InputMethodDescriptor</CODE>
interface, one class implementing the
<CODE>java.awt.im.spi.InputMethod</CODE> interface. The input method
should separate the implementations for these interfaces, so that
loading of the class implementing <CODE>InputMethod</CODE> can be
deferred until actually needed.</P>
<H4><A NAME="Loading"></A>Loading Input Methods</H4>
<P>The input method framework will usually defer loading of input
method classes until they are absolutely needed. It loads only the
<CODE>InputMethodDescriptor</CODE> implementations during AWT
initialization. It loads an <CODE>InputMethod</CODE> implementation
when the input method has been selected.</P>
<H4><A NAME="PeeredComponents"></A>Java Input Methods and Peered Text
Components</H4>
<P>The Java input method framework intends to support all
combinations of input methods (host input methods and Java input
methods) and components (peered and lightweight). However, because of
limitations in the underlying platform, it may not always be possible
to enable the communication between Java input methods and peered AWT
components. Support for this specific combination is therefore
platform dependent. In Sun's Java SE Runtime Environments, this
combination is supported on Windows, but not on Solaris.</P>
<H2>Related Documentation</H2>
<P>For overviews, tutorials, examples, guides, and tool
documentation, please see:</P>
<UL>
<LI><B><A HREF="../../../../../technotes/guides/imf/overview.html">Input
Method Framework Overview</A></B>
<LI><B><A HREF="../../../../../technotes/guides/imf/spi-tutorial.html">Input
Method Engine SPI Tutorial</A></B>
</UL>
@since JDK1.3
</BODY>
</HTML>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides classes for creating and modifying images.
Images are processed using a streaming framework that involves an
image producer, optional image filters, and an image consumer. This
framework makes it possible to progressively render an image while it
is being fetched and generated. Moreover, the framework allows an
application to discard the storage used by an image and to regenerate
it at any time. This package provides a number of image producers,
consumers, and filters that you can configure for your image
processing needs.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.0
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides classes and interfaces for producing
rendering-independent images.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Contains all of the classes for creating user
interfaces and for painting graphics and images. A user interface object such as a button or a
scrollbar is called, in AWT terminology, a component. The Component class is the root of all
AWT components. See Component for a detailed description of properties that all AWT
components share.
<p>
Some components fire events when a user interacts with the components. The AWTEvent
class and its subclasses are used to represent the events that AWT components can fire. See
AWTEvent for a description of the AWT event model.
<p>
A container is a component that can contain components and other containers. A con
tainer can also have a layout manager that controls the visual placement of components in the
container. The AWT package contains several layout manager classes and an interface for
building your own layout manager. See Container and LayoutManager for more information.
<p>
Each {@code Component} object is limited in its maximum size and
its location because the values are stored as an integer.
Also, a platform may further restrict maximum size and location
coordinates. The exact maximum values are dependent on the platform.
There is no way to change these maximum values, either in Java
code or in native code.
These limitations also impose restrictions on component layout.
If the bounds of a Component object exceed a platform limit,
there is no way to properly arrange them within a Container object.
The object's bounds are defined by any object's coordinate
in combination with its size on a respective axis.
<h2>Additional Specification</h2>
<ul>
<li><a href="doc-files/FocusSpec.html">The AWT Focus Subsystem</a>
<li><a href="doc-files/Modality.html">The AWT Modality</a>
</ul>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.0
</body>
</html>
<!--
Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides for interfacing with the underlying window system.
It is for accessing the platform-specific facilities in order to
build AWT toolkits. It is only used by AWT toolkit developers.
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title></title></head>
<body bgcolor="white">
Provides classes and interfaces for a general printing API. The
API includes such features as:
<ul>
<li>the ability to specify document types
<li>mechanisms for control of page setup and page formats
<li>the ability to manage job control dialogs
</ul>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides classes and interfaces relating to bean context.
A bean context is a container for beans and defines the execution
environment for the beans it contains. There can be several beans in
a single bean context, and a bean context can be nested within another
bean context. This package also contains events and listener
interface for beans being added and removed from a bean context.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Contains classes related to developing
<em>beans</em> -- components
based on the JavaBeans&trade; architecture.
A few of the
classes are used by beans while they run in an application.
For example, the event classes are
used by beans that fire property and vetoable change
events (see
{@link java.beans.PropertyChangeEvent}). However, most of the classes in this
package are meant to be used by a bean editor (that is, a development environment
for customizing and putting together beans to create an application). In
particular, these classes help the bean editor create a user
interface that the user can use to customize the bean. For example, a bean may
contain a property of a special type that a bean editor may not know how to handle.
By using the <code>PropertyEditor</code> interface, a bean developer can
provide an editor for this special type.
<p>
To minimize the resources used by a bean, the classes used by bean editors are loaded only
when the bean is being edited. They are not needed while the bean is running in an application
and therefore not loaded. This information is kept in what's called a bean-info (see {@link java.beans.BeanInfo}).
<p>
Unless explicitly stated, null values or empty Strings are not valid
parameters for the methods in this package. You may expect to see
exceptions if these parameters are used.
<h2>Long-Term Persistence</h2>
As of v1.4,
the <code>java.beans</code> package provides support for
<em>long-term persistence</em> -- reading and
writing a bean as a textual representation of its property values.
The property values are treated as beans,
and are recursively read or written to capture
their publicly available state.
This approach is suitable for long-term storage
because it relies only on public API,
rather than the likely-to-change private implementation.
<blockquote>
<hr>
<b>Note:</b>
The persistence scheme cannot automatically instantiate
custom inner classes, such as you might use for event handlers.
By using the {@link java.beans.EventHandler} class
instead of inner classes for custom event handlers,
you can avoid this problem.
<hr>
</blockquote>
<p>
You read and write beans in XML format using the
{@link java.beans.XMLDecoder}
and
{@link java.beans.XMLEncoder}
classes, respectively.
One notable feature of the persistence scheme is that
reading in a bean requires no special knowledge of the bean.
<p>
Writing out a bean, on the other hand,
sometimes requires special knowledge of the bean's type.
If the bean's state can be
expressed using only the no-argument constructor and
public getter and setter methods for properties,
no special knowledge is required.
Otherwise, the bean requires a custom <em>persistence delegate</em> --
an object that is in charge of writing out beans of a particular type.
All classes provided in the JDK that descend
from <code>java.awt.Component</code>,
as well as all their properties,
automatically have persistence delegates.
<p>
If you need (or choose) to provide a persistence delegate for a bean,
you can do so either by using a
{@link java.beans.DefaultPersistenceDelegate}
instance
or by creating your own subclass of <code>PersistenceDelegate</code>.
If the only reason a bean needs a persistence delegate
is because you want to invoke the bean's constructor with
property values as arguments,
you can create the bean's persistence delegate
with the one-argument
<code>DefaultPersistenceDelegate</code>
constructor.
Otherwise,
you need to implement your own persistence delegate,
for which you're likely to need the following classes:
<dl>
<dt> {@link java.beans.PersistenceDelegate}
<dd> The abstract class from which all persistence delegates descend.
Your subclass should use its knowledge of the bean's type to provide
whatever <code>Statement</code>s and <code>Expression</code>s
are necessary to create the bean
and restore its state.
<dt> {@link java.beans.Statement}
<dd> Represents the invocation of a single method on an object.
Includes a set of arguments to the method.
<dt> {@link java.beans.Expression}
<dd> A subclass of <code>Statement</code>
used for methods that return a value.
</dl>
<p>
Once you create a persistence delegate,
you register it using the
<code>setPersistenceDelegate</code> method of
<code>XMLEncoder</code>.
<h2>Related Documentation</h2>
For overview, architecture, and tutorial documentation, please see:
<ul>
<li><a href="http://docs.oracle.com/javase/tutorial/javabeans/">JavaBeans</a>, a trail in <em>The Java Tutorial</em>.
<li><a href="http://www.oracle.com/technetwork/java/persistence2-141443.html">Long-Term Persistence</a>, an article in <em>The Swing Connection</em>.
</ul>
<p>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<!--
Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides for system input and output through data streams,
serialization and the file system.
Unless otherwise noted, passing a null argument to a constructor
or method in any class or interface in this package will cause a
<tt>NullPointerException</tt> to be thrown.
<h2>Package Specification</h2>
<ul>
<li><a href="../../../platform/serialization/spec/serialTOC.html"> Java Object Serialization Specification </a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation,
please see:
<ul>
<li><a href="../../../technotes/guides/serialization">Serialization Enhancements</a>
</ul>
@since JDK1.0
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Value-based Classes</title>
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
</head>
<body>
<h2 id="ValueBased">Value-based Classes</h2>
Some classes, such as <code>java.util.Optional</code> and
<code>java.time.LocalDateTime</code>, are <em>value-based</em>. Instances of a
value-based class:
<ul>
<li>are final and immutable (though may contain references to mutable
objects);</li>
<li>have implementations of <code>equals</code>,
<code>hashCode</code>, and <code>toString</code> which are computed
solely from the instance's state and not from its identity or the state
of any other object or variable;</li>
<li>make no use of identity-sensitive operations such as reference
equality (<code>==</code>) between instances, identity hash code of
instances, or synchronization on an instances's intrinsic lock;</li>
<li>are considered equal solely based on <code>equals()</code>, not
based on reference equality (<code>==</code>);</li>
<li>do not have accessible constructors, but are instead instantiated
through factory methods which make no committment as to the identity
of returned instances;</li>
<li>are <em>freely substitutable</em> when equal, meaning that interchanging
any two instances <code>x</code> and <code>y</code> that are equal
according to <code>equals()</code> in any computation or method
invocation should produce no visible change in behavior.
</li>
</ul>
<p>A program may produce unpredictable results if it attempts to distinguish two
references to equal values of a value-based class, whether directly via reference
equality or indirectly via an appeal to synchronization, identity hashing,
serialization, or any other identity-sensitive mechanism. Use of such
identity-sensitive operations on instances of value-based classes may have
unpredictable effects and should be avoided.</p>
</body>
</html>
<!--
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright 2003 Wily Technology, Inc.
-->
</head>
<body bgcolor="white">
Provides services that allow Java programming language agents to instrument programs running on the JVM.
The mechanism for instrumentation is modification of the byte-codes of methods.
<h2>Package Specification</h2>
<P>
An agent is deployed as a JAR file. An attribute in the JAR file manifest specifies the
agent class which will be loaded to start the agent. For implementations that support a command-line
interface, an agent is started by specifying an option on the command-line.
Implementations may also support a mechanism to start agents some time after the VM has
started. For example, an implementation may provide a mechanism that allows a tool to
<i>attach</i> to a running application, and initiate the loading of the tool's agent into
the running application. The details as to how the load is initiated, is implementation
dependent.
<h3>Command-Line Interface</h3>
<P>
An implementation is not required to provide a way to start agents from the
command-line interface. On implementations that do provide a way to start agents
from the command-line interface, an agent is started by adding this option to
the command-line:
<blockquote>
<code><b>-javaagent:</b></code><i>jarpath[</i><code><b>=</b></code><i>options]</i>
</blockquote>
<i>jarpath</i> is the path to the agent JAR file.
<i>options</i> is the agent options.
This switch may be used multiple times on the same command-line,
thus creating multiple agents.
More than one agent may use the same <i>jarpath</i>.
An agent JAR file must conform to the JAR file specification.
<P>
The manifest of the agent JAR file must contain the attribute <code>Premain-Class</code>. The
value of this attribute is the name of the <i>agent class</i>. The agent class must implement a
public static <code>premain</code> method similar in principle to the <code>main</code> application
entry point. After the Java Virtual Machine (JVM) has initialized, each <code>premain</code> method
will be called in the order the agents were specified, then the real application
<code>main</code> method will be called.
Each <code>premain</code> method must return in order for the startup sequence to proceed.
<P>
The <code>premain</code> method has one of two possible signatures. The JVM first attempts to
invoke the following method on the agent class:
<blockquote>
<code>public static void
premain(String agentArgs, Instrumentation inst);
</code>
</blockquote>
<P>
If the agent class does not implement this method then the JVM will attempt to invoke:
<blockquote>
<code>public static void
premain(String agentArgs);
</code>
</blockquote>
<P>
The agent class may also have an <code>agentmain</code> method for use when the agent is started
after VM startup. When the agent is started using a command-line option, the <code>agentmain</code>
method is not invoked.
<P>
The agent class will be loaded by the system class loader
(see {@link java.lang.ClassLoader#getSystemClassLoader ClassLoader.getSystemClassLoader}). This is
the class loader which typically loads the class containing the application <code>main</code> method.
The <code>premain</code> methods will be run under the same security and classloader
rules as the application <code>main</code> method.
There are no modeling restrictions on what the agent <code>premain</code> method may do.
Anything application <code>main</code> can do, including creating threads, is legal from <code>premain</code>.
<P>
Each agent is passed its agent options via the <code>agentArgs</code> parameter.
The agent options are passed as a single string,
any additional parsing should be performed by the agent itself.
<P>
If the agent cannot be resolved
(for example, because the agent class cannot be loaded,
or because the agent class does not have an appropriate <code>premain</code> method), the JVM will abort.
If a <code>premain</code> method throws an uncaught exception, the JVM will abort.
<h3>Starting Agents After VM Startup</h3>
<p>
An implementation may provide a mechanism to start agents sometime after the
the VM has started. The details as to how this is initiated are implementation
specific but typically the application has already started and its <code>
main</code> method has already been invoked. In cases where an implementation
supports the starting of agents after the VM has started the following applies:
<ol>
<li><p>The manifest of the agent JAR must contain the attribute <code>Agent-Class</code>.
The value of this attribute is the name of the <i>agent class</i>. </p></li>
<li><p>The agent class must implement a public static <code>agentmain</code> method. </p></li>
<li><p>The system class loader (
{@link java.lang.ClassLoader#getSystemClassLoader ClassLoader.getSystemClassLoader}) must
support a mechanism to add an agent JAR file to the system class path. <p></li>
</ol>
<P>
The agent JAR is appended to the system class path. This is the class loader that typically loads
the class containing the application <code>main</code> method. The agent class is loaded and the
JVM attempts to invoke the <code>agentmain</code> method. The JVM first attempts to invoke
the following method on the agent class:
<blockquote>
<code>public static void
agentmain(String agentArgs, Instrumentation inst);
</code>
</blockquote>
<P>
If the agent class does not implement this method then the JVM will attempt to invoke:
<blockquote>
<code>public static void
agentmain(String agentArgs);
</code>
</blockquote>
<P>
The agent class may also have an <code>premain</code> method for use when the agent is started
using a command-line option. When the agent is started after VM startup the <code>premain</code>
method is not invoked.
<P>
The agent is passed its agent options via the <code>agentArgs</code> parameter.
The agent options are passed as a single string,
any additional parsing should be performed by the agent itself.
<P>
The <code>agentmain</code> method should do any necessary initialization
required to start the agent. When startup is complete the method should
return. If the agent cannot be started
(for example, because the agent class cannot be loaded,
or because the agent class does not have a conformant <code>agentmain</code> method), the JVM will
not abort. If the <code>agentmain</code> method throws an uncaught exception it will be ignored.
<h3>Manifest Attributes</h3>
The following manifest attributes are defined for an agent JAR file:
<blockquote>
<dl>
<dt><code>Premain-Class</code></dt>
<dd>
When an agent is specified at JVM launch time this attribute
specifies the agent class.
That is, the class containing the <code>premain</code> method.
When an agent is specified at JVM launch time this attribute
is required. If the attribute is not present the JVM will abort.
Note: this is a class name, not a file name or path.
</dd>
<dt><code>Agent-Class</code></dt>
<dd>
If an implementation supports a mechanism to start agents
sometime after the VM has started then this attribute specifies
the agent class.
That is, the class containing the <code>agentmain</code> method.
This attribute is required, if it is not present the agent
will not be started.
Note: this is a class name, not a file name or path.
</dd>
<dt><code>Boot-Class-Path</code></dt>
<dd>
A list of paths to be searched by the bootstrap class
loader. Paths represent directories or libraries
(commonly referred to as JAR or zip libraries on
many platforms).
These paths are searched by the
bootstrap class loader after the platform specific
mechanisms of locating a class have failed.
Paths are searched in the order listed.
Paths in the list are separated by one or more spaces.
A path takes the syntax of the path component of a
hierarchical URI. The path is
absolute if it begins with a slash character ('/'),
otherwise it is relative. A relative path is resolved
against the absolute path of the agent JAR file.
Malformed and non-existent paths are ignored.
When an agent is started sometime after the VM has
started then paths that do not represent a JAR file
are ignored.
This attribute is optional.
</dd>
<dt><code>Can-Redefine-Classes</code></dt>
<dd>
Boolean (<code>true</code> or <code>false</code>, case irrelevant).
Is the ability to redefine classes
needed by this agent.
Values other than <code>true</code> are considered <code>false</code>.
This attribute is optional, the default is <code>false</code>.
</dd>
<dt><code>Can-Retransform-Classes</code></dt>
<dd>
Boolean (<code>true</code> or <code>false</code>, case irrelevant).
Is the ability to retransform classes
needed by this agent.
Values other than <code>true</code> are considered <code>false</code>.
This attribute is optional, the default is <code>false</code>.
</dd>
<dt><code>Can-Set-Native-Method-Prefix</code></dt>
<dd>
Boolean (<code>true</code> or <code>false</code>, case irrelevant).
Is the ability to set native method prefix needed by this agent.
Values other than <code>true</code> are considered <code>false</code>.
This attribute is optional, the default is <code>false</code>.
</dd>
</dl>
</blockquote>
<p>
An agent JAR file may have both the <code>Premain-Class</code> and <code>Agent-Class</code>
attributes present in the manifest. When the agent is started on the command-line using
the <code>-javaagent</code> option then the <code>Premain-Class</code> attribute
specifies the name of the agent class and the <code>Agent-Class</code> attribute is
ignored. Similarly, if the agent is started sometime after the VM has started, then
the <code>Agent-Class</code> attribute specifies the name of the agent class
(the value of <code>Premain-Class</code> attribute is ignored).
<h2>Related Documentation</h2>
For tool documentation, please see:
<ul>
<li><a href="{@docRoot}/../technotes/tools/index.html">JDK Tools and Utilities</a>
</ul>
@since JDK1.5
@revised 1.6
</body>
</html>
<!--
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides the management interfaces for monitoring and management of the
Java virtual machine and other components in the Java runtime.
It allows both local and remote
monitoring and management of the running Java virtual machine.
<p>
<h4><a name="MXBean">Platform MXBean</a></h4>
<p>
A platform MXBean is a <i>managed bean</i> that
conforms to the <a href="../../../javax/management/package-summary.html">JMX</a>
Instrumentation Specification and only uses a set of basic data types.
Each platform MXBean is a {@link java.lang.management.PlatformManagedObject}
with a unique
{@linkplain java.lang.management.PlatformManagedObject#getObjectName name}.
<p>
<h4>ManagementFactory</h4>
<p>The {@link java.lang.management.ManagementFactory} class is the management
factory class for the Java platform. This class provides a set of
static factory methods to obtain the MXBeans for the Java platform
to allow an application to access the MXBeans directly.
<p>A <em>platform MBeanServer</em> can be accessed with the
{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
getPlatformMBeanServer} method. On the first call to this method,
it creates the platform MBeanServer and registers all platform MXBeans
including {@linkplain java.lang.management.PlatformManagedObject
platform MXBeans}.
Each platform MXBean is registered with a unique name defined in
the specification of the management interface.
This is a single MBeanServer that can be shared by different managed
components running within the same Java virtual machine.
<h4>Interoperability</h4>
<p>A management application and a platform MBeanServer of a running
virtual machine can interoperate
without requiring classes used by the platform MXBean interfaces.
The data types being transmitted between the JMX connector
server and the connector client are JMX
{@linkplain javax.management.openmbean.OpenType open types} and
this allows interoperation across versions.
A data type used by the MXBean interfaces are mapped to an
open type when being accessed via MBeanServer interface.
See the <a href="../../../javax/management/MXBean.html#MXBean-spec">
MXBean</a> specification for details.
<h4><a name="examples">Ways to Access MXBeans</a></h4>
<p>An application can monitor the instrumentation of the
Java virtual machine and the runtime in the following ways:
<p>
<b>1. Direct access to an MXBean interface</b>
<p>
<ul>
<li>Get an MXBean instance locally in the running Java virtual machine:
<pre>
RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
// Get the standard attribute "VmVendor"
String vendor = mxbean.getVmVendor();
</pre>
<p>Or by calling the
{@link java.lang.management.ManagementFactory#getPlatformMXBean(Class)
getPlatformMXBean} or
{@link java.lang.management.ManagementFactory#getPlatformMXBeans(Class)
getPlatformMXBeans} method:
<pre>
RuntimeMXBean mxbean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class);
// Get the standard attribute "VmVendor"
String vendor = mxbean.getVmVendor();
</pre>
<p>
</li>
<li>Construct an MXBean proxy instance that forwards the
method calls to a given MBeanServer:
<pre>
MBeanServerConnection mbs;
// Connect to a running JVM (or itself) and get MBeanServerConnection
// that has the JVM MBeans registered in it
...
// Get a MBean proxy for RuntimeMXBean interface
RuntimeMXBean proxy =
{@link java.lang.management.ManagementFactory#getPlatformMXBean(MBeanServerConnection, Class)
ManagementFactory.getPlatformMXBean}(mbs,
RuntimeMXBean.class);
// Get standard attribute "VmVendor"
String vendor = proxy.getVmVendor();
</pre>
<p>A proxy is typically used to access an MXBean
in a remote Java virtual machine.
An alternative way to create an MXBean proxy is:
<pre>
RuntimeMXBean proxy =
{@link java.lang.management.ManagementFactory#newPlatformMXBeanProxy
ManagementFactory.newPlatformMXBeanProxy}(mbs,
ManagementFactory.RUNTIME_MXBEAN_NAME,
RuntimeMXBean.class);
</pre>
</li>
</ul>
<p>
<b>2. Indirect access to an MXBean interface via MBeanServer</b><p>
<ul>
<li>Go through the
{@link java.lang.management.ManagementFactory#getPlatformMBeanServer
platform MBeanServer} to access MXBeans locally or
a specific {@code MBeanServerConnection} to access
MXBeans remotely.
The attributes and operations of an MXBean use only
<em>JMX open types</em> which include basic data types,
{@link javax.management.openmbean.CompositeData CompositeData},
and {@link javax.management.openmbean.TabularData TabularData}
defined in {@link javax.management.openmbean.OpenType OpenType}.<p>
<pre>
MBeanServerConnection mbs;
// Connect to a running JVM (or itself) and get MBeanServerConnection
// that has the JVM MXBeans registered in it
...
try {
// Assuming the RuntimeMXBean has been registered in mbs
ObjectName oname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
// Get standard attribute "VmVendor"
String vendor = (String) mbs.getAttribute(oname, "VmVendor");
} catch (....) {
// Catch the exceptions thrown by ObjectName constructor
// and MBeanServer.getAttribute method
...
}
</pre>
</li>
</ul>
<h4><a name="extension">Platform Extension</a></h4>
<p>A Java virtual machine implementation may add its platform extension to
the management interface by defining platform-dependent
interfaces that extend the standard management interfaces to include
platform-specific metrics and management operations.
The static factory methods in the <tt>ManagementFactory</tt> class will
return the MXBeans with the platform extension.
<p>
It is recommended to name the platform-specific attributes with
a vendor-specific prefix such as the vendor's name to
avoid collisions of the attribute name between the future extension
to the standard management interface and the platform extension.
If the future extension to the standard management interface defines
a new attribute for a management interface and the attribute name
is happened to be same as some vendor-specific attribute's name,
the applications accessing that vendor-specific attribute would have
to be modified to cope with versioning and compatibility issues.
<p>Below is an example showing how to access an attribute
from the platform extension:
<p>
1) Direct access to the Oracle-specific MXBean interface
<blockquote>
<pre>
List&lt;com.sun.management.GarbageCollectorMXBean&gt; mxbeans =
ManagementFactory.getPlatformMXBeans(com.sun.management.GarbageCollectorMXBean.class);
for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
// Get the standard attribute "CollectionCount"
String count = mxbean.getCollectionCount();
// Get the platform-specific attribute "LastGcInfo"
GcInfo gcinfo = gc.getLastGcInfo();
...
}
</pre>
</blockquote>
<p>
2) Access the Oracle-specific MXBean interface via <tt>MBeanServer</tt>
through proxy
<blockquote><pre>
MBeanServerConnection mbs;
// Connect to a running JVM (or itself) and get MBeanServerConnection
// that has the JVM MXBeans registered in it
...
List&lt;com.sun.management.GarbageCollectorMXBean&gt; mxbeans =
ManagementFactory.getPlatformMXBeans(mbs, com.sun.management.GarbageCollectorMXBean.class);
for (com.sun.management.GarbageCollectorMXBean gc : mxbeans) {
// Get the standard attribute "CollectionCount"
String count = mxbean.getCollectionCount();
// Get the platform-specific attribute "LastGcInfo"
GcInfo gcinfo = gc.getLastGcInfo();
...
}
</pre></blockquote>
<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
or method in any class or interface in this package will cause a {@link
java.lang.NullPointerException NullPointerException} to be thrown.
<p> The java.lang.management API is thread-safe.
@see <a href="../../../javax/management/package-summary.html">
JMX Specification.</a>
@author Mandy Chung
@since 1.5
</body>
</html>
<!--
Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides reference-object classes, which support a limited degree of
interaction with the garbage collector. A program may use a reference object
to maintain a reference to some other object in such a way that the latter
object may still be reclaimed by the collector. A program may also arrange to
be notified some time after the collector has determined that the reachability
of a given object has changed.
<h2>Package Specification</h2>
A <em>reference object</em> encapsulates a reference to some other object so
that the reference itself may be examined and manipulated like any other
object. Three types of reference objects are provided, each weaker than the
last: <em>soft</em>, <em>weak</em>, and <em>phantom</em>. Each type
corresponds to a different level of reachability, as defined below. Soft
references are for implementing memory-sensitive caches, weak references are
for implementing canonicalizing mappings that do not prevent their keys (or
values) from being reclaimed, and phantom references are for scheduling
pre-mortem cleanup actions in a more flexible way than is possible with the
Java finalization mechanism.
<p> Each reference-object type is implemented by a subclass of the abstract
base <code>{@link java.lang.ref.Reference}</code> class. An instance of one of
these subclasses encapsulates a single reference to a particular object, called
the <em>referent</em>. Every reference object provides methods for getting and
clearing the reference. Aside from the clearing operation reference objects
are otherwise immutable, so no <code>set</code> operation is provided. A
program may further subclass these subclasses, adding whatever fields and
methods are required for its purposes, or it may use these subclasses without
change.
<h3>Notification</h3>
A program may request to be notified of changes in an object's reachability by
<em>registering</em> an appropriate reference object with a <em>reference
queue</em> at the time the reference object is created. Some time after the
garbage collector determines that the reachability of the referent has changed
to the value corresponding to the type of the reference, it will add the
reference to the associated queue. At this point, the reference is considered
to be <em>enqueued</em>. The program may remove references from a queue either
by polling or by blocking until a reference becomes available. Reference
queues are implemented by the <code>{@link java.lang.ref.ReferenceQueue}</code>
class.
<p> The relationship between a registered reference object and its queue is
one-sided. That is, a queue does not keep track of the references that are
registered with it. If a registered reference becomes unreachable itself, then
it will never be enqueued. It is the responsibility of the program using
reference objects to ensure that the objects remain reachable for as long as
the program is interested in their referents.
<p> While some programs will choose to dedicate a thread to removing reference
objects from one or more queues and processing them, this is by no means
necessary. A tactic that often works well is to examine a reference queue in
the course of performing some other fairly-frequent action. For example, a
hashtable that uses weak references to implement weak keys could poll its
reference queue each time the table is accessed. This is how the <code>{@link
java.util.WeakHashMap}</code> class works. Because the <code>{@link
java.lang.ref.ReferenceQueue#poll ReferenceQueue.poll}</code> method simply
checks an internal data structure, this check will add little overhead to the
hashtable access methods.
<h3>Automatically-cleared references</h3>
Soft and weak references are automatically cleared by the collector before
being added to the queues with which they are registered, if any. Therefore
soft and weak references need not be registered with a queue in order to be
useful, while phantom references do. An object that is reachable via phantom
references will remain so until all such references are cleared or themselves
become unreachable.
<a name="reachability"></a>
<h3>Reachability</h3>
Going from strongest to weakest, the different levels of reachability reflect
the life cycle of an object. They are operationally defined as follows:
<ul>
<li> An object is <em>strongly reachable</em> if it can be reached by some
thread without traversing any reference objects. A newly-created object is
strongly reachable by the thread that created it.
<li> An object is <em>softly reachable</em> if it is not strongly reachable but
can be reached by traversing a soft reference.
<li> An object is <em>weakly reachable</em> if it is neither strongly nor
softly reachable but can be reached by traversing a weak reference. When the
weak references to a weakly-reachable object are cleared, the object becomes
eligible for finalization.
<li> An object is <em>phantom reachable</em> if it is neither strongly, softly,
nor weakly reachable, it has been finalized, and some phantom reference refers
to it.
<li> Finally, an object is <em>unreachable</em>, and therefore eligible for
reclamation, when it is not reachable in any of the above ways.
</ul>
@author Mark Reinhold
@since 1.2
<!--
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
</body>
</html>
<!--
Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Networking Properties</TITLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<H1 ALIGN=CENTER>Networking Properties</H1>
<P ALIGN=LEFT>There are a few standard system properties used to
alter the mechanisms and behavior of the various classes of the
java.net package. Some are checked only once at startup of the VM,
and therefore are best set using the -D option of the java command,
while others have a more dynamic nature and can also be changed using
the <a href="../../lang/System.html#setProperty(java.lang.String, java.lang.String)">System.setProperty()</a> API. The purpose of this document is to list
and detail all of these properties.</P>
<P>If there is no special note, a property value is checked every time it is used.</P>
<a name="Ipv4IPv6"></a>
<H2>IPv4 / IPv6</H2>
<UL>
<LI><P><B>java.net.preferIPv4Stack</B> (default: false)<BR>
If IPv6 is available on the operating system the
underlying native socket will be, by default, an IPv6 socket which
lets applications connect to, and accept connections from, both
IPv4 and IPv6 hosts. However, in the case an application would
rather use IPv4 only sockets, then this property can be set to <B>true</B>.
The implication is that it will not be possible for the application
to communicate with IPv6 only hosts.</P>
<LI><P><B>java.net.preferIPv6Addresses</B> (default: false)<BR>
When dealing with a host which has both IPv4
and IPv6 addresses, and if IPv6 is available on the operating
system, the default behavior is to prefer using IPv4 addresses over
IPv6 ones. This is to ensure backward compatibility, for example
applications that depend on the representation of an IPv4 address
(e.g. 192.168.1.1). This property can be set to <B>true</B> to
change that preference and use IPv6 addresses over IPv4 ones where
possible.</P>
</UL>
<P>Both of these properties are checked only once, at startup.</P>
<a name="Proxies"></a>
<H2>Proxies</H2>
<P>A proxy server allows indirect connection to network services and
is used mainly for security (to get through firewalls) and
performance reasons (proxies often do provide caching mechanisms).
The following properties allow for configuration of the various type
of proxies.</P>
<UL>
<LI><P>HTTP</P>
<P>The following proxy settings are used by the HTTP protocol handler.</P>
<UL>
<LI><P><B>http.proxyHost</B> (default: &lt;none&gt;)<BR>
The hostname, or address, of the proxy server
</P>
<LI><P><B>http.proxyPort</B> (default: 80)<BR>
The port number of the proxy server.</P>
<LI><P><B>http.nonProxyHosts</B> (default: localhost|127.*|[::1])<BR>
Indicates the hosts that should be accessed without going
through the proxy. Typically this defines internal hosts.
The value of this property is a list of hosts,
separated by the '|' character. In addition the wildcard
character '*' can be used for pattern matching. For example
<code>-Dhttp.nonProxyHosts=&rdquo;*.foo.com|localhost&rdquo;</code>
will indicate that every hosts in the foo.com domain and the
localhost should be accessed directly even if a proxy server is
specified.</P>
<P>The default value excludes all common variations of the loopback address.</P>
</UL>
<LI><P>HTTPS<BR>This is HTTP over SSL, a secure version of HTTP
mainly used when confidentiality (like on payment sites) is needed.</P>
<P>The following proxy settings are used by the HTTPS protocol handler.</P>
<UL>
<LI><P><B>https.proxyHost</B>(default: &lt;none&gt;)<BR>
The hostname, or address, of the proxy server
</P>
<LI><P><B>https.proxyPort</B> (default: 443)<BR>
The port number of the proxy server.</P>
<P>The HTTPS protocol handler will use the same nonProxyHosts
property as the HTTP protocol.</P>
</UL>
<LI><P>FTP</P>
<P>The following proxy settings are used by the FTP protocol handler.</P>
<UL>
<LI><P><B>ftp.proxyHost</B>(default: &lt;none&gt;)<BR>
The hostname, or address, of the proxy server
</P>
<LI><P><B>ftp.proxyPort</B> (default: 80)<BR>
The port number of the proxy server.</P>
<LI><P><B>ftp.nonProxyHosts</B> (default: localhost|127.*|[::1])<BR>
Indicates the hosts that should be accessed without going
through the proxy. Typically this defines internal hosts.
The value of this property is a list of hosts, separated by
the '|' character. In addition the wildcard character
'*' can be used for pattern matching. For example
<code>-Dhttp.nonProxyHosts=&rdquo;*.foo.com|localhost&rdquo;</code>
will indicate that every hosts in the foo.com domain and the
localhost should be accessed directly even if a proxy server is
specified.</P>
<P>The default value excludes all common variations of the loopback address.</P>
</UL>
<LI><P>SOCKS<BR>This is another type of proxy. It allows for lower
level type of tunneling since it works at the TCP level. In effect,
in the Java(tm) platform setting a SOCKS proxy server will result in
all TCP connections to go through that proxy, unless other proxies
are specified. If SOCKS is supported by a Java SE implementation, the
following properties will be used:</P>
<UL>
<LI><P><B>socksProxyHost</B> (default: &lt;none&gt;)<BR>
The hostname, or address, of the proxy server.</P>
<LI><P><B>socksProxyPort</B> (default: 1080)<BR>
The port number of the proxy server.</P>
<LI><P><B>socksProxyVersion</B> (default: 5)<BR>
The version of the SOCKS protocol supported by the server. The
default is <code>5</code> indicating SOCKS V5, alternatively
<code>4</code> can be specified for SOCKS V4. Setting the property
to values other than these leads to unspecified behavior.</P>
<LI><P><B>java.net.socks.username</B> (default: &lt;none&gt;)<BR>
Username to use if the SOCKSv5 server asks for authentication
and no java.net.Authenticator instance was found.</P>
<LI><P><B>java.net.socks.password</B> (default: &lt;none&gt;)<BR>
Password to use if the SOCKSv5 server asks for authentication
and no java.net.Authenticator instance was found.</P>
<P>Note that if no authentication is provided with either the above
properties or an Authenticator, and the proxy requires one, then
the <B>user.name</B> property will be used with no password.</P>
</UL>
<LI><P><B>java.net.useSystemProxies</B> (default: false)<BR>
On recent Windows systems and on Gnome 2.x systems it is possible to
tell the java.net stack, setting this property to <B>true</B>, to use
the system proxy settings (both these systems let you set proxies
globally through their user interface). Note that this property is
checked only once at startup.</P>
</UL>
<a name="MiscHTTP"></a>
<H2>Misc HTTP properties</H2>
<UL>
<LI><P><B>http.agent</B> (default: &ldquo;Java/&lt;version&gt;&rdquo;)<BR>
Defines the string sent in the User-Agent request header in http
requests. Note that the string &ldquo;Java/&lt;version&gt;&rdquo; will
be appended to the one provided in the property (e.g. if
-Dhttp.agent=&rdquo;foobar&rdquo; is used, the User-Agent header will
contain &ldquo;foobar Java/1.5.0&rdquo; if the version of the VM is
1.5.0). This property is checked only once at startup.</P>
<LI><P><B>http.keepalive</B> (default: true)<BR>
Indicates if persistent connections should be supported. They improve
performance by allowing the underlying socket connection to be reused
for multiple http requests. If this is set to true then persistent
connections will be requested with HTTP 1.1 servers.</P>
<LI><P><B>http.maxConnections</B> (default: 5)<BR>
If HTTP keepalive is enabled (see above) this value determines the
maximum number of idle connections that will be simultaneously kept
alive, per destination.</P>
<LI><P><B>http.maxRedirects</B> (default: 20)<BR>
This integer value determines the maximum number, for a given request,
of HTTP redirects that will be automatically followed by the
protocol handler.</P>
<LI><P><B>http.auth.digest.validateServer</B> (default: false)</P>
<LI><P><B>http.auth.digest.validateProxy</B> (default: false)</P>
<LI><P><B>http.auth.digest.cnonceRepeat</B> (default: 5)</P>
<P>These 3 properties modify the behavior of the HTTP digest
authentication mechanism. Digest authentication provides a limited
ability for the server to authenticate itself to the client (i.e.
By proving it knows the user's password). However not all HTTP
servers support this capability and by default it is turned off. The
first two properties can be set to true to enforce this check for
authentication with either an origin or proxy server, respectively.</P>
<P>It is usually not necessary to change the third property. It
determines how many times a cnonce value is re-used. This can be
useful when the MD5-sess algorithm is being used. Increasing this
value reduces the computational overhead on both client and server
by reducing the amount of material that has to be hashed for each
HTTP request.</P>
<LI><P><B>http.auth.ntlm.domain</B> (default: &lt;none&gt;)<BR>
NTLM is another authentication scheme. It uses the
java.net.Authenticator class to acquire usernames and passwords when
they are needed. However NTLM also needs the NT domain name. There are
3 options for specifying that domain:</P>
<OL>
<LI><P>Do not specify it. In some environments the domain is
actually not required and the application does not have to specify
it.</P>
<LI><P>The domain name can be encoded within the username by
prefixing the domain name, followed by a back-slash '\' before the
username. With this method existing applications that use the
authenticator class do not need to be modified, as long as users
are made aware that this notation must be used.</P>
<LI><P>If a domain name is not specified as in method 2) and these
property is defined, then its value will be used a the domain
name.</P>
</OL>
</UL>
<P>All these properties are checked only once at startup.</P>
<a name="AddressCache"></a>
<H2>Address Cache</H2>
<P>The java.net package, when doing name resolution, uses an address
cache for both security and performance reasons. Any address
resolution attempt, be it forward (name to IP address) or reverse (IP
address to name), will have its result cached, whether it was
successful or not, so that subsequent identical requests will not
have to access the naming service. These properties allow for some
tuning on how the cache is operating.</P>
<UL>
<LI><P><B>networkaddress.cache.ttl</B> (default: see below)<BR>
Value is an integer corresponding to the number of seconds successful
name lookups will be kept in the cache. A value of -1, or any other
negative value for that matter, indicates a &ldquo;cache forever&rdquo;
policy, while a value of 0 (zero) means no caching. The default value
is -1 (forever) if a security manager is installed, and implementation
specific when no security manager is installed.</P>
<LI><P><B>networkaddress.cache.negative.ttl</B> (default: 10)<BR>
Value is an integer corresponding to the number of seconds an
unsuccessful name lookup will be kept in the cache. A value of -1,
or any negative value, means &ldquo;cache forever&rdquo;, while a
value of 0 (zero) means no caching.</P>
</UL>
<P>Since these 2 properties are part of the security policy, they are
not set by either the -D option or the System.setProperty() API,
instead they are set as security properties.</P>
</BODY>
</HTML>
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#warn This file is preprocessed before being compiled
package java.nio;
class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
{
#if[rw]
protected final ByteBuffer bb;
protected final int offset;
#end[rw]
ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) { // package-private
#if[rw]
super(-1, 0,
bb.remaining() >> $LG_BYTES_PER_VALUE$,
bb.remaining() >> $LG_BYTES_PER_VALUE$);
this.bb = bb;
// enforce limit == capacity
int cap = this.capacity();
this.limit(cap);
int pos = this.position();
assert (pos <= cap);
offset = pos;
#else[rw]
super(bb);
#end[rw]
}
ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb,
int mark, int pos, int lim, int cap,
int off)
{
#if[rw]
super(mark, pos, lim, cap);
this.bb = bb;
offset = off;
#else[rw]
super(bb, mark, pos, lim, cap, off);
#end[rw]
}
public $Type$Buffer slice() {
int pos = this.position();
int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
int off = (pos << $LG_BYTES_PER_VALUE$) + offset;
assert (off >= 0);
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, off);
}
public $Type$Buffer duplicate() {
return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
offset);
}
public $Type$Buffer asReadOnlyBuffer() {
#if[rw]
return new ByteBufferAs$Type$BufferR$BO$(bb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
offset);
#else[rw]
return duplicate();
#end[rw]
}
#if[rw]
protected int ix(int i) {
return (i << $LG_BYTES_PER_VALUE$) + offset;
}
public $type$ get() {
return Bits.get$Type$$BO$(bb, ix(nextGetIndex()));
}
public $type$ get(int i) {
return Bits.get$Type$$BO$(bb, ix(checkIndex(i)));
}
#if[streamableType]
$type$ getUnchecked(int i) {
return Bits.get$Type$$BO$(bb, ix(i));
}
#end[streamableType]
#end[rw]
public $Type$Buffer put($type$ x) {
#if[rw]
Bits.put$Type$$BO$(bb, ix(nextPutIndex()), x);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer put(int i, $type$ x) {
#if[rw]
Bits.put$Type$$BO$(bb, ix(checkIndex(i)), x);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer compact() {
#if[rw]
int pos = position();
int lim = limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
ByteBuffer db = bb.duplicate();
db.limit(ix(lim));
db.position(ix(0));
ByteBuffer sb = db.slice();
sb.position(pos << $LG_BYTES_PER_VALUE$);
sb.compact();
position(rem);
limit(capacity());
discardMark();
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public boolean isDirect() {
return bb.isDirect();
}
public boolean isReadOnly() {
return {#if[rw]?false:true};
}
#if[char]
public String toString(int start, int end) {
if ((end > limit()) || (start > end))
throw new IndexOutOfBoundsException();
try {
int len = end - start;
char[] ca = new char[len];
CharBuffer cb = CharBuffer.wrap(ca);
CharBuffer db = this.duplicate();
db.position(start);
db.limit(end);
cb.put(db);
return new String(ca);
} catch (StringIndexOutOfBoundsException x) {
throw new IndexOutOfBoundsException();
}
}
// --- Methods to support CharSequence ---
public CharBuffer subSequence(int start, int end) {
int pos = position();
int lim = limit();
assert (pos <= lim);
pos = (pos <= lim ? pos : lim);
int len = lim - pos;
if ((start < 0) || (end > len) || (start > end))
throw new IndexOutOfBoundsException();
return new ByteBufferAsCharBuffer$RW$$BO$(bb,
-1,
pos + start,
pos + end,
capacity(),
offset);
}
#end[char]
public ByteOrder order() {
#if[boB]
return ByteOrder.BIG_ENDIAN;
#end[boB]
#if[boL]
return ByteOrder.LITTLE_ENDIAN;
#end[boL]
}
}
/*
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#warn This file is preprocessed before being compiled
class XXX {
#begin
#if[rw]
private $type$ get$Type$(long a) {
if (unaligned) {
$memtype$ x = unsafe.get$Memtype$(a);
return $fromBits$(nativeByteOrder ? x : Bits.swap(x));
}
return Bits.get$Type$(a, bigEndian);
}
public $type$ get$Type$() {
return get$Type$(ix(nextGetIndex($BYTES_PER_VALUE$)));
}
public $type$ get$Type$(int i) {
return get$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)));
}
#end[rw]
private ByteBuffer put$Type$(long a, $type$ x) {
#if[rw]
if (unaligned) {
$memtype$ y = $toBits$(x);
unsafe.put$Memtype$(a, (nativeByteOrder ? y : Bits.swap(y)));
} else {
Bits.put$Type$(a, x, bigEndian);
}
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public ByteBuffer put$Type$($type$ x) {
#if[rw]
put$Type$(ix(nextPutIndex($BYTES_PER_VALUE$)), x);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public ByteBuffer put$Type$(int i, $type$ x) {
#if[rw]
put$Type$(ix(checkIndex(i, $BYTES_PER_VALUE$)), x);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer as$Type$Buffer() {
int off = this.position();
int lim = this.limit();
assert (off <= lim);
int rem = (off <= lim ? lim - off : 0);
int size = rem >> $LG_BYTES_PER_VALUE$;
if (!unaligned && ((address + off) % $BYTES_PER_VALUE$ != 0)) {
return (bigEndian
? ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$B(this,
-1,
0,
size,
size,
off))
: ($Type$Buffer)(new ByteBufferAs$Type$Buffer$RW$L(this,
-1,
0,
size,
size,
off)));
} else {
return (nativeByteOrder
? ($Type$Buffer)(new Direct$Type$Buffer$RW$U(this,
-1,
0,
size,
size,
off))
: ($Type$Buffer)(new Direct$Type$Buffer$RW$S(this,
-1,
0,
size,
size,
off)));
}
}
#end
}
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#warn This file is preprocessed before being compiled
package java.nio;
import java.io.FileDescriptor;
import sun.misc.Cleaner;
import sun.misc.Unsafe;
import sun.misc.VM;
import sun.nio.ch.DirectBuffer;
class Direct$Type$Buffer$RW$$BO$
#if[rw]
extends {#if[byte]?Mapped$Type$Buffer:$Type$Buffer}
#else[rw]
extends Direct$Type$Buffer$BO$
#end[rw]
implements DirectBuffer
{
#if[rw]
// Cached unsafe-access object
protected static final Unsafe unsafe = Bits.unsafe();
// Cached array base offset
private static final long arrayBaseOffset = (long)unsafe.arrayBaseOffset($type$[].class);
// Cached unaligned-access capability
protected static final boolean unaligned = Bits.unaligned();
// Base address, used in all indexing calculations
// NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
// protected long address;
// An object attached to this buffer. If this buffer is a view of another
// buffer then we use this field to keep a reference to that buffer to
// ensure that its memory isn't freed before we are done with it.
private final Object att;
public Object attachment() {
return att;
}
#if[byte]
private static class Deallocator
implements Runnable
{
private static Unsafe unsafe = Unsafe.getUnsafe();
private long address;
private long size;
private int capacity;
private Deallocator(long address, long size, int capacity) {
assert (address != 0);
this.address = address;
this.size = size;
this.capacity = capacity;
}
public void run() {
if (address == 0) {
// Paranoia
return;
}
unsafe.freeMemory(address);
address = 0;
Bits.unreserveMemory(size, capacity);
}
}
private final Cleaner cleaner;
public Cleaner cleaner() { return cleaner; }
#else[byte]
public Cleaner cleaner() { return null; }
#end[byte]
#end[rw]
#if[byte]
// Primary constructor
//
Direct$Type$Buffer$RW$(int cap) { // package-private
#if[rw]
super(-1, 0, cap, cap);
boolean pa = VM.isDirectMemoryPageAligned();
int ps = Bits.pageSize();
long size = Math.max(1L, (long)cap + (pa ? ps : 0));
Bits.reserveMemory(size, cap);
long base = 0;
try {
base = unsafe.allocateMemory(size);
} catch (OutOfMemoryError x) {
Bits.unreserveMemory(size, cap);
throw x;
}
unsafe.setMemory(base, size, (byte) 0);
if (pa && (base % ps != 0)) {
// Round up to page boundary
address = base + ps - (base & (ps - 1));
} else {
address = base;
}
cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
att = null;
#else[rw]
super(cap);
#end[rw]
}
#if[rw]
// Invoked to construct a direct ByteBuffer referring to the block of
// memory. A given arbitrary object may also be attached to the buffer.
//
Direct$Type$Buffer(long addr, int cap, Object ob) {
super(-1, 0, cap, cap);
address = addr;
cleaner = null;
att = ob;
}
// Invoked only by JNI: NewDirectByteBuffer(void*, long)
//
private Direct$Type$Buffer(long addr, int cap) {
super(-1, 0, cap, cap);
address = addr;
cleaner = null;
att = null;
}
#end[rw]
// For memory-mapped buffers -- invoked by FileChannelImpl via reflection
//
protected Direct$Type$Buffer$RW$(int cap, long addr,
FileDescriptor fd,
Runnable unmapper)
{
#if[rw]
super(-1, 0, cap, cap, fd);
address = addr;
cleaner = Cleaner.create(this, unmapper);
att = null;
#else[rw]
super(cap, addr, fd, unmapper);
#end[rw]
}
#end[byte]
// For duplicates and slices
//
Direct$Type$Buffer$RW$$BO$(DirectBuffer db, // package-private
int mark, int pos, int lim, int cap,
int off)
{
#if[rw]
super(mark, pos, lim, cap);
address = db.address() + off;
#if[byte]
cleaner = null;
#end[byte]
att = db;
#else[rw]
super(db, mark, pos, lim, cap, off);
#end[rw]
}
public $Type$Buffer slice() {
int pos = this.position();
int lim = this.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
int off = (pos << $LG_BYTES_PER_VALUE$);
assert (off >= 0);
return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off);
}
public $Type$Buffer duplicate() {
return new Direct$Type$Buffer$RW$$BO$(this,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
0);
}
public $Type$Buffer asReadOnlyBuffer() {
#if[rw]
return new Direct$Type$BufferR$BO$(this,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
0);
#else[rw]
return duplicate();
#end[rw]
}
#if[rw]
public long address() {
return address;
}
private long ix(int i) {
return address + (i << $LG_BYTES_PER_VALUE$);
}
public $type$ get() {
return $fromBits$($swap$(unsafe.get$Swaptype$(ix(nextGetIndex()))));
}
public $type$ get(int i) {
return $fromBits$($swap$(unsafe.get$Swaptype$(ix(checkIndex(i)))));
}
#if[streamableType]
$type$ getUnchecked(int i) {
return $fromBits$($swap$(unsafe.get$Swaptype$(ix(i))));
}
#end[streamableType]
public $Type$Buffer get($type$[] dst, int offset, int length) {
#if[rw]
if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
checkBounds(offset, length, dst.length);
int pos = position();
int lim = limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
if (length > rem)
throw new BufferUnderflowException();
#if[!byte]
if (order() != ByteOrder.nativeOrder())
Bits.copyTo$Memtype$Array(ix(pos), dst,
offset << $LG_BYTES_PER_VALUE$,
length << $LG_BYTES_PER_VALUE$);
else
#end[!byte]
Bits.copyToArray(ix(pos), dst, arrayBaseOffset,
offset << $LG_BYTES_PER_VALUE$,
length << $LG_BYTES_PER_VALUE$);
position(pos + length);
} else {
super.get(dst, offset, length);
}
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
#end[rw]
public $Type$Buffer put($type$ x) {
#if[rw]
unsafe.put$Swaptype$(ix(nextPutIndex()), $swap$($toBits$(x)));
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer put(int i, $type$ x) {
#if[rw]
unsafe.put$Swaptype$(ix(checkIndex(i)), $swap$($toBits$(x)));
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer put($Type$Buffer src) {
#if[rw]
if (src instanceof Direct$Type$Buffer$BO$) {
if (src == this)
throw new IllegalArgumentException();
Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
int spos = sb.position();
int slim = sb.limit();
assert (spos <= slim);
int srem = (spos <= slim ? slim - spos : 0);
int pos = position();
int lim = limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
if (srem > rem)
throw new BufferOverflowException();
unsafe.copyMemory(sb.ix(spos), ix(pos), srem << $LG_BYTES_PER_VALUE$);
sb.position(spos + srem);
position(pos + srem);
} else if (src.hb != null) {
int spos = src.position();
int slim = src.limit();
assert (spos <= slim);
int srem = (spos <= slim ? slim - spos : 0);
put(src.hb, src.offset + spos, srem);
src.position(spos + srem);
} else {
super.put(src);
}
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer put($type$[] src, int offset, int length) {
#if[rw]
if ((length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
checkBounds(offset, length, src.length);
int pos = position();
int lim = limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
if (length > rem)
throw new BufferOverflowException();
#if[!byte]
if (order() != ByteOrder.nativeOrder())
Bits.copyFrom$Memtype$Array(src, offset << $LG_BYTES_PER_VALUE$,
ix(pos), length << $LG_BYTES_PER_VALUE$);
else
#end[!byte]
Bits.copyFromArray(src, arrayBaseOffset, offset << $LG_BYTES_PER_VALUE$,
ix(pos), length << $LG_BYTES_PER_VALUE$);
position(pos + length);
} else {
super.put(src, offset, length);
}
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer compact() {
#if[rw]
int pos = position();
int lim = limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
unsafe.copyMemory(ix(pos), ix(0), rem << $LG_BYTES_PER_VALUE$);
position(rem);
limit(capacity());
discardMark();
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public boolean isDirect() {
return true;
}
public boolean isReadOnly() {
return {#if[rw]?false:true};
}
#if[char]
public String toString(int start, int end) {
if ((end > limit()) || (start > end))
throw new IndexOutOfBoundsException();
try {
int len = end - start;
char[] ca = new char[len];
CharBuffer cb = CharBuffer.wrap(ca);
CharBuffer db = this.duplicate();
db.position(start);
db.limit(end);
cb.put(db);
return new String(ca);
} catch (StringIndexOutOfBoundsException x) {
throw new IndexOutOfBoundsException();
}
}
// --- Methods to support CharSequence ---
public CharBuffer subSequence(int start, int end) {
int pos = position();
int lim = limit();
assert (pos <= lim);
pos = (pos <= lim ? pos : lim);
int len = lim - pos;
if ((start < 0) || (end > len) || (start > end))
throw new IndexOutOfBoundsException();
return new DirectCharBuffer$RW$$BO$(this,
-1,
pos + start,
pos + end,
capacity(),
offset);
}
#end[char]
#if[!byte]
public ByteOrder order() {
#if[boS]
return ((ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
#end[boS]
#if[boU]
return ((ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN)
? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
#end[boU]
}
#end[!byte]
#if[byte]
byte _get(int i) { // package-private
return unsafe.getByte(address + i);
}
void _put(int i, byte b) { // package-private
#if[rw]
unsafe.putByte(address + i, b);
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
// #BIN
//
// Binary-data access methods for short, char, int, long, float,
// and double will be inserted here
#end[byte]
}
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#warn This file is preprocessed before being compiled
package java.nio;
/**
#if[rw]
* A read/write Heap$Type$Buffer.
#else[rw]
* A read-only Heap$Type$Buffer. This class extends the corresponding
* read/write class, overriding the mutation methods to throw a {@link
* ReadOnlyBufferException} and overriding the view-buffer methods to return an
* instance of this class rather than of the superclass.
#end[rw]
*/
class Heap$Type$Buffer$RW$
extends {#if[ro]?Heap}$Type$Buffer
{
// For speed these fields are actually declared in X-Buffer;
// these declarations are here as documentation
/*
#if[rw]
protected final $type$[] hb;
protected final int offset;
#end[rw]
*/
Heap$Type$Buffer$RW$(int cap, int lim) { // package-private
#if[rw]
super(-1, 0, lim, cap, new $type$[cap], 0);
/*
hb = new $type$[cap];
offset = 0;
*/
#else[rw]
super(cap, lim);
this.isReadOnly = true;
#end[rw]
}
Heap$Type$Buffer$RW$($type$[] buf, int off, int len) { // package-private
#if[rw]
super(-1, off, off + len, buf.length, buf, 0);
/*
hb = buf;
offset = 0;
*/
#else[rw]
super(buf, off, len);
this.isReadOnly = true;
#end[rw]
}
protected Heap$Type$Buffer$RW$($type$[] buf,
int mark, int pos, int lim, int cap,
int off)
{
#if[rw]
super(mark, pos, lim, cap, buf, off);
/*
hb = buf;
offset = off;
*/
#else[rw]
super(buf, mark, pos, lim, cap, off);
this.isReadOnly = true;
#end[rw]
}
public $Type$Buffer slice() {
return new Heap$Type$Buffer$RW$(hb,
-1,
0,
this.remaining(),
this.remaining(),
this.position() + offset);
}
public $Type$Buffer duplicate() {
return new Heap$Type$Buffer$RW$(hb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
offset);
}
public $Type$Buffer asReadOnlyBuffer() {
#if[rw]
return new Heap$Type$BufferR(hb,
this.markValue(),
this.position(),
this.limit(),
this.capacity(),
offset);
#else[rw]
return duplicate();
#end[rw]
}
#if[rw]
protected int ix(int i) {
return i + offset;
}
public $type$ get() {
return hb[ix(nextGetIndex())];
}
public $type$ get(int i) {
return hb[ix(checkIndex(i))];
}
#if[streamableType]
$type$ getUnchecked(int i) {
return hb[ix(i)];
}
#end[streamableType]
public $Type$Buffer get($type$[] dst, int offset, int length) {
checkBounds(offset, length, dst.length);
if (length > remaining())
throw new BufferUnderflowException();
System.arraycopy(hb, ix(position()), dst, offset, length);
position(position() + length);
return this;
}
public boolean isDirect() {
return false;
}
#end[rw]
public boolean isReadOnly() {
return {#if[rw]?false:true};
}
public $Type$Buffer put($type$ x) {
#if[rw]
hb[ix(nextPutIndex())] = x;
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer put(int i, $type$ x) {
#if[rw]
hb[ix(checkIndex(i))] = x;
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer put($type$[] src, int offset, int length) {
#if[rw]
checkBounds(offset, length, src.length);
if (length > remaining())
throw new BufferOverflowException();
System.arraycopy(src, offset, hb, ix(position()), length);
position(position() + length);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer put($Type$Buffer src) {
#if[rw]
if (src instanceof Heap$Type$Buffer) {
if (src == this)
throw new IllegalArgumentException();
Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
int n = sb.remaining();
if (n > remaining())
throw new BufferOverflowException();
System.arraycopy(sb.hb, sb.ix(sb.position()),
hb, ix(position()), n);
sb.position(sb.position() + n);
position(position() + n);
} else if (src.isDirect()) {
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
src.get(hb, ix(position()), n);
position(position() + n);
} else {
super.put(src);
}
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer compact() {
#if[rw]
System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
position(remaining());
limit(capacity());
discardMark();
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
#if[byte]
byte _get(int i) { // package-private
return hb[i];
}
void _put(int i, byte b) { // package-private
#if[rw]
hb[i] = b;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
// char
#if[rw]
public char getChar() {
return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian);
}
public char getChar(int i) {
return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian);
}
#end[rw]
public $Type$Buffer putChar(char x) {
#if[rw]
Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer putChar(int i, char x) {
#if[rw]
Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public CharBuffer asCharBuffer() {
int size = this.remaining() >> 1;
int off = offset + position();
return (bigEndian
? (CharBuffer)(new ByteBufferAsCharBuffer$RW$B(this,
-1,
0,
size,
size,
off))
: (CharBuffer)(new ByteBufferAsCharBuffer$RW$L(this,
-1,
0,
size,
size,
off)));
}
// short
#if[rw]
public short getShort() {
return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian);
}
public short getShort(int i) {
return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian);
}
#end[rw]
public $Type$Buffer putShort(short x) {
#if[rw]
Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer putShort(int i, short x) {
#if[rw]
Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public ShortBuffer asShortBuffer() {
int size = this.remaining() >> 1;
int off = offset + position();
return (bigEndian
? (ShortBuffer)(new ByteBufferAsShortBuffer$RW$B(this,
-1,
0,
size,
size,
off))
: (ShortBuffer)(new ByteBufferAsShortBuffer$RW$L(this,
-1,
0,
size,
size,
off)));
}
// int
#if[rw]
public int getInt() {
return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
}
public int getInt(int i) {
return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian);
}
#end[rw]
public $Type$Buffer putInt(int x) {
#if[rw]
Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer putInt(int i, int x) {
#if[rw]
Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public IntBuffer asIntBuffer() {
int size = this.remaining() >> 2;
int off = offset + position();
return (bigEndian
? (IntBuffer)(new ByteBufferAsIntBuffer$RW$B(this,
-1,
0,
size,
size,
off))
: (IntBuffer)(new ByteBufferAsIntBuffer$RW$L(this,
-1,
0,
size,
size,
off)));
}
// long
#if[rw]
public long getLong() {
return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian);
}
public long getLong(int i) {
return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian);
}
#end[rw]
public $Type$Buffer putLong(long x) {
#if[rw]
Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer putLong(int i, long x) {
#if[rw]
Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public LongBuffer asLongBuffer() {
int size = this.remaining() >> 3;
int off = offset + position();
return (bigEndian
? (LongBuffer)(new ByteBufferAsLongBuffer$RW$B(this,
-1,
0,
size,
size,
off))
: (LongBuffer)(new ByteBufferAsLongBuffer$RW$L(this,
-1,
0,
size,
size,
off)));
}
// float
#if[rw]
public float getFloat() {
return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian);
}
public float getFloat(int i) {
return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian);
}
#end[rw]
public $Type$Buffer putFloat(float x) {
#if[rw]
Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer putFloat(int i, float x) {
#if[rw]
Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public FloatBuffer asFloatBuffer() {
int size = this.remaining() >> 2;
int off = offset + position();
return (bigEndian
? (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$B(this,
-1,
0,
size,
size,
off))
: (FloatBuffer)(new ByteBufferAsFloatBuffer$RW$L(this,
-1,
0,
size,
size,
off)));
}
// double
#if[rw]
public double getDouble() {
return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian);
}
public double getDouble(int i) {
return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian);
}
#end[rw]
public $Type$Buffer putDouble(double x) {
#if[rw]
Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public $Type$Buffer putDouble(int i, double x) {
#if[rw]
Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian);
return this;
#else[rw]
throw new ReadOnlyBufferException();
#end[rw]
}
public DoubleBuffer asDoubleBuffer() {
int size = this.remaining() >> 3;
int off = offset + position();
return (bigEndian
? (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$B(this,
-1,
0,
size,
size,
off))
: (DoubleBuffer)(new ByteBufferAsDoubleBuffer$RW$L(this,
-1,
0,
size,
size,
off)));
}
#end[byte]
#if[char]
String toString(int start, int end) { // package-private
try {
return new String(hb, start + offset, end - start);
} catch (StringIndexOutOfBoundsException x) {
throw new IndexOutOfBoundsException();
}
}
// --- Methods to support CharSequence ---
public CharBuffer subSequence(int start, int end) {
if ((start < 0)
|| (end > length())
|| (start > end))
throw new IndexOutOfBoundsException();
int pos = position();
return new HeapCharBuffer$RW$(hb,
-1,
pos + start,
pos + end,
capacity(),
offset);
}
#end[char]
#if[!byte]
public ByteOrder order() {
return ByteOrder.nativeOrder();
}
#end[!byte]
}
/*
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#warn This file is preprocessed before being compiled
class XXX {
#begin
/**
* Relative <i>get</i> method for reading $a$ $type$ value.
*
* <p> Reads the next $nbytes$ bytes at this buffer's current position,
* composing them into $a$ $type$ value according to the current byte order,
* and then increments the position by $nbytes$. </p>
*
* @return The $type$ value at the buffer's current position
*
* @throws BufferUnderflowException
* If there are fewer than $nbytes$ bytes
* remaining in this buffer
*/
public abstract $type$ get$Type$();
/**
* Relative <i>put</i> method for writing $a$ $type$
* value&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> Writes $nbytes$ bytes containing the given $type$ value, in the
* current byte order, into this buffer at the current position, and then
* increments the position by $nbytes$. </p>
*
* @param value
* The $type$ value to be written
*
* @return This buffer
*
* @throws BufferOverflowException
* If there are fewer than $nbytes$ bytes
* remaining in this buffer
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public abstract ByteBuffer put$Type$($type$ value);
/**
* Absolute <i>get</i> method for reading $a$ $type$ value.
*
* <p> Reads $nbytes$ bytes at the given index, composing them into a
* $type$ value according to the current byte order. </p>
*
* @param index
* The index from which the bytes will be read
*
* @return The $type$ value at the given index
*
* @throws IndexOutOfBoundsException
* If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus $nbytesButOne$
*/
public abstract $type$ get$Type$(int index);
/**
* Absolute <i>put</i> method for writing $a$ $type$
* value&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> Writes $nbytes$ bytes containing the given $type$ value, in the
* current byte order, into this buffer at the given index. </p>
*
* @param index
* The index at which the bytes will be written
*
* @param value
* The $type$ value to be written
*
* @return This buffer
*
* @throws IndexOutOfBoundsException
* If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus $nbytesButOne$
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public abstract ByteBuffer put$Type$(int index, $type$ value);
/**
* Creates a view of this byte buffer as $a$ $type$ buffer.
*
* <p> The content of the new buffer will start at this buffer's current
* position. Changes to this buffer's content will be visible in the new
* buffer, and vice versa; the two buffers' position, limit, and mark
* values will be independent.
*
* <p> The new buffer's position will be zero, its capacity and its limit
* will be the number of bytes remaining in this buffer divided by
* $nbytes$, and its mark will be undefined. The new buffer will be direct
* if, and only if, this buffer is direct, and it will be read-only if, and
* only if, this buffer is read-only. </p>
*
* @return A new $type$ buffer
*/
public abstract $Type$Buffer as$Type$Buffer();
#end
}
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#warn This file is preprocessed before being compiled
package java.nio;
#if[char]
import java.io.IOException;
#end[char]
#if[streamableType]
import java.util.Spliterator;
import java.util.stream.StreamSupport;
import java.util.stream.$Streamtype$Stream;
#end[streamableType]
/**
* $A$ $type$ buffer.
*
* <p> This class defines {#if[byte]?six:four} categories of operations upon
* $type$ buffers:
*
* <ul>
*
* <li><p> Absolute and relative {@link #get() <i>get</i>} and
* {@link #put($type$) <i>put</i>} methods that read and write
* single $type$s; </p></li>
*
* <li><p> Relative {@link #get($type$[]) <i>bulk get</i>}
* methods that transfer contiguous sequences of $type$s from this buffer
* into an array; {#if[!byte]?and}</p></li>
*
* <li><p> Relative {@link #put($type$[]) <i>bulk put</i>}
* methods that transfer contiguous sequences of $type$s from $a$
* $type$ array{#if[char]?,&#32;a&#32;string,} or some other $type$
* buffer into this buffer;{#if[!byte]?&#32;and} </p></li>
*
#if[byte]
*
* <li><p> Absolute and relative {@link #getChar() <i>get</i>}
* and {@link #putChar(char) <i>put</i>} methods that read and
* write values of other primitive types, translating them to and from
* sequences of bytes in a particular byte order; </p></li>
*
* <li><p> Methods for creating <i><a href="#views">view buffers</a></i>,
* which allow a byte buffer to be viewed as a buffer containing values of
* some other primitive type; and </p></li>
*
#end[byte]
*
* <li><p> Methods for {@link #compact compacting}, {@link
* #duplicate duplicating}, and {@link #slice slicing}
* $a$ $type$ buffer. </p></li>
*
* </ul>
*
* <p> $Type$ buffers can be created either by {@link #allocate
* <i>allocation</i>}, which allocates space for the buffer's
*
#if[byte]
*
* content, or by {@link #wrap($type$[]) <i>wrapping</i>} an
* existing $type$ array {#if[char]?or&#32;string} into a buffer.
*
#else[byte]
*
* content, by {@link #wrap($type$[]) <i>wrapping</i>} an existing
* $type$ array {#if[char]?or&#32;string} into a buffer, or by creating a
* <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer.
*
#end[byte]
*
#if[byte]
*
* <a name="direct"></a>
* <h2> Direct <i>vs.</i> non-direct buffers </h2>
*
* <p> A byte buffer is either <i>direct</i> or <i>non-direct</i>. Given a
* direct byte buffer, the Java virtual machine will make a best effort to
* perform native I/O operations directly upon it. That is, it will attempt to
* avoid copying the buffer's content to (or from) an intermediate buffer
* before (or after) each invocation of one of the underlying operating
* system's native I/O operations.
*
* <p> A direct byte buffer may be created by invoking the {@link
* #allocateDirect(int) allocateDirect} factory method of this class. The
* buffers returned by this method typically have somewhat higher allocation
* and deallocation costs than non-direct buffers. The contents of direct
* buffers may reside outside of the normal garbage-collected heap, and so
* their impact upon the memory footprint of an application might not be
* obvious. It is therefore recommended that direct buffers be allocated
* primarily for large, long-lived buffers that are subject to the underlying
* system's native I/O operations. In general it is best to allocate direct
* buffers only when they yield a measureable gain in program performance.
*
* <p> A direct byte buffer may also be created by {@link
* java.nio.channels.FileChannel#map mapping} a region of a file
* directly into memory. An implementation of the Java platform may optionally
* support the creation of direct byte buffers from native code via JNI. If an
* instance of one of these kinds of buffers refers to an inaccessible region
* of memory then an attempt to access that region will not change the buffer's
* content and will cause an unspecified exception to be thrown either at the
* time of the access or at some later time.
*
* <p> Whether a byte buffer is direct or non-direct may be determined by
* invoking its {@link #isDirect isDirect} method. This method is provided so
* that explicit buffer management can be done in performance-critical code.
*
*
* <a name="bin"></a>
* <h2> Access to binary data </h2>
*
* <p> This class defines methods for reading and writing values of all other
* primitive types, except <tt>boolean</tt>. Primitive values are translated
* to (or from) sequences of bytes according to the buffer's current byte
* order, which may be retrieved and modified via the {@link #order order}
* methods. Specific byte orders are represented by instances of the {@link
* ByteOrder} class. The initial order of a byte buffer is always {@link
* ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
*
* <p> For access to heterogeneous binary data, that is, sequences of values of
* different types, this class defines a family of absolute and relative
* <i>get</i> and <i>put</i> methods for each type. For 32-bit floating-point
* values, for example, this class defines:
*
* <blockquote><pre>
* float {@link #getFloat()}
* float {@link #getFloat(int) getFloat(int index)}
* void {@link #putFloat(float) putFloat(float f)}
* void {@link #putFloat(int,float) putFloat(int index, float f)}</pre></blockquote>
*
* <p> Corresponding methods are defined for the types <tt>char</tt>,
* <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and <tt>double</tt>. The index
* parameters of the absolute <i>get</i> and <i>put</i> methods are in terms of
* bytes rather than of the type being read or written.
*
* <a name="views"></a>
*
* <p> For access to homogeneous binary data, that is, sequences of values of
* the same type, this class defines methods that can create <i>views</i> of a
* given byte buffer. A <i>view buffer</i> is simply another buffer whose
* content is backed by the byte buffer. Changes to the byte buffer's content
* will be visible in the view buffer, and vice versa; the two buffers'
* position, limit, and mark values are independent. The {@link
* #asFloatBuffer() asFloatBuffer} method, for example, creates an instance of
* the {@link FloatBuffer} class that is backed by the byte buffer upon which
* the method is invoked. Corresponding view-creation methods are defined for
* the types <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>long</tt>, and
* <tt>double</tt>.
*
* <p> View buffers have three important advantages over the families of
* type-specific <i>get</i> and <i>put</i> methods described above:
*
* <ul>
*
* <li><p> A view buffer is indexed not in terms of bytes but rather in terms
* of the type-specific size of its values; </p></li>
*
* <li><p> A view buffer provides relative bulk <i>get</i> and <i>put</i>
* methods that can transfer contiguous sequences of values between a buffer
* and an array or some other buffer of the same type; and </p></li>
*
* <li><p> A view buffer is potentially much more efficient because it will
* be direct if, and only if, its backing byte buffer is direct. </p></li>
*
* </ul>
*
* <p> The byte order of a view buffer is fixed to be that of its byte buffer
* at the time that the view is created. </p>
*
#end[byte]
*
#if[!byte]
*
* <p> Like a byte buffer, $a$ $type$ buffer is either <a
* href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>. A
* $type$ buffer created via the <tt>wrap</tt> methods of this class will
* be non-direct. $A$ $type$ buffer created as a view of a byte buffer will
* be direct if, and only if, the byte buffer itself is direct. Whether or not
* $a$ $type$ buffer is direct may be determined by invoking the {@link
* #isDirect isDirect} method. </p>
*
#end[!byte]
*
#if[char]
*
* <p> This class implements the {@link CharSequence} interface so that
* character buffers may be used wherever character sequences are accepted, for
* example in the regular-expression package <tt>{@link java.util.regex}</tt>.
* </p>
*
#end[char]
*
#if[byte]
* <h2> Invocation chaining </h2>
#end[byte]
*
* <p> Methods in this class that do not otherwise have a value to return are
* specified to return the buffer upon which they are invoked. This allows
* method invocations to be chained.
*
#if[byte]
*
* The sequence of statements
*
* <blockquote><pre>
* bb.putInt(0xCAFEBABE);
* bb.putShort(3);
* bb.putShort(45);</pre></blockquote>
*
* can, for example, be replaced by the single statement
*
* <blockquote><pre>
* bb.putInt(0xCAFEBABE).putShort(3).putShort(45);</pre></blockquote>
*
#end[byte]
#if[char]
*
* The sequence of statements
*
* <blockquote><pre>
* cb.put("text/");
* cb.put(subtype);
* cb.put("; charset=");
* cb.put(enc);</pre></blockquote>
*
* can, for example, be replaced by the single statement
*
* <blockquote><pre>
* cb.put("text/").put(subtype).put("; charset=").put(enc);</pre></blockquote>
*
#end[char]
*
*
* @author Mark Reinhold
* @author JSR-51 Expert Group
* @since 1.4
*/
public abstract class $Type$Buffer
extends Buffer
implements Comparable<$Type$Buffer>{#if[char]?, Appendable, CharSequence, Readable}
{
// These fields are declared here rather than in Heap-X-Buffer in order to
// reduce the number of virtual method invocations needed to access these
// values, which is especially costly when coding small buffers.
//
final $type$[] hb; // Non-null only for heap buffers
final int offset;
boolean isReadOnly; // Valid only for heap buffers
// Creates a new buffer with the given mark, position, limit, capacity,
// backing array, and array offset
//
$Type$Buffer(int mark, int pos, int lim, int cap, // package-private
$type$[] hb, int offset)
{
super(mark, pos, lim, cap);
this.hb = hb;
this.offset = offset;
}
// Creates a new buffer with the given mark, position, limit, and capacity
//
$Type$Buffer(int mark, int pos, int lim, int cap) { // package-private
this(mark, pos, lim, cap, null, 0);
}
#if[byte]
/**
* Allocates a new direct $type$ buffer.
*
* <p> The new buffer's position will be zero, its limit will be its
* capacity, its mark will be undefined, and each of its elements will be
* initialized to zero. Whether or not it has a
* {@link #hasArray backing array} is unspecified.
*
* @param capacity
* The new buffer's capacity, in $type$s
*
* @return The new $type$ buffer
*
* @throws IllegalArgumentException
* If the <tt>capacity</tt> is a negative integer
*/
public static $Type$Buffer allocateDirect(int capacity) {
return new Direct$Type$Buffer(capacity);
}
#end[byte]
/**
* Allocates a new $type$ buffer.
*
* <p> The new buffer's position will be zero, its limit will be its
* capacity, its mark will be undefined, and each of its elements will be
* initialized to zero. It will have a {@link #array backing array},
* and its {@link #arrayOffset array offset} will be zero.
*
* @param capacity
* The new buffer's capacity, in $type$s
*
* @return The new $type$ buffer
*
* @throws IllegalArgumentException
* If the <tt>capacity</tt> is a negative integer
*/
public static $Type$Buffer allocate(int capacity) {
if (capacity < 0)
throw new IllegalArgumentException();
return new Heap$Type$Buffer(capacity, capacity);
}
/**
* Wraps $a$ $type$ array into a buffer.
*
* <p> The new buffer will be backed by the given $type$ array;
* that is, modifications to the buffer will cause the array to be modified
* and vice versa. The new buffer's capacity will be
* <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
* will be <tt>offset + length</tt>, and its mark will be undefined. Its
* {@link #array backing array} will be the given array, and
* its {@link #arrayOffset array offset} will be zero. </p>
*
* @param array
* The array that will back the new buffer
*
* @param offset
* The offset of the subarray to be used; must be non-negative and
* no larger than <tt>array.length</tt>. The new buffer's position
* will be set to this value.
*
* @param length
* The length of the subarray to be used;
* must be non-negative and no larger than
* <tt>array.length - offset</tt>.
* The new buffer's limit will be set to <tt>offset + length</tt>.
*
* @return The new $type$ buffer
*
* @throws IndexOutOfBoundsException
* If the preconditions on the <tt>offset</tt> and <tt>length</tt>
* parameters do not hold
*/
public static $Type$Buffer wrap($type$[] array,
int offset, int length)
{
try {
return new Heap$Type$Buffer(array, offset, length);
} catch (IllegalArgumentException x) {
throw new IndexOutOfBoundsException();
}
}
/**
* Wraps $a$ $type$ array into a buffer.
*
* <p> The new buffer will be backed by the given $type$ array;
* that is, modifications to the buffer will cause the array to be modified
* and vice versa. The new buffer's capacity and limit will be
* <tt>array.length</tt>, its position will be zero, and its mark will be
* undefined. Its {@link #array backing array} will be the
* given array, and its {@link #arrayOffset array offset>} will
* be zero. </p>
*
* @param array
* The array that will back this buffer
*
* @return The new $type$ buffer
*/
public static $Type$Buffer wrap($type$[] array) {
return wrap(array, 0, array.length);
}
#if[char]
/**
* Attempts to read characters into the specified character buffer.
* The buffer is used as a repository of characters as-is: the only
* changes made are the results of a put operation. No flipping or
* rewinding of the buffer is performed.
*
* @param target the buffer to read characters into
* @return The number of characters added to the buffer, or
* -1 if this source of characters is at its end
* @throws IOException if an I/O error occurs
* @throws NullPointerException if target is null
* @throws ReadOnlyBufferException if target is a read only buffer
* @since 1.5
*/
public int read(CharBuffer target) throws IOException {
// Determine the number of bytes n that can be transferred
int targetRemaining = target.remaining();
int remaining = remaining();
if (remaining == 0)
return -1;
int n = Math.min(remaining, targetRemaining);
int limit = limit();
// Set source limit to prevent target overflow
if (targetRemaining < remaining)
limit(position() + n);
try {
if (n > 0)
target.put(this);
} finally {
limit(limit); // restore real limit
}
return n;
}
/**
* Wraps a character sequence into a buffer.
*
* <p> The content of the new, read-only buffer will be the content of the
* given character sequence. The buffer's capacity will be
* <tt>csq.length()</tt>, its position will be <tt>start</tt>, its limit
* will be <tt>end</tt>, and its mark will be undefined. </p>
*
* @param csq
* The character sequence from which the new character buffer is to
* be created
*
* @param start
* The index of the first character to be used;
* must be non-negative and no larger than <tt>csq.length()</tt>.
* The new buffer's position will be set to this value.
*
* @param end
* The index of the character following the last character to be
* used; must be no smaller than <tt>start</tt> and no larger
* than <tt>csq.length()</tt>.
* The new buffer's limit will be set to this value.
*
* @return The new character buffer
*
* @throws IndexOutOfBoundsException
* If the preconditions on the <tt>start</tt> and <tt>end</tt>
* parameters do not hold
*/
public static CharBuffer wrap(CharSequence csq, int start, int end) {
try {
return new StringCharBuffer(csq, start, end);
} catch (IllegalArgumentException x) {
throw new IndexOutOfBoundsException();
}
}
/**
* Wraps a character sequence into a buffer.
*
* <p> The content of the new, read-only buffer will be the content of the
* given character sequence. The new buffer's capacity and limit will be
* <tt>csq.length()</tt>, its position will be zero, and its mark will be
* undefined. </p>
*
* @param csq
* The character sequence from which the new character buffer is to
* be created
*
* @return The new character buffer
*/
public static CharBuffer wrap(CharSequence csq) {
return wrap(csq, 0, csq.length());
}
#end[char]
/**
* Creates a new $type$ buffer whose content is a shared subsequence of
* this buffer's content.
*
* <p> The content of the new buffer will start at this buffer's current
* position. Changes to this buffer's content will be visible in the new
* buffer, and vice versa; the two buffers' position, limit, and mark
* values will be independent.
*
* <p> The new buffer's position will be zero, its capacity and its limit
* will be the number of $type$s remaining in this buffer, and its mark
* will be undefined. The new buffer will be direct if, and only if, this
* buffer is direct, and it will be read-only if, and only if, this buffer
* is read-only. </p>
*
* @return The new $type$ buffer
*/
public abstract $Type$Buffer slice();
/**
* Creates a new $type$ buffer that shares this buffer's content.
*
* <p> The content of the new buffer will be that of this buffer. Changes
* to this buffer's content will be visible in the new buffer, and vice
* versa; the two buffers' position, limit, and mark values will be
* independent.
*
* <p> The new buffer's capacity, limit, position, and mark values will be
* identical to those of this buffer. The new buffer will be direct if,
* and only if, this buffer is direct, and it will be read-only if, and
* only if, this buffer is read-only. </p>
*
* @return The new $type$ buffer
*/
public abstract $Type$Buffer duplicate();
/**
* Creates a new, read-only $type$ buffer that shares this buffer's
* content.
*
* <p> The content of the new buffer will be that of this buffer. Changes
* to this buffer's content will be visible in the new buffer; the new
* buffer itself, however, will be read-only and will not allow the shared
* content to be modified. The two buffers' position, limit, and mark
* values will be independent.
*
* <p> The new buffer's capacity, limit, position, and mark values will be
* identical to those of this buffer.
*
* <p> If this buffer is itself read-only then this method behaves in
* exactly the same way as the {@link #duplicate duplicate} method. </p>
*
* @return The new, read-only $type$ buffer
*/
public abstract $Type$Buffer asReadOnlyBuffer();
// -- Singleton get/put methods --
/**
* Relative <i>get</i> method. Reads the $type$ at this buffer's
* current position, and then increments the position.
*
* @return The $type$ at the buffer's current position
*
* @throws BufferUnderflowException
* If the buffer's current position is not smaller than its limit
*/
public abstract $type$ get();
/**
* Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> Writes the given $type$ into this buffer at the current
* position, and then increments the position. </p>
*
* @param $x$
* The $type$ to be written
*
* @return This buffer
*
* @throws BufferOverflowException
* If this buffer's current position is not smaller than its limit
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public abstract $Type$Buffer put($type$ $x$);
/**
* Absolute <i>get</i> method. Reads the $type$ at the given
* index.
*
* @param index
* The index from which the $type$ will be read
*
* @return The $type$ at the given index
*
* @throws IndexOutOfBoundsException
* If <tt>index</tt> is negative
* or not smaller than the buffer's limit
*/
public abstract $type$ get(int index);
#if[streamableType]
/**
* Absolute <i>get</i> method. Reads the $type$ at the given
* index without any validation of the index.
*
* @param index
* The index from which the $type$ will be read
*
* @return The $type$ at the given index
*/
abstract $type$ getUnchecked(int index); // package-private
#end[streamableType]
/**
* Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> Writes the given $type$ into this buffer at the given
* index. </p>
*
* @param index
* The index at which the $type$ will be written
*
* @param $x$
* The $type$ value to be written
*
* @return This buffer
*
* @throws IndexOutOfBoundsException
* If <tt>index</tt> is negative
* or not smaller than the buffer's limit
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public abstract $Type$Buffer put(int index, $type$ $x$);
// -- Bulk get operations --
/**
* Relative bulk <i>get</i> method.
*
* <p> This method transfers $type$s from this buffer into the given
* destination array. If there are fewer $type$s remaining in the
* buffer than are required to satisfy the request, that is, if
* <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
* $type$s are transferred and a {@link BufferUnderflowException} is
* thrown.
*
* <p> Otherwise, this method copies <tt>length</tt> $type$s from this
* buffer into the given array, starting at the current position of this
* buffer and at the given offset in the array. The position of this
* buffer is then incremented by <tt>length</tt>.
*
* <p> In other words, an invocation of this method of the form
* <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
* the loop
*
* <pre>{@code
* for (int i = off; i < off + len; i++)
* dst[i] = src.get():
* }</pre>
*
* except that it first checks that there are sufficient $type$s in
* this buffer and it is potentially much more efficient.
*
* @param dst
* The array into which $type$s are to be written
*
* @param offset
* The offset within the array of the first $type$ to be
* written; must be non-negative and no larger than
* <tt>dst.length</tt>
*
* @param length
* The maximum number of $type$s to be written to the given
* array; must be non-negative and no larger than
* <tt>dst.length - offset</tt>
*
* @return This buffer
*
* @throws BufferUnderflowException
* If there are fewer than <tt>length</tt> $type$s
* remaining in this buffer
*
* @throws IndexOutOfBoundsException
* If the preconditions on the <tt>offset</tt> and <tt>length</tt>
* parameters do not hold
*/
public $Type$Buffer get($type$[] dst, int offset, int length) {
checkBounds(offset, length, dst.length);
if (length > remaining())
throw new BufferUnderflowException();
int end = offset + length;
for (int i = offset; i < end; i++)
dst[i] = get();
return this;
}
/**
* Relative bulk <i>get</i> method.
*
* <p> This method transfers $type$s from this buffer into the given
* destination array. An invocation of this method of the form
* <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
*
* <pre>
* src.get(a, 0, a.length) </pre>
*
* @param dst
* The destination array
*
* @return This buffer
*
* @throws BufferUnderflowException
* If there are fewer than <tt>length</tt> $type$s
* remaining in this buffer
*/
public $Type$Buffer get($type$[] dst) {
return get(dst, 0, dst.length);
}
// -- Bulk put operations --
/**
* Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> This method transfers the $type$s remaining in the given source
* buffer into this buffer. If there are more $type$s remaining in the
* source buffer than in this buffer, that is, if
* <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
* then no $type$s are transferred and a {@link
* BufferOverflowException} is thrown.
*
* <p> Otherwise, this method copies
* <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> $type$s from the given
* buffer into this buffer, starting at each buffer's current position.
* The positions of both buffers are then incremented by <i>n</i>.
*
* <p> In other words, an invocation of this method of the form
* <tt>dst.put(src)</tt> has exactly the same effect as the loop
*
* <pre>
* while (src.hasRemaining())
* dst.put(src.get()); </pre>
*
* except that it first checks that there is sufficient space in this
* buffer and it is potentially much more efficient.
*
* @param src
* The source buffer from which $type$s are to be read;
* must not be this buffer
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
* for the remaining $type$s in the source buffer
*
* @throws IllegalArgumentException
* If the source buffer is this buffer
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public $Type$Buffer put($Type$Buffer src) {
if (src == this)
throw new IllegalArgumentException();
if (isReadOnly())
throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
for (int i = 0; i < n; i++)
put(src.get());
return this;
}
/**
* Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> This method transfers $type$s into this buffer from the given
* source array. If there are more $type$s to be copied from the array
* than remain in this buffer, that is, if
* <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
* $type$s are transferred and a {@link BufferOverflowException} is
* thrown.
*
* <p> Otherwise, this method copies <tt>length</tt> $type$s from the
* given array into this buffer, starting at the given offset in the array
* and at the current position of this buffer. The position of this buffer
* is then incremented by <tt>length</tt>.
*
* <p> In other words, an invocation of this method of the form
* <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
* the loop
*
* <pre>{@code
* for (int i = off; i < off + len; i++)
* dst.put(a[i]);
* }</pre>
*
* except that it first checks that there is sufficient space in this
* buffer and it is potentially much more efficient.
*
* @param src
* The array from which $type$s are to be read
*
* @param offset
* The offset within the array of the first $type$ to be read;
* must be non-negative and no larger than <tt>array.length</tt>
*
* @param length
* The number of $type$s to be read from the given array;
* must be non-negative and no larger than
* <tt>array.length - offset</tt>
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
*
* @throws IndexOutOfBoundsException
* If the preconditions on the <tt>offset</tt> and <tt>length</tt>
* parameters do not hold
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public $Type$Buffer put($type$[] src, int offset, int length) {
checkBounds(offset, length, src.length);
if (length > remaining())
throw new BufferOverflowException();
int end = offset + length;
for (int i = offset; i < end; i++)
this.put(src[i]);
return this;
}
/**
* Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> This method transfers the entire content of the given source
* $type$ array into this buffer. An invocation of this method of the
* form <tt>dst.put(a)</tt> behaves in exactly the same way as the
* invocation
*
* <pre>
* dst.put(a, 0, a.length) </pre>
*
* @param src
* The source array
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public final $Type$Buffer put($type$[] src) {
return put(src, 0, src.length);
}
#if[char]
/**
* Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> This method transfers $type$s from the given string into this
* buffer. If there are more $type$s to be copied from the string than
* remain in this buffer, that is, if
* <tt>end&nbsp;-&nbsp;start</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
* then no $type$s are transferred and a {@link
* BufferOverflowException} is thrown.
*
* <p> Otherwise, this method copies
* <i>n</i>&nbsp;=&nbsp;<tt>end</tt>&nbsp;-&nbsp;<tt>start</tt> $type$s
* from the given string into this buffer, starting at the given
* <tt>start</tt> index and at the current position of this buffer. The
* position of this buffer is then incremented by <i>n</i>.
*
* <p> In other words, an invocation of this method of the form
* <tt>dst.put(src,&nbsp;start,&nbsp;end)</tt> has exactly the same effect
* as the loop
*
* <pre>{@code
* for (int i = start; i < end; i++)
* dst.put(src.charAt(i));
* }</pre>
*
* except that it first checks that there is sufficient space in this
* buffer and it is potentially much more efficient.
*
* @param src
* The string from which $type$s are to be read
*
* @param start
* The offset within the string of the first $type$ to be read;
* must be non-negative and no larger than
* <tt>string.length()</tt>
*
* @param end
* The offset within the string of the last $type$ to be read,
* plus one; must be non-negative and no larger than
* <tt>string.length()</tt>
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
*
* @throws IndexOutOfBoundsException
* If the preconditions on the <tt>start</tt> and <tt>end</tt>
* parameters do not hold
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public $Type$Buffer put(String src, int start, int end) {
checkBounds(start, end - start, src.length());
if (isReadOnly())
throw new ReadOnlyBufferException();
if (end - start > remaining())
throw new BufferOverflowException();
for (int i = start; i < end; i++)
this.put(src.charAt(i));
return this;
}
/**
* Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> This method transfers the entire content of the given source string
* into this buffer. An invocation of this method of the form
* <tt>dst.put(s)</tt> behaves in exactly the same way as the invocation
*
* <pre>
* dst.put(s, 0, s.length()) </pre>
*
* @param src
* The source string
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public final $Type$Buffer put(String src) {
return put(src, 0, src.length());
}
#end[char]
// -- Other stuff --
/**
* Tells whether or not this buffer is backed by an accessible $type$
* array.
*
* <p> If this method returns <tt>true</tt> then the {@link #array() array}
* and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
* </p>
*
* @return <tt>true</tt> if, and only if, this buffer
* is backed by an array and is not read-only
*/
public final boolean hasArray() {
return (hb != null) && !isReadOnly;
}
/**
* Returns the $type$ array that backs this
* buffer&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> Modifications to this buffer's content will cause the returned
* array's content to be modified, and vice versa.
*
* <p> Invoke the {@link #hasArray hasArray} method before invoking this
* method in order to ensure that this buffer has an accessible backing
* array. </p>
*
* @return The array that backs this buffer
*
* @throws ReadOnlyBufferException
* If this buffer is backed by an array but is read-only
*
* @throws UnsupportedOperationException
* If this buffer is not backed by an accessible array
*/
public final $type$[] array() {
if (hb == null)
throw new UnsupportedOperationException();
if (isReadOnly)
throw new ReadOnlyBufferException();
return hb;
}
/**
* Returns the offset within this buffer's backing array of the first
* element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> If this buffer is backed by an array then buffer position <i>p</i>
* corresponds to array index <i>p</i>&nbsp;+&nbsp;<tt>arrayOffset()</tt>.
*
* <p> Invoke the {@link #hasArray hasArray} method before invoking this
* method in order to ensure that this buffer has an accessible backing
* array. </p>
*
* @return The offset within this buffer's array
* of the first element of the buffer
*
* @throws ReadOnlyBufferException
* If this buffer is backed by an array but is read-only
*
* @throws UnsupportedOperationException
* If this buffer is not backed by an accessible array
*/
public final int arrayOffset() {
if (hb == null)
throw new UnsupportedOperationException();
if (isReadOnly)
throw new ReadOnlyBufferException();
return offset;
}
/**
* Compacts this buffer&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> The $type$s between the buffer's current position and its limit,
* if any, are copied to the beginning of the buffer. That is, the
* $type$ at index <i>p</i>&nbsp;=&nbsp;<tt>position()</tt> is copied
* to index zero, the $type$ at index <i>p</i>&nbsp;+&nbsp;1 is copied
* to index one, and so forth until the $type$ at index
* <tt>limit()</tt>&nbsp;-&nbsp;1 is copied to index
* <i>n</i>&nbsp;=&nbsp;<tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>&nbsp;-&nbsp;<i>p</i>.
* The buffer's position is then set to <i>n+1</i> and its limit is set to
* its capacity. The mark, if defined, is discarded.
*
* <p> The buffer's position is set to the number of $type$s copied,
* rather than to zero, so that an invocation of this method can be
* followed immediately by an invocation of another relative <i>put</i>
* method. </p>
*
#if[byte]
*
* <p> Invoke this method after writing data from a buffer in case the
* write was incomplete. The following loop, for example, copies bytes
* from one channel to another via the buffer <tt>buf</tt>:
*
* <blockquote><pre>{@code
* buf.clear(); // Prepare buffer for use
* while (in.read(buf) >= 0 || buf.position != 0) {
* buf.flip();
* out.write(buf);
* buf.compact(); // In case of partial write
* }
* }</pre></blockquote>
*
#end[byte]
*
* @return This buffer
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public abstract $Type$Buffer compact();
/**
* Tells whether or not this $type$ buffer is direct.
*
* @return <tt>true</tt> if, and only if, this buffer is direct
*/
public abstract boolean isDirect();
#if[!char]
/**
* Returns a string summarizing the state of this buffer.
*
* @return A summary string
*/
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(getClass().getName());
sb.append("[pos=");
sb.append(position());
sb.append(" lim=");
sb.append(limit());
sb.append(" cap=");
sb.append(capacity());
sb.append("]");
return sb.toString();
}
#end[!char]
// ## Should really use unchecked accessors here for speed
/**
* Returns the current hash code of this buffer.
*
* <p> The hash code of a $type$ buffer depends only upon its remaining
* elements; that is, upon the elements from <tt>position()</tt> up to, and
* including, the element at <tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>.
*
* <p> Because buffer hash codes are content-dependent, it is inadvisable
* to use buffers as keys in hash maps or similar data structures unless it
* is known that their contents will not change. </p>
*
* @return The current hash code of this buffer
*/
public int hashCode() {
int h = 1;
int p = position();
for (int i = limit() - 1; i >= p; i--)
#if[int]
h = 31 * h + get(i);
#else[int]
h = 31 * h + (int)get(i);
#end[int]
return h;
}
/**
* Tells whether or not this buffer is equal to another object.
*
* <p> Two $type$ buffers are equal if, and only if,
*
* <ol>
*
* <li><p> They have the same element type, </p></li>
*
* <li><p> They have the same number of remaining elements, and
* </p></li>
*
* <li><p> The two sequences of remaining elements, considered
* independently of their starting positions, are pointwise equal.
#if[floatingPointType]
* This method considers two $type$ elements {@code a} and {@code b}
* to be equal if
* {@code (a == b) || ($Fulltype$.isNaN(a) && $Fulltype$.isNaN(b))}.
* The values {@code -0.0} and {@code +0.0} are considered to be
* equal, unlike {@link $Fulltype$#equals(Object)}.
#end[floatingPointType]
* </p></li>
*
* </ol>
*
* <p> A $type$ buffer is not equal to any other type of object. </p>
*
* @param ob The object to which this buffer is to be compared
*
* @return <tt>true</tt> if, and only if, this buffer is equal to the
* given object
*/
public boolean equals(Object ob) {
if (this == ob)
return true;
if (!(ob instanceof $Type$Buffer))
return false;
$Type$Buffer that = ($Type$Buffer)ob;
if (this.remaining() != that.remaining())
return false;
int p = this.position();
for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--)
if (!equals(this.get(i), that.get(j)))
return false;
return true;
}
private static boolean equals($type$ x, $type$ y) {
#if[floatingPointType]
return (x == y) || ($Fulltype$.isNaN(x) && $Fulltype$.isNaN(y));
#else[floatingPointType]
return x == y;
#end[floatingPointType]
}
/**
* Compares this buffer to another.
*
* <p> Two $type$ buffers are compared by comparing their sequences of
* remaining elements lexicographically, without regard to the starting
* position of each sequence within its corresponding buffer.
#if[floatingPointType]
* Pairs of {@code $type$} elements are compared as if by invoking
* {@link $Fulltype$#compare($type$,$type$)}, except that
* {@code -0.0} and {@code 0.0} are considered to be equal.
* {@code $Fulltype$.NaN} is considered by this method to be equal
* to itself and greater than all other {@code $type$} values
* (including {@code $Fulltype$.POSITIVE_INFINITY}).
#else[floatingPointType]
* Pairs of {@code $type$} elements are compared as if by invoking
* {@link $Fulltype$#compare($type$,$type$)}.
#end[floatingPointType]
*
* <p> A $type$ buffer is not comparable to any other type of object.
*
* @return A negative integer, zero, or a positive integer as this buffer
* is less than, equal to, or greater than the given buffer
*/
public int compareTo($Type$Buffer that) {
int n = this.position() + Math.min(this.remaining(), that.remaining());
for (int i = this.position(), j = that.position(); i < n; i++, j++) {
int cmp = compare(this.get(i), that.get(j));
if (cmp != 0)
return cmp;
}
return this.remaining() - that.remaining();
}
private static int compare($type$ x, $type$ y) {
#if[floatingPointType]
return ((x < y) ? -1 :
(x > y) ? +1 :
(x == y) ? 0 :
$Fulltype$.isNaN(x) ? ($Fulltype$.isNaN(y) ? 0 : +1) : -1);
#else[floatingPointType]
return $Fulltype$.compare(x, y);
#end[floatingPointType]
}
// -- Other char stuff --
#if[char]
/**
* Returns a string containing the characters in this buffer.
*
* <p> The first character of the resulting string will be the character at
* this buffer's position, while the last character will be the character
* at index <tt>limit()</tt>&nbsp;-&nbsp;1. Invoking this method does not
* change the buffer's position. </p>
*
* @return The specified string
*/
public String toString() {
return toString(position(), limit());
}
abstract String toString(int start, int end); // package-private
// --- Methods to support CharSequence ---
/**
* Returns the length of this character buffer.
*
* <p> When viewed as a character sequence, the length of a character
* buffer is simply the number of characters between the position
* (inclusive) and the limit (exclusive); that is, it is equivalent to
* <tt>remaining()</tt>. </p>
*
* @return The length of this character buffer
*/
public final int length() {
return remaining();
}
/**
* Reads the character at the given index relative to the current
* position.
*
* @param index
* The index of the character to be read, relative to the position;
* must be non-negative and smaller than <tt>remaining()</tt>
*
* @return The character at index
* <tt>position()&nbsp;+&nbsp;index</tt>
*
* @throws IndexOutOfBoundsException
* If the preconditions on <tt>index</tt> do not hold
*/
public final char charAt(int index) {
return get(position() + checkIndex(index, 1));
}
/**
* Creates a new character buffer that represents the specified subsequence
* of this buffer, relative to the current position.
*
* <p> The new buffer will share this buffer's content; that is, if the
* content of this buffer is mutable then modifications to one buffer will
* cause the other to be modified. The new buffer's capacity will be that
* of this buffer, its position will be
* <tt>position()</tt>&nbsp;+&nbsp;<tt>start</tt>, and its limit will be
* <tt>position()</tt>&nbsp;+&nbsp;<tt>end</tt>. The new buffer will be
* direct if, and only if, this buffer is direct, and it will be read-only
* if, and only if, this buffer is read-only. </p>
*
* @param start
* The index, relative to the current position, of the first
* character in the subsequence; must be non-negative and no larger
* than <tt>remaining()</tt>
*
* @param end
* The index, relative to the current position, of the character
* following the last character in the subsequence; must be no
* smaller than <tt>start</tt> and no larger than
* <tt>remaining()</tt>
*
* @return The new character buffer
*
* @throws IndexOutOfBoundsException
* If the preconditions on <tt>start</tt> and <tt>end</tt>
* do not hold
*/
public abstract CharBuffer subSequence(int start, int end);
// --- Methods to support Appendable ---
/**
* Appends the specified character sequence to this
* buffer&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> An invocation of this method of the form <tt>dst.append(csq)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* dst.put(csq.toString()) </pre>
*
* <p> Depending on the specification of <tt>toString</tt> for the
* character sequence <tt>csq</tt>, the entire sequence may not be
* appended. For instance, invoking the {@link $Type$Buffer#toString()
* toString} method of a character buffer will return a subsequence whose
* content depends upon the buffer's position and limit.
*
* @param csq
* The character sequence to append. If <tt>csq</tt> is
* <tt>null</tt>, then the four characters <tt>"null"</tt> are
* appended to this character buffer.
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*
* @since 1.5
*/
public $Type$Buffer append(CharSequence csq) {
if (csq == null)
return put("null");
else
return put(csq.toString());
}
/**
* Appends a subsequence of the specified character sequence to this
* buffer&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> An invocation of this method of the form <tt>dst.append(csq, start,
* end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in exactly the
* same way as the invocation
*
* <pre>
* dst.put(csq.subSequence(start, end).toString()) </pre>
*
* @param csq
* The character sequence from which a subsequence will be
* appended. If <tt>csq</tt> is <tt>null</tt>, then characters
* will be appended as if <tt>csq</tt> contained the four
* characters <tt>"null"</tt>.
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
*
* @throws IndexOutOfBoundsException
* If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
* is greater than <tt>end</tt>, or <tt>end</tt> is greater than
* <tt>csq.length()</tt>
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*
* @since 1.5
*/
public $Type$Buffer append(CharSequence csq, int start, int end) {
CharSequence cs = (csq == null ? "null" : csq);
return put(cs.subSequence(start, end).toString());
}
/**
* Appends the specified $type$ to this
* buffer&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> An invocation of this method of the form <tt>dst.append($x$)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* dst.put($x$) </pre>
*
* @param $x$
* The 16-bit $type$ to append
*
* @return This buffer
*
* @throws BufferOverflowException
* If there is insufficient space in this buffer
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*
* @since 1.5
*/
public $Type$Buffer append($type$ $x$) {
return put($x$);
}
#end[char]
// -- Other byte stuff: Access to binary data --
#if[!byte]
/**
* Retrieves this buffer's byte order.
*
* <p> The byte order of $a$ $type$ buffer created by allocation or by
* wrapping an existing <tt>$type$</tt> array is the {@link
* ByteOrder#nativeOrder native order} of the underlying
* hardware. The byte order of $a$ $type$ buffer created as a <a
* href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
* byte buffer at the moment that the view is created. </p>
*
* @return This buffer's byte order
*/
public abstract ByteOrder order();
#end[!byte]
#if[byte]
boolean bigEndian // package-private
= true;
boolean nativeByteOrder // package-private
= (Bits.byteOrder() == ByteOrder.BIG_ENDIAN);
/**
* Retrieves this buffer's byte order.
*
* <p> The byte order is used when reading or writing multibyte values, and
* when creating buffers that are views of this byte buffer. The order of
* a newly-created byte buffer is always {@link ByteOrder#BIG_ENDIAN
* BIG_ENDIAN}. </p>
*
* @return This buffer's byte order
*/
public final ByteOrder order() {
return bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
}
/**
* Modifies this buffer's byte order.
*
* @param bo
* The new byte order,
* either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
* or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}
*
* @return This buffer
*/
public final $Type$Buffer order(ByteOrder bo) {
bigEndian = (bo == ByteOrder.BIG_ENDIAN);
nativeByteOrder =
(bigEndian == (Bits.byteOrder() == ByteOrder.BIG_ENDIAN));
return this;
}
// Unchecked accessors, for use by ByteBufferAs-X-Buffer classes
//
abstract byte _get(int i); // package-private
abstract void _put(int i, byte b); // package-private
// #BIN
//
// Binary-data access methods for short, char, int, long, float,
// and double will be inserted here
#end[byte]
#if[streamableType]
#if[char]
@Override
#end[char]
public $Streamtype$Stream $type$s() {
return StreamSupport.$streamtype$Stream(() -> new $Type$BufferSpliterator(this),
Buffer.SPLITERATOR_CHARACTERISTICS, false);
}
#end[streamableType]
}
#
# Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code 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
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# Generated exception classes for java.nio.channels
SINCE=1.4
PACKAGE=java.nio.channels
# This year should only change if the generated source is modified.
COPYRIGHT_YEARS="2000, 2007,"
SUPER=java.io.IOException
gen ClosedChannelException "
* Checked exception thrown when an attempt is made to invoke or complete an
* I/O operation upon channel that is closed, or at least closed to that
* operation. That this exception is thrown does not necessarily imply that
* the channel is completely closed. A socket channel whose write half has
* been shut down, for example, may still be open for reading." \
882777185433553857L
gen FileLockInterruptionException "
* Checked exception received by a thread when another thread interrupts it
* while it is waiting to acquire a file lock. Before this exception is thrown
* the interrupt status of the previously-blocked thread will have been set." \
7104080643653532383L
SUPER=ClosedChannelException
gen AsynchronousCloseException "
* Checked exception received by a thread when another thread closes the
* channel or the part of the channel upon which it is blocked in an I/O
* operation." \
6891178312432313966L
SUPER=AsynchronousCloseException
gen ClosedByInterruptException "
* Checked exception received by a thread when another thread interrupts it
* while it is blocked in an I/O operation upon a channel. Before this
* exception is thrown the channel will have been closed and the interrupt
* status of the previously-blocked thread will have been set." \
-4488191543534286750L
SUPER=IllegalArgumentException
gen IllegalSelectorException "
* Unchecked exception thrown when an attempt is made to register a channel
* with a selector that was not created by the provider that created the
* channel." \
-8406323347253320987L
gen UnresolvedAddressException "
* Unchecked exception thrown when an attempt is made to invoke a network
* operation upon an unresolved socket address." \
6136959093620794148L
gen UnsupportedAddressTypeException "
* Unchecked exception thrown when an attempt is made to bind or connect
* to a socket address of a type that is not supported." \
-2964323842829700493L
SUPER=IllegalStateException
gen AlreadyConnectedException "
* Unchecked exception thrown when an attempt is made to connect a {@link
* SocketChannel} that is already connected." \
-7331895245053773357L
gen ConnectionPendingException "
* Unchecked exception thrown when an attempt is made to connect a {@link
* SocketChannel} for which a non-blocking connection operation is already in
* progress." \
2008393366501760879L
gen ClosedSelectorException "
* Unchecked exception thrown when an attempt is made to invoke an I/O
* operation upon a closed selector." \
6466297122317847835L
gen CancelledKeyException "
* Unchecked exception thrown when an attempt is made to use
* a selection key that is no longer valid." \
-8438032138028814268L
gen IllegalBlockingModeException "
* Unchecked exception thrown when a blocking-mode-specific operation
* is invoked upon a channel in the incorrect blocking mode." \
-3335774961855590474L
gen NoConnectionPendingException "
* Unchecked exception thrown when the {@link SocketChannel#finishConnect
* finishConnect} method of a {@link SocketChannel} is invoked without first
* successfully invoking its {@link SocketChannel#connect connect} method." \
-8296561183633134743L
gen NonReadableChannelException "
* Unchecked exception thrown when an attempt is made to read
* from a channel that was not originally opened for reading." \
-3200915679294993514L
gen NonWritableChannelException "
* Unchecked exception thrown when an attempt is made to write
* to a channel that was not originally opened for writing." \
-7071230488279011621L
gen NotYetBoundException "
* Unchecked exception thrown when an attempt is made to invoke an I/O
* operation upon a server socket channel that is not yet bound." \
4640999303950202242L
gen NotYetConnectedException "
* Unchecked exception thrown when an attempt is made to invoke an I/O
* operation upon a socket channel that is not yet connected." \
4697316551909513464L
gen OverlappingFileLockException "
* Unchecked exception thrown when an attempt is made to acquire a lock on a
* region of a file that overlaps a region already locked by the same Java
* virtual machine, or when another thread is already waiting to lock an
* overlapping region of the same file." \
2047812138163068433L
SINCE=1.7
SUPER=java.io.IOException
gen InterruptedByTimeoutException "
* Checked exception received by a thread when a timeout elapses before an
* asynchronous operation completes." \
-4268008601014042947L
SUPER=IllegalArgumentException
gen IllegalChannelGroupException "
* Unchecked exception thrown when an attempt is made to open a channel
* in a group that was not created by the same provider. " \
-2495041211157744253L
SUPER=IllegalStateException
gen AlreadyBoundException "
* Unchecked exception thrown when an attempt is made to bind the socket a
* network oriented channel that is already bound." \
6796072983322737592L
gen AcceptPendingException "
* Unchecked exception thrown when an attempt is made to initiate an accept
* operation on a channel and a previous accept operation has not completed." \
2721339977965416421L
gen ReadPendingException "
* Unchecked exception thrown when an attempt is made to read from an
* asynchronous socket channel and a previous read has not completed." \
1986315242191227217L
gen WritePendingException "
* Unchecked exception thrown when an attempt is made to write to an
* asynchronous socket channel and a previous write has not completed." \
7031871839266032276L
gen ShutdownChannelGroupException "
* Unchecked exception thrown when an attempt is made to construct a channel in
* a group that is shutdown or the completion handler for an I/O operation
* cannot be invoked because the channel group has terminated." \
-3903801676350154157L
<!--
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!doctype html public "-//IETF//DTD HTML//EN">
<html>
<body bgcolor="white">
Service-provider classes for the <tt>{@link java.nio.channels}</tt> package.
<p> Only developers who are defining new selector providers or asynchronous
channel providers should need to make direct use of this package. </p>
<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
or method in any class or interface in this package will cause a {@link
java.lang.NullPointerException NullPointerException} to be thrown.
@since 1.4
@author Mark Reinhold
@author JSR-51 Expert Group
</body>
</html>
/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#warn This file is preprocessed before being compiled
package java.nio.charset;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
import java.lang.ref.WeakReference;
import java.nio.charset.CoderMalfunctionError; // javadoc
import java.util.Arrays;
/**
* An engine that can transform a sequence of $itypesPhrase$ into a sequence of
* $otypesPhrase$.
*
* <a name="steps"></a>
*
* <p> The input $itype$ sequence is provided in a $itype$ buffer or a series
* of such buffers. The output $otype$ sequence is written to a $otype$ buffer
* or a series of such buffers. $A$ $coder$ should always be used by making
* the following sequence of method invocations, hereinafter referred to as $a$
* <i>$coding$ operation</i>:
*
* <ol>
*
* <li><p> Reset the $coder$ via the {@link #reset reset} method, unless it
* has not been used before; </p></li>
*
* <li><p> Invoke the {@link #$code$ $code$} method zero or more times, as
* long as additional input may be available, passing <tt>false</tt> for the
* <tt>endOfInput</tt> argument and filling the input buffer and flushing the
* output buffer between invocations; </p></li>
*
* <li><p> Invoke the {@link #$code$ $code$} method one final time, passing
* <tt>true</tt> for the <tt>endOfInput</tt> argument; and then </p></li>
*
* <li><p> Invoke the {@link #flush flush} method so that the $coder$ can
* flush any internal state to the output buffer. </p></li>
*
* </ol>
*
* Each invocation of the {@link #$code$ $code$} method will $code$ as many
* $itype$s as possible from the input buffer, writing the resulting $otype$s
* to the output buffer. The {@link #$code$ $code$} method returns when more
* input is required, when there is not enough room in the output buffer, or
* when $a$ $coding$ error has occurred. In each case a {@link CoderResult}
* object is returned to describe the reason for termination. An invoker can
* examine this object and fill the input buffer, flush the output buffer, or
* attempt to recover from $a$ $coding$ error, as appropriate, and try again.
*
* <a name="ce"></a>
*
* <p> There are two general types of $coding$ errors. If the input $itype$
* sequence is $notLegal$ then the input is considered <i>malformed</i>. If
* the input $itype$ sequence is legal but cannot be mapped to a valid
* $outSequence$ then an <i>unmappable character</i> has been encountered.
*
* <a name="cae"></a>
*
* <p> How $a$ $coding$ error is handled depends upon the action requested for
* that type of error, which is described by an instance of the {@link
* CodingErrorAction} class. The possible error actions are to {@linkplain
* CodingErrorAction#IGNORE ignore} the erroneous input, {@linkplain
* CodingErrorAction#REPORT report} the error to the invoker via
* the returned {@link CoderResult} object, or {@linkplain CodingErrorAction#REPLACE
* replace} the erroneous input with the current value of the
* replacement $replTypeName$. The replacement
*
#if[encoder]
* is initially set to the $coder$'s default replacement, which often
* (but not always) has the initial value&nbsp;$defaultReplName$;
#end[encoder]
#if[decoder]
* has the initial value $defaultReplName$;
#end[decoder]
*
* its value may be changed via the {@link #replaceWith($replFQType$)
* replaceWith} method.
*
* <p> The default action for malformed-input and unmappable-character errors
* is to {@linkplain CodingErrorAction#REPORT report} them. The
* malformed-input error action may be changed via the {@link
* #onMalformedInput(CodingErrorAction) onMalformedInput} method; the
* unmappable-character action may be changed via the {@link
* #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter} method.
*
* <p> This class is designed to handle many of the details of the $coding$
* process, including the implementation of error actions. $A$ $coder$ for a
* specific charset, which is a concrete subclass of this class, need only
* implement the abstract {@link #$code$Loop $code$Loop} method, which
* encapsulates the basic $coding$ loop. A subclass that maintains internal
* state should, additionally, override the {@link #implFlush implFlush} and
* {@link #implReset implReset} methods.
*
* <p> Instances of this class are not safe for use by multiple concurrent
* threads. </p>
*
*
* @author Mark Reinhold
* @author JSR-51 Expert Group
* @since 1.4
*
* @see ByteBuffer
* @see CharBuffer
* @see Charset
* @see Charset$OtherCoder$
*/
public abstract class Charset$Coder$ {
private final Charset charset;
private final float average$ItypesPerOtype$;
private final float max$ItypesPerOtype$;
private $replType$ replacement;
private CodingErrorAction malformedInputAction
= CodingErrorAction.REPORT;
private CodingErrorAction unmappableCharacterAction
= CodingErrorAction.REPORT;
// Internal states
//
private static final int ST_RESET = 0;
private static final int ST_CODING = 1;
private static final int ST_END = 2;
private static final int ST_FLUSHED = 3;
private int state = ST_RESET;
private static String stateNames[]
= { "RESET", "CODING", "CODING_END", "FLUSHED" };
/**
* Initializes a new $coder$. The new $coder$ will have the given
* $otypes-per-itype$ and replacement values.
*
* @param cs
* The charset that created this $coder$
*
* @param average$ItypesPerOtype$
* A positive float value indicating the expected number of
* $otype$s that will be produced for each input $itype$
*
* @param max$ItypesPerOtype$
* A positive float value indicating the maximum number of
* $otype$s that will be produced for each input $itype$
*
* @param replacement
* The initial replacement; must not be <tt>null</tt>, must have
* non-zero length, must not be longer than max$ItypesPerOtype$,
* and must be {@linkplain #isLegalReplacement legal}
*
* @throws IllegalArgumentException
* If the preconditions on the parameters do not hold
*/
{#if[encoder]?protected:private}
Charset$Coder$(Charset cs,
float average$ItypesPerOtype$,
float max$ItypesPerOtype$,
$replType$ replacement)
{
this.charset = cs;
if (average$ItypesPerOtype$ <= 0.0f)
throw new IllegalArgumentException("Non-positive "
+ "average$ItypesPerOtype$");
if (max$ItypesPerOtype$ <= 0.0f)
throw new IllegalArgumentException("Non-positive "
+ "max$ItypesPerOtype$");
if (!Charset.atBugLevel("1.4")) {
if (average$ItypesPerOtype$ > max$ItypesPerOtype$)
throw new IllegalArgumentException("average$ItypesPerOtype$"
+ " exceeds "
+ "max$ItypesPerOtype$");
}
this.replacement = replacement;
this.average$ItypesPerOtype$ = average$ItypesPerOtype$;
this.max$ItypesPerOtype$ = max$ItypesPerOtype$;
replaceWith(replacement);
}
/**
* Initializes a new $coder$. The new $coder$ will have the given
* $otypes-per-itype$ values and its replacement will be the
* $replTypeName$ $defaultReplName$.
*
* @param cs
* The charset that created this $coder$
*
* @param average$ItypesPerOtype$
* A positive float value indicating the expected number of
* $otype$s that will be produced for each input $itype$
*
* @param max$ItypesPerOtype$
* A positive float value indicating the maximum number of
* $otype$s that will be produced for each input $itype$
*
* @throws IllegalArgumentException
* If the preconditions on the parameters do not hold
*/
protected Charset$Coder$(Charset cs,
float average$ItypesPerOtype$,
float max$ItypesPerOtype$)
{
this(cs,
average$ItypesPerOtype$, max$ItypesPerOtype$,
$defaultRepl$);
}
/**
* Returns the charset that created this $coder$.
*
* @return This $coder$'s charset
*/
public final Charset charset() {
return charset;
}
/**
* Returns this $coder$'s replacement value.
*
* @return This $coder$'s current replacement,
* which is never <tt>null</tt> and is never empty
*/
public final $replType$ replacement() {
#if[decoder]
return replacement;
#end[decoder]
#if[encoder]
return Arrays.copyOf(replacement, replacement.$replLength$);
#end[encoder]
}
/**
* Changes this $coder$'s replacement value.
*
* <p> This method invokes the {@link #implReplaceWith implReplaceWith}
* method, passing the new replacement, after checking that the new
* replacement is acceptable. </p>
*
* @param newReplacement The replacement value
*
#if[decoder]
* The new replacement; must not be <tt>null</tt>
* and must have non-zero length
#end[decoder]
#if[encoder]
* The new replacement; must not be <tt>null</tt>, must have
* non-zero length, must not be longer than the value returned by
* the {@link #max$ItypesPerOtype$() max$ItypesPerOtype$} method, and
* must be {@link #isLegalReplacement legal}
#end[encoder]
*
* @return This $coder$
*
* @throws IllegalArgumentException
* If the preconditions on the parameter do not hold
*/
public final Charset$Coder$ replaceWith($replType$ newReplacement) {
if (newReplacement == null)
throw new IllegalArgumentException("Null replacement");
int len = newReplacement.$replLength$;
if (len == 0)
throw new IllegalArgumentException("Empty replacement");
if (len > max$ItypesPerOtype$)
throw new IllegalArgumentException("Replacement too long");
#if[decoder]
this.replacement = newReplacement;
#end[decoder]
#if[encoder]
if (!isLegalReplacement(newReplacement))
throw new IllegalArgumentException("Illegal replacement");
this.replacement = Arrays.copyOf(newReplacement, newReplacement.$replLength$);
#end[encoder]
implReplaceWith(this.replacement);
return this;
}
/**
* Reports a change to this $coder$'s replacement value.
*
* <p> The default implementation of this method does nothing. This method
* should be overridden by $coder$s that require notification of changes to
* the replacement. </p>
*
* @param newReplacement The replacement value
*/
protected void implReplaceWith($replType$ newReplacement) {
}
#if[encoder]
private WeakReference<CharsetDecoder> cachedDecoder = null;
/**
* Tells whether or not the given byte array is a legal replacement value
* for this encoder.
*
* <p> A replacement is legal if, and only if, it is a legal sequence of
* bytes in this encoder's charset; that is, it must be possible to decode
* the replacement into one or more sixteen-bit Unicode characters.
*
* <p> The default implementation of this method is not very efficient; it
* should generally be overridden to improve performance. </p>
*
* @param repl The byte array to be tested
*
* @return <tt>true</tt> if, and only if, the given byte array
* is a legal replacement value for this encoder
*/
public boolean isLegalReplacement(byte[] repl) {
WeakReference<CharsetDecoder> wr = cachedDecoder;
CharsetDecoder dec = null;
if ((wr == null) || ((dec = wr.get()) == null)) {
dec = charset().newDecoder();
dec.onMalformedInput(CodingErrorAction.REPORT);
dec.onUnmappableCharacter(CodingErrorAction.REPORT);
cachedDecoder = new WeakReference<CharsetDecoder>(dec);
} else {
dec.reset();
}
ByteBuffer bb = ByteBuffer.wrap(repl);
CharBuffer cb = CharBuffer.allocate((int)(bb.remaining()
* dec.maxCharsPerByte()));
CoderResult cr = dec.decode(bb, cb, true);
return !cr.isError();
}
#end[encoder]
/**
* Returns this $coder$'s current action for malformed-input errors.
*
* @return The current malformed-input action, which is never <tt>null</tt>
*/
public CodingErrorAction malformedInputAction() {
return malformedInputAction;
}
/**
* Changes this $coder$'s action for malformed-input errors.
*
* <p> This method invokes the {@link #implOnMalformedInput
* implOnMalformedInput} method, passing the new action. </p>
*
* @param newAction The new action; must not be <tt>null</tt>
*
* @return This $coder$
*
* @throws IllegalArgumentException
* If the precondition on the parameter does not hold
*/
public final Charset$Coder$ onMalformedInput(CodingErrorAction newAction) {
if (newAction == null)
throw new IllegalArgumentException("Null action");
malformedInputAction = newAction;
implOnMalformedInput(newAction);
return this;
}
/**
* Reports a change to this $coder$'s malformed-input action.
*
* <p> The default implementation of this method does nothing. This method
* should be overridden by $coder$s that require notification of changes to
* the malformed-input action. </p>
*
* @param newAction The new action
*/
protected void implOnMalformedInput(CodingErrorAction newAction) { }
/**
* Returns this $coder$'s current action for unmappable-character errors.
*
* @return The current unmappable-character action, which is never
* <tt>null</tt>
*/
public CodingErrorAction unmappableCharacterAction() {
return unmappableCharacterAction;
}
/**
* Changes this $coder$'s action for unmappable-character errors.
*
* <p> This method invokes the {@link #implOnUnmappableCharacter
* implOnUnmappableCharacter} method, passing the new action. </p>
*
* @param newAction The new action; must not be <tt>null</tt>
*
* @return This $coder$
*
* @throws IllegalArgumentException
* If the precondition on the parameter does not hold
*/
public final Charset$Coder$ onUnmappableCharacter(CodingErrorAction
newAction)
{
if (newAction == null)
throw new IllegalArgumentException("Null action");
unmappableCharacterAction = newAction;
implOnUnmappableCharacter(newAction);
return this;
}
/**
* Reports a change to this $coder$'s unmappable-character action.
*
* <p> The default implementation of this method does nothing. This method
* should be overridden by $coder$s that require notification of changes to
* the unmappable-character action. </p>
*
* @param newAction The new action
*/
protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
/**
* Returns the average number of $otype$s that will be produced for each
* $itype$ of input. This heuristic value may be used to estimate the size
* of the output buffer required for a given input sequence.
*
* @return The average number of $otype$s produced
* per $itype$ of input
*/
public final float average$ItypesPerOtype$() {
return average$ItypesPerOtype$;
}
/**
* Returns the maximum number of $otype$s that will be produced for each
* $itype$ of input. This value may be used to compute the worst-case size
* of the output buffer required for a given input sequence.
*
* @return The maximum number of $otype$s that will be produced per
* $itype$ of input
*/
public final float max$ItypesPerOtype$() {
return max$ItypesPerOtype$;
}
/**
* $Code$s as many $itype$s as possible from the given input buffer,
* writing the results to the given output buffer.
*
* <p> The buffers are read from, and written to, starting at their current
* positions. At most {@link Buffer#remaining in.remaining()} $itype$s
* will be read and at most {@link Buffer#remaining out.remaining()}
* $otype$s will be written. The buffers' positions will be advanced to
* reflect the $itype$s read and the $otype$s written, but their marks and
* limits will not be modified.
*
* <p> In addition to reading $itype$s from the input buffer and writing
* $otype$s to the output buffer, this method returns a {@link CoderResult}
* object to describe its reason for termination:
*
* <ul>
*
* <li><p> {@link CoderResult#UNDERFLOW} indicates that as much of the
* input buffer as possible has been $code$d. If there is no further
* input then the invoker can proceed to the next step of the
* <a href="#steps">$coding$ operation</a>. Otherwise this method
* should be invoked again with further input. </p></li>
*
* <li><p> {@link CoderResult#OVERFLOW} indicates that there is
* insufficient space in the output buffer to $code$ any more $itype$s.
* This method should be invoked again with an output buffer that has
* more {@linkplain Buffer#remaining remaining} $otype$s. This is
* typically done by draining any $code$d $otype$s from the output
* buffer. </p></li>
*
* <li><p> A {@linkplain CoderResult#malformedForLength
* malformed-input} result indicates that a malformed-input
* error has been detected. The malformed $itype$s begin at the input
* buffer's (possibly incremented) position; the number of malformed
* $itype$s may be determined by invoking the result object's {@link
* CoderResult#length() length} method. This case applies only if the
* {@linkplain #onMalformedInput malformed action} of this $coder$
* is {@link CodingErrorAction#REPORT}; otherwise the malformed input
* will be ignored or replaced, as requested. </p></li>
*
* <li><p> An {@linkplain CoderResult#unmappableForLength
* unmappable-character} result indicates that an
* unmappable-character error has been detected. The $itype$s that
* $code$ the unmappable character begin at the input buffer's (possibly
* incremented) position; the number of such $itype$s may be determined
* by invoking the result object's {@link CoderResult#length() length}
* method. This case applies only if the {@linkplain #onUnmappableCharacter
* unmappable action} of this $coder$ is {@link
* CodingErrorAction#REPORT}; otherwise the unmappable character will be
* ignored or replaced, as requested. </p></li>
*
* </ul>
*
* In any case, if this method is to be reinvoked in the same $coding$
* operation then care should be taken to preserve any $itype$s remaining
* in the input buffer so that they are available to the next invocation.
*
* <p> The <tt>endOfInput</tt> parameter advises this method as to whether
* the invoker can provide further input beyond that contained in the given
* input buffer. If there is a possibility of providing additional input
* then the invoker should pass <tt>false</tt> for this parameter; if there
* is no possibility of providing further input then the invoker should
* pass <tt>true</tt>. It is not erroneous, and in fact it is quite
* common, to pass <tt>false</tt> in one invocation and later discover that
* no further input was actually available. It is critical, however, that
* the final invocation of this method in a sequence of invocations always
* pass <tt>true</tt> so that any remaining un$code$d input will be treated
* as being malformed.
*
* <p> This method works by invoking the {@link #$code$Loop $code$Loop}
* method, interpreting its results, handling error conditions, and
* reinvoking it as necessary. </p>
*
*
* @param in
* The input $itype$ buffer
*
* @param out
* The output $otype$ buffer
*
* @param endOfInput
* <tt>true</tt> if, and only if, the invoker can provide no
* additional input $itype$s beyond those in the given buffer
*
* @return A coder-result object describing the reason for termination
*
* @throws IllegalStateException
* If $a$ $coding$ operation is already in progress and the previous
* step was an invocation neither of the {@link #reset reset}
* method, nor of this method with a value of <tt>false</tt> for
* the <tt>endOfInput</tt> parameter, nor of this method with a
* value of <tt>true</tt> for the <tt>endOfInput</tt> parameter
* but a return value indicating an incomplete $coding$ operation
*
* @throws CoderMalfunctionError
* If an invocation of the $code$Loop method threw
* an unexpected exception
*/
public final CoderResult $code$($Itype$Buffer in, $Otype$Buffer out,
boolean endOfInput)
{
int newState = endOfInput ? ST_END : ST_CODING;
if ((state != ST_RESET) && (state != ST_CODING)
&& !(endOfInput && (state == ST_END)))
throwIllegalStateException(state, newState);
state = newState;
for (;;) {
CoderResult cr;
try {
cr = $code$Loop(in, out);
} catch (BufferUnderflowException x) {
throw new CoderMalfunctionError(x);
} catch (BufferOverflowException x) {
throw new CoderMalfunctionError(x);
}
if (cr.isOverflow())
return cr;
if (cr.isUnderflow()) {
if (endOfInput && in.hasRemaining()) {
cr = CoderResult.malformedForLength(in.remaining());
// Fall through to malformed-input case
} else {
return cr;
}
}
CodingErrorAction action = null;
if (cr.isMalformed())
action = malformedInputAction;
else if (cr.isUnmappable())
action = unmappableCharacterAction;
else
assert false : cr.toString();
if (action == CodingErrorAction.REPORT)
return cr;
if (action == CodingErrorAction.REPLACE) {
if (out.remaining() < replacement.$replLength$)
return CoderResult.OVERFLOW;
out.put(replacement);
}
if ((action == CodingErrorAction.IGNORE)
|| (action == CodingErrorAction.REPLACE)) {
// Skip erroneous input either way
in.position(in.position() + cr.length());
continue;
}
assert false;
}
}
/**
* Flushes this $coder$.
*
* <p> Some $coder$s maintain internal state and may need to write some
* final $otype$s to the output buffer once the overall input sequence has
* been read.
*
* <p> Any additional output is written to the output buffer beginning at
* its current position. At most {@link Buffer#remaining out.remaining()}
* $otype$s will be written. The buffer's position will be advanced
* appropriately, but its mark and limit will not be modified.
*
* <p> If this method completes successfully then it returns {@link
* CoderResult#UNDERFLOW}. If there is insufficient room in the output
* buffer then it returns {@link CoderResult#OVERFLOW}. If this happens
* then this method must be invoked again, with an output buffer that has
* more room, in order to complete the current <a href="#steps">$coding$
* operation</a>.
*
* <p> If this $coder$ has already been flushed then invoking this method
* has no effect.
*
* <p> This method invokes the {@link #implFlush implFlush} method to
* perform the actual flushing operation. </p>
*
* @param out
* The output $otype$ buffer
*
* @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
* {@link CoderResult#OVERFLOW}
*
* @throws IllegalStateException
* If the previous step of the current $coding$ operation was an
* invocation neither of the {@link #flush flush} method nor of
* the three-argument {@link
* #$code$($Itype$Buffer,$Otype$Buffer,boolean) $code$} method
* with a value of <tt>true</tt> for the <tt>endOfInput</tt>
* parameter
*/
public final CoderResult flush($Otype$Buffer out) {
if (state == ST_END) {
CoderResult cr = implFlush(out);
if (cr.isUnderflow())
state = ST_FLUSHED;
return cr;
}
if (state != ST_FLUSHED)
throwIllegalStateException(state, ST_FLUSHED);
return CoderResult.UNDERFLOW; // Already flushed
}
/**
* Flushes this $coder$.
*
* <p> The default implementation of this method does nothing, and always
* returns {@link CoderResult#UNDERFLOW}. This method should be overridden
* by $coder$s that may need to write final $otype$s to the output buffer
* once the entire input sequence has been read. </p>
*
* @param out
* The output $otype$ buffer
*
* @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
* {@link CoderResult#OVERFLOW}
*/
protected CoderResult implFlush($Otype$Buffer out) {
return CoderResult.UNDERFLOW;
}
/**
* Resets this $coder$, clearing any internal state.
*
* <p> This method resets charset-independent state and also invokes the
* {@link #implReset() implReset} method in order to perform any
* charset-specific reset actions. </p>
*
* @return This $coder$
*
*/
public final Charset$Coder$ reset() {
implReset();
state = ST_RESET;
return this;
}
/**
* Resets this $coder$, clearing any charset-specific internal state.
*
* <p> The default implementation of this method does nothing. This method
* should be overridden by $coder$s that maintain internal state. </p>
*/
protected void implReset() { }
/**
* $Code$s one or more $itype$s into one or more $otype$s.
*
* <p> This method encapsulates the basic $coding$ loop, $coding$ as many
* $itype$s as possible until it either runs out of input, runs out of room
* in the output buffer, or encounters $a$ $coding$ error. This method is
* invoked by the {@link #$code$ $code$} method, which handles result
* interpretation and error recovery.
*
* <p> The buffers are read from, and written to, starting at their current
* positions. At most {@link Buffer#remaining in.remaining()} $itype$s
* will be read, and at most {@link Buffer#remaining out.remaining()}
* $otype$s will be written. The buffers' positions will be advanced to
* reflect the $itype$s read and the $otype$s written, but their marks and
* limits will not be modified.
*
* <p> This method returns a {@link CoderResult} object to describe its
* reason for termination, in the same manner as the {@link #$code$ $code$}
* method. Most implementations of this method will handle $coding$ errors
* by returning an appropriate result object for interpretation by the
* {@link #$code$ $code$} method. An optimized implementation may instead
* examine the relevant error action and implement that action itself.
*
* <p> An implementation of this method may perform arbitrary lookahead by
* returning {@link CoderResult#UNDERFLOW} until it receives sufficient
* input. </p>
*
* @param in
* The input $itype$ buffer
*
* @param out
* The output $otype$ buffer
*
* @return A coder-result object describing the reason for termination
*/
protected abstract CoderResult $code$Loop($Itype$Buffer in,
$Otype$Buffer out);
/**
* Convenience method that $code$s the remaining content of a single input
* $itype$ buffer into a newly-allocated $otype$ buffer.
*
* <p> This method implements an entire <a href="#steps">$coding$
* operation</a>; that is, it resets this $coder$, then it $code$s the
* $itype$s in the given $itype$ buffer, and finally it flushes this
* $coder$. This method should therefore not be invoked if $a$ $coding$
* operation is already in progress. </p>
*
* @param in
* The input $itype$ buffer
*
* @return A newly-allocated $otype$ buffer containing the result of the
* $coding$ operation. The buffer's position will be zero and its
* limit will follow the last $otype$ written.
*
* @throws IllegalStateException
* If $a$ $coding$ operation is already in progress
*
* @throws MalformedInputException
* If the $itype$ sequence starting at the input buffer's current
* position is $notLegal$ and the current malformed-input action
* is {@link CodingErrorAction#REPORT}
*
* @throws UnmappableCharacterException
* If the $itype$ sequence starting at the input buffer's current
* position cannot be mapped to an equivalent $otype$ sequence and
* the current unmappable-character action is {@link
* CodingErrorAction#REPORT}
*/
public final $Otype$Buffer $code$($Itype$Buffer in)
throws CharacterCodingException
{
int n = (int)(in.remaining() * average$ItypesPerOtype$());
$Otype$Buffer out = $Otype$Buffer.allocate(n);
if ((n == 0) && (in.remaining() == 0))
return out;
reset();
for (;;) {
CoderResult cr = in.hasRemaining() ?
$code$(in, out, true) : CoderResult.UNDERFLOW;
if (cr.isUnderflow())
cr = flush(out);
if (cr.isUnderflow())
break;
if (cr.isOverflow()) {
n = 2*n + 1; // Ensure progress; n might be 0!
$Otype$Buffer o = $Otype$Buffer.allocate(n);
out.flip();
o.put(out);
out = o;
continue;
}
cr.throwException();
}
out.flip();
return out;
}
#if[decoder]
/**
* Tells whether or not this decoder implements an auto-detecting charset.
*
* <p> The default implementation of this method always returns
* <tt>false</tt>; it should be overridden by auto-detecting decoders to
* return <tt>true</tt>. </p>
*
* @return <tt>true</tt> if, and only if, this decoder implements an
* auto-detecting charset
*/
public boolean isAutoDetecting() {
return false;
}
/**
* Tells whether or not this decoder has yet detected a
* charset&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> If this decoder implements an auto-detecting charset then at a
* single point during a decoding operation this method may start returning
* <tt>true</tt> to indicate that a specific charset has been detected in
* the input byte sequence. Once this occurs, the {@link #detectedCharset
* detectedCharset} method may be invoked to retrieve the detected charset.
*
* <p> That this method returns <tt>false</tt> does not imply that no bytes
* have yet been decoded. Some auto-detecting decoders are capable of
* decoding some, or even all, of an input byte sequence without fixing on
* a particular charset.
*
* <p> The default implementation of this method always throws an {@link
* UnsupportedOperationException}; it should be overridden by
* auto-detecting decoders to return <tt>true</tt> once the input charset
* has been determined. </p>
*
* @return <tt>true</tt> if, and only if, this decoder has detected a
* specific charset
*
* @throws UnsupportedOperationException
* If this decoder does not implement an auto-detecting charset
*/
public boolean isCharsetDetected() {
throw new UnsupportedOperationException();
}
/**
* Retrieves the charset that was detected by this
* decoder&nbsp;&nbsp;<i>(optional operation)</i>.
*
* <p> If this decoder implements an auto-detecting charset then this
* method returns the actual charset once it has been detected. After that
* point, this method returns the same value for the duration of the
* current decoding operation. If not enough input bytes have yet been
* read to determine the actual charset then this method throws an {@link
* IllegalStateException}.
*
* <p> The default implementation of this method always throws an {@link
* UnsupportedOperationException}; it should be overridden by
* auto-detecting decoders to return the appropriate value. </p>
*
* @return The charset detected by this auto-detecting decoder,
* or <tt>null</tt> if the charset has not yet been determined
*
* @throws IllegalStateException
* If insufficient bytes have been read to determine a charset
*
* @throws UnsupportedOperationException
* If this decoder does not implement an auto-detecting charset
*/
public Charset detectedCharset() {
throw new UnsupportedOperationException();
}
#end[decoder]
#if[encoder]
private boolean canEncode(CharBuffer cb) {
if (state == ST_FLUSHED)
reset();
else if (state != ST_RESET)
throwIllegalStateException(state, ST_CODING);
CodingErrorAction ma = malformedInputAction();
CodingErrorAction ua = unmappableCharacterAction();
try {
onMalformedInput(CodingErrorAction.REPORT);
onUnmappableCharacter(CodingErrorAction.REPORT);
encode(cb);
} catch (CharacterCodingException x) {
return false;
} finally {
onMalformedInput(ma);
onUnmappableCharacter(ua);
reset();
}
return true;
}
/**
* Tells whether or not this encoder can encode the given character.
*
* <p> This method returns <tt>false</tt> if the given character is a
* surrogate character; such characters can be interpreted only when they
* are members of a pair consisting of a high surrogate followed by a low
* surrogate. The {@link #canEncode(java.lang.CharSequence)
* canEncode(CharSequence)} method may be used to test whether or not a
* character sequence can be encoded.
*
* <p> This method may modify this encoder's state; it should therefore not
* be invoked if an <a href="#steps">encoding operation</a> is already in
* progress.
*
* <p> The default implementation of this method is not very efficient; it
* should generally be overridden to improve performance. </p>
*
* @param c
* The given character
*
* @return <tt>true</tt> if, and only if, this encoder can encode
* the given character
*
* @throws IllegalStateException
* If $a$ $coding$ operation is already in progress
*/
public boolean canEncode(char c) {
CharBuffer cb = CharBuffer.allocate(1);
cb.put(c);
cb.flip();
return canEncode(cb);
}
/**
* Tells whether or not this encoder can encode the given character
* sequence.
*
* <p> If this method returns <tt>false</tt> for a particular character
* sequence then more information about why the sequence cannot be encoded
* may be obtained by performing a full <a href="#steps">encoding
* operation</a>.
*
* <p> This method may modify this encoder's state; it should therefore not
* be invoked if an encoding operation is already in progress.
*
* <p> The default implementation of this method is not very efficient; it
* should generally be overridden to improve performance. </p>
*
* @param cs
* The given character sequence
*
* @return <tt>true</tt> if, and only if, this encoder can encode
* the given character without throwing any exceptions and without
* performing any replacements
*
* @throws IllegalStateException
* If $a$ $coding$ operation is already in progress
*/
public boolean canEncode(CharSequence cs) {
CharBuffer cb;
if (cs instanceof CharBuffer)
cb = ((CharBuffer)cs).duplicate();
else
cb = CharBuffer.wrap(cs.toString());
return canEncode(cb);
}
#end[encoder]
private void throwIllegalStateException(int from, int to) {
throw new IllegalStateException("Current state = " + stateNames[from]
+ ", new state = " + stateNames[to]);
}
}
#
# Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code 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
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# Generated exception classes for java.nio.charset
SINCE=1.4
PACKAGE=java.nio.charset
# This year should only change if the generated source is modified.
COPYRIGHT_YEARS="2000, 2007,"
SUPER=java.io.IOException
gen CharacterCodingException "
* Checked exception thrown when a character encoding
* or decoding error occurs." \
8421532232154627783L
SUPER=IllegalArgumentException
gen IllegalCharsetNameException "
* Unchecked exception thrown when a string that is not a
* <a href="Charset.html#names">legal charset name</a> is used as such." \
1457525358470002989L \
String charsetName CharsetName "illegal charset name"
gen UnsupportedCharsetException "
* Unchecked exception thrown when no support is available
* for a requested charset." \
1490765524727386367L \
String charsetName CharsetName "name of the unsupported charset"
<!--
Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!doctype html public "-//IETF//DTD HTML//EN">
<html>
<body bgcolor="white">
Defines charsets, decoders, and encoders, for translating between bytes and
Unicode characters.
<blockquote><table cellspacing=1 cellpadding=0 summary="Summary of charsets, decoders, and encoders in this package">
<tr><th><p align="left">Class name</p></th><th><p align="left">Description</p></th></tr>
<tr><td valign=top><tt>{@link java.nio.charset.Charset}</tt></td>
<td>A named mapping between characters<br>and bytes</td></tr>
<tr><td valign=top><tt>{@link java.nio.charset.CharsetDecoder}</tt></td>
<td>Decodes bytes into characters</td></tr>
<tr><td valign=top><tt>{@link java.nio.charset.CharsetEncoder}&nbsp;&nbsp;</tt></td>
<td>Encodes characters into bytes</td></tr>
<tr><td valign=top><tt>{@link java.nio.charset.CoderResult}&nbsp;&nbsp;</tt></td>
<td>Describes coder results</td></tr>
<tr><td valign=top><tt>{@link java.nio.charset.CodingErrorAction}&nbsp;&nbsp;</tt></td>
<td>Describes actions to take when<br>coding errors are detected</td></tr>
</table></blockquote>
<p> A <i>charset</i> is named mapping between sequences of sixteen-bit Unicode
characters and sequences of bytes, in the sense defined in <a
href="http://www.ietf.org/rfc/rfc2278.txt"><i>RFC&nbsp;2278</i></a>. A
<i>decoder</i> is an engine which transforms bytes in a specific charset into
characters, and an <i>encoder</i> is an engine which transforms characters into
bytes. Encoders and decoders operate on byte and character buffers. They are
collectively referred to as <i>coders</i>.
<p> The {@link java.nio.charset.Charset} class defines methods for creating
coders for a given charset and for retrieving the various names associated with
a charset. It also defines static methods for testing whether a particular
charset is supported, for locating charset instances by name, and for
constructing a map that contains every charset for which support is available
in the current Java virtual machine.
<p> Most users will not use these classes directly; instead they will use the
existing charset-related constructors and methods in the {@link
java.lang.String} class, together with the existing {@link
java.io.InputStreamReader} and {@link java.io.OutputStreamWriter} classes, all
of whose implementations have been reworked to make use of the charset
facilities defined in this package. A small number of changes have been made
to the {@link java.io.InputStreamReader} and {@link java.io.OutputStreamWriter}
classes in order to allow explicit charset objects to be specified in the
construction of instances of those classes.
<p> Support for new charsets can be made available via the interface defined in
the {@link java.nio.charset.spi.CharsetProvider} class in the <tt>{@link
java.nio.charset.spi}</tt> package.
<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
or method in any class or interface in this package will cause a {@link
java.lang.NullPointerException NullPointerException} to be thrown.
@since 1.4
@author Mark Reinhold
@author JSR-51 Expert Group
</body>
</html>
<!--
Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!doctype html public "-//IETF//DTD HTML//EN">
<html>
<body bgcolor="white">
Service-provider classes for the <tt>{@link java.nio.charset}</tt> package.
<p> Only developers who are defining new charsets should need to make direct
use of this package. </p>
<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
or method in any class or interface in this package will cause a {@link
java.lang.NullPointerException NullPointerException} to be thrown.
@since 1.4
@author Mark Reinhold
@author JSR-51 Expert Group
</body>
</html>
#
# Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code 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
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# Generated exception classes for java.nio
SINCE=1.4
PACKAGE=java.nio
# This year should only change if the generated source is modified.
COPYRIGHT_YEARS="2000, 2007,"
SUPER=RuntimeException
gen BufferOverflowException "
* Unchecked exception thrown when a relative <i>put</i> operation reaches
* the target buffer's limit." \
-5484897634319144535L
gen BufferUnderflowException "
* Unchecked exception thrown when a relative <i>get</i> operation reaches
* the source buffer's limit." \
-1713313658691622206L
SUPER=IllegalStateException
gen InvalidMarkException "
* Unchecked exception thrown when an attempt is made to reset a buffer
* when its mark is not defined." \
1698329710438510774L
SUPER=UnsupportedOperationException
gen ReadOnlyBufferException "
* Unchecked exception thrown when a content-mutation method such as
* <tt>put</tt> or <tt>compact</tt> is invoked upon a read-only buffer." \
-1210063976496234090L
<!--
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!doctype html public "-//IETF//DTD HTML//EN">
<html>
<body bgcolor="white">
Defines buffers, which are containers for data, and provides an overview of the
other NIO packages.
<p> The central abstractions of the NIO APIs are: </p>
<ul>
<li><p> <a href="#buffers"><i>Buffers</i></a>, which are containers for data;
</p></li>
<li><p> <a href="charset/package-summary.html"><i>Charsets</i></a> and their
associated <i>decoders</i> and <i>encoders</i>, <br> which translate between
bytes and Unicode characters; </p></li>
<li><p> <a href="channels/package-summary.html"><i>Channels</i></a> of
various types, which represent connections <br> to entities capable of
performing I/O operations; and </p></li>
<li><p> <i>Selectors</i> and <i>selection keys</i>, which together with <br>
<i>selectable channels</i> define a <a
href="channels/package-summary.html#multiplex">multiplexed, non-blocking <br>
I/O</a>&nbsp;facility. </p></li>
</ul>
<p> The <tt>java.nio</tt> package defines the buffer classes, which are used
throughout the NIO APIs. The charset API is defined in the {@link
java.nio.charset} package, and the channel and selector APIs are defined in the
{@link java.nio.channels} package. Each of these subpackages has its own
service-provider (SPI) subpackage, the contents of which can be used to extend
the platform's default implementations or to construct alternative
implementations.
<a name="buffers"> </a>
<blockquote><table cellspacing=1 cellpadding=0 summary="Description of the various buffers">
<tr><th><p align="left">Buffers</p></th><th><p align="left">Description</p></th></tr>
<tr><td valign=top><tt>{@link java.nio.Buffer}</tt></td>
<td>Position, limit, and capacity;
<br>clear, flip, rewind, and mark/reset</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.ByteBuffer}</tt></td>
<td>Get/put, compact, views; allocate,&nbsp;wrap</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;&nbsp;&nbsp;{@link java.nio.MappedByteBuffer}&nbsp;&nbsp;</tt></td>
<td>A byte buffer mapped to a file</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.CharBuffer}</tt></td>
<td>Get/put, compact; allocate,&nbsp;wrap</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.DoubleBuffer}</tt></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.FloatBuffer}</tt></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.IntBuffer}</tt></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.LongBuffer}</tt></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
<tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.ShortBuffer}</tt></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
<tr><td valign=top><tt>{@link java.nio.ByteOrder}</tt></td>
<td>Typesafe enumeration for&nbsp;byte&nbsp;orders</td></tr>
</table></blockquote>
<p> A <i>buffer</i> is a container for a fixed amount of data of a specific
primitive type. In addition to its content a buffer has a <i>position</i>,
which is the index of the next element to be read or written, and a
<i>limit</i>, which is the index of the first element that should not be read
or written. The base {@link java.nio.Buffer} class defines these properties as
well as methods for <i>clearing</i>, <i>flipping</i>, and <i>rewinding</i>, for
<i>marking</i> the current position, and for <i>resetting</i> the position to
the previous mark.
<p> There is a buffer class for each non-boolean primitive type. Each class
defines a family of <i>get</i> and <i>put</i> methods for moving data out of
and in to a buffer, methods for <i>compacting</i>, <i>duplicating</i>, and
<i>slicing</i> a buffer, and static methods for <i>allocating</i> a new buffer
as well as for <i>wrapping</i> an existing array into a buffer.
<p> Byte buffers are distinguished in that they can be used as the sources and
targets of I/O operations. They also support several features not found in the
other buffer classes:
<ul>
<li><p> A byte buffer can be allocated as a <a href="ByteBuffer.html#direct">
<i>direct</i></a> buffer, in which case the Java virtual machine will make a
best effort to perform native I/O operations directly upon it. </p></li>
<li><p> A byte buffer can be created by {@link
java.nio.channels.FileChannel#map <i>mapping</i>} a region of a
file directly into memory, in which case a few additional file-related
operations defined in the {@link java.nio.MappedByteBuffer} class are
available. </p></li>
<li><p> A byte buffer provides access to its content as either a heterogeneous
or homogeneous sequence of <a href="ByteBuffer.html#bin">binary data</i></a>
of any non-boolean primitive type, in either big-endian or little-endian <a
href="ByteOrder.html">byte order</a>. </p></li>
</ul>
<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
or method in any class or interface in this package will cause a {@link
java.lang.NullPointerException NullPointerException} to be thrown.
@since 1.4
@author Mark Reinhold
@author JSR-51 Expert Group
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides support for RMI Object Activation. A remote
object's reference can be made ``persistent'' and later activated into a
``live'' object using the RMI activation mechanism.
<p>Implementations are not required to support the activation
mechanism. If activation is not supported by this implementation,
several specific activation API methods are all required to throw
{@code UnsupportedOperationException}. If activation is supported by this
implementation, these methods must never throw {@code
UnsupportedOperationException}. These methods are denoted by the
presence of an entry for {@code UnsupportedOperationException} in the
<strong>Throws</strong> section of each method's specification.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!--
Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides classes and interface for RMI distributed
garbage-collection (DGC). When the RMI server returns an object to
its client (caller of the remote method), it tracks the remote
object's usage in the client. When there are no more references to the
remote object on the client, or if the reference's ``lease'' expires and
not renewed, the server garbage-collects the remote object.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
<!--
Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides the RMI package. RMI is Remote Method Invocation. It is a
mechanism that enables an object on one Java virtual machine to invoke
methods on an object in another Java virtual machine. Any object that
can be invoked this way must implement the Remote interface. When such
an object is invoked, its arguments are ``marshalled'' and sent from the
local virtual machine to the remote one, where the arguments are
``unmarshalled.'' When the method terminates, the results are
marshalled from the remote machine and sent to the caller's virtual
machine. If the method invocation results in an exception being
thrown, the exception is indicated to caller.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
<!--
Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
</head>
<body bgcolor="white">
Provides a class and two interfaces for the RMI registry.
A registry is a remote object that maps names to remote objects. A
server registers its remote objects with the registry so that they can
be looked up. When an object wants to invoke a method on a remote
object, it must first lookup the remote object using its name. The
registry returns to the calling object a reference to the remote
object, using which a remote method can be invoked.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
Provides classes and interfaces for supporting the server
side of RMI. A group of classes are used by the stubs and skeletons
generated by the rmic stub compiler. Another group of classes
implements the RMI Transport protocol and HTTP tunneling.
<p><strong>Deprecated: HTTP Tunneling.</strong> <em>The HTTP tunneling
mechanism has been deprecated. See {@link java.rmi.server.RMISocketFactory} for
further information.</em>
<p><strong>Deprecated: Skeletons and Static Stubs.</strong>
<em>Skeletons and statically generated stubs are deprecated. This
includes the APIs in this package that require the use of skeletons
or static stubs, the runtime support for them, and the use of the
{@code rmic} stub compiler to generate them. Support for skeletons
and static stubs may be removed in a future release of the
platform. Skeletons are unnecessary, as server-side method dispatching
is handled directly by the RMI runtime. Statically generated stubs are
unnecessary, as stubs are generated dynamically using {@link
java.lang.reflect.Proxy Proxy} objects. See {@link
java.rmi.server.UnicastRemoteObject UnicastRemoteObject} for
information about dynamic stub generation. Generation of skeletons and
static stubs was typically performed as part of an application's build
process by calling the {@code rmic} tool. This is unnecessary, and
calls to {@code rmic} can simply be omitted.</em>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Provides the API for accessing and processing data stored in a
data source (usually a relational database) using the
Java<sup><font size=-2>TM</font></sup> programming language.
This API includes a framework whereby different
drivers can be installed dynamically to access different data sources.
Although the JDBC<sup><font size=-2>TM</font></sup> API is mainly geared
to passing SQL statements to a database, it provides for reading and
writing data from any data source with a tabular format.
The reader/writer facility, available through the
<code>javax.sql.RowSet</code> group of interfaces, can be customized to
use and update data from a spread sheet, flat file, or any other tabular
data source.
<P>
<h2>What the JDBC<sup><font size=-2>TM</font></sup> 4.2 API Includes</h2>
The JDBC<sup><font size=-2>TM</font></sup> 4.2 API includes both
the <code>java.sql</code> package, referred to as the JDBC core API,
and the <code>javax.sql</code> package, referred to as the JDBC Optional
Package API. This complete JDBC API
is included in the Java<sup><font size=-2>TM</font></sup>
Standard Edition (Java SE<sup><font size=-2>TM</font></sup>), version 7.
The <code>javax.sql</code> package extends the functionality of the JDBC API
from a client-side API to a server-side API, and it is an essential part
of the Java<sup><font size=-2>TM</font></sup> Enterprise Edition
(Java EE<sup><font size=-2>TM</font></sup>) technology.
<P>
<h2>Versions</h2>
The JDBC 4.2 API incorporates all of the previous JDBC API versions:
<UL>
<LI> The JDBC 4.1 API</li>
<LI> The JDBC 4.0 API</li>
<LI> The JDBC 3.0 API</li>
<LI> The JDBC 2.1 core API</li>
<LI> The JDBC 2.0 Optional Package API<br>
(Note that the JDBC 2.1 core API and the JDBC 2.0 Optional Package
API together are referred to as the JDBC 2.0 API.)</li>
<LI> The JDBC 1.2 API</li>
<LI> The JDBC 1.0 API</li>
</UL>
<P>
Classes, interfaces, methods, fields, constructors, and exceptions
have the following "since" tags that indicate when they were introduced
into the Java platform. When these "since" tags are used in
Javadoc<sup><font size=-2>TM</font></sup> comments for the JDBC API,
they indicate the following:
<UL>
<LI>Since 1.8 -- new in the JDBC 4.2 API and part of the Java SE platform,
version 8</li>
<LI>Since 1.7 -- new in the JDBC 4.1 API and part of the Java SE platform,
version 7</li>
<LI>Since 1.6 -- new in the JDBC 4.0 API and part of the Java SE platform,
version 6</li>
<LI>Since 1.4 -- new in the JDBC 3.0 API and part of the J2SE platform,
version 1.4</li>
<LI>Since 1.2 -- new in the JDBC 2.0 API and part of the J2SE platform,
version 1.2</li>
<LI>Since 1.1 or no "since" tag -- in the original JDBC 1.0 API and part of
the JDK<sup><font size=-2>TM</font></sup>, version 1.1</li>
</UL>
<P>
<b>NOTE:</b> Many of the new features are optional; consequently, there is
some variation in drivers and the features they support. Always
check your driver's documentation to see whether it supports a feature before
you try to use it.
<P>
<b>NOTE:</b> The class <code>SQLPermission</code> was added in the
Java<sup><font size=-2>TM</font></sup> 2 SDK, Standard Edition,
version 1.3 release. This class is used to prevent unauthorized
access to the logging stream associated with the <code>DriverManager</code>,
which may contain information such as table names, column data, and so on.
<p>
<h2>What the <code>java.sql</code> Package Contains</h2>
The <code>java.sql</code> package contains API for the following:
<UL>
<LI>Making a connection with a database via the <code>DriverManager</code> facility
<UL>
<LI><code>DriverManager</code> class -- makes a connection with a driver
<LI><code>SQLPermission</code> class -- provides permission when code
running within a Security Manager, such as an applet,
attempts to set up a logging stream through the
<code>DriverManager</code>
<LI><code>Driver</code> interface -- provides the API for registering
and connecting drivers based on JDBC technology ("JDBC drivers");
generally used only by the <code>DriverManager</code> class
<LI><code>DriverPropertyInfo</code> class -- provides properties for a
JDBC driver; not used by the general user
</UL>
<LI>Sending SQL statements to a database
<UL>
<LI><code>Statement</code> -- used to send basic SQL statements
<LI><code>PreparedStatement</code> -- used to send prepared statements or
basic SQL statements (derived from <code>Statement</code>)
<LI><code>CallableStatement</code> -- used to call database stored
procedures (derived from <code>PreparedStatement</code>)
<LI><code>Connection</code> interface -- provides methods for creating
statements and managing connections and their properties
<LI><code>Savepoint</code> -- provides savepoints in a transaction
</UL>
<LI>Retrieving and updating the results of a query
<UL>
<LI><code>ResultSet</code> interface
</UL>
<LI>Standard mappings for SQL types to classes and interfaces in the
Java programming language
<UL>
<LI><code>Array</code> interface -- mapping for SQL <code>ARRAY</code>
<LI><code>Blob</code> interface -- mapping for SQL <code>BLOB</code>
<LI><code>Clob</code> interface -- mapping for SQL <code>CLOB</code>
<LI><code>Date</code> class -- mapping for SQL <code>DATE</code>
<LI><code>NClob</code> interface -- mapping for SQL <code>NCLOB</code>
<LI><code>Ref</code> interface -- mapping for SQL <code>REF</code>
<LI><code>RowId</code> interface -- mapping for SQL <code>ROWID</code>
<LI><code>Struct</code> interface -- mapping for SQL <code>STRUCT</code>
<LI><code>SQLXML</code> interface -- mapping for SQL <code>XML</code>
<LI><code>Time</code> class -- mapping for SQL <code>TIME</code>
<LI><code>Timestamp</code> class -- mapping for SQL <code>TIMESTAMP</code>
<LI><code>Types</code> class -- provides constants for SQL types
</UL>
<LI>Custom mapping an SQL user-defined type (UDT) to a class in the
Java programming language
<UL>
<LI><code>SQLData</code> interface -- specifies the mapping of
a UDT to an instance of this class
<LI><code>SQLInput</code> interface -- provides methods for reading
UDT attributes from a stream
<LI><code>SQLOutput</code> interface -- provides methods for writing
UDT attributes back to a stream
</UL>
<LI>Metadata
<UL>
<LI><code>DatabaseMetaData</code> interface -- provides information
about the database
<LI><code>ResultSetMetaData</code> interface -- provides information
about the columns of a <code>ResultSet</code> object
<LI><code>ParameterMetaData</code> interface -- provides information
about the parameters to <code>PreparedStatement</code> commands
</UL>
<LI>Exceptions
<UL>
<LI><code>SQLException</code> -- thrown by most methods when there
is a problem accessing data and by some methods for other reasons
<LI><code>SQLWarning</code> -- thrown to indicate a warning
<LI><code>DataTruncation</code> -- thrown to indicate that data may have
been truncated
<LI><code>BatchUpdateException</code> -- thrown to indicate that not all
commands in a batch update executed successfully
</UL>
</UL>
<P>
<h3><code>java.sql</code> and <code>javax.sql</code> Features Introduced in the JDBC 4.2 API</h3>
<UL>
<LI>Added <code>JDBCType</code> enum and <code>SQLType</code> interface</li>
<LI>Support for <code>REF CURSORS</code> in <code>CallableStatement</code>
</LI>
<LI><code>DatabaseMetaData</code> methods to return maximum Logical LOB size
and if Ref Cursors are supported</LI>
<LI>Added support for large update counts</LI>
</UL>
<P>
<h3><code>java.sql</code> and <code>javax.sql</code> Features Introduced in the JDBC 4.1 API</h3>
<UL>
<LI>Allow <code>Connection</code>,
<code>ResultSet</code> and <code>Statement</code> objects to be
used with the try-with-resources statement</LI>
<LI>Supported added to <code>CallableStatement</code> and
<code>ResultSet</code> to specify the Java type to convert to via the
<code>getObject</code> method</LI>
<LI><code>DatabaseMetaData</code> methods to return PseudoColumns and if a
generated key is always returned</LI>
<LI>Added support to <code>Connection</code> to specify a database schema,
abort and timeout a physical connection.</LI>
<LI>Added support to close a <code>Statement</code> object when its dependent
objects have been closed</LI>
<LI>Support for obtaining the parent logger for a <code>Driver</code>,
<code>DataSource</code>, <code>ConnectionPoolDataSource</code> and
<code>XADataSource</code></LI>
</UL>
<h3><code>java.sql</code> and <code>javax.sql</code> Features Introduced in the JDBC 4.0 API</h3>
<UL>
<LI>auto java.sql.Driver discovery -- no longer need to load a
<code>java.sql.Driver</code> class via <code>Class.forName</code>
<LI>National Character Set support added
<li>Support added for the SQL:2003 XML data type
<lI>SQLException enhancements -- Added support for cause chaining; New SQLExceptions
added for common SQLState class value codes
<li>Enhanced Blob/Clob functionality -- Support provided to create and free a Blob/Clob instance
as well as additional methods added to improve accessibility
<li>Support added for accessing a SQL ROWID
<li>Support added to allow a JDBC application to access an instance of a JDBC resource
that has been wrapped by a vendor, usually in an application server or connection
pooling environment.
<li>Availability to be notified when a <code>PreparedStatement</code> that is associated
with a <code>PooledConnection</code> has been closed or the driver determines is invalid
</UL>
<P>
<P>
<h3><code>java.sql</code> and <code>javax.sql</code> Features Introduced in the JDBC 3.0 API</h3>
<UL>
<LI>Pooled statements -- reuse of statements associated with a pooled
connection
<LI>Savepoints -- allow a transaction to be rolled back to a designated
savepoint
<LI>Properties defined for <code>ConnectionPoolDataSource</code> -- specify
how connections are to be pooled
<LI>Metadata for parameters of a <code>PreparedStatement</code> object
<LI>Ability to retrieve values from automatically generated columns
<LI>Ability to have multiple <code>ResultSet</code> objects
returned from <code>CallableStatement</code> objects open at the
same time
<LI>Ability to identify parameters to <code>CallableStatement</code>
objects by name as well as by index
<LI><code>ResultSet</code> holdability -- ability to specify whether cursors
should be held open or closed at the end of a transaction
<LI>Ability to retrieve and update the SQL structured type instance that a
<code>Ref</code> object references
<LI>Ability to programmatically update <code>BLOB</code>,
<code>CLOB</code>, <code>ARRAY</code>, and <code>REF</code> values.
<LI>Addition of the <code>java.sql.Types.DATALINK</code> data type --
allows JDBC drivers access to objects stored outside a data source
<LI>Addition of metadata for retrieving SQL type hierarchies
</UL>
<P>
<h3><code>java.sql</code> Features Introduced in the JDBC 2.1 Core API</h3>
<UL>
<LI>Scrollable result sets--using new methods in the <code>ResultSet</code>
interface that allow the cursor to be moved to a particular row or to a
position relative to its current position
<LI>Batch updates
<LI>Programmatic updates--using <code>ResultSet</code> updater methods
<LI>New data types--interfaces mapping the SQL3 data types
<LI>Custom mapping of user-defined types (UDTs)
<LI>Miscellaneous features, including performance hints, the use of character
streams, full precision for <code>java.math.BigDecimal</code> values,
additional security, and
support for time zones in date, time, and timestamp values.
</UL>
<P>
<h3><code>javax.sql</code> Features Introduced in the JDBC 2.0 Optional
Package API</h3>
<UL>
<LI>The <code>DataSource</code> interface as a means of making a connection. The
Java Naming and Directory Interface<sup><font size=-2>TM</font></sup>
(JNDI) is used for registering a <code>DataSource</code> object with a
naming service and also for retrieving it.
<LI>Pooled connections -- allowing connections to be used and reused
<LI>Distributed transactions -- allowing a transaction to span diverse
DBMS servers
<LI><code>RowSet</code> technology -- providing a convenient means of
handling and passing data
</UL>
<P>
<P>
<h3>Custom Mapping of UDTs</h3>
A user-defined type (UDT) defined in SQL can be mapped to a class in the Java
programming language. An SQL structured type or an SQL <code>DISTINCT</code>
type are the UDTs that may be custom mapped. The following three
steps set up a custom mapping:
<ol>
<li>Defining the SQL structured type or <code>DISTINCT</code> type in SQL
<li>Defining the class in the Java programming language to which the
SQL UDT will be mapped. This class must implement the
<code>SQLData</code> interface.
<li>Making an entry in a <code>Connection</code> object's type map
that contains two things:
<ul>
<li>the fully-qualified SQL name of the UDT
<li>the <code>Class</code> object for the class that implements the
<code>SQLData</code> interface
</ul>
</ol>
<p>
When these are in place for a UDT, calling the methods
<code>ResultSet.getObject</code> or <code>CallableStatement.getObject</code>
on that UDT will automatically retrieve the custom mapping for it. Also, the
<code>PreparedStatement.setObject</code> method will automatically map the
object back to its SQL type to store it in the data source.
<h2>Package Specification</h2>
<ul>
<li><a href="http://java.sun.com/products/jdbc/download.html">Specification
of the JDBC 4.0 API</a>
</ul>
<h2>Related Documentation</h2>
<ul>
<li><a href="../../../technotes/guides/jdbc/getstart/GettingStartedTOC.fm.html">Getting Started</a>--overviews of the major interfaces
<P>
<li><a href="http://java.sun.com/docs/books/tutorial/jdbc">Chapters on the JDBC
API</a>--from the online version of <i>The Java Tutorial Continued</i>
<P>
<li><a href="http://java.sun.com/docs/books/jdbc">
<i>JDBC<sup><font size=-2>TM</font></sup>API Tutorial and Reference,
Third Edition</i></a>--
a complete reference and tutorial for the JDBC 3.0 API
</ul>
<P>
@since 1.1
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Provides classes and interfaces for handling text, dates, numbers, and messages
in a manner independent of natural languages. This means your main application
or applet can be written to be language-independent, and it can rely upon
separate, dynamically-linked localized resources. This allows the flexibility
of adding localizations for new localizations at any time.
<p>
These classes are capable of formatting dates, numbers, and messages, parsing;
searching and sorting strings; and iterating over characters, words, sentences,
and line breaks. This package contains three main groups of classes and
interfaces:
<ul>
<li>Classes for iteration over text
<li>Classes for formatting and parsing
<li>Classes for string collation
</ul>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Service provider classes for the classes in the java.text package.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.6
</body>
</html>
<!--
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of JSR-310 nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-->
<body>
<p>
A new Date and Time API for Java.
The design includes a relatively large number of classes and methods,
however each follows a common design language, especially in method prefixes.
Once the prefixes are understood, the API is relatively simple to comprehend.
</p>
<p>
The Java Time API is composed of several packages, each with a primary function:
</p>
<p>
{@link java.time} contains the main API based on the ISO-8601 standard.
The classes defined here represent the principal date-time concepts,
including instants, durations, dates, times, time-zones and periods.
They are based on the ISO calendar system, which is the <i>de facto</i> world
calendar following the proleptic Gregorian rules.
All the classes are immutable and thread-safe.
</p>
<p>
{@link java.time.temporal} contains the API for accessing the fields and units
of date-time. Units are measurable, such as years, months and hours.
For example, the expression "2 hours later" uses the hours unit.
By contrast, fields are mini-calculations, defining a value.
For example, month-of-year, day-of-week and hour-of-day are all fields.
The set of supported units and fields can be extended by applications if desired.
</p>
<p>
{@link java.time.format} contains the API to print and parse fields into date-time
objects and to customize parsing and printing.
Formatters can be created in a variety of ways, including constants, patterns,
localized styles and a builder.
Formatters are immutable and thread-safe.
</p>
<p>
{@link java.time.zone} contains the API to handle time-zones.
Detailed information is made available about the rules of each time-zone.
</p>
<p>
{@link java.time.chrono} contains the basic part of the calendar neutral API
and alternate calendar systems.
This is intended for use by applications that need to use localized calendars.
Support is provided for the Hijrah, Japanese, Minguo, and Thai Buddhist Calendars.
</p>
<h3>Design notes</h3>
<p>
Where possible, the API avoids the use of null.
All methods define whether they accept or return null in the Javadoc.
As a general rule, methods do not accept or return null.
A key exception is any method that takes an object and returns a boolean, for the purpose
of checking or validating, will generally return false for null.
</p>
<p>
The API is designed to be type-safe where reasonable in the main high-level API.
Thus, there are separate classes for the distinct concepts of date, time and date-time, plus variants
for offset and time-zones. The core 7 date-time classes, plus Instant, handle the needs of most applications.
Further classes handle other combinations - year, year-month and month-day in a type-safe manner.
</p>
<p>
In a language like Java, the use of many different types tends to cause API bloat.
This is handled here through the use of common method naming patterns throughout the API.
The common prefixes are 'of', 'get', 'is', 'with', 'plus', 'minus', 'to' and 'at'.
See {@link java.time.LocalDate} for an example of each of these methods.
</p>
<p>
Following type-safety to its logical conclusion would result in more classes, especially for time -
hour-minute, hour-minute-second and hour-minute-second-nanosecond.
While logically pure, this was not possible in practice, as the additional classes would have
excessively complicated the API. Notably, there would be additional combinations at the offset
and date-time levels, such as offset-date-hour-minute.
To avoid this explosion of types, {@link java.time.LocalTime} is used for all precisions of time.
By contrast, some additional classes were used for dates, such as {@link java.time.YearMonth}.
This proved necessary, as the API for year-month is significantly different to that for a date, whereas
an absence of nanoseconds in a time can be approximated by returning zero.
</p>
<p>
Similarly, full type-safety might argue for a separate class for each field in date-time,
such as a class for HourOfDay and another for DayOfMonth.
This approach was tried, but was excessively complicated in the Java language, lacking usability.
A similar problem occurs with periods.
There is a case for a separate class for each period unit, such as a type for Years and a type for Minutes.
However, this yields a lot of classes and a problem of type conversion.
As such, general access to fields and units is not wrapped in a class.
</p>
<p>
Multiple calendar systems is an awkward addition to the design challenges.
The first principal is that most users want the standard ISO calendar system.
As such, the main classes are ISO-only. The second principal is that most of those that want a
non-ISO calendar system want it for user interaction, thus it is a UI localization issue.
As such, date and time objects should be held as ISO objects in the data model and persistent
storage, only being converted to and from a local calendar for display.
The calendar system would be stored separately in the user preferences.
</p>
<p>
There are, however, some limited use cases where users believe they need to store and use
dates in arbitrary calendar systems throughout the application.
This is supported by {@link java.time.chrono.ChronoLocalDate}, however it is vital to read
all the associated warnings in the Javadoc of that interface before using it.
In summary, applications that require general interoperation between multiple calendar systems
typically need to be written in a very different way to those only using the ISO calendar,
thus most applications should just use ISO and avoid {@code ChronoLocalDate}.
</p>
<p>
Throughout all of this, a key goal was to allow date-time fields and units to be defined by applications.
This has been achieved having tried many different designs.
</p>
</body>
#
# Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code 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
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# Version of the currency data format.
# 1: initial
# 2: Change in minor unit (allowing 4-9 digits)
formatVersion=2
# Version of the currency code information in this class.
# It is a serial number that accompanies with each amendment.
dataVersion=159
# List of all valid ISO 4217 currency codes.
# To ensure compatibility, do not remove codes.
all=ADP020-AED784-AFA004-AFN971-ALL008-AMD051-ANG532-AOA973-ARS032-ATS040-AUD036-\
AWG533-AYM945-AZM031-AZN944-BAM977-BBD052-BDT050-BEF056-BGL100-BGN975-BHD048-BIF108-\
BMD060-BND096-BOB068-BOV984-BRL986-BSD044-BTN064-BWP072-BYB112-BYR974-\
BZD084-CAD124-CDF976-CHE947-CHF756-CHW948-CLF990-CLP152-CNY156-COP170-COU970-CRC188-CSD891-CUP192-CUC931-\
CVE132-CYP196-CZK203-DEM276-DJF262-DKK208-DOP214-DZD012-EEK233-EGP818-\
ERN232-ESP724-ETB230-EUR978-FIM246-FJD242-FKP238-FRF250-GBP826-GEL981-\
GHC288-GHS936-GIP292-GMD270-GNF324-GRD300-GTQ320-GWP624-GYD328-HKD344-HNL340-\
HRK191-HTG332-HUF348-IDR360-IEP372-ILS376-INR356-IQD368-IRR364-ISK352-\
ITL380-JMD388-JOD400-JPY392-KES404-KGS417-KHR116-KMF174-KPW408-KRW410-\
KWD414-KYD136-KZT398-LAK418-LBP422-LKR144-LRD430-LSL426-LTL440-LUF442-\
LVL428-LYD434-MAD504-MDL498-MGA969-MGF450-MKD807-MMK104-MNT496-MOP446-MRO478-\
MTL470-MUR480-MVR462-MWK454-MXN484-MXV979-MYR458-MZM508-MZN943-NAD516-NGN566-\
NIO558-NLG528-NOK578-NPR524-NZD554-OMR512-PAB590-PEN604-PGK598-PHP608-\
PKR586-PLN985-PTE620-PYG600-QAR634-ROL946-RON946-RSD941-RUB643-RUR810-RWF646-SAR682-\
SBD090-SCR690-SDD736-SDG938-SEK752-SGD702-SHP654-SIT705-SKK703-SLL694-SOS706-\
SRD968-SRG740-SSP728-STD678-SVC222-SYP760-SZL748-THB764-TJS972-TMM795-TMT934-TND788-TOP776-\
TPE626-TRL792-TRY949-TTD780-TWD901-TZS834-UAH980-UGX800-USD840-USN997-USS998-UYI940-\
UYU858-UZS860-VEB862-VEF937-VND704-VUV548-WST882-XAF950-XAG961-XAU959-XBA955-\
XBB956-XBC957-XBD958-XCD951-XDR960-XFO000-XFU000-XOF952-XPD964-XPF953-\
XPT962-XSU994-XTS963-XUA965-XXX999-YER886-YUM891-ZAR710-ZMK894-ZMW967-ZWD716-ZWL932-\
ZWN942-ZWR935
# Mappings from ISO 3166 country codes to ISO 4217 currency codes.
#
# Three forms are used:
# Form 1: <country code>=<currency code>
# Form 2: <country code>=<currency code 1>;<time stamp>;<currency code 2>
# Form 3: <country code>=
# Form 1 is used if no future change in currency is known.
# Form 2 indicates that before the specified time currency 1 is used, from
# the specified time currency 2. The time is given in SimpleDateFormat's
# yyyy-MM-dd-HH-mm-ss format in the GMT time zone.
# Form 3 indicates the country doesn't have a currency (the entry is still
# needed to verify that the country code is valid).
#
# The table is based on the following web sites:
# http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/db_en.html
# http://www.currency-iso.org/iso_index/iso_tables.htm
# http://www.cia.gov/cia/publications/factbook/indexgeo.html
# AFGHANISTAN
AF=AFN
# \u00c5LAND ISLANDS
AX=EUR
# ALBANIA
AL=ALL
# ALGERIA
DZ=DZD
# AMERICAN SAMOA
AS=USD
# ANDORRA
AD=EUR
# ANGOLA
AO=AOA
# ANGUILLA
AI=XCD
# ANTARCTICA
AQ=
# ANTIGUA AND BARBUDA
AG=XCD
# ARGENTINA
AR=ARS
# ARMENIA
AM=AMD
# ARUBA
AW=AWG
# AUSTRALIA
AU=AUD
# AUSTRIA
AT=EUR
# AZERBAIJAN
AZ=AZN
# BAHAMAS
BS=BSD
# BAHRAIN
BH=BHD
# BANGLADESH
BD=BDT
# BARBADOS
BB=BBD
# BELARUS
BY=BYR
# BELGIUM
BE=EUR
# BELIZE
BZ=BZD
# BENIN
BJ=XOF
# BERMUDA
BM=BMD
# Bonaire, Sint Eustatius and Saba
BQ=USD
# BHUTAN
BT=BTN
# BOLIVIA
BO=BOB
# BOSNIA AND HERZEGOVINA
BA=BAM
# BOTSWANA
BW=BWP
# BOUVET ISLAND
BV=NOK
# BRAZIL
BR=BRL
# BRITISH INDIAN OCEAN TERRITORY
IO=USD
# BRUNEI DARUSSALAM
BN=BND
# BULGARIA
BG=BGN
# BURKINA FASO
BF=XOF
# BURUNDI
BI=BIF
# CAMBODIA
KH=KHR
# CAMEROON
CM=XAF
# CANADA
CA=CAD
# CAPE VERDE
CV=CVE
# CAYMAN ISLANDS
KY=KYD
# CENTRAL AFRICAN REPUBLIC
CF=XAF
# CHAD
TD=XAF
# CHILE
CL=CLP
# CHINA
CN=CNY
# CHRISTMAS ISLAND
CX=AUD
# COCOS (KEELING) ISLANDS
CC=AUD
# COLOMBIA
CO=COP
# COMOROS
KM=KMF
# CONGO
CG=XAF
# CONGO, THE DEMOCRATIC REPUBLIC OF THE
CD=CDF
# COOK ISLANDS
CK=NZD
# COSTA RICA
CR=CRC
# COTE D'IVOIRE
CI=XOF
# CROATIA
HR=HRK
# CUBA
CU=CUP
# Cura\u00e7ao
CW=ANG
# CYPRUS
CY=EUR
# CZECH REPUBLIC
CZ=CZK
# DENMARK
DK=DKK
# DJIBOUTI
DJ=DJF
# DOMINICA
DM=XCD
# DOMINICAN REPUBLIC
DO=DOP
# ECUADOR
EC=USD
# EGYPT
EG=EGP
# EL SALVADOR
# USD is also legal currency as of 2001/01/01
SV=SVC
# EQUATORIAL GUINEA
GQ=XAF
# ERITREA
ER=ERN
# ESTONIA
EE=EUR
# ETHIOPIA
ET=ETB
# FALKLAND ISLANDS (MALVINAS)
FK=FKP
# FAROE ISLANDS
FO=DKK
# FIJI
FJ=FJD
# FINLAND
FI=EUR
# FRANCE
FR=EUR
# FRENCH GUIANA
GF=EUR
# FRENCH POLYNESIA
PF=XPF
# FRENCH SOUTHERN TERRITORIES
TF=EUR
# GABON
GA=XAF
# GAMBIA
GM=GMD
# GEORGIA
GE=GEL
# GERMANY
DE=EUR
# GHANA
GH=GHS
# GIBRALTAR
GI=GIP
# GREECE
GR=EUR
# GREENLAND
GL=DKK
# GRENADA
GD=XCD
# GUADELOUPE
GP=EUR
# GUAM
GU=USD
# GUATEMALA
GT=GTQ
# GUERNSEY
GG=GBP
# GUINEA
GN=GNF
# GUINEA-BISSAU
GW=XOF
# GUYANA
GY=GYD
# HAITI
HT=HTG
# HEARD ISLAND AND MCDONALD ISLANDS
HM=AUD
# HOLY SEE (VATICAN CITY STATE)
VA=EUR
# HONDURAS
HN=HNL
# HONG KONG
HK=HKD
# HUNGARY
HU=HUF
# ICELAND
IS=ISK
# INDIA
IN=INR
# INDONESIA
ID=IDR
# IRAN, ISLAMIC REPUBLIC OF
IR=IRR
# IRAQ
IQ=IQD
# IRELAND
IE=EUR
# ISLE OF MAN
IM=GBP
# ISRAEL
IL=ILS
# ITALY
IT=EUR
# JAMAICA
JM=JMD
# JAPAN
JP=JPY
# JERSEY
JE=GBP
# JORDAN
JO=JOD
# KAZAKSTAN
KZ=KZT
# KENYA
KE=KES
# KIRIBATI
KI=AUD
# KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF
KP=KPW
# KOREA, REPUBLIC OF
KR=KRW
# KUWAIT
KW=KWD
# KYRGYZSTAN
KG=KGS
# LAO PEOPLE'S DEMOCRATIC REPUBLIC
LA=LAK
# LATVIA
LV=LVL;2013-12-31-22-00-00;EUR
# LEBANON
LB=LBP
# LESOTHO
LS=LSL
# LIBERIA
LR=LRD
# LIBYAN ARAB JAMAHIRIYA
LY=LYD
# LIECHTENSTEIN
LI=CHF
# LITHUANIA
LT=LTL;2014-12-31-22-00-00;EUR
# LUXEMBOURG
LU=EUR
# MACAU
MO=MOP
# MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF
MK=MKD
# MADAGASCAR
MG=MGA
# MALAWI
MW=MWK
# MALAYSIA
MY=MYR
# MALDIVES
MV=MVR
# MALI
ML=XOF
# MALTA
MT=EUR
# MARSHALL ISLANDS
MH=USD
# MARTINIQUE
MQ=EUR
# MAURITANIA
MR=MRO
# MAURITIUS
MU=MUR
# MAYOTTE
YT=EUR
# MEXICO
MX=MXN
# MICRONESIA, FEDERATED STATES OF
FM=USD
# MOLDOVA, REPUBLIC OF
MD=MDL
# MONACO
MC=EUR
# MONGOLIA
MN=MNT
# MONTENEGRO
ME=EUR
# MONTSERRAT
MS=XCD
# MOROCCO
MA=MAD
# MOZAMBIQUE
MZ=MZN
# MYANMAR
MM=MMK
# NAMIBIA
NA=NAD
# NAURU
NR=AUD
# NEPAL
NP=NPR
# NETHERLANDS
NL=EUR
# NETHERLANDS ANTILLES
AN=ANG
# NEW CALEDONIA
NC=XPF
# NEW ZEALAND
NZ=NZD
# NICARAGUA
NI=NIO
# NIGER
NE=XOF
# NIGERIA
NG=NGN
# NIUE
NU=NZD
# NORFOLK ISLAND
NF=AUD
# NORTHERN MARIANA ISLANDS
MP=USD
# NORWAY
NO=NOK
# OMAN
OM=OMR
# PAKISTAN
PK=PKR
# PALAU
PW=USD
# PALESTINIAN TERRITORY, OCCUPIED
PS=ILS
# PANAMA
PA=PAB
# PAPUA NEW GUINEA
PG=PGK
# PARAGUAY
PY=PYG
# PERU
PE=PEN
# PHILIPPINES
PH=PHP
# PITCAIRN
PN=NZD
# POLAND
PL=PLN
# PORTUGAL
PT=EUR
# PUERTO RICO
PR=USD
# QATAR
QA=QAR
# REUNION
RE=EUR
# ROMANIA
RO=RON
# RUSSIAN FEDERATION
RU=RUB
# RWANDA
RW=RWF
# SAINT BARTHELEMY
BL=EUR
# SAINT HELENA
SH=SHP
# SAINT KITTS AND NEVIS
KN=XCD
# SAINT LUCIA
LC=XCD
# SAINT MARTIN
MF=EUR
# SAINT PIERRE AND MIQUELON
PM=EUR
# SAINT VINCENT AND THE GRENADINES
VC=XCD
# SAMOA
WS=WST
# SAN MARINO
SM=EUR
# SOUTH SUDAN
SS=SSP
# SAO TOME AND PRINCIPE
ST=STD
# SAUDI ARABIA
SA=SAR
# SENEGAL
SN=XOF
# SERBIA
RS=RSD
# SERBIA AND MONTENEGRO
CS=CSD
# SEYCHELLES
SC=SCR
# SIERRA LEONE
SL=SLL
# SINGAPORE
SG=SGD
# SLOVAKIA
SK=EUR
# SLOVENIA
SI=EUR
# SOLOMON ISLANDS
SB=SBD
# SOMALIA
SO=SOS
# SOUTH AFRICA
ZA=ZAR
# SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS
GS=GBP
# SPAIN
ES=EUR
# SRI LANKA
LK=LKR
# SUDAN
SD=SDG
# SURINAME
SR=SRD
# SVALBARD AND JAN MAYEN
SJ=NOK
# Sint Maarten (Dutch part)
SX=ANG
# SWAZILAND
SZ=SZL
# SWEDEN
SE=SEK
# SWITZERLAND
CH=CHF
# SYRIAN ARAB REPUBLIC
SY=SYP
# TAIWAN
TW=TWD
# TAJIKISTAN
TJ=TJS
# TANZANIA, UNITED REPUBLIC OF
TZ=TZS
# THAILAND
TH=THB
# TIMOR-LESTE
TL=USD
# TOGO
TG=XOF
# TOKELAU
TK=NZD
# TONGA
TO=TOP
# TRINIDAD AND TOBAGO
TT=TTD
# TUNISIA
TN=TND
# TURKEY
TR=TRY
# TURKMENISTAN
TM=TMT
# TURKS AND CAICOS ISLANDS
TC=USD
# TUVALU
TV=AUD
# UGANDA
UG=UGX
# UKRAINE
UA=UAH
# UNITED ARAB EMIRATES
AE=AED
# UNITED KINGDOM
GB=GBP
# UNITED STATES
US=USD
# UNITED STATES MINOR OUTLYING ISLANDS
UM=USD
# URUGUAY
UY=UYU
# UZBEKISTAN
UZ=UZS
# VANUATU
VU=VUV
# VENEZUELA
VE=VEF
# VIET NAM
VN=VND
# VIRGIN ISLANDS, BRITISH
VG=USD
# VIRGIN ISLANDS, U.S.
VI=USD
# WALLIS AND FUTUNA
WF=XPF
# WESTERN SAHARA
EH=MAD
# YEMEN
YE=YER
# ZAMBIA
ZM=ZMW
# ZIMBABWE
ZW=ZWL
# List of currencies with non-2digit decimals for minor units,
# or where there are no minor units defined. All others use 2 decimals.
minor0=\
ADP-BEF-BIF-BYB-BYR-CLP-DJF-ESP-GNF-\
GRD-ISK-ITL-JPY-KMF-KRW-LUF-MGF-PYG-PTE-RWF-\
TPE-TRL-UGX-UYI-VND-VUV-XAF-XOF-XPF
minor3=\
BHD-IQD-JOD-KWD-LYD-OMR-TND
minor4=\
CLF
minorUndefined=\
XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-\
XPT-XSU-XTS-XUA-XXX
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Provides classes for reading and writing the JAR (Java ARchive) file
format, which is based on the standard ZIP file format with an
optional manifest file. The manifest stores meta-information about the
JAR file contents and is also used for signing JAR files.
<h2>Package Specification</h2>
The <code>java.util.jar</code> package is based on the following specifications:
<ul>
<li><b>Info-ZIP file format</b> - The JAR format is based on the Info-ZIP
file format. See
<a href="../zip/package-summary.html#package_description">java.util.zip
package description.</a> <p>
In JAR files, all file names must be encoded in the UTF-8 encoding.
<p>
<li><a href="../../../../technotes/guides/jar/jar.html">
Manifest and Signature Specification</a> - The manifest format specification.
</ul>
<!--
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.2
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
<P>
Provides the classes and interfaces of
the Java<SUP><FONT SIZE="-2">TM</FONT></SUP> 2
platform's core logging facilities.
The central goal of the logging APIs is to support maintaining and servicing
software at customer sites.
<P>
There are four main target uses of the logs:
</P>
<OL>
<LI> <I>Problem diagnosis by end users and system administrators</I>.
This consists of simple logging of common problems that can be fixed
or tracked locally, such as running out of resources, security failures,
and simple configuration errors.
<LI> <I>Problem diagnosis by field service engineers</I>. The logging information
used by field service engineers may be considerably more complex and
verbose than that required by system administrators. Typically such information
will require extra logging within particular subsystems.
<LI> <I>Problem diagnosis by the development organization</I>.
When a problem occurs in the field, it may be necessary to return the captured logging
information to the original development team for diagnosis. This logging
information may be extremely detailed and fairly inscrutable. Such information might include
detailed tracing on the internal execution of particular subsystems.
<LI> <I>Problem diagnosis by developers</I>. The Logging APIs may also be
used to help debug an application under development. This may
include logging information generated by the target application
as well as logging information generated by lower-level libraries.
Note however that while this use is perfectly reasonable,
the logging APIs are not intended to replace the normal debugging
and profiling tools that may already exist in the development environment.
</OL>
</P>
The key elements of this package include:
<UL>
<LI> <I>Logger</I>: The main entity on which applications make
logging calls. A Logger object is used to log messages
for a specific system or application
component.
<LI> <I>LogRecord</I>: Used to pass logging requests between the logging
framework and individual log handlers.
<LI> <I>Handler</I>: Exports LogRecord objects to a variety of destinations
including memory, output streams, consoles, files, and sockets.
A variety of Handler subclasses exist for this purpose. Additional Handlers
may be developed by third parties and delivered on top of the core platform.
<LI> <I>Level</I>: Defines a set of standard logging levels that can be used
to control logging output. Programs can be configured to output logging
for some levels while ignoring output for others.
<LI> <I>Filter</I>: Provides fine-grained control over what gets logged,
beyond the control provided by log levels. The logging APIs support a general-purpose
filter mechanism that allows application code to attach arbitrary filters to
control logging output.
<LI> <I>Formatter</I>: Provides support for formatting LogRecord objects. This
package includes two formatters, SimpleFormatter and
XMLFormatter, for formatting log records in plain text
or XML respectively. As with Handlers, additional Formatters
may be developed by third parties.
</UL>
<P>
The Logging APIs offer both static and dynamic configuration control.
Static control enables field service staff to set up a particular configuration and then re-launch the
application with the new logging settings. Dynamic control allows for updates to the
logging configuration within a currently running program. The APIs also allow for logging to be
enabled or disabled for different functional areas of the system. For example,
a field service engineer might be interested in tracing all AWT events, but might have no interest in
socket events or memory management.
</P>
<h2>Null Pointers</h2>
<p>
In general, unless otherwise noted in the javadoc, methods and
constructors will throw NullPointerException if passed a null argument.
The one broad exception to this rule is that the logging convenience
methods in the Logger class (the config, entering, exiting, fine, finer, finest,
log, logp, logrb, severe, throwing, and warning methods)
will accept null values
for all arguments except for the initial Level argument (if any).
<p>
<H2>Related Documentation</H2>
<P>
For an overview of control flow,
please refer to the
<a href="../../../../technotes/guides/logging/overview.html">
Java Logging Overview</a>.
</P>
<!-- Put @see and @since tags down here. -->
@since 1.4
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Contains the collections framework, legacy collection classes, event model,
date and time facilities, internationalization, and miscellaneous utility
classes (a string tokenizer, a random-number generator, and a bit array).
<h2>Package Specification</h2>
<ul>
<li><a href="../../../technotes/guides/collections/overview.html"><b>Collections Framework Overview</b></a>
<li><a href="../../../technotes/guides/collections/reference.html"><b>
Collections Framework Annotated Outline</b></a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="http://www.java.sun.com/docs/books/tutorial/collections/">
<b>Collections Framework Tutorial</b></a>
<li><a
href="../../../technotes/guides/collections/designfaq.html"><b>Collections
Framework Design FAQ</b></a>
</ul>
@since JDK1.0
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
This package allows applications to store and retrieve user and system
preference and configuration data. This data is stored persistently in an
implementation-dependent backing store. There are two separate trees of
preference nodes, one for user preferences and one for system preferences.
<!--
<h2>Package Specification</h2>
<h2>Related Documentation</h2>
-->
@since JDK1.4
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Classes for matching character sequences against patterns specified by regular
expressions.
<p> An instance of the {@link java.util.regex.Pattern} class represents a
regular expression that is specified in string form in a syntax similar to
that used by Perl.
<p> Instances of the {@link java.util.regex.Matcher} class are used to match
character sequences against a given pattern. Input is provided to matchers via
the {@link java.lang.CharSequence} interface in order to support matching
against characters from a wide variety of input sources. </p>
<p> Unless otherwise noted, passing a <tt>null</tt> argument to a method
in any class or interface in this package will cause a
{@link java.lang.NullPointerException NullPointerException} to be thrown.
<h2>Related Documentation</h2>
<p> An excellent tutorial and overview of regular expressions is <a
href="http://www.oreilly.com/catalog/regex/"><i>Mastering Regular
Expressions</i>, Jeffrey E. F. Friedl, O'Reilly and Associates, 1997.</a> </p>
<!--
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.4
@author Mike McCloskey
@author Mark Reinhold
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Service provider classes for the classes in the java.util package.
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since 1.6
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation. Oracle designates this
particular file as subject to the "Classpath" exception as provided
by Oracle in the LICENSE file that accompanied this code.
This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).
You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
or visit www.oracle.com if you need additional information or have any
questions.
-->
</head>
<body bgcolor="white">
Provides classes for reading and writing the standard ZIP and GZIP
file formats. Also includes classes for compressing and decompressing
data using the DEFLATE compression algorithm, which is used by the
ZIP and GZIP file formats. Additionally, there are utility classes
for computing the CRC-32 and Adler-32 checksums of arbitrary
input streams.
<h2>Package Specification</h2>
</a>
<ul>
<li><a href="http://www.info-zip.org/doc/appnote-19970311-iz.zip">
Info-ZIP Application Note 970311
</a> - a detailed description of the Info-ZIP format upon which
the <code>java.util.zip</code> classes are based.
<p>
<a name="zip64">
<li>An implementation may optionally support the ZIP64(tm) format extensions
defined by the
<a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
PKWARE ZIP File Format Specification</a>. The ZIP64(tm) format extensions
are used to overcome the size limitations of the original ZIP format.
<p>
<a name="lang_encoding">
<li>APPENDIX D of <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">
PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to
encode ZIP entry filename and comment fields using UTF-8.
<p>
<li><a href="http://www.ietf.org/rfc/rfc1950.txt">
ZLIB Compressed Data Format Specification version 3.3</a>
&nbsp;
<a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a>
(RFC 1950)
<p>
<li><a href="http://www.ietf.org/rfc/rfc1951.txt">
DEFLATE Compressed Data Format Specification version 1.3</a>
&nbsp;
<a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a>
(RFC 1951)
<p>
<li><a href="http://www.ietf.org/rfc/rfc1952.txt">
GZIP file format specification version 4.3</a>
&nbsp;
<a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a>
(RFC 1952)
<p>
<li>CRC-32 checksum is described in RFC 1952 (above)
<p>
<li>Adler-32 checksum is described in RFC 1950 (above)
</ul>
<!--
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
@since JDK1.1
</body>
</html>
...@@ -92,7 +92,7 @@ import java.util.function.Function; ...@@ -92,7 +92,7 @@ import java.util.function.Function;
* associated with a key that an instance already contains is not a * associated with a key that an instance already contains is not a
* structural modification.) This is typically accomplished by * structural modification.) This is typically accomplished by
* synchronizing on some object that naturally encapsulates the map. * synchronizing on some object that naturally encapsulates the map.
* * <p>
* If no such object exists, the map should be "wrapped" using the * If no such object exists, the map should be "wrapped" using the
* {@link Collections#synchronizedMap Collections.synchronizedMap} * {@link Collections#synchronizedMap Collections.synchronizedMap}
* method. This is best done at creation time, to prevent accidental * method. This is best done at creation time, to prevent accidental
...@@ -122,7 +122,6 @@ import java.util.function.Function; ...@@ -122,7 +122,6 @@ import java.util.function.Function;
* *
* @param <K> the type of keys maintained by this map * @param <K> the type of keys maintained by this map
* @param <V> the type of mapped values * @param <V> the type of mapped values
*
* @author Doug Lea * @author Doug Lea
* @author Josh Bloch * @author Josh Bloch
* @author Arthur van Hoff * @author Arthur van Hoff
...@@ -134,8 +133,8 @@ import java.util.function.Function; ...@@ -134,8 +133,8 @@ import java.util.function.Function;
* @see Hashtable * @see Hashtable
* @since 1.2 * @since 1.2
*/ */
public class HashMap<K,V> extends AbstractMap<K,V> public class HashMap<K, V> extends AbstractMap<K, V>
implements Map<K,V>, Cloneable, Serializable { implements Map<K, V>, Cloneable, Serializable {
private static final long serialVersionUID = 362498820763181265L; private static final long serialVersionUID = 362498820763181265L;
...@@ -275,38 +274,52 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -275,38 +274,52 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* Basic hash bin node, used for most entries. (See below for * Basic hash bin node, used for most entries. (See below for
* TreeNode subclass, and in LinkedHashMap for its Entry subclass.) * TreeNode subclass, and in LinkedHashMap for its Entry subclass.)
*/ */
static class Node<K,V> implements Map.Entry<K,V> { static class Node<K, V> implements Map.Entry<K, V> {
final int hash; final int hash;
final K key; final K key;
V value; V value;
Node<K,V> next; Node<K, V> next;
Node(int hash, K key, V value, Node<K,V> next) { Node(int hash, K key, V value, Node<K, V> next) {
this.hash = hash; this.hash = hash;
this.key = key; this.key = key;
this.value = value; this.value = value;
this.next = next; this.next = next;
} }
public final K getKey() { return key; } @Override
public final V getValue() { return value; } public final K getKey() {
public final String toString() { return key + "=" + value; } return key;
}
@Override
public final V getValue() {
return value;
}
@Override
public final String toString() {
return key + "=" + value;
}
@Override
public final int hashCode() { public final int hashCode() {
return Objects.hashCode(key) ^ Objects.hashCode(value); return Objects.hashCode(key) ^ Objects.hashCode(value);
} }
@Override
public final V setValue(V newValue) { public final V setValue(V newValue) {
V oldValue = value; V oldValue = value;
value = newValue; value = newValue;
return oldValue; return oldValue;
} }
@Override
public final boolean equals(Object o) { public final boolean equals(Object o) {
if (o == this) if (o == this)
return true; return true;
if (o instanceof Map.Entry) { if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>)o; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
if (Objects.equals(key, e.getKey()) && if (Objects.equals(key, e.getKey()) &&
Objects.equals(value, e.getValue())) Objects.equals(value, e.getValue()))
return true; return true;
...@@ -344,13 +357,16 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -344,13 +357,16 @@ public class HashMap<K,V> extends AbstractMap<K,V>
*/ */
static Class<?> comparableClassFor(Object x) { static Class<?> comparableClassFor(Object x) {
if (x instanceof Comparable) { if (x instanceof Comparable) {
Class<?> c; Type[] ts, as; Type t; ParameterizedType p; Class<?> c;
Type[] ts, as;
Type t;
ParameterizedType p;
if ((c = x.getClass()) == String.class) // bypass checks if ((c = x.getClass()) == String.class) // bypass checks
return c; return c;
if ((ts = c.getGenericInterfaces()) != null) { if ((ts = c.getGenericInterfaces()) != null) {
for (int i = 0; i < ts.length; ++i) { for (int i = 0; i < ts.length; ++i) {
if (((t = ts[i]) instanceof ParameterizedType) && if (((t = ts[i]) instanceof ParameterizedType) &&
((p = (ParameterizedType)t).getRawType() == ((p = (ParameterizedType) t).getRawType() ==
Comparable.class) && Comparable.class) &&
(as = p.getActualTypeArguments()) != null && (as = p.getActualTypeArguments()) != null &&
as.length == 1 && as[0] == c) // type arg is c as.length == 1 && as[0] == c) // type arg is c
...@@ -365,10 +381,10 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -365,10 +381,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* Returns k.compareTo(x) if x matches kc (k's screened comparable * Returns k.compareTo(x) if x matches kc (k's screened comparable
* class), else 0. * class), else 0.
*/ */
@SuppressWarnings({"rawtypes","unchecked"}) // for cast to Comparable @SuppressWarnings({"rawtypes", "unchecked"}) // for cast to Comparable
static int compareComparables(Class<?> kc, Object k, Object x) { static int compareComparables(Class<?> kc, Object k, Object x) {
return (x == null || x.getClass() != kc ? 0 : return (x == null || x.getClass() != kc ? 0 :
((Comparable)k).compareTo(x)); ((Comparable) k).compareTo(x));
} }
/** /**
...@@ -392,13 +408,13 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -392,13 +408,13 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* (We also tolerate length zero in some operations to allow * (We also tolerate length zero in some operations to allow
* bootstrapping mechanics that are currently not needed.) * bootstrapping mechanics that are currently not needed.)
*/ */
transient Node<K,V>[] table; transient Node<K, V>[] table;
/** /**
* Holds cached entrySet(). Note that AbstractMap fields are used * Holds cached entrySet(). Note that AbstractMap fields are used
* for keySet() and values(). * for keySet() and values().
*/ */
transient Set<Map.Entry<K,V>> entrySet; transient Set<Map.Entry<K, V>> entrySet;
/** /**
* The number of key-value mappings contained in this map. * The number of key-value mappings contained in this map.
...@@ -500,13 +516,12 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -500,13 +516,12 @@ public class HashMap<K,V> extends AbstractMap<K,V>
int s = m.size(); int s = m.size();
if (s > 0) { if (s > 0) {
if (table == null) { // pre-size if (table == null) { // pre-size
float ft = ((float)s / loadFactor) + 1.0F; float ft = ((float) s / loadFactor) + 1.0F;
int t = ((ft < (float)MAXIMUM_CAPACITY) ? int t = ((ft < (float) MAXIMUM_CAPACITY) ?
(int)ft : MAXIMUM_CAPACITY); (int) ft : MAXIMUM_CAPACITY);
if (t > threshold) if (t > threshold)
threshold = tableSizeFor(t); threshold = tableSizeFor(t);
} } else if (s > threshold)
else if (s > threshold)
resize(); resize();
for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) { for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
K key = e.getKey(); K key = e.getKey();
...@@ -521,6 +536,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -521,6 +536,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* *
* @return the number of key-value mappings in this map * @return the number of key-value mappings in this map
*/ */
@Override
public int size() { public int size() {
return size; return size;
} }
...@@ -530,6 +546,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -530,6 +546,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* *
* @return <tt>true</tt> if this map contains no key-value mappings * @return <tt>true</tt> if this map contains no key-value mappings
*/ */
@Override
public boolean isEmpty() { public boolean isEmpty() {
return size == 0; return size == 0;
} }
...@@ -551,8 +568,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -551,8 +568,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* *
* @see #put(Object, Object) * @see #put(Object, Object)
*/ */
@Override
public V get(Object key) { public V get(Object key) {
Node<K,V> e; Node<K, V> e;
return (e = getNode(hash(key), key)) == null ? null : e.value; return (e = getNode(hash(key), key)) == null ? null : e.value;
} }
...@@ -563,8 +581,11 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -563,8 +581,11 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* @param key the key * @param key the key
* @return the node, or null if none * @return the node, or null if none
*/ */
final Node<K,V> getNode(int hash, Object key) { final Node<K, V> getNode(int hash, Object key) {
Node<K,V>[] tab; Node<K,V> first, e; int n; K k; Node<K, V>[] tab;
Node<K, V> first, e;
int n;
K k;
if ((tab = table) != null && (n = tab.length) > 0 && if ((tab = table) != null && (n = tab.length) > 0 &&
(first = tab[(n - 1) & hash]) != null) { (first = tab[(n - 1) & hash]) != null) {
if (first.hash == hash && // always check first node if (first.hash == hash && // always check first node
...@@ -572,7 +593,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -572,7 +593,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return first; return first;
if ((e = first.next) != null) { if ((e = first.next) != null) {
if (first instanceof TreeNode) if (first instanceof TreeNode)
return ((TreeNode<K,V>)first).getTreeNode(hash, key); return ((TreeNode<K, V>) first).getTreeNode(hash, key);
do { do {
if (e.hash == hash && if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k)))) ((k = e.key) == key || (key != null && key.equals(k))))
...@@ -591,6 +612,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -591,6 +612,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* @return <tt>true</tt> if this map contains a mapping for the specified * @return <tt>true</tt> if this map contains a mapping for the specified
* key. * key.
*/ */
@Override
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
return getNode(hash(key), key) != null; return getNode(hash(key), key) != null;
} }
...@@ -607,6 +629,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -607,6 +629,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* (A <tt>null</tt> return can also indicate that the map * (A <tt>null</tt> return can also indicate that the map
* previously associated <tt>null</tt> with <tt>key</tt>.) * previously associated <tt>null</tt> with <tt>key</tt>.)
*/ */
@Override
public V put(K key, V value) { public V put(K key, V value) {
return putVal(hash(key), key, value, false, true); return putVal(hash(key), key, value, false, true);
} }
...@@ -623,18 +646,21 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -623,18 +646,21 @@ public class HashMap<K,V> extends AbstractMap<K,V>
*/ */
final V putVal(int hash, K key, V value, boolean onlyIfAbsent, final V putVal(int hash, K key, V value, boolean onlyIfAbsent,
boolean evict) { boolean evict) {
Node<K,V>[] tab; Node<K,V> p; int n, i; Node<K, V>[] tab;
Node<K, V> p;
int n, i;
if ((tab = table) == null || (n = tab.length) == 0) if ((tab = table) == null || (n = tab.length) == 0)
n = (tab = resize()).length; n = (tab = resize()).length;
if ((p = tab[i = (n - 1) & hash]) == null) if ((p = tab[i = (n - 1) & hash]) == null)
tab[i] = newNode(hash, key, value, null); tab[i] = newNode(hash, key, value, null);
else { else {
Node<K,V> e; K k; Node<K, V> e;
K k;
if (p.hash == hash && if (p.hash == hash &&
((k = p.key) == key || (key != null && key.equals(k)))) ((k = p.key) == key || (key != null && key.equals(k))))
e = p; e = p;
else if (p instanceof TreeNode) else if (p instanceof TreeNode)
e = ((TreeNode<K,V>)p).putTreeVal(this, tab, hash, key, value); e = ((TreeNode<K, V>) p).putTreeVal(this, tab, hash, key, value);
else { else {
for (int binCount = 0; ; ++binCount) { for (int binCount = 0; ; ++binCount) {
if ((e = p.next) == null) { if ((e = p.next) == null) {
...@@ -673,8 +699,8 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -673,8 +699,8 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* *
* @return the table * @return the table
*/ */
final Node<K,V>[] resize() { final Node<K, V>[] resize() {
Node<K,V>[] oldTab = table; Node<K, V>[] oldTab = table;
int oldCap = (oldTab == null) ? 0 : oldTab.length; int oldCap = (oldTab == null) ? 0 : oldTab.length;
int oldThr = threshold; int oldThr = threshold;
int newCap, newThr = 0; int newCap, newThr = 0;
...@@ -682,39 +708,37 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -682,39 +708,37 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (oldCap >= MAXIMUM_CAPACITY) { if (oldCap >= MAXIMUM_CAPACITY) {
threshold = Integer.MAX_VALUE; threshold = Integer.MAX_VALUE;
return oldTab; return oldTab;
} } else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY &&
else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY &&
oldCap >= DEFAULT_INITIAL_CAPACITY) oldCap >= DEFAULT_INITIAL_CAPACITY)
newThr = oldThr << 1; // double threshold newThr = oldThr << 1; // double threshold
} } else if (oldThr > 0) // initial capacity was placed in threshold
else if (oldThr > 0) // initial capacity was placed in threshold
newCap = oldThr; newCap = oldThr;
else { // zero initial threshold signifies using defaults else { // zero initial threshold signifies using defaults
newCap = DEFAULT_INITIAL_CAPACITY; newCap = DEFAULT_INITIAL_CAPACITY;
newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); newThr = (int) (DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY);
} }
if (newThr == 0) { if (newThr == 0) {
float ft = (float)newCap * loadFactor; float ft = (float) newCap * loadFactor;
newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ? newThr = (newCap < MAXIMUM_CAPACITY && ft < (float) MAXIMUM_CAPACITY ?
(int)ft : Integer.MAX_VALUE); (int) ft : Integer.MAX_VALUE);
} }
threshold = newThr; threshold = newThr;
@SuppressWarnings({"rawtypes","unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap]; Node<K, V>[] newTab = (Node<K, V>[]) new Node[newCap];
table = newTab; table = newTab;
if (oldTab != null) { if (oldTab != null) {
for (int j = 0; j < oldCap; ++j) { for (int j = 0; j < oldCap; ++j) {
Node<K,V> e; Node<K, V> e;
if ((e = oldTab[j]) != null) { if ((e = oldTab[j]) != null) {
oldTab[j] = null; oldTab[j] = null;
if (e.next == null) if (e.next == null)
newTab[e.hash & (newCap - 1)] = e; newTab[e.hash & (newCap - 1)] = e;
else if (e instanceof TreeNode) else if (e instanceof TreeNode)
((TreeNode<K,V>)e).split(this, newTab, j, oldCap); ((TreeNode<K, V>) e).split(this, newTab, j, oldCap);
else { // preserve order else { // preserve order
Node<K,V> loHead = null, loTail = null; Node<K, V> loHead = null, loTail = null;
Node<K,V> hiHead = null, hiTail = null; Node<K, V> hiHead = null, hiTail = null;
Node<K,V> next; Node<K, V> next;
do { do {
next = e.next; next = e.next;
if ((e.hash & oldCap) == 0) { if ((e.hash & oldCap) == 0) {
...@@ -723,8 +747,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -723,8 +747,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
else else
loTail.next = e; loTail.next = e;
loTail = e; loTail = e;
} } else {
else {
if (hiTail == null) if (hiTail == null)
hiHead = e; hiHead = e;
else else
...@@ -751,14 +774,15 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -751,14 +774,15 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* Replaces all linked nodes in bin at index for given hash unless * Replaces all linked nodes in bin at index for given hash unless
* table is too small, in which case resizes instead. * table is too small, in which case resizes instead.
*/ */
final void treeifyBin(Node<K,V>[] tab, int hash) { final void treeifyBin(Node<K, V>[] tab, int hash) {
int n, index; Node<K,V> e; int n, index;
Node<K, V> e;
if (tab == null || (n = tab.length) < MIN_TREEIFY_CAPACITY) if (tab == null || (n = tab.length) < MIN_TREEIFY_CAPACITY)
resize(); resize();
else if ((e = tab[index = (n - 1) & hash]) != null) { else if ((e = tab[index = (n - 1) & hash]) != null) {
TreeNode<K,V> hd = null, tl = null; TreeNode<K, V> hd = null, tl = null;
do { do {
TreeNode<K,V> p = replacementTreeNode(e, null); TreeNode<K, V> p = replacementTreeNode(e, null);
if (tl == null) if (tl == null)
hd = p; hd = p;
else { else {
...@@ -780,6 +804,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -780,6 +804,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* @param m mappings to be stored in this map * @param m mappings to be stored in this map
* @throws NullPointerException if the specified map is null * @throws NullPointerException if the specified map is null
*/ */
@Override
public void putAll(Map<? extends K, ? extends V> m) { public void putAll(Map<? extends K, ? extends V> m) {
putMapEntries(m, true); putMapEntries(m, true);
} }
...@@ -793,8 +818,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -793,8 +818,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* (A <tt>null</tt> return can also indicate that the map * (A <tt>null</tt> return can also indicate that the map
* previously associated <tt>null</tt> with <tt>key</tt>.) * previously associated <tt>null</tt> with <tt>key</tt>.)
*/ */
@Override
public V remove(Object key) { public V remove(Object key) {
Node<K,V> e; Node<K, V> e;
return (e = removeNode(hash(key), key, null, false, true)) == null ? return (e = removeNode(hash(key), key, null, false, true)) == null ?
null : e.value; null : e.value;
} }
...@@ -809,18 +835,22 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -809,18 +835,22 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* @param movable if false do not move other nodes while removing * @param movable if false do not move other nodes while removing
* @return the node, or null if none * @return the node, or null if none
*/ */
final Node<K,V> removeNode(int hash, Object key, Object value, final Node<K, V> removeNode(int hash, Object key, Object value,
boolean matchValue, boolean movable) { boolean matchValue, boolean movable) {
Node<K,V>[] tab; Node<K,V> p; int n, index; Node<K, V>[] tab;
Node<K, V> p;
int n, index;
if ((tab = table) != null && (n = tab.length) > 0 && if ((tab = table) != null && (n = tab.length) > 0 &&
(p = tab[index = (n - 1) & hash]) != null) { (p = tab[index = (n - 1) & hash]) != null) {
Node<K,V> node = null, e; K k; V v; Node<K, V> node = null, e;
K k;
V v;
if (p.hash == hash && if (p.hash == hash &&
((k = p.key) == key || (key != null && key.equals(k)))) ((k = p.key) == key || (key != null && key.equals(k))))
node = p; node = p;
else if ((e = p.next) != null) { else if ((e = p.next) != null) {
if (p instanceof TreeNode) if (p instanceof TreeNode)
node = ((TreeNode<K,V>)p).getTreeNode(hash, key); node = ((TreeNode<K, V>) p).getTreeNode(hash, key);
else { else {
do { do {
if (e.hash == hash && if (e.hash == hash &&
...@@ -836,7 +866,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -836,7 +866,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (node != null && (!matchValue || (v = node.value) == value || if (node != null && (!matchValue || (v = node.value) == value ||
(value != null && value.equals(v)))) { (value != null && value.equals(v)))) {
if (node instanceof TreeNode) if (node instanceof TreeNode)
((TreeNode<K,V>)node).removeTreeNode(this, tab, movable); ((TreeNode<K, V>) node).removeTreeNode(this, tab, movable);
else if (node == p) else if (node == p)
tab[index] = node.next; tab[index] = node.next;
else else
...@@ -854,8 +884,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -854,8 +884,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* Removes all of the mappings from this map. * Removes all of the mappings from this map.
* The map will be empty after this call returns. * The map will be empty after this call returns.
*/ */
@Override
public void clear() { public void clear() {
Node<K,V>[] tab; Node<K, V>[] tab;
modCount++; modCount++;
if ((tab = table) != null && size > 0) { if ((tab = table) != null && size > 0) {
size = 0; size = 0;
...@@ -872,11 +903,13 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -872,11 +903,13 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* @return <tt>true</tt> if this map maps one or more keys to the * @return <tt>true</tt> if this map maps one or more keys to the
* specified value * specified value
*/ */
@Override
public boolean containsValue(Object value) { public boolean containsValue(Object value) {
Node<K,V>[] tab; V v; Node<K, V>[] tab;
V v;
if ((tab = table) != null && size > 0) { if ((tab = table) != null && size > 0) {
for (int i = 0; i < tab.length; ++i) { for (int i = 0; i < tab.length; ++i) {
for (Node<K,V> e = tab[i]; e != null; e = e.next) { for (Node<K, V> e = tab[i]; e != null; e = e.next) {
if ((v = e.value) == value || if ((v = e.value) == value ||
(value != null && value.equals(v))) (value != null && value.equals(v)))
return true; return true;
...@@ -901,30 +934,52 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -901,30 +934,52 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* *
* @return a set view of the keys contained in this map * @return a set view of the keys contained in this map
*/ */
@Override
public Set<K> keySet() { public Set<K> keySet() {
Set<K> ks; Set<K> ks;
return (ks = keySet) == null ? (keySet = new KeySet()) : ks; return (ks = keySet) == null ? (keySet = new KeySet()) : ks;
} }
final class KeySet extends AbstractSet<K> { final class KeySet extends AbstractSet<K> {
public final int size() { return size; } @Override
public final void clear() { HashMap.this.clear(); } public final int size() {
public final Iterator<K> iterator() { return new KeyIterator(); } return size;
public final boolean contains(Object o) { return containsKey(o); } }
@Override
public final void clear() {
HashMap.this.clear();
}
@Override
public final Iterator<K> iterator() {
return new KeyIterator();
}
@Override
public final boolean contains(Object o) {
return containsKey(o);
}
@Override
public final boolean remove(Object key) { public final boolean remove(Object key) {
return removeNode(hash(key), key, null, false, true) != null; return removeNode(hash(key), key, null, false, true) != null;
} }
@Override
public final Spliterator<K> spliterator() { public final Spliterator<K> spliterator() {
return new KeySpliterator<>(HashMap.this, 0, -1, 0, 0); return new KeySpliterator<>(HashMap.this, 0, -1, 0, 0);
} }
@Override
public final void forEach(Consumer<? super K> action) { public final void forEach(Consumer<? super K> action) {
Node<K,V>[] tab; Node<K, V>[] tab;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
if (size > 0 && (tab = table) != null) { if (size > 0 && (tab = table) != null) {
int mc = modCount; int mc = modCount;
for (int i = 0; i < tab.length; ++i) { for (int i = 0; i < tab.length; ++i) {
for (Node<K,V> e = tab[i]; e != null; e = e.next) for (Node<K, V> e = tab[i]; e != null; e = e.next)
action.accept(e.key); action.accept(e.key);
} }
if (modCount != mc) if (modCount != mc)
...@@ -948,27 +1003,47 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -948,27 +1003,47 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* *
* @return a view of the values contained in this map * @return a view of the values contained in this map
*/ */
@Override
public Collection<V> values() { public Collection<V> values() {
Collection<V> vs; Collection<V> vs;
return (vs = values) == null ? (values = new Values()) : vs; return (vs = values) == null ? (values = new Values()) : vs;
} }
final class Values extends AbstractCollection<V> { final class Values extends AbstractCollection<V> {
public final int size() { return size; } @Override
public final void clear() { HashMap.this.clear(); } public final int size() {
public final Iterator<V> iterator() { return new ValueIterator(); } return size;
public final boolean contains(Object o) { return containsValue(o); } }
@Override
public final void clear() {
HashMap.this.clear();
}
@Override
public final Iterator<V> iterator() {
return new ValueIterator();
}
@Override
public final boolean contains(Object o) {
return containsValue(o);
}
@Override
public final Spliterator<V> spliterator() { public final Spliterator<V> spliterator() {
return new ValueSpliterator<>(HashMap.this, 0, -1, 0, 0); return new ValueSpliterator<>(HashMap.this, 0, -1, 0, 0);
} }
@Override
public final void forEach(Consumer<? super V> action) { public final void forEach(Consumer<? super V> action) {
Node<K,V>[] tab; Node<K, V>[] tab;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
if (size > 0 && (tab = table) != null) { if (size > 0 && (tab = table) != null) {
int mc = modCount; int mc = modCount;
for (int i = 0; i < tab.length; ++i) { for (int i = 0; i < tab.length; ++i) {
for (Node<K,V> e = tab[i]; e != null; e = e.next) for (Node<K, V> e = tab[i]; e != null; e = e.next)
action.accept(e.value); action.accept(e.value);
} }
if (modCount != mc) if (modCount != mc)
...@@ -993,45 +1068,63 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -993,45 +1068,63 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* *
* @return a set view of the mappings contained in this map * @return a set view of the mappings contained in this map
*/ */
public Set<Map.Entry<K,V>> entrySet() { @Override
Set<Map.Entry<K,V>> es; public Set<Map.Entry<K, V>> entrySet() {
Set<Map.Entry<K, V>> es;
return (es = entrySet) == null ? (entrySet = new EntrySet()) : es; return (es = entrySet) == null ? (entrySet = new EntrySet()) : es;
} }
final class EntrySet extends AbstractSet<Map.Entry<K,V>> { final class EntrySet extends AbstractSet<Map.Entry<K, V>> {
public final int size() { return size; } @Override
public final void clear() { HashMap.this.clear(); } public final int size() {
public final Iterator<Map.Entry<K,V>> iterator() { return size;
}
@Override
public final void clear() {
HashMap.this.clear();
}
@Override
public final Iterator<Map.Entry<K, V>> iterator() {
return new EntryIterator(); return new EntryIterator();
} }
@Override
public final boolean contains(Object o) { public final boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
Object key = e.getKey(); Object key = e.getKey();
Node<K,V> candidate = getNode(hash(key), key); Node<K, V> candidate = getNode(hash(key), key);
return candidate != null && candidate.equals(e); return candidate != null && candidate.equals(e);
} }
@Override
public final boolean remove(Object o) { public final boolean remove(Object o) {
if (o instanceof Map.Entry) { if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>) o; Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
Object key = e.getKey(); Object key = e.getKey();
Object value = e.getValue(); Object value = e.getValue();
return removeNode(hash(key), key, value, true, true) != null; return removeNode(hash(key), key, value, true, true) != null;
} }
return false; return false;
} }
public final Spliterator<Map.Entry<K,V>> spliterator() {
@Override
public final Spliterator<Map.Entry<K, V>> spliterator() {
return new EntrySpliterator<>(HashMap.this, 0, -1, 0, 0); return new EntrySpliterator<>(HashMap.this, 0, -1, 0, 0);
} }
public final void forEach(Consumer<? super Map.Entry<K,V>> action) {
Node<K,V>[] tab; @Override
public final void forEach(Consumer<? super Map.Entry<K, V>> action) {
Node<K, V>[] tab;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
if (size > 0 && (tab = table) != null) { if (size > 0 && (tab = table) != null) {
int mc = modCount; int mc = modCount;
for (int i = 0; i < tab.length; ++i) { for (int i = 0; i < tab.length; ++i) {
for (Node<K,V> e = tab[i]; e != null; e = e.next) for (Node<K, V> e = tab[i]; e != null; e = e.next)
action.accept(e); action.accept(e);
} }
if (modCount != mc) if (modCount != mc)
...@@ -1044,7 +1137,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1044,7 +1137,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
@Override @Override
public V getOrDefault(Object key, V defaultValue) { public V getOrDefault(Object key, V defaultValue) {
Node<K,V> e; Node<K, V> e;
return (e = getNode(hash(key), key)) == null ? defaultValue : e.value; return (e = getNode(hash(key), key)) == null ? defaultValue : e.value;
} }
...@@ -1060,7 +1153,8 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1060,7 +1153,8 @@ public class HashMap<K,V> extends AbstractMap<K,V>
@Override @Override
public boolean replace(K key, V oldValue, V newValue) { public boolean replace(K key, V oldValue, V newValue) {
Node<K,V> e; V v; Node<K, V> e;
V v;
if ((e = getNode(hash(key), key)) != null && if ((e = getNode(hash(key), key)) != null &&
((v = e.value) == oldValue || (v != null && v.equals(oldValue)))) { ((v = e.value) == oldValue || (v != null && v.equals(oldValue)))) {
e.value = newValue; e.value = newValue;
...@@ -1072,7 +1166,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1072,7 +1166,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
@Override @Override
public V replace(K key, V value) { public V replace(K key, V value) {
Node<K,V> e; Node<K, V> e;
if ((e = getNode(hash(key), key)) != null) { if ((e = getNode(hash(key), key)) != null) {
V oldValue = e.value; V oldValue = e.value;
e.value = value; e.value = value;
...@@ -1088,18 +1182,21 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1088,18 +1182,21 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (mappingFunction == null) if (mappingFunction == null)
throw new NullPointerException(); throw new NullPointerException();
int hash = hash(key); int hash = hash(key);
Node<K,V>[] tab; Node<K,V> first; int n, i; Node<K, V>[] tab;
Node<K, V> first;
int n, i;
int binCount = 0; int binCount = 0;
TreeNode<K,V> t = null; TreeNode<K, V> t = null;
Node<K,V> old = null; Node<K, V> old = null;
if (size > threshold || (tab = table) == null || if (size > threshold || (tab = table) == null ||
(n = tab.length) == 0) (n = tab.length) == 0)
n = (tab = resize()).length; n = (tab = resize()).length;
if ((first = tab[i = (n - 1) & hash]) != null) { if ((first = tab[i = (n - 1) & hash]) != null) {
if (first instanceof TreeNode) if (first instanceof TreeNode)
old = (t = (TreeNode<K,V>)first).getTreeNode(hash, key); old = (t = (TreeNode<K, V>) first).getTreeNode(hash, key);
else { else {
Node<K,V> e = first; K k; Node<K, V> e = first;
K k;
do { do {
if (e.hash == hash && if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k)))) { ((k = e.key) == key || (key != null && key.equals(k)))) {
...@@ -1122,8 +1219,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1122,8 +1219,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
old.value = v; old.value = v;
afterNodeAccess(old); afterNodeAccess(old);
return v; return v;
} } else if (t != null)
else if (t != null)
t.putTreeVal(this, tab, hash, key, v); t.putTreeVal(this, tab, hash, key, v);
else { else {
tab[i] = newNode(hash, key, v, first); tab[i] = newNode(hash, key, v, first);
...@@ -1136,11 +1232,13 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1136,11 +1232,13 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return v; return v;
} }
@Override
public V computeIfPresent(K key, public V computeIfPresent(K key,
BiFunction<? super K, ? super V, ? extends V> remappingFunction) { BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
if (remappingFunction == null) if (remappingFunction == null)
throw new NullPointerException(); throw new NullPointerException();
Node<K,V> e; V oldValue; Node<K, V> e;
V oldValue;
int hash = hash(key); int hash = hash(key);
if ((e = getNode(hash, key)) != null && if ((e = getNode(hash, key)) != null &&
(oldValue = e.value) != null) { (oldValue = e.value) != null) {
...@@ -1149,8 +1247,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1149,8 +1247,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
e.value = v; e.value = v;
afterNodeAccess(e); afterNodeAccess(e);
return v; return v;
} } else
else
removeNode(hash, key, null, false, true); removeNode(hash, key, null, false, true);
} }
return null; return null;
...@@ -1162,18 +1259,21 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1162,18 +1259,21 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (remappingFunction == null) if (remappingFunction == null)
throw new NullPointerException(); throw new NullPointerException();
int hash = hash(key); int hash = hash(key);
Node<K,V>[] tab; Node<K,V> first; int n, i; Node<K, V>[] tab;
Node<K, V> first;
int n, i;
int binCount = 0; int binCount = 0;
TreeNode<K,V> t = null; TreeNode<K, V> t = null;
Node<K,V> old = null; Node<K, V> old = null;
if (size > threshold || (tab = table) == null || if (size > threshold || (tab = table) == null ||
(n = tab.length) == 0) (n = tab.length) == 0)
n = (tab = resize()).length; n = (tab = resize()).length;
if ((first = tab[i = (n - 1) & hash]) != null) { if ((first = tab[i = (n - 1) & hash]) != null) {
if (first instanceof TreeNode) if (first instanceof TreeNode)
old = (t = (TreeNode<K,V>)first).getTreeNode(hash, key); old = (t = (TreeNode<K, V>) first).getTreeNode(hash, key);
else { else {
Node<K,V> e = first; K k; Node<K, V> e = first;
K k;
do { do {
if (e.hash == hash && if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k)))) { ((k = e.key) == key || (key != null && key.equals(k)))) {
...@@ -1190,11 +1290,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1190,11 +1290,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (v != null) { if (v != null) {
old.value = v; old.value = v;
afterNodeAccess(old); afterNodeAccess(old);
} } else
else
removeNode(hash, key, null, false, true); removeNode(hash, key, null, false, true);
} } else if (v != null) {
else if (v != null) {
if (t != null) if (t != null)
t.putTreeVal(this, tab, hash, key, v); t.putTreeVal(this, tab, hash, key, v);
else { else {
...@@ -1217,18 +1315,21 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1217,18 +1315,21 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (remappingFunction == null) if (remappingFunction == null)
throw new NullPointerException(); throw new NullPointerException();
int hash = hash(key); int hash = hash(key);
Node<K,V>[] tab; Node<K,V> first; int n, i; Node<K, V>[] tab;
Node<K, V> first;
int n, i;
int binCount = 0; int binCount = 0;
TreeNode<K,V> t = null; TreeNode<K, V> t = null;
Node<K,V> old = null; Node<K, V> old = null;
if (size > threshold || (tab = table) == null || if (size > threshold || (tab = table) == null ||
(n = tab.length) == 0) (n = tab.length) == 0)
n = (tab = resize()).length; n = (tab = resize()).length;
if ((first = tab[i = (n - 1) & hash]) != null) { if ((first = tab[i = (n - 1) & hash]) != null) {
if (first instanceof TreeNode) if (first instanceof TreeNode)
old = (t = (TreeNode<K,V>)first).getTreeNode(hash, key); old = (t = (TreeNode<K, V>) first).getTreeNode(hash, key);
else { else {
Node<K,V> e = first; K k; Node<K, V> e = first;
K k;
do { do {
if (e.hash == hash && if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k)))) { ((k = e.key) == key || (key != null && key.equals(k)))) {
...@@ -1248,8 +1349,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1248,8 +1349,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (v != null) { if (v != null) {
old.value = v; old.value = v;
afterNodeAccess(old); afterNodeAccess(old);
} } else
else
removeNode(hash, key, null, false, true); removeNode(hash, key, null, false, true);
return v; return v;
} }
...@@ -1270,13 +1370,13 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1270,13 +1370,13 @@ public class HashMap<K,V> extends AbstractMap<K,V>
@Override @Override
public void forEach(BiConsumer<? super K, ? super V> action) { public void forEach(BiConsumer<? super K, ? super V> action) {
Node<K,V>[] tab; Node<K, V>[] tab;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
if (size > 0 && (tab = table) != null) { if (size > 0 && (tab = table) != null) {
int mc = modCount; int mc = modCount;
for (int i = 0; i < tab.length; ++i) { for (int i = 0; i < tab.length; ++i) {
for (Node<K,V> e = tab[i]; e != null; e = e.next) for (Node<K, V> e = tab[i]; e != null; e = e.next)
action.accept(e.key, e.value); action.accept(e.key, e.value);
} }
if (modCount != mc) if (modCount != mc)
...@@ -1286,13 +1386,13 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1286,13 +1386,13 @@ public class HashMap<K,V> extends AbstractMap<K,V>
@Override @Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Node<K,V>[] tab; Node<K, V>[] tab;
if (function == null) if (function == null)
throw new NullPointerException(); throw new NullPointerException();
if (size > 0 && (tab = table) != null) { if (size > 0 && (tab = table) != null) {
int mc = modCount; int mc = modCount;
for (int i = 0; i < tab.length; ++i) { for (int i = 0; i < tab.length; ++i) {
for (Node<K,V> e = tab[i]; e != null; e = e.next) { for (Node<K, V> e = tab[i]; e != null; e = e.next) {
e.value = function.apply(e.key, e.value); e.value = function.apply(e.key, e.value);
} }
} }
...@@ -1313,9 +1413,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1313,9 +1413,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Object clone() { public Object clone() {
HashMap<K,V> result; HashMap<K, V> result;
try { try {
result = (HashMap<K,V>)super.clone(); result = (HashMap<K, V>) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable // this shouldn't happen, since we are Cloneable
throw new InternalError(e); throw new InternalError(e);
...@@ -1326,7 +1426,10 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1326,7 +1426,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
// These methods are also used when serializing HashSets // These methods are also used when serializing HashSets
final float loadFactor() { return loadFactor; } final float loadFactor() {
return loadFactor;
}
final int capacity() { final int capacity() {
return (table != null) ? table.length : return (table != null) ? table.length :
(threshold > 0) ? threshold : (threshold > 0) ? threshold :
...@@ -1375,17 +1478,17 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1375,17 +1478,17 @@ public class HashMap<K,V> extends AbstractMap<K,V>
// Size the table using given load factor only if within // Size the table using given load factor only if within
// range of 0.25...4.0 // range of 0.25...4.0
float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f); float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f);
float fc = (float)mappings / lf + 1.0f; float fc = (float) mappings / lf + 1.0f;
int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ? int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ?
DEFAULT_INITIAL_CAPACITY : DEFAULT_INITIAL_CAPACITY :
(fc >= MAXIMUM_CAPACITY) ? (fc >= MAXIMUM_CAPACITY) ?
MAXIMUM_CAPACITY : MAXIMUM_CAPACITY :
tableSizeFor((int)fc)); tableSizeFor((int) fc));
float ft = (float)cap * lf; float ft = (float) cap * lf;
threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ? threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ?
(int)ft : Integer.MAX_VALUE); (int) ft : Integer.MAX_VALUE);
@SuppressWarnings({"rawtypes","unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
Node<K,V>[] tab = (Node<K,V>[])new Node[cap]; Node<K, V>[] tab = (Node<K, V>[]) new Node[cap];
table = tab; table = tab;
// Read the keys and values, and put the mappings in the HashMap // Read the keys and values, and put the mappings in the HashMap
...@@ -1403,18 +1506,19 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1403,18 +1506,19 @@ public class HashMap<K,V> extends AbstractMap<K,V>
// iterators // iterators
abstract class HashIterator { abstract class HashIterator {
Node<K,V> next; // next entry to return Node<K, V> next; // next entry to return
Node<K,V> current; // current entry Node<K, V> current; // current entry
int expectedModCount; // for fast-fail int expectedModCount; // for fast-fail
int index; // current slot int index; // current slot
HashIterator() { HashIterator() {
expectedModCount = modCount; expectedModCount = modCount;
Node<K,V>[] t = table; Node<K, V>[] t = table;
current = next = null; current = next = null;
index = 0; index = 0;
if (t != null && size > 0) { // advance to first entry if (t != null && size > 0) { // advance to first entry
do {} while (index < t.length && (next = t[index++]) == null); do {
} while (index < t.length && (next = t[index++]) == null);
} }
} }
...@@ -1422,21 +1526,22 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1422,21 +1526,22 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return next != null; return next != null;
} }
final Node<K,V> nextNode() { final Node<K, V> nextNode() {
Node<K,V>[] t; Node<K, V>[] t;
Node<K,V> e = next; Node<K, V> e = next;
if (modCount != expectedModCount) if (modCount != expectedModCount)
throw new ConcurrentModificationException(); throw new ConcurrentModificationException();
if (e == null) if (e == null)
throw new NoSuchElementException(); throw new NoSuchElementException();
if ((next = (current = e).next) == null && (t = table) != null) { if ((next = (current = e).next) == null && (t = table) != null) {
do {} while (index < t.length && (next = t[index++]) == null); do {
} while (index < t.length && (next = t[index++]) == null);
} }
return e; return e;
} }
public final void remove() { public final void remove() {
Node<K,V> p = current; Node<K, V> p = current;
if (p == null) if (p == null)
throw new IllegalStateException(); throw new IllegalStateException();
if (modCount != expectedModCount) if (modCount != expectedModCount)
...@@ -1450,31 +1555,40 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1450,31 +1555,40 @@ public class HashMap<K,V> extends AbstractMap<K,V>
final class KeyIterator extends HashIterator final class KeyIterator extends HashIterator
implements Iterator<K> { implements Iterator<K> {
public final K next() { return nextNode().key; } @Override
public final K next() {
return nextNode().key;
}
} }
final class ValueIterator extends HashIterator final class ValueIterator extends HashIterator
implements Iterator<V> { implements Iterator<V> {
public final V next() { return nextNode().value; } @Override
public final V next() {
return nextNode().value;
}
} }
final class EntryIterator extends HashIterator final class EntryIterator extends HashIterator
implements Iterator<Map.Entry<K,V>> { implements Iterator<Map.Entry<K, V>> {
public final Map.Entry<K,V> next() { return nextNode(); } @Override
public final Map.Entry<K, V> next() {
return nextNode();
}
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
// spliterators // spliterators
static class HashMapSpliterator<K,V> { static class HashMapSpliterator<K, V> {
final HashMap<K,V> map; final HashMap<K, V> map;
Node<K,V> current; // current node Node<K, V> current; // current node
int index; // current index, modified on advance/split int index; // current index, modified on advance/split
int fence; // one past last index int fence; // one past last index
int est; // size estimate int est; // size estimate
int expectedModCount; // for comodification checks int expectedModCount; // for comodification checks
HashMapSpliterator(HashMap<K,V> m, int origin, HashMapSpliterator(HashMap<K, V> m, int origin,
int fence, int est, int fence, int est,
int expectedModCount) { int expectedModCount) {
this.map = m; this.map = m;
...@@ -1487,10 +1601,10 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1487,10 +1601,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
final int getFence() { // initialize fence and size on first use final int getFence() { // initialize fence and size on first use
int hi; int hi;
if ((hi = fence) < 0) { if ((hi = fence) < 0) {
HashMap<K,V> m = map; HashMap<K, V> m = map;
est = m.size; est = m.size;
expectedModCount = m.modCount; expectedModCount = m.modCount;
Node<K,V>[] tab = m.table; Node<K, V>[] tab = m.table;
hi = fence = (tab == null) ? 0 : tab.length; hi = fence = (tab == null) ? 0 : tab.length;
} }
return hi; return hi;
...@@ -1502,36 +1616,37 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1502,36 +1616,37 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
} }
static final class KeySpliterator<K,V> static final class KeySpliterator<K, V>
extends HashMapSpliterator<K,V> extends HashMapSpliterator<K, V>
implements Spliterator<K> { implements Spliterator<K> {
KeySpliterator(HashMap<K,V> m, int origin, int fence, int est, KeySpliterator(HashMap<K, V> m, int origin, int fence, int est,
int expectedModCount) { int expectedModCount) {
super(m, origin, fence, est, expectedModCount); super(m, origin, fence, est, expectedModCount);
} }
public KeySpliterator<K,V> trySplit() { @Override
public KeySpliterator<K, V> trySplit() {
int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
return (lo >= mid || current != null) ? null : return (lo >= mid || current != null) ? null :
new KeySpliterator<>(map, lo, index = mid, est >>>= 1, new KeySpliterator<>(map, lo, index = mid, est >>>= 1,
expectedModCount); expectedModCount);
} }
@Override
public void forEachRemaining(Consumer<? super K> action) { public void forEachRemaining(Consumer<? super K> action) {
int i, hi, mc; int i, hi, mc;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
HashMap<K,V> m = map; HashMap<K, V> m = map;
Node<K,V>[] tab = m.table; Node<K, V>[] tab = m.table;
if ((hi = fence) < 0) { if ((hi = fence) < 0) {
mc = expectedModCount = m.modCount; mc = expectedModCount = m.modCount;
hi = fence = (tab == null) ? 0 : tab.length; hi = fence = (tab == null) ? 0 : tab.length;
} } else
else
mc = expectedModCount; mc = expectedModCount;
if (tab != null && tab.length >= hi && if (tab != null && tab.length >= hi &&
(i = index) >= 0 && (i < (index = hi) || current != null)) { (i = index) >= 0 && (i < (index = hi) || current != null)) {
Node<K,V> p = current; Node<K, V> p = current;
current = null; current = null;
do { do {
if (p == null) if (p == null)
...@@ -1546,11 +1661,12 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1546,11 +1661,12 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
} }
@Override
public boolean tryAdvance(Consumer<? super K> action) { public boolean tryAdvance(Consumer<? super K> action) {
int hi; int hi;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
Node<K,V>[] tab = map.table; Node<K, V>[] tab = map.table;
if (tab != null && tab.length >= (hi = getFence()) && index >= 0) { if (tab != null && tab.length >= (hi = getFence()) && index >= 0) {
while (current != null || index < hi) { while (current != null || index < hi) {
if (current == null) if (current == null)
...@@ -1568,42 +1684,44 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1568,42 +1684,44 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return false; return false;
} }
@Override
public int characteristics() { public int characteristics() {
return (fence < 0 || est == map.size ? Spliterator.SIZED : 0) | return (fence < 0 || est == map.size ? Spliterator.SIZED : 0) |
Spliterator.DISTINCT; Spliterator.DISTINCT;
} }
} }
static final class ValueSpliterator<K,V> static final class ValueSpliterator<K, V>
extends HashMapSpliterator<K,V> extends HashMapSpliterator<K, V>
implements Spliterator<V> { implements Spliterator<V> {
ValueSpliterator(HashMap<K,V> m, int origin, int fence, int est, ValueSpliterator(HashMap<K, V> m, int origin, int fence, int est,
int expectedModCount) { int expectedModCount) {
super(m, origin, fence, est, expectedModCount); super(m, origin, fence, est, expectedModCount);
} }
public ValueSpliterator<K,V> trySplit() { @Override
public ValueSpliterator<K, V> trySplit() {
int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
return (lo >= mid || current != null) ? null : return (lo >= mid || current != null) ? null :
new ValueSpliterator<>(map, lo, index = mid, est >>>= 1, new ValueSpliterator<>(map, lo, index = mid, est >>>= 1,
expectedModCount); expectedModCount);
} }
@Override
public void forEachRemaining(Consumer<? super V> action) { public void forEachRemaining(Consumer<? super V> action) {
int i, hi, mc; int i, hi, mc;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
HashMap<K,V> m = map; HashMap<K, V> m = map;
Node<K,V>[] tab = m.table; Node<K, V>[] tab = m.table;
if ((hi = fence) < 0) { if ((hi = fence) < 0) {
mc = expectedModCount = m.modCount; mc = expectedModCount = m.modCount;
hi = fence = (tab == null) ? 0 : tab.length; hi = fence = (tab == null) ? 0 : tab.length;
} } else
else
mc = expectedModCount; mc = expectedModCount;
if (tab != null && tab.length >= hi && if (tab != null && tab.length >= hi &&
(i = index) >= 0 && (i < (index = hi) || current != null)) { (i = index) >= 0 && (i < (index = hi) || current != null)) {
Node<K,V> p = current; Node<K, V> p = current;
current = null; current = null;
do { do {
if (p == null) if (p == null)
...@@ -1618,11 +1736,12 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1618,11 +1736,12 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
} }
@Override
public boolean tryAdvance(Consumer<? super V> action) { public boolean tryAdvance(Consumer<? super V> action) {
int hi; int hi;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
Node<K,V>[] tab = map.table; Node<K, V>[] tab = map.table;
if (tab != null && tab.length >= (hi = getFence()) && index >= 0) { if (tab != null && tab.length >= (hi = getFence()) && index >= 0) {
while (current != null || index < hi) { while (current != null || index < hi) {
if (current == null) if (current == null)
...@@ -1640,41 +1759,43 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1640,41 +1759,43 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return false; return false;
} }
@Override
public int characteristics() { public int characteristics() {
return (fence < 0 || est == map.size ? Spliterator.SIZED : 0); return (fence < 0 || est == map.size ? Spliterator.SIZED : 0);
} }
} }
static final class EntrySpliterator<K,V> static final class EntrySpliterator<K, V>
extends HashMapSpliterator<K,V> extends HashMapSpliterator<K, V>
implements Spliterator<Map.Entry<K,V>> { implements Spliterator<Map.Entry<K, V>> {
EntrySpliterator(HashMap<K,V> m, int origin, int fence, int est, EntrySpliterator(HashMap<K, V> m, int origin, int fence, int est,
int expectedModCount) { int expectedModCount) {
super(m, origin, fence, est, expectedModCount); super(m, origin, fence, est, expectedModCount);
} }
public EntrySpliterator<K,V> trySplit() { @Override
public EntrySpliterator<K, V> trySplit() {
int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
return (lo >= mid || current != null) ? null : return (lo >= mid || current != null) ? null :
new EntrySpliterator<>(map, lo, index = mid, est >>>= 1, new EntrySpliterator<>(map, lo, index = mid, est >>>= 1,
expectedModCount); expectedModCount);
} }
public void forEachRemaining(Consumer<? super Map.Entry<K,V>> action) { @Override
public void forEachRemaining(Consumer<? super Map.Entry<K, V>> action) {
int i, hi, mc; int i, hi, mc;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
HashMap<K,V> m = map; HashMap<K, V> m = map;
Node<K,V>[] tab = m.table; Node<K, V>[] tab = m.table;
if ((hi = fence) < 0) { if ((hi = fence) < 0) {
mc = expectedModCount = m.modCount; mc = expectedModCount = m.modCount;
hi = fence = (tab == null) ? 0 : tab.length; hi = fence = (tab == null) ? 0 : tab.length;
} } else
else
mc = expectedModCount; mc = expectedModCount;
if (tab != null && tab.length >= hi && if (tab != null && tab.length >= hi &&
(i = index) >= 0 && (i < (index = hi) || current != null)) { (i = index) >= 0 && (i < (index = hi) || current != null)) {
Node<K,V> p = current; Node<K, V> p = current;
current = null; current = null;
do { do {
if (p == null) if (p == null)
...@@ -1689,17 +1810,18 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1689,17 +1810,18 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
} }
public boolean tryAdvance(Consumer<? super Map.Entry<K,V>> action) { @Override
public boolean tryAdvance(Consumer<? super Map.Entry<K, V>> action) {
int hi; int hi;
if (action == null) if (action == null)
throw new NullPointerException(); throw new NullPointerException();
Node<K,V>[] tab = map.table; Node<K, V>[] tab = map.table;
if (tab != null && tab.length >= (hi = getFence()) && index >= 0) { if (tab != null && tab.length >= (hi = getFence()) && index >= 0) {
while (current != null || index < hi) { while (current != null || index < hi) {
if (current == null) if (current == null)
current = tab[index++]; current = tab[index++];
else { else {
Node<K,V> e = current; Node<K, V> e = current;
current = current.next; current = current.next;
action.accept(e); action.accept(e);
if (map.modCount != expectedModCount) if (map.modCount != expectedModCount)
...@@ -1711,6 +1833,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1711,6 +1833,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return false; return false;
} }
@Override
public int characteristics() { public int characteristics() {
return (fence < 0 || est == map.size ? Spliterator.SIZED : 0) | return (fence < 0 || est == map.size ? Spliterator.SIZED : 0) |
Spliterator.DISTINCT; Spliterator.DISTINCT;
...@@ -1730,22 +1853,22 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1730,22 +1853,22 @@ public class HashMap<K,V> extends AbstractMap<K,V>
*/ */
// Create a regular (non-tree) node // Create a regular (non-tree) node
Node<K,V> newNode(int hash, K key, V value, Node<K,V> next) { Node<K, V> newNode(int hash, K key, V value, Node<K, V> next) {
return new Node<>(hash, key, value, next); return new Node<>(hash, key, value, next);
} }
// For conversion from TreeNodes to plain nodes // For conversion from TreeNodes to plain nodes
Node<K,V> replacementNode(Node<K,V> p, Node<K,V> next) { Node<K, V> replacementNode(Node<K, V> p, Node<K, V> next) {
return new Node<>(p.hash, p.key, p.value, next); return new Node<>(p.hash, p.key, p.value, next);
} }
// Create a tree bin node // Create a tree bin node
TreeNode<K,V> newTreeNode(int hash, K key, V value, Node<K,V> next) { TreeNode<K, V> newTreeNode(int hash, K key, V value, Node<K, V> next) {
return new TreeNode<>(hash, key, value, next); return new TreeNode<>(hash, key, value, next);
} }
// For treeifyBin // For treeifyBin
TreeNode<K,V> replacementTreeNode(Node<K,V> p, Node<K,V> next) { TreeNode<K, V> replacementTreeNode(Node<K, V> p, Node<K, V> next) {
return new TreeNode<>(p.hash, p.key, p.value, next); return new TreeNode<>(p.hash, p.key, p.value, next);
} }
...@@ -1763,16 +1886,21 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1763,16 +1886,21 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
// Callbacks to allow LinkedHashMap post-actions // Callbacks to allow LinkedHashMap post-actions
void afterNodeAccess(Node<K,V> p) { } void afterNodeAccess(Node<K, V> p) {
void afterNodeInsertion(boolean evict) { } }
void afterNodeRemoval(Node<K,V> p) { }
void afterNodeInsertion(boolean evict) {
}
void afterNodeRemoval(Node<K, V> p) {
}
// Called only from writeObject, to ensure compatible ordering. // Called only from writeObject, to ensure compatible ordering.
void internalWriteEntries(java.io.ObjectOutputStream s) throws IOException { void internalWriteEntries(java.io.ObjectOutputStream s) throws IOException {
Node<K,V>[] tab; Node<K, V>[] tab;
if (size > 0 && (tab = table) != null) { if (size > 0 && (tab = table) != null) {
for (int i = 0; i < tab.length; ++i) { for (int i = 0; i < tab.length; ++i) {
for (Node<K,V> e = tab[i]; e != null; e = e.next) { for (Node<K, V> e = tab[i]; e != null; e = e.next) {
s.writeObject(e.key); s.writeObject(e.key);
s.writeObject(e.value); s.writeObject(e.value);
} }
...@@ -1788,21 +1916,22 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1788,21 +1916,22 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* extends Node) so can be used as extension of either regular or * extends Node) so can be used as extension of either regular or
* linked node. * linked node.
*/ */
static final class TreeNode<K,V> extends LinkedHashMap.Entry<K,V> { static final class TreeNode<K, V> extends LinkedHashMap.Entry<K, V> {
TreeNode<K,V> parent; // red-black tree links TreeNode<K, V> parent; // red-black tree links
TreeNode<K,V> left; TreeNode<K, V> left;
TreeNode<K,V> right; TreeNode<K, V> right;
TreeNode<K,V> prev; // needed to unlink next upon deletion TreeNode<K, V> prev; // needed to unlink next upon deletion
boolean red; boolean red;
TreeNode(int hash, K key, V val, Node<K,V> next) {
TreeNode(int hash, K key, V val, Node<K, V> next) {
super(hash, key, val, next); super(hash, key, val, next);
} }
/** /**
* Returns root of tree containing this node. * Returns root of tree containing this node.
*/ */
final TreeNode<K,V> root() { final TreeNode<K, V> root() {
for (TreeNode<K,V> r = this, p;;) { for (TreeNode<K, V> r = this, p; ; ) {
if ((p = r.parent) == null) if ((p = r.parent) == null)
return r; return r;
r = p; r = p;
...@@ -1812,17 +1941,17 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1812,17 +1941,17 @@ public class HashMap<K,V> extends AbstractMap<K,V>
/** /**
* Ensures that the given root is the first node of its bin. * Ensures that the given root is the first node of its bin.
*/ */
static <K,V> void moveRootToFront(Node<K,V>[] tab, TreeNode<K,V> root) { static <K, V> void moveRootToFront(Node<K, V>[] tab, TreeNode<K, V> root) {
int n; int n;
if (root != null && tab != null && (n = tab.length) > 0) { if (root != null && tab != null && (n = tab.length) > 0) {
int index = (n - 1) & root.hash; int index = (n - 1) & root.hash;
TreeNode<K,V> first = (TreeNode<K,V>)tab[index]; TreeNode<K, V> first = (TreeNode<K, V>) tab[index];
if (root != first) { if (root != first) {
Node<K,V> rn; Node<K, V> rn;
tab[index] = root; tab[index] = root;
TreeNode<K,V> rp = root.prev; TreeNode<K, V> rp = root.prev;
if ((rn = root.next) != null) if ((rn = root.next) != null)
((TreeNode<K,V>)rn).prev = rp; ((TreeNode<K, V>) rn).prev = rp;
if (rp != null) if (rp != null)
rp.next = rn; rp.next = rn;
if (first != null) if (first != null)
...@@ -1839,11 +1968,12 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1839,11 +1968,12 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* The kc argument caches comparableClassFor(key) upon first use * The kc argument caches comparableClassFor(key) upon first use
* comparing keys. * comparing keys.
*/ */
final TreeNode<K,V> find(int h, Object k, Class<?> kc) { final TreeNode<K, V> find(int h, Object k, Class<?> kc) {
TreeNode<K,V> p = this; TreeNode<K, V> p = this;
do { do {
int ph, dir; K pk; int ph, dir;
TreeNode<K,V> pl = p.left, pr = p.right, q; K pk;
TreeNode<K, V> pl = p.left, pr = p.right, q;
if ((ph = p.hash) > h) if ((ph = p.hash) > h)
p = pl; p = pl;
else if (ph < h) else if (ph < h)
...@@ -1869,7 +1999,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1869,7 +1999,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
/** /**
* Calls find for root node. * Calls find for root node.
*/ */
final TreeNode<K,V> getTreeNode(int h, Object k) { final TreeNode<K, V> getTreeNode(int h, Object k) {
return ((parent != null) ? root() : this).find(h, k, null); return ((parent != null) ? root() : this).find(h, k, null);
} }
...@@ -1892,23 +2022,23 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1892,23 +2022,23 @@ public class HashMap<K,V> extends AbstractMap<K,V>
/** /**
* Forms tree of the nodes linked from this node. * Forms tree of the nodes linked from this node.
*
* @return root of tree * @return root of tree
*/ */
final void treeify(Node<K,V>[] tab) { final void treeify(Node<K, V>[] tab) {
TreeNode<K,V> root = null; TreeNode<K, V> root = null;
for (TreeNode<K,V> x = this, next; x != null; x = next) { for (TreeNode<K, V> x = this, next; x != null; x = next) {
next = (TreeNode<K,V>)x.next; next = (TreeNode<K, V>) x.next;
x.left = x.right = null; x.left = x.right = null;
if (root == null) { if (root == null) {
x.parent = null; x.parent = null;
x.red = false; x.red = false;
root = x; root = x;
} } else {
else {
K k = x.key; K k = x.key;
int h = x.hash; int h = x.hash;
Class<?> kc = null; Class<?> kc = null;
for (TreeNode<K,V> p = root;;) { for (TreeNode<K, V> p = root; ; ) {
int dir, ph; int dir, ph;
K pk = p.key; K pk = p.key;
if ((ph = p.hash) > h) if ((ph = p.hash) > h)
...@@ -1920,7 +2050,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1920,7 +2050,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
(dir = compareComparables(kc, k, pk)) == 0) (dir = compareComparables(kc, k, pk)) == 0)
dir = tieBreakOrder(k, pk); dir = tieBreakOrder(k, pk);
TreeNode<K,V> xp = p; TreeNode<K, V> xp = p;
if ((p = (dir <= 0) ? p.left : p.right) == null) { if ((p = (dir <= 0) ? p.left : p.right) == null) {
x.parent = xp; x.parent = xp;
if (dir <= 0) if (dir <= 0)
...@@ -1940,10 +2070,10 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1940,10 +2070,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* Returns a list of non-TreeNodes replacing those linked from * Returns a list of non-TreeNodes replacing those linked from
* this node. * this node.
*/ */
final Node<K,V> untreeify(HashMap<K,V> map) { final Node<K, V> untreeify(HashMap<K, V> map) {
Node<K,V> hd = null, tl = null; Node<K, V> hd = null, tl = null;
for (Node<K,V> q = this; q != null; q = q.next) { for (Node<K, V> q = this; q != null; q = q.next) {
Node<K,V> p = map.replacementNode(q, null); Node<K, V> p = map.replacementNode(q, null);
if (tl == null) if (tl == null)
hd = p; hd = p;
else else
...@@ -1956,13 +2086,14 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1956,13 +2086,14 @@ public class HashMap<K,V> extends AbstractMap<K,V>
/** /**
* Tree version of putVal. * Tree version of putVal.
*/ */
final TreeNode<K,V> putTreeVal(HashMap<K,V> map, Node<K,V>[] tab, final TreeNode<K, V> putTreeVal(HashMap<K, V> map, Node<K, V>[] tab,
int h, K k, V v) { int h, K k, V v) {
Class<?> kc = null; Class<?> kc = null;
boolean searched = false; boolean searched = false;
TreeNode<K,V> root = (parent != null) ? root() : this; TreeNode<K, V> root = (parent != null) ? root() : this;
for (TreeNode<K,V> p = root;;) { for (TreeNode<K, V> p = root; ; ) {
int dir, ph; K pk; int dir, ph;
K pk;
if ((ph = p.hash) > h) if ((ph = p.hash) > h)
dir = -1; dir = -1;
else if (ph < h) else if (ph < h)
...@@ -1973,7 +2104,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1973,7 +2104,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
(kc = comparableClassFor(k)) == null) || (kc = comparableClassFor(k)) == null) ||
(dir = compareComparables(kc, k, pk)) == 0) { (dir = compareComparables(kc, k, pk)) == 0) {
if (!searched) { if (!searched) {
TreeNode<K,V> q, ch; TreeNode<K, V> q, ch;
searched = true; searched = true;
if (((ch = p.left) != null && if (((ch = p.left) != null &&
(q = ch.find(h, k, kc)) != null) || (q = ch.find(h, k, kc)) != null) ||
...@@ -1984,10 +2115,10 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1984,10 +2115,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
dir = tieBreakOrder(k, pk); dir = tieBreakOrder(k, pk);
} }
TreeNode<K,V> xp = p; TreeNode<K, V> xp = p;
if ((p = (dir <= 0) ? p.left : p.right) == null) { if ((p = (dir <= 0) ? p.left : p.right) == null) {
Node<K,V> xpn = xp.next; Node<K, V> xpn = xp.next;
TreeNode<K,V> x = map.newTreeNode(h, k, v, xpn); TreeNode<K, V> x = map.newTreeNode(h, k, v, xpn);
if (dir <= 0) if (dir <= 0)
xp.left = x; xp.left = x;
else else
...@@ -1995,7 +2126,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -1995,7 +2126,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
xp.next = x; xp.next = x;
x.parent = x.prev = xp; x.parent = x.prev = xp;
if (xpn != null) if (xpn != null)
((TreeNode<K,V>)xpn).prev = x; ((TreeNode<K, V>) xpn).prev = x;
moveRootToFront(tab, balanceInsertion(root, x)); moveRootToFront(tab, balanceInsertion(root, x));
return null; return null;
} }
...@@ -2012,14 +2143,14 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2012,14 +2143,14 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* the bin is converted back to a plain bin. (The test triggers * the bin is converted back to a plain bin. (The test triggers
* somewhere between 2 and 6 nodes, depending on tree structure). * somewhere between 2 and 6 nodes, depending on tree structure).
*/ */
final void removeTreeNode(HashMap<K,V> map, Node<K,V>[] tab, final void removeTreeNode(HashMap<K, V> map, Node<K, V>[] tab,
boolean movable) { boolean movable) {
int n; int n;
if (tab == null || (n = tab.length) == 0) if (tab == null || (n = tab.length) == 0)
return; return;
int index = (n - 1) & hash; int index = (n - 1) & hash;
TreeNode<K,V> first = (TreeNode<K,V>)tab[index], root = first, rl; TreeNode<K, V> first = (TreeNode<K, V>) tab[index], root = first, rl;
TreeNode<K,V> succ = (TreeNode<K,V>)next, pred = prev; TreeNode<K, V> succ = (TreeNode<K, V>) next, pred = prev;
if (pred == null) if (pred == null)
tab[index] = first = succ; tab[index] = first = succ;
else else
...@@ -2035,20 +2166,21 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2035,20 +2166,21 @@ public class HashMap<K,V> extends AbstractMap<K,V>
tab[index] = first.untreeify(map); // too small tab[index] = first.untreeify(map); // too small
return; return;
} }
TreeNode<K,V> p = this, pl = left, pr = right, replacement; TreeNode<K, V> p = this, pl = left, pr = right, replacement;
if (pl != null && pr != null) { if (pl != null && pr != null) {
TreeNode<K,V> s = pr, sl; TreeNode<K, V> s = pr, sl;
while ((sl = s.left) != null) // find successor while ((sl = s.left) != null) // find successor
s = sl; s = sl;
boolean c = s.red; s.red = p.red; p.red = c; // swap colors boolean c = s.red;
TreeNode<K,V> sr = s.right; s.red = p.red;
TreeNode<K,V> pp = p.parent; p.red = c; // swap colors
TreeNode<K, V> sr = s.right;
TreeNode<K, V> pp = p.parent;
if (s == pr) { // p was s's direct parent if (s == pr) { // p was s's direct parent
p.parent = s; p.parent = s;
s.right = p; s.right = p;
} } else {
else { TreeNode<K, V> sp = s.parent;
TreeNode<K,V> sp = s.parent;
if ((p.parent = sp) != null) { if ((p.parent = sp) != null) {
if (s == sp.left) if (s == sp.left)
sp.left = p; sp.left = p;
...@@ -2073,15 +2205,14 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2073,15 +2205,14 @@ public class HashMap<K,V> extends AbstractMap<K,V>
replacement = sr; replacement = sr;
else else
replacement = p; replacement = p;
} } else if (pl != null)
else if (pl != null)
replacement = pl; replacement = pl;
else if (pr != null) else if (pr != null)
replacement = pr; replacement = pr;
else else
replacement = p; replacement = p;
if (replacement != p) { if (replacement != p) {
TreeNode<K,V> pp = replacement.parent = p.parent; TreeNode<K, V> pp = replacement.parent = p.parent;
if (pp == null) if (pp == null)
root = replacement; root = replacement;
else if (p == pp.left) else if (p == pp.left)
...@@ -2091,10 +2222,10 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2091,10 +2222,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
p.left = p.right = p.parent = null; p.left = p.right = p.parent = null;
} }
TreeNode<K,V> r = p.red ? root : balanceDeletion(root, replacement); TreeNode<K, V> r = p.red ? root : balanceDeletion(root, replacement);
if (replacement == p) { // detach if (replacement == p) { // detach
TreeNode<K,V> pp = p.parent; TreeNode<K, V> pp = p.parent;
p.parent = null; p.parent = null;
if (pp != null) { if (pp != null) {
if (p == pp.left) if (p == pp.left)
...@@ -2117,14 +2248,14 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2117,14 +2248,14 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* @param index the index of the table being split * @param index the index of the table being split
* @param bit the bit of hash to split on * @param bit the bit of hash to split on
*/ */
final void split(HashMap<K,V> map, Node<K,V>[] tab, int index, int bit) { final void split(HashMap<K, V> map, Node<K, V>[] tab, int index, int bit) {
TreeNode<K,V> b = this; TreeNode<K, V> b = this;
// Relink into lo and hi lists, preserving order // Relink into lo and hi lists, preserving order
TreeNode<K,V> loHead = null, loTail = null; TreeNode<K, V> loHead = null, loTail = null;
TreeNode<K,V> hiHead = null, hiTail = null; TreeNode<K, V> hiHead = null, hiTail = null;
int lc = 0, hc = 0; int lc = 0, hc = 0;
for (TreeNode<K,V> e = b, next; e != null; e = next) { for (TreeNode<K, V> e = b, next; e != null; e = next) {
next = (TreeNode<K,V>)e.next; next = (TreeNode<K, V>) e.next;
e.next = null; e.next = null;
if ((e.hash & bit) == 0) { if ((e.hash & bit) == 0) {
if ((e.prev = loTail) == null) if ((e.prev = loTail) == null)
...@@ -2133,8 +2264,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2133,8 +2264,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
loTail.next = e; loTail.next = e;
loTail = e; loTail = e;
++lc; ++lc;
} } else {
else {
if ((e.prev = hiTail) == null) if ((e.prev = hiTail) == null)
hiHead = e; hiHead = e;
else else
...@@ -2167,9 +2297,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2167,9 +2297,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
// Red-black tree methods, all adapted from CLR // Red-black tree methods, all adapted from CLR
static <K,V> TreeNode<K,V> rotateLeft(TreeNode<K,V> root, static <K, V> TreeNode<K, V> rotateLeft(TreeNode<K, V> root,
TreeNode<K,V> p) { TreeNode<K, V> p) {
TreeNode<K,V> r, pp, rl; TreeNode<K, V> r, pp, rl;
if (p != null && (r = p.right) != null) { if (p != null && (r = p.right) != null) {
if ((rl = p.right = r.left) != null) if ((rl = p.right = r.left) != null)
rl.parent = p; rl.parent = p;
...@@ -2185,9 +2315,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2185,9 +2315,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return root; return root;
} }
static <K,V> TreeNode<K,V> rotateRight(TreeNode<K,V> root, static <K, V> TreeNode<K, V> rotateRight(TreeNode<K, V> root,
TreeNode<K,V> p) { TreeNode<K, V> p) {
TreeNode<K,V> l, pp, lr; TreeNode<K, V> l, pp, lr;
if (p != null && (l = p.left) != null) { if (p != null && (l = p.left) != null) {
if ((lr = p.left = l.right) != null) if ((lr = p.left = l.right) != null)
lr.parent = p; lr.parent = p;
...@@ -2203,15 +2333,14 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2203,15 +2333,14 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return root; return root;
} }
static <K,V> TreeNode<K,V> balanceInsertion(TreeNode<K,V> root, static <K, V> TreeNode<K, V> balanceInsertion(TreeNode<K, V> root,
TreeNode<K,V> x) { TreeNode<K, V> x) {
x.red = true; x.red = true;
for (TreeNode<K,V> xp, xpp, xppl, xppr;;) { for (TreeNode<K, V> xp, xpp, xppl, xppr; ; ) {
if ((xp = x.parent) == null) { if ((xp = x.parent) == null) {
x.red = false; x.red = false;
return x; return x;
} } else if (!xp.red || (xpp = xp.parent) == null)
else if (!xp.red || (xpp = xp.parent) == null)
return root; return root;
if (xp == (xppl = xpp.left)) { if (xp == (xppl = xpp.left)) {
if ((xppr = xpp.right) != null && xppr.red) { if ((xppr = xpp.right) != null && xppr.red) {
...@@ -2219,8 +2348,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2219,8 +2348,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
xp.red = false; xp.red = false;
xpp.red = true; xpp.red = true;
x = xpp; x = xpp;
} } else {
else {
if (x == xp.right) { if (x == xp.right) {
root = rotateLeft(root, x = xp); root = rotateLeft(root, x = xp);
xpp = (xp = x.parent) == null ? null : xp.parent; xpp = (xp = x.parent) == null ? null : xp.parent;
...@@ -2233,15 +2361,13 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2233,15 +2361,13 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
} }
} }
} } else {
else {
if (xppl != null && xppl.red) { if (xppl != null && xppl.red) {
xppl.red = false; xppl.red = false;
xp.red = false; xp.red = false;
xpp.red = true; xpp.red = true;
x = xpp; x = xpp;
} } else {
else {
if (x == xp.left) { if (x == xp.left) {
root = rotateRight(root, x = xp); root = rotateRight(root, x = xp);
xpp = (xp = x.parent) == null ? null : xp.parent; xpp = (xp = x.parent) == null ? null : xp.parent;
...@@ -2258,20 +2384,18 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2258,20 +2384,18 @@ public class HashMap<K,V> extends AbstractMap<K,V>
} }
} }
static <K,V> TreeNode<K,V> balanceDeletion(TreeNode<K,V> root, static <K, V> TreeNode<K, V> balanceDeletion(TreeNode<K, V> root,
TreeNode<K,V> x) { TreeNode<K, V> x) {
for (TreeNode<K,V> xp, xpl, xpr;;) { for (TreeNode<K, V> xp, xpl, xpr; ; ) {
if (x == null || x == root) if (x == null || x == root)
return root; return root;
else if ((xp = x.parent) == null) { else if ((xp = x.parent) == null) {
x.red = false; x.red = false;
return x; return x;
} } else if (x.red) {
else if (x.red) {
x.red = false; x.red = false;
return root; return root;
} } else if ((xpl = xp.left) == x) {
else if ((xpl = xp.left) == x) {
if ((xpr = xp.right) != null && xpr.red) { if ((xpr = xp.right) != null && xpr.red) {
xpr.red = false; xpr.red = false;
xp.red = true; xp.red = true;
...@@ -2281,13 +2405,12 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2281,13 +2405,12 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (xpr == null) if (xpr == null)
x = xp; x = xp;
else { else {
TreeNode<K,V> sl = xpr.left, sr = xpr.right; TreeNode<K, V> sl = xpr.left, sr = xpr.right;
if ((sr == null || !sr.red) && if ((sr == null || !sr.red) &&
(sl == null || !sl.red)) { (sl == null || !sl.red)) {
xpr.red = true; xpr.red = true;
x = xp; x = xp;
} } else {
else {
if (sr == null || !sr.red) { if (sr == null || !sr.red) {
if (sl != null) if (sl != null)
sl.red = false; sl.red = false;
...@@ -2308,8 +2431,7 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2308,8 +2431,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
x = root; x = root;
} }
} }
} } else { // symmetric
else { // symmetric
if (xpl != null && xpl.red) { if (xpl != null && xpl.red) {
xpl.red = false; xpl.red = false;
xp.red = true; xp.red = true;
...@@ -2319,13 +2441,12 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2319,13 +2441,12 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (xpl == null) if (xpl == null)
x = xp; x = xp;
else { else {
TreeNode<K,V> sl = xpl.left, sr = xpl.right; TreeNode<K, V> sl = xpl.left, sr = xpl.right;
if ((sl == null || !sl.red) && if ((sl == null || !sl.red) &&
(sr == null || !sr.red)) { (sr == null || !sr.red)) {
xpl.red = true; xpl.red = true;
x = xp; x = xp;
} } else {
else {
if (sl == null || !sl.red) { if (sl == null || !sl.red) {
if (sr != null) if (sr != null)
sr.red = false; sr.red = false;
...@@ -2353,9 +2474,9 @@ public class HashMap<K,V> extends AbstractMap<K,V> ...@@ -2353,9 +2474,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
/** /**
* Recursive invariant check * Recursive invariant check
*/ */
static <K,V> boolean checkInvariants(TreeNode<K,V> t) { static <K, V> boolean checkInvariants(TreeNode<K, V> t) {
TreeNode<K,V> tp = t.parent, tl = t.left, tr = t.right, TreeNode<K, V> tp = t.parent, tl = t.left, tr = t.right,
tb = t.prev, tn = (TreeNode<K,V>)t.next; tb = t.prev, tn = (TreeNode<K, V>) t.next;
if (tb != null && tb.next != t) if (tb != null && tb.next != t)
return false; return false;
if (tn != null && tn.prev != t) if (tn != null && tn.prev != t)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册