text
stringlengths 30
1.67M
|
|---|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAttribute ; import javax . xml . bind . annotation . XmlType ; import javax . xml . namespace . QName ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" } ) public class Event { protected EventPayload payload ; protected List < Extension > extensions ; @ XmlAttribute ( required = true ) protected QName name ; @ XmlAttribute protected QName type ; public EventPayload getPayload ( ) { return payload ; } public void setPayload ( EventPayload value ) { this . payload = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } public QName getName ( ) { return name ; } public void setName ( QName value ) { this . name = value ; } public QName getType ( ) { return type ; } public void setType ( QName value ) { this . type = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class MimeRequest { protected boolean secureClientCommunication ; @ XmlElement ( required = true ) protected List < String > locales ; @ XmlElement ( required = true ) protected List < String > mimeTypes ; @ XmlElement ( required = true ) protected String mode ; @ XmlElement ( required = true ) protected String windowState ; protected ClientData clientData ; protected NavigationalContext navigationalContext ; protected List < String > markupCharacterSets ; protected String validateTag ; protected List < String > validNewModes ; protected List < String > validNewWindowStates ; protected List < Extension > extensions ; public boolean isSecureClientCommunication ( ) { return secureClientCommunication ; } public void setSecureClientCommunication ( boolean value ) { this . secureClientCommunication = value ; } public List < String > getLocales ( ) { if ( locales == null ) { locales = new ArrayList < String > ( ) ; } return this . locales ; } public List < String > getMimeTypes ( ) { if ( mimeTypes == null ) { mimeTypes = new ArrayList < String > ( ) ; } return this . mimeTypes ; } public String getMode ( ) { return mode ; } public void setMode ( String value ) { this . mode = value ; } public String getWindowState ( ) { return windowState ; } public void setWindowState ( String value ) { this . windowState = value ; } public ClientData getClientData ( ) { return clientData ; } public void setClientData ( ClientData value ) { this . clientData = value ; } public NavigationalContext getNavigationalContext ( ) { return navigationalContext ; } public void setNavigationalContext ( NavigationalContext value ) { this . navigationalContext = value ; } public List < String > getMarkupCharacterSets ( ) { if ( markupCharacterSets == null ) { markupCharacterSets = new ArrayList < String > ( ) ; } return this . markupCharacterSets ; } public String getValidateTag ( ) { return validateTag ; } public void setValidateTag ( String value ) { this . validateTag = value ; } public List < String > getValidNewModes ( ) { if ( validNewModes == null ) { validNewModes = new ArrayList < String > ( ) ; } return this . validNewModes ; } public List < String > getValidNewWindowStates ( ) { if ( validNewWindowStates == null ) { validNewWindowStates = new ArrayList < String > ( ) ; } return this . validNewWindowStates ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" ) public class UnsupportedModeFault extends Fault { } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" } ) public class NamedStringArray { @ XmlElement ( name = "<STR_LIT>" ) protected List < NamedString > namedString ; public List < NamedString > getNamedString ( ) { if ( namedString == null ) { namedString = new ArrayList < NamedString > ( ) ; } return this . namedString ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . math . BigInteger ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAttribute ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" } ) public class ExportDescription { protected List < Extension > extensions ; @ XmlAttribute protected BigInteger recommendedExportSize ; public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } public BigInteger getRecommendedExportSize ( ) { return recommendedExportSize ; } public void setRecommendedExportSize ( BigInteger value ) { this . recommendedExportSize = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class UploadContext { @ XmlElement ( required = true ) protected String mimeType ; @ XmlElement ( required = true ) protected byte [ ] uploadData ; protected List < NamedString > mimeAttributes ; protected List < Extension > extensions ; public String getMimeType ( ) { return mimeType ; } public void setMimeType ( String value ) { this . mimeType = value ; } public byte [ ] getUploadData ( ) { return uploadData ; } public void setUploadData ( byte [ ] value ) { this . uploadData = ( ( byte [ ] ) value ) ; } public List < NamedString > getMimeAttributes ( ) { if ( mimeAttributes == null ) { mimeAttributes = new ArrayList < NamedString > ( ) ; } return this . mimeAttributes ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAttribute ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT:value>" } ) public class NamedString { protected String value ; @ XmlAttribute ( required = true ) protected String name ; public String getValue ( ) { return value ; } public void setValue ( String value ) { this . value = value ; } public String getName ( ) { return name ; } public void setName ( String value ) { this . name = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class SetPortletsLifetime { @ XmlElement ( required = true , nillable = true ) protected RegistrationContext registrationContext ; @ XmlElement ( required = true ) protected List < PortletContext > portletContext ; @ XmlElement ( required = true , nillable = true ) protected UserContext userContext ; @ XmlElement ( required = true , nillable = true ) protected Lifetime lifetime ; public RegistrationContext getRegistrationContext ( ) { return registrationContext ; } public void setRegistrationContext ( RegistrationContext value ) { this . registrationContext = value ; } public List < PortletContext > getPortletContext ( ) { if ( portletContext == null ) { portletContext = new ArrayList < PortletContext > ( ) ; } return this . portletContext ; } public UserContext getUserContext ( ) { return userContext ; } public void setUserContext ( UserContext value ) { this . userContext = value ; } public Lifetime getLifetime ( ) { return lifetime ; } public void setLifetime ( Lifetime value ) { this . lifetime = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" ) public class AccessDeniedFault extends Fault { } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . ws . WebFault ; @ WebFault ( name = "<STR_LIT>" , targetNamespace = "<STR_LIT>" ) public class InvalidSession extends Exception { private InvalidSessionFault faultInfo ; public InvalidSession ( String message , InvalidSessionFault faultInfo ) { super ( message ) ; this . faultInfo = faultInfo ; } public InvalidSession ( String message , InvalidSessionFault faultInfo , Throwable cause ) { super ( message , cause ) ; this . faultInfo = faultInfo ; } public InvalidSessionFault getFaultInfo ( ) { return faultInfo ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" } ) public class ImportPortletsFailed extends BaseFailed { @ XmlElement ( required = true ) protected List < String > importID ; public List < String > getImportID ( ) { if ( importID == null ) { importID = new ArrayList < String > ( ) ; } return this . importID ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" } ) public class ResourceList { @ XmlElement ( required = true ) protected List < Resource > resources ; protected List < Extension > extensions ; public List < Resource > getResources ( ) { if ( resources == null ) { resources = new ArrayList < Resource > ( ) ; } return this . resources ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAnyElement ; import javax . xml . bind . annotation . XmlRootElement ; import javax . xml . bind . annotation . XmlType ; import org . w3c . dom . Element ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" } ) @ XmlRootElement ( name = "<STR_LIT>" ) public class NewMode { @ XmlAnyElement ( lax = true ) protected Object any ; public Object getAny ( ) { return any ; } public void setAny ( Object value ) { this . any = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class DestroyPortlets { @ XmlElement ( required = true , nillable = true ) protected RegistrationContext registrationContext ; @ XmlElement ( required = true ) protected List < String > portletHandles ; @ XmlElement ( required = true , nillable = true ) protected UserContext userContext ; public RegistrationContext getRegistrationContext ( ) { return registrationContext ; } public void setRegistrationContext ( RegistrationContext value ) { this . registrationContext = value ; } public List < String > getPortletHandles ( ) { if ( portletHandles == null ) { portletHandles = new ArrayList < String > ( ) ; } return this . portletHandles ; } public UserContext getUserContext ( ) { return userContext ; } public void setUserContext ( UserContext value ) { this . userContext = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class ModelDescription { protected List < PropertyDescription > propertyDescriptions ; protected ModelTypes modelTypes ; protected List < Extension > extensions ; public List < PropertyDescription > getPropertyDescriptions ( ) { if ( propertyDescriptions == null ) { propertyDescriptions = new ArrayList < PropertyDescription > ( ) ; } return this . propertyDescriptions ; } public ModelTypes getModelTypes ( ) { return modelTypes ; } public void setModelTypes ( ModelTypes value ) { this . modelTypes = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" ) public class OperationFailedFault extends Fault { } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class UserContext { @ XmlElement ( required = true ) protected String userContextKey ; protected List < String > userCategories ; protected UserProfile profile ; protected List < Extension > extensions ; public String getUserContextKey ( ) { return userContextKey ; } public void setUserContextKey ( String value ) { this . userContextKey = value ; } public List < String > getUserCategories ( ) { if ( userCategories == null ) { userCategories = new ArrayList < String > ( ) ; } return this . userCategories ; } public UserProfile getProfile ( ) { return profile ; } public void setProfile ( UserProfile value ) { this . profile = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class Contact { protected Postal postal ; protected Telecom telecom ; protected Online online ; protected List < Extension > extensions ; public Postal getPostal ( ) { return postal ; } public void setPostal ( Postal value ) { this . postal = value ; } public Telecom getTelecom ( ) { return telecom ; } public void setTelecom ( Telecom value ) { this . telecom = value ; } public Online getOnline ( ) { return online ; } public void setOnline ( Online value ) { this . online = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAttribute ; import javax . xml . bind . annotation . XmlType ; import javax . xml . namespace . QName ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class BaseFailed { protected LocalizedString reason ; protected ResourceList resourceList ; protected List < Extension > extensions ; @ XmlAttribute ( required = true ) protected QName errorCode ; public LocalizedString getReason ( ) { return reason ; } public void setReason ( LocalizedString value ) { this . reason = value ; } public ResourceList getResourceList ( ) { return resourceList ; } public void setResourceList ( ResourceList value ) { this . resourceList = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } public QName getErrorCode ( ) { return errorCode ; } public void setErrorCode ( QName value ) { this . errorCode = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class ExportPortlets { @ XmlElement ( required = true , nillable = true ) protected RegistrationContext registrationContext ; @ XmlElement ( required = true ) protected List < PortletContext > portletContext ; @ XmlElement ( required = true , nillable = true ) protected UserContext userContext ; @ XmlElement ( required = true , nillable = true ) protected Lifetime lifetime ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean exportByValueRequired ; public RegistrationContext getRegistrationContext ( ) { return registrationContext ; } public void setRegistrationContext ( RegistrationContext value ) { this . registrationContext = value ; } public List < PortletContext > getPortletContext ( ) { if ( portletContext == null ) { portletContext = new ArrayList < PortletContext > ( ) ; } return this . portletContext ; } public UserContext getUserContext ( ) { return userContext ; } public void setUserContext ( UserContext value ) { this . userContext = value ; } public Lifetime getLifetime ( ) { return lifetime ; } public void setLifetime ( Lifetime value ) { this . lifetime = value ; } public Boolean isExportByValueRequired ( ) { return exportByValueRequired ; } public void setExportByValueRequired ( Boolean value ) { this . exportByValueRequired = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class PropertyList { protected List < Property > properties ; protected List < ResetProperty > resetProperties ; protected List < Extension > extensions ; public List < Property > getProperties ( ) { if ( properties == null ) { properties = new ArrayList < Property > ( ) ; } return this . properties ; } public List < ResetProperty > getResetProperties ( ) { if ( resetProperties == null ) { resetProperties = new ArrayList < ResetProperty > ( ) ; } return this . resetProperties ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class HandleEventsResponse { protected UpdateResponse updateResponse ; protected List < HandleEventsFailed > failedEvents ; protected List < Extension > extensions ; public UpdateResponse getUpdateResponse ( ) { return updateResponse ; } public void setUpdateResponse ( UpdateResponse value ) { this . updateResponse = value ; } public List < HandleEventsFailed > getFailedEvents ( ) { if ( failedEvents == null ) { failedEvents = new ArrayList < HandleEventsFailed > ( ) ; } return this . failedEvents ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class SetPortletProperties { @ XmlElement ( required = true , nillable = true ) protected RegistrationContext registrationContext ; @ XmlElement ( required = true ) protected PortletContext portletContext ; @ XmlElement ( required = true , nillable = true ) protected UserContext userContext ; @ XmlElement ( required = true ) protected PropertyList propertyList ; public RegistrationContext getRegistrationContext ( ) { return registrationContext ; } public void setRegistrationContext ( RegistrationContext value ) { this . registrationContext = value ; } public PortletContext getPortletContext ( ) { return portletContext ; } public void setPortletContext ( PortletContext value ) { this . portletContext = value ; } public UserContext getUserContext ( ) { return userContext ; } public void setUserContext ( UserContext value ) { this . userContext = value ; } public PropertyList getPropertyList ( ) { return propertyList ; } public void setPropertyList ( PropertyList value ) { this . propertyList = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAnyElement ; import javax . xml . bind . annotation . XmlType ; import org . w3c . dom . Element ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" } ) public class EventPayload { protected NamedStringArray namedStringArray ; @ XmlAnyElement ( lax = true ) protected Object any ; public NamedStringArray getNamedStringArray ( ) { return namedStringArray ; } public void setNamedStringArray ( NamedStringArray value ) { this . namedStringArray = value ; } public Object getAny ( ) { return any ; } public void setAny ( Object value ) { this . any = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class RegistrationState { protected byte [ ] registrationState ; protected Lifetime scheduledDestruction ; protected List < Extension > extensions ; public byte [ ] getRegistrationState ( ) { return registrationState ; } public void setRegistrationState ( byte [ ] value ) { this . registrationState = ( ( byte [ ] ) value ) ; } public Lifetime getScheduledDestruction ( ) { return scheduledDestruction ; } public void setScheduledDestruction ( Lifetime value ) { this . scheduledDestruction = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT:name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class Postal { protected String name ; protected String street ; protected String city ; protected String stateprov ; protected String postalcode ; protected String country ; protected String organization ; protected List < Extension > extensions ; public String getName ( ) { return name ; } public void setName ( String value ) { this . name = value ; } public String getStreet ( ) { return street ; } public void setStreet ( String value ) { this . street = value ; } public String getCity ( ) { return city ; } public void setCity ( String value ) { this . city = value ; } public String getStateprov ( ) { return stateprov ; } public void setStateprov ( String value ) { this . stateprov = value ; } public String getPostalcode ( ) { return postalcode ; } public void setPostalcode ( String value ) { this . postalcode = value ; } public String getCountry ( ) { return country ; } public void setCountry ( String value ) { this . country = value ; } public String getOrganization ( ) { return organization ; } public void setOrganization ( String value ) { this . organization = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class PortletDescriptionResponse { @ XmlElement ( required = true ) protected PortletDescription portletDescription ; protected ResourceList resourceList ; protected List < Extension > extensions ; public PortletDescription getPortletDescription ( ) { return portletDescription ; } public void setPortletDescription ( PortletDescription value ) { this . portletDescription = value ; } public ResourceList getResourceList ( ) { return resourceList ; } public void setResourceList ( ResourceList value ) { this . resourceList = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class GetMarkup { @ XmlElement ( required = true , nillable = true ) protected RegistrationContext registrationContext ; @ XmlElement ( required = true ) protected PortletContext portletContext ; @ XmlElement ( required = true ) protected RuntimeContext runtimeContext ; @ XmlElement ( required = true , nillable = true ) protected UserContext userContext ; @ XmlElement ( required = true ) protected MarkupParams markupParams ; public RegistrationContext getRegistrationContext ( ) { return registrationContext ; } public void setRegistrationContext ( RegistrationContext value ) { this . registrationContext = value ; } public PortletContext getPortletContext ( ) { return portletContext ; } public void setPortletContext ( PortletContext value ) { this . portletContext = value ; } public RuntimeContext getRuntimeContext ( ) { return runtimeContext ; } public void setRuntimeContext ( RuntimeContext value ) { this . runtimeContext = value ; } public UserContext getUserContext ( ) { return userContext ; } public void setUserContext ( UserContext value ) { this . userContext = value ; } public MarkupParams getMarkupParams ( ) { return markupParams ; } public void setMarkupParams ( MarkupParams value ) { this . markupParams = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAttribute ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; import javax . xml . namespace . QName ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:description>" , "<STR_LIT>" , "<STR_LIT:title>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class PortletDescription { @ XmlElement ( required = true ) protected String portletHandle ; @ XmlElement ( required = true ) protected List < MarkupType > markupTypes ; protected String groupID ; protected LocalizedString description ; protected LocalizedString shortTitle ; protected LocalizedString title ; protected LocalizedString displayName ; protected List < LocalizedString > keywords ; protected List < QName > publishedEvents ; protected List < QName > handledEvents ; protected List < ParameterDescription > navigationalPublicValueDescriptions ; protected List < String > userCategories ; protected List < String > userProfileItems ; protected List < String > portletManagedModes ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean usesMethodGet ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean defaultMarkupSecure ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean onlySecure ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean userContextStoredInSession ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean templatesStoredInSession ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean hasUserSpecificState ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean doesUrlTemplateProcessing ; @ XmlElement ( defaultValue = "<STR_LIT:false>" ) protected Boolean mayReturnPortletState ; protected List < Extension > extensions ; @ XmlAttribute protected String portletID ; public String getPortletHandle ( ) { return portletHandle ; } public void setPortletHandle ( String value ) { this . portletHandle = value ; } public List < MarkupType > getMarkupTypes ( ) { if ( markupTypes == null ) { markupTypes = new ArrayList < MarkupType > ( ) ; } return this . markupTypes ; } public String getGroupID ( ) { return groupID ; } public void setGroupID ( String value ) { this . groupID = value ; } public LocalizedString getDescription ( ) { return description ; } public void setDescription ( LocalizedString value ) { this . description = value ; } public LocalizedString getShortTitle ( ) { return shortTitle ; } public void setShortTitle ( LocalizedString value ) { this . shortTitle = value ; } public LocalizedString getTitle ( ) { return title ; } public void setTitle ( LocalizedString value ) { this . title = value ; } public LocalizedString getDisplayName ( ) { return displayName ; } public void setDisplayName ( LocalizedString value ) { this . displayName = value ; } public List < LocalizedString > getKeywords ( ) { if ( keywords == null ) { keywords = new ArrayList < LocalizedString > ( ) ; } return this . keywords ; } public List < QName > getPublishedEvents ( ) { if ( publishedEvents == null ) { publishedEvents = new ArrayList < QName > ( ) ; } return this . publishedEvents ; } public List < QName > getHandledEvents ( ) { if ( handledEvents == null ) { handledEvents = new ArrayList < QName > ( ) ; } return this . handledEvents ; } public List < ParameterDescription > getNavigationalPublicValueDescriptions ( ) { if ( navigationalPublicValueDescriptions == null ) { navigationalPublicValueDescriptions = new ArrayList < ParameterDescription > ( ) ; } return this . navigationalPublicValueDescriptions ; } public List < String > getUserCategories ( ) { if ( userCategories == null ) { userCategories = new ArrayList < String > ( ) ; } return this . userCategories ; } public List < String > getUserProfileItems ( ) { if ( userProfileItems == null ) { userProfileItems = new ArrayList < String > ( ) ; } return this . userProfileItems ; } public List < String > getPortletManagedModes ( ) { if ( portletManagedModes == null ) { portletManagedModes = new ArrayList < String > ( ) ; } return this . portletManagedModes ; } public Boolean isUsesMethodGet ( ) { return usesMethodGet ; } public void setUsesMethodGet ( Boolean value ) { this . usesMethodGet = value ; } public Boolean isDefaultMarkupSecure ( ) { return defaultMarkupSecure ; } public void setDefaultMarkupSecure ( Boolean value ) { this . defaultMarkupSecure = value ; } public Boolean isOnlySecure ( ) { return onlySecure ; } public void setOnlySecure ( Boolean value ) { this . onlySecure = value ; } public Boolean isUserContextStoredInSession ( ) { return userContextStoredInSession ; } public void setUserContextStoredInSession ( Boolean value ) { this . userContextStoredInSession = value ; } public Boolean isTemplatesStoredInSession ( ) { return templatesStoredInSession ; } public void setTemplatesStoredInSession ( Boolean value ) { this . templatesStoredInSession = value ; } public Boolean isHasUserSpecificState ( ) { return hasUserSpecificState ; } public void setHasUserSpecificState ( Boolean value ) { this . hasUserSpecificState = value ; } public Boolean isDoesUrlTemplateProcessing ( ) { return doesUrlTemplateProcessing ; } public void setDoesUrlTemplateProcessing ( Boolean value ) { this . doesUrlTemplateProcessing = value ; } public Boolean isMayReturnPortletState ( ) { return mayReturnPortletState ; } public void setMayReturnPortletState ( Boolean value ) { this . mayReturnPortletState = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } public String getPortletID ( ) { return portletID ; } public void setPortletID ( String value ) { this . portletID = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" } ) public class ReturnAny { protected List < Extension > extensions ; public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import java . util . ArrayList ; import java . util . List ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlAttribute ; import javax . xml . bind . annotation . XmlSchemaType ; import javax . xml . bind . annotation . XmlType ; import javax . xml . namespace . QName ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) public class ExtensionPart { protected List < String > extendedTypes ; protected ModelTypes schemaType ; protected List < Extension > extensions ; @ XmlAttribute ( required = true ) protected QName name ; @ XmlAttribute ( required = true ) protected QName type ; @ XmlAttribute @ XmlSchemaType ( name = "<STR_LIT>" ) protected String schemaLocation ; public List < String > getExtendedTypes ( ) { if ( extendedTypes == null ) { extendedTypes = new ArrayList < String > ( ) ; } return this . extendedTypes ; } public ModelTypes getSchemaType ( ) { return schemaType ; } public void setSchemaType ( ModelTypes value ) { this . schemaType = value ; } public List < Extension > getExtensions ( ) { if ( extensions == null ) { extensions = new ArrayList < Extension > ( ) ; } return this . extensions ; } public QName getName ( ) { return name ; } public void setName ( QName value ) { this . name = value ; } public QName getType ( ) { return type ; } public void setType ( QName value ) { this . type = value ; } public String getSchemaLocation ( ) { return schemaLocation ; } public void setSchemaLocation ( String value ) { this . schemaLocation = value ; } } </s>
|
<s> package org . oasis . wsrp . v2 ; import javax . xml . bind . annotation . XmlAccessType ; import javax . xml . bind . annotation . XmlAccessorType ; import javax . xml . bind . annotation . XmlElement ; import javax . xml . bind . annotation . XmlType ; @ XmlAccessorType ( XmlAccessType . FIELD ) @ XmlType ( name = "<STR_LIT>" , propOrder = { "<STR_LIT>" , "<STR_LIT>" } ) public class GetRegistrationLifetime { @ XmlElement ( required = true , nillable = true ) protected RegistrationContext registrationContext ; @ XmlElement ( required = true , nillable = true ) protected UserContext userContext ; public RegistrationContext getRegistrationContext ( ) { return registrationContext ; } public void setRegistrationContext ( RegistrationContext value ) { this . registrationContext = value ; } public UserContext getUserContext ( ) { return userContext ; } public void setUserContext ( UserContext value ) { this . userContext = value ; } } </s>
|
<s> package com . sn . solr . plugin . common ; import java . text . DecimalFormat ; public class AppHelper { static final DecimalFormat NUMBER_FORMAT = new DecimalFormat ( "<STR_LIT>" ) ; public static String getDiffTime ( long startTime ) { return NUMBER_FORMAT . format ( ( System . nanoTime ( ) - startTime ) * <NUM_LIT> ) + "<STR_LIT>" ; } public static boolean isInteger ( String str ) { if ( str == null ) { return false ; } int length = str . length ( ) ; if ( length == <NUM_LIT:0> ) { return false ; } int i = <NUM_LIT:0> ; if ( str . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT:->' ) { if ( length == <NUM_LIT:1> ) { return false ; } i = <NUM_LIT:1> ; } for ( ; i < length ; i ++ ) { char c = str . charAt ( i ) ; if ( c <= '<CHAR_LIT:/>' || c >= '<CHAR_LIT::>' ) { return false ; } } return true ; } } </s>
|
<s> package com . sn . solr . plugin . common ; public class Pair < K , V > { private final K k ; private final V v ; public Pair ( K k , V v ) { this . k = k ; this . v = v ; } public K getKey ( ) { return k ; } public V getValue ( ) { return v ; } public String toString ( ) { return "<STR_LIT>" + k + "<STR_LIT>" + v ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public boolean equals ( Object o ) { if ( o instanceof Pair ) { Pair p = ( Pair ) o ; return ( ( this . k == p . k || ( this . k != null && p . k != null && this . k . equals ( p . k ) ) ) && ( this . v == p . v || ( this . v != null && p . v != null && this . v . equals ( p . v ) ) ) ) ; } return false ; } } </s>
|
<s> package com . sn . solr . plugin . common ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Fieldable ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . solr . client . solrj . SolrQuery ; import org . apache . solr . common . SolrDocument ; import org . apache . solr . common . SolrDocumentList ; import org . apache . solr . common . params . CommonParams ; import org . apache . solr . common . util . NamedList ; import org . apache . solr . request . SolrQueryRequest ; import org . apache . solr . response . SolrQueryResponse ; import org . apache . solr . schema . IndexSchema ; import org . apache . solr . schema . SchemaField ; import org . apache . solr . search . DocIterator ; import org . apache . solr . search . DocSlice ; public class SolrHelper { public static final String RESP_EL_TAG = "<STR_LIT>" ; public static final String FACET_CNT_TAG = "<STR_LIT>" ; public static final String FACET_FIELD_TAG = "<STR_LIT>" ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public static NamedList < Number > getFacetsByField ( SolrQueryResponse res , String fieldName ) { NamedList < Number > list = null ; try { NamedList < Object > respList = res . getValues ( ) ; if ( respList != null ) { NamedList < Object > fc = ( NamedList < Object > ) respList . get ( FACET_CNT_TAG ) ; if ( fc != null ) { NamedList < NamedList < Number > > ff = ( NamedList < NamedList < Number > > ) fc . get ( FACET_FIELD_TAG ) ; if ( ff != null ) { list = ff . get ( fieldName ) ; } } } } catch ( Exception e ) { e . printStackTrace ( ) ; } return list ; } public static SolrDocumentList getSolrDocList ( SolrQueryRequest req , SolrQueryResponse res ) throws CorruptIndexException , IOException { DocSlice slice = ( DocSlice ) res . getValues ( ) . get ( RESP_EL_TAG ) ; Set < String > returnFields = SolrHelper . getReturnFields ( req ) ; SolrDocumentList docList = new SolrDocumentList ( ) ; for ( DocIterator it = slice . iterator ( ) ; it . hasNext ( ) ; ) { int docId = it . nextDoc ( ) ; Document doc = req . getSearcher ( ) . getReader ( ) . document ( docId ) ; SolrDocument sdoc = new SolrDocument ( ) ; for ( Fieldable f : doc . getFields ( ) ) { String fn = f . name ( ) ; if ( returnFields . contains ( fn ) ) { sdoc . addField ( fn , doc . get ( fn ) ) ; } } docList . add ( sdoc ) ; } docList . setMaxScore ( slice . maxScore ( ) ) ; docList . setNumFound ( slice . matches ( ) ) ; docList . setStart ( slice . offset ( ) ) ; return docList ; } public static Set < String > getReturnFields ( SolrQueryRequest req ) { Set < String > fields = new HashSet < String > ( ) ; String fl = req . getParams ( ) . get ( CommonParams . FL ) ; if ( fl == null || fl . equals ( "<STR_LIT>" ) ) { return fields ; } String [ ] fls = fl . split ( "<STR_LIT:U+002C>" ) ; IndexSchema schema = req . getSchema ( ) ; for ( String f : fls ) { if ( "<STR_LIT:*>" . equals ( f ) ) { Map < String , SchemaField > fm = schema . getFields ( ) ; for ( String fieldname : fm . keySet ( ) ) { SchemaField sf = fm . get ( fieldname ) ; if ( sf . stored ( ) ) { fields . add ( fieldname ) ; } } } else { fields . add ( f ) ; } } return fields ; } public static List < Pair < String , Number > > createPairList ( NamedList < Number > list , SolrQuery . ORDER order ) { List < Pair < String , Number > > pairList = new ArrayList < Pair < String , Number > > ( ) ; if ( list != null ) { for ( Map . Entry < String , Number > e : list ) { pairList . add ( new Pair < String , Number > ( e . getKey ( ) , e . getValue ( ) ) ) ; } } if ( order . equals ( SolrQuery . ORDER . desc ) ) { Collections . reverse ( pairList ) ; } return pairList ; } public static List < Pair < String , Number > > createPairList ( SolrDocumentList list , String fieldName ) { List < Pair < String , Number > > pairList = new ArrayList < Pair < String , Number > > ( ) ; if ( list != null ) { for ( SolrDocument doc : list ) { pairList . add ( new Pair < String , Number > ( ( String ) doc . get ( fieldName ) , <NUM_LIT:1> ) ) ; } } return pairList ; } } </s>
|
<s> package com . sn . solr . plugin . handler ; import org . apache . solr . handler . StandardRequestHandler ; import org . apache . solr . request . SolrQueryRequest ; import org . apache . solr . response . SolrQueryResponse ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; public class AppRankHandler extends StandardRequestHandler { private static final Logger LOG = LoggerFactory . getLogger ( AppRankHandler . class ) ; public void handleRequestBody ( SolrQueryRequest request , SolrQueryResponse response ) throws Exception { super . handleRequestBody ( request , response ) ; LOG . info ( "<STR_LIT>" ) ; } } </s>
|
<s> package com . sn . solr . plugin . comp ; import static com . sn . solr . plugin . common . SolrHelper . RESP_EL_TAG ; import java . io . IOException ; import java . util . List ; import java . util . Map ; import org . apache . solr . client . solrj . SolrQuery ; import org . apache . solr . common . SolrDocument ; import org . apache . solr . common . SolrDocumentList ; import org . apache . solr . common . params . AppendedSolrParams ; import org . apache . solr . common . params . CommonParams ; import org . apache . solr . common . params . SolrParams ; import org . apache . solr . handler . component . FacetComponent ; import org . apache . solr . handler . component . ResponseBuilder ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import com . sn . solr . plugin . common . AppHelper ; import com . sn . solr . plugin . common . Pair ; import com . sn . solr . plugin . common . SolrHelper ; import com . sn . solr . plugin . rank . RankEngine ; import com . sn . solr . plugin . rank . RankStrategy ; public class RankComponent extends FacetComponent { private static final Logger LOG = LoggerFactory . getLogger ( RankComponent . class ) ; public static final String PARAM_ID_FIELD = "<STR_LIT>" ; public static final String PARAM_RANK_STRATEGY = "<STR_LIT>" ; public static final String PARAM_RANK_FIELD = "<STR_LIT>" ; public static final String PARAM_RANK_FIELD_SORT = "<STR_LIT>" ; private static final String RANK_TAG = "<STR_LIT>" ; private static final RankStrategy DEFAULT_RANK_STRATEGY = RankStrategy . ORDINAL ; private static final String FIELD_ID = "<STR_LIT:ID>" ; private static final String FIELD_RANK = "<STR_LIT>" ; private static final SolrQuery . ORDER FIELD_RANK_SORT = SolrQuery . ORDER . asc ; @ SuppressWarnings ( "<STR_LIT:deprecation>" ) @ Override public void prepare ( ResponseBuilder rb ) throws IOException { SolrParams params = rb . req . getParams ( ) ; RankStrategy rankStrategy = getRankStrategy ( params ) ; String rankField = getRankField ( params ) ; if ( ! ( rankStrategy . equals ( RankStrategy . ORDINAL ) || rankStrategy . equals ( RankStrategy . LEGACY_DENSE ) ) ) { SolrQuery invariants = new SolrQuery ( ) . setFacet ( true ) . addFacetField ( rankField ) . setFacetLimit ( - <NUM_LIT:1> ) ; AppendedSolrParams appendedParams = new AppendedSolrParams ( params , invariants ) ; LOG . info ( "<STR_LIT>" , new Object [ ] { invariants , appendedParams } ) ; rb . req . setParams ( appendedParams ) ; } super . prepare ( rb ) ; } @ SuppressWarnings ( "<STR_LIT:deprecation>" ) @ Override public void process ( ResponseBuilder rb ) throws IOException { super . process ( rb ) ; long startTime = System . nanoTime ( ) ; SolrParams params = rb . req . getParams ( ) ; RankStrategy rankStrategy = getRankStrategy ( params ) ; String idField = getIdField ( params ) ; String rankField = getRankField ( params ) ; SolrQuery . ORDER rankFieldSort = getRankFieldSortOrder ( params , rankField ) ; LOG . info ( "<STR_LIT>" , new Object [ ] { rankStrategy , idField , rankField , rankFieldSort } ) ; SolrDocumentList docList = SolrHelper . getSolrDocList ( rb . req , rb . rsp ) ; rb . rsp . add ( RESP_EL_TAG , docList ) ; Map < String , Number > rankMap = null ; List < Pair < String , Number > > pairList = null ; if ( rankStrategy . equals ( RankStrategy . LEGACY_DENSE ) ) { rankMap = RankEngine . computeLegacyDenseRank ( rb , idField , rankField ) ; } else if ( rankStrategy . equals ( RankStrategy . ORDINAL ) ) { pairList = SolrHelper . createPairList ( docList , idField ) ; String _start = rb . req . getParams ( ) . get ( CommonParams . START ) ; int start = <NUM_LIT:0> ; if ( _start != null && AppHelper . isInteger ( _start ) ) start = new Integer ( _start ) ; rankMap = RankEngine . computeOrdinalBasedRank ( pairList , start ) ; } else { pairList = SolrHelper . createPairList ( SolrHelper . getFacetsByField ( rb . rsp , rankField ) , rankFieldSort ) ; rankMap = RankEngine . computeFacetBasedRank ( pairList , rankStrategy ) ; } LOG . debug ( "<STR_LIT>" , rankMap ) ; for ( SolrDocument d : docList ) { if ( rankStrategy . equals ( RankStrategy . ORDINAL ) || rankStrategy . equals ( RankStrategy . LEGACY_DENSE ) ) { d . addField ( RANK_TAG , rankMap . get ( d . get ( idField ) ) ) ; } else { d . addField ( RANK_TAG , rankMap . get ( d . get ( rankField ) ) ) ; } } if ( rb . rsp . getValues ( ) != null ) { rb . rsp . getValues ( ) . remove ( SolrHelper . FACET_CNT_TAG ) ; } rb . rsp . getValues ( ) . remove ( RESP_EL_TAG ) ; LOG . info ( "<STR_LIT>" , AppHelper . getDiffTime ( startTime ) ) ; } @ Override public String getDescription ( ) { return "<STR_LIT>" ; } @ Override public String getSource ( ) { return "<STR_LIT>" ; } @ Override public String getSourceId ( ) { return "<STR_LIT>" ; } @ Override public String getVersion ( ) { return "<STR_LIT>" ; } private static RankStrategy getRankStrategy ( SolrParams params ) { RankStrategy rankStrategy = DEFAULT_RANK_STRATEGY ; String _rankStrategy = params . get ( PARAM_RANK_STRATEGY , null ) ; if ( _rankStrategy != null ) { rankStrategy = RankStrategy . getByKey ( _rankStrategy ) ; } return rankStrategy ; } private static String getIdField ( SolrParams params ) { return params . get ( PARAM_ID_FIELD , FIELD_ID ) ; } private static String getRankField ( SolrParams params ) { return params . get ( PARAM_RANK_FIELD , FIELD_RANK ) ; } private static SolrQuery . ORDER getRankFieldSortOrder ( SolrParams params , String rankField ) { SolrQuery . ORDER rankFieldSort = FIELD_RANK_SORT ; if ( params . get ( CommonParams . SORT , rankField + "<STR_LIT>" ) . contains ( rankField + "<STR_LIT>" ) ) { rankFieldSort = SolrQuery . ORDER . desc ; } return rankFieldSort ; } } </s>
|
<s> package com . sn . solr . plugin . rank ; public enum RankStrategy { STANDARD ( "<STR_LIT>" , "<STR_LIT>" ) , MODIFIED ( "<STR_LIT>" , "<STR_LIT>" ) , DENSE ( "<STR_LIT>" , "<STR_LIT>" ) , ORDINAL ( "<STR_LIT>" , "<STR_LIT>" ) , FRACTIONAL ( "<STR_LIT>" , "<STR_LIT>" ) , LEGACY_DENSE ( "<STR_LIT>" , "<STR_LIT>" ) ; private String key ; private String description ; private RankStrategy ( String key , String description ) { this . key = key ; this . description = description ; } public String getKey ( ) { return key ; } public String getDescription ( ) { return description ; } public static RankStrategy getByKey ( String key ) { for ( RankStrategy r : values ( ) ) { if ( r . getKey ( ) . equals ( key ) ) { return r ; } } return null ; } } </s>
|
<s> package com . sn . solr . plugin . rank ; import java . io . IOException ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . FieldSelector ; import org . apache . lucene . document . MapFieldSelector ; import org . apache . solr . common . params . CommonParams ; import org . apache . solr . common . params . SolrParams ; import org . apache . solr . handler . component . ResponseBuilder ; import org . apache . solr . search . DocIterator ; import org . apache . solr . search . DocList ; import org . apache . solr . search . SolrIndexSearcher ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import com . sn . solr . plugin . common . AppHelper ; import com . sn . solr . plugin . common . Pair ; public class RankEngine { private static final Logger LOG = LoggerFactory . getLogger ( RankEngine . class ) ; public static Map < String , Number > computeFacetBasedRank ( List < Pair < String , Number > > pairList , RankStrategy rankStrategy ) { Map < String , Number > rankMap = null ; LOG . info ( "<STR_LIT>" , rankStrategy . getDescription ( ) ) ; switch ( rankStrategy ) { case DENSE : rankMap = computeDenseRank ( pairList ) ; break ; case STANDARD : rankMap = computeStandardRank ( pairList ) ; break ; case MODIFIED : rankMap = computeModifiedRank ( pairList ) ; break ; case FRACTIONAL : rankMap = computeFractionalRank ( pairList ) ; break ; case ORDINAL : rankMap = computeDenseRank ( pairList ) ; break ; } return rankMap ; } public static Map < String , Number > computeDenseRank ( List < Pair < String , Number > > pairList ) { Map < String , Number > rankMap = new HashMap < String , Number > ( ) ; int rank = <NUM_LIT:1> ; for ( Pair < String , Number > p : pairList ) { rankMap . put ( p . getKey ( ) , rank ) ; rank ++ ; } return rankMap ; } public static Map < String , Number > computeStandardRank ( List < Pair < String , Number > > pairList ) { Map < String , Number > rankMap = new HashMap < String , Number > ( ) ; int rank = <NUM_LIT:1> ; for ( Pair < String , Number > p : pairList ) { rankMap . put ( p . getKey ( ) , rank ) ; rank = rank + p . getValue ( ) . intValue ( ) ; } return rankMap ; } public static Map < String , Number > computeModifiedRank ( List < Pair < String , Number > > pairList ) { Map < String , Number > rankMap = new HashMap < String , Number > ( ) ; int rank = <NUM_LIT:0> ; for ( Pair < String , Number > p : pairList ) { rank = rank + p . getValue ( ) . intValue ( ) ; rankMap . put ( p . getKey ( ) , rank ) ; } return rankMap ; } public static Map < String , Number > computeFractionalRank ( List < Pair < String , Number > > pairList ) { Map < String , Number > rankMap = new HashMap < String , Number > ( ) ; Map < String , Number > stdCompRankMap = computeStandardRank ( pairList ) ; Map < String , Number > modCompRankMap = computeModifiedRank ( pairList ) ; float rank = <NUM_LIT:1> ; int stdCompRank = <NUM_LIT:0> , modCompRank = <NUM_LIT:0> ; for ( Pair < String , Number > p : pairList ) { stdCompRank = stdCompRankMap . get ( p . getKey ( ) ) . intValue ( ) ; modCompRank = modCompRankMap . get ( p . getKey ( ) ) . intValue ( ) ; rank = ( stdCompRank + modCompRank ) / <NUM_LIT> ; rankMap . put ( p . getKey ( ) , rank ) ; } return rankMap ; } public static Map < String , Number > computeOrdinalBasedRank ( List < Pair < String , Number > > pairList , long start ) { LOG . info ( "<STR_LIT>" , RankStrategy . ORDINAL . getDescription ( ) ) ; Map < String , Number > rankMap = new HashMap < String , Number > ( ) ; long rank = start ; for ( Pair < String , Number > p : pairList ) { rank ++ ; rankMap . put ( p . getKey ( ) , rank ) ; } return rankMap ; } @ Deprecated public static Map < String , Number > computeLegacyDenseRank ( ResponseBuilder rb , String idField , String rankField ) throws IOException { SolrIndexSearcher searcher = rb . req . getSearcher ( ) ; SolrParams params = rb . req . getParams ( ) ; String _start = params . get ( CommonParams . START ) ; String _rows = params . get ( CommonParams . ROWS ) ; int start = <NUM_LIT:0> ; int rows = <NUM_LIT:10> ; if ( _start != null & AppHelper . isInteger ( _start ) ) start = new Integer ( _start ) ; if ( _rows != null & AppHelper . isInteger ( _rows ) ) rows = new Integer ( _rows ) ; LOG . info ( "<STR_LIT>" , RankStrategy . ORDINAL . getDescription ( ) ) ; FieldSelector fs = new MapFieldSelector ( new String [ ] { idField , rankField } ) ; Map < String , Number > rankMap = new HashMap < String , Number > ( ) ; DocList docs = searcher . getDocList ( rb . getQuery ( ) , rb . getFilters ( ) , rb . getSortSpec ( ) . getSort ( ) , <NUM_LIT:0> , start + rows , <NUM_LIT:0> ) ; int denseRank = <NUM_LIT:1> ; int _CurrScore = <NUM_LIT:0> ; int _PrevScore = <NUM_LIT:0> ; int i = <NUM_LIT:0> ; for ( DocIterator it = docs . iterator ( ) ; it . hasNext ( ) ; ) { Document doc = searcher . doc ( it . nextDoc ( ) , fs ) ; _CurrScore = new Integer ( doc . get ( rankField ) ) ; if ( i == <NUM_LIT:0> ) { _PrevScore = _CurrScore ; } if ( _PrevScore != _CurrScore ) { _PrevScore = _CurrScore ; denseRank ++ ; } if ( i >= start ) { rankMap . put ( doc . get ( idField ) , denseRank ) ; } i ++ ; } return rankMap ; } } </s>
|
<s> package com . sn . solr . plugin . rank . test ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import org . testng . Assert ; import org . testng . annotations . Parameters ; import org . testng . annotations . Test ; import com . sn . solr . plugin . common . Pair ; import com . sn . solr . plugin . rank . RankEngine ; import com . sn . solr . plugin . rank . RankStrategy ; import com . sn . solr . plugin . rank . data . RankDataProvider ; import com . sn . solr . plugin . rank . data . RankDataSet ; public class RankAlgorithmTest { List < Pair < String , Number > > pairList = new ArrayList < Pair < String , Number > > ( ) ; @ Test ( testName = "<STR_LIT>" , dataProvider = "<STR_LIT>" , dataProviderClass = RankDataProvider . class ) @ Parameters ( { "<STR_LIT>" } ) public void testRank ( String [ ] rankStrategies ) { for ( String rankStrategyKey : rankStrategies ) { RankStrategy rankStrategy = RankStrategy . getByKey ( rankStrategyKey ) ; validateResult ( RankEngine . computeFacetBasedRank ( RankDataSet . getDataSet ( ) , rankStrategy ) , rankStrategy ) ; } } public static void validateResult ( Map < String , Number > result , RankStrategy rankType ) { for ( RankDataSet testData : RankDataSet . values ( ) ) { String key = testData . getRankKey ( ) ; Assert . assertNotNull ( key , "<STR_LIT>" ) ; switch ( rankType ) { case DENSE : assertResult ( result . get ( key ) . intValue ( ) , testData . getDenseResult ( ) ) ; break ; case STANDARD : assertResult ( result . get ( key ) . intValue ( ) , testData . getStdCompResult ( ) ) ; break ; case MODIFIED : assertResult ( result . get ( key ) . intValue ( ) , testData . getModCompResult ( ) ) ; break ; case FRACTIONAL : assertResult ( result . get ( key ) . floatValue ( ) , testData . getFractionalResult ( ) ) ; break ; } } } public static void assertResult ( Number key , Number result ) { Assert . assertEquals ( key , result , "<STR_LIT>" + key ) ; } } </s>
|
<s> package com . sn . solr . plugin . rank . data ; import java . util . ArrayList ; import java . util . List ; import com . sn . solr . plugin . common . Pair ; public enum RankDataSet { SET_1 ( "<STR_LIT:1>" , <NUM_LIT:10> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:10> , ( <NUM_LIT:1> + <NUM_LIT:10> ) / <NUM_LIT> ) , SET_2 ( "<STR_LIT:2>" , <NUM_LIT:20> , <NUM_LIT:2> , <NUM_LIT:11> , <NUM_LIT:30> , ( <NUM_LIT:11> + <NUM_LIT:30> ) / <NUM_LIT> ) , SET_3 ( "<STR_LIT>" , <NUM_LIT:10> , <NUM_LIT:3> , <NUM_LIT:31> , <NUM_LIT> , ( <NUM_LIT:31> + <NUM_LIT> ) / <NUM_LIT> ) , SET_4 ( "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT> , ( <NUM_LIT> + <NUM_LIT> ) / <NUM_LIT> ) , SET_5 ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , ( <NUM_LIT> + <NUM_LIT> ) / <NUM_LIT> ) , SET_6 ( "<STR_LIT>" , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> , ( <NUM_LIT> + <NUM_LIT> ) / <NUM_LIT> ) , SET_7 ( "<STR_LIT>" , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT> , ( <NUM_LIT> + <NUM_LIT> ) / <NUM_LIT> ) , SET_8 ( "<STR_LIT>" , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , ( <NUM_LIT> + <NUM_LIT> ) / <NUM_LIT> ) , SET_9 ( "<STR_LIT>" , <NUM_LIT:10> , <NUM_LIT:9> , <NUM_LIT:100> , <NUM_LIT> , ( <NUM_LIT:100> + <NUM_LIT> ) / <NUM_LIT> ) , SET_10 ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> , ( <NUM_LIT> + <NUM_LIT> ) / <NUM_LIT> ) ; private String rankKey ; private int rankValue ; private int denseResult ; private int stdCompResult ; private int modCompResult ; private float fractionalResult ; private Pair < String , Number > pair ; RankDataSet ( String rankKey , int rankValue , int denseResult , int stdCompResult , int modCompResult , float fractionalResult ) { this . rankKey = rankKey ; this . rankValue = rankValue ; this . denseResult = denseResult ; this . stdCompResult = stdCompResult ; this . modCompResult = modCompResult ; this . fractionalResult = fractionalResult ; this . pair = new Pair < String , Number > ( rankKey , rankValue ) ; } public String getRankKey ( ) { return rankKey ; } public int getDenseResult ( ) { return denseResult ; } public int getRankValue ( ) { return rankValue ; } public int getStdCompResult ( ) { return stdCompResult ; } public int getModCompResult ( ) { return modCompResult ; } public float getFractionalResult ( ) { return fractionalResult ; } public Pair < String , Number > getPair ( ) { return pair ; } private static List < Pair < String , Number > > pairList = null ; public static List < Pair < String , Number > > getDataSet ( ) { if ( pairList == null ) { pairList = new ArrayList < Pair < String , Number > > ( ) ; for ( RankDataSet data : RankDataSet . values ( ) ) { pairList . add ( data . getPair ( ) ) ; } } return pairList ; } } </s>
|
<s> package com . sn . solr . plugin . rank . data ; import org . testng . annotations . DataProvider ; public class RankDataProvider { public static final Object [ ] [ ] RANK_STRATEGIES = new Object [ ] [ ] { { new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } } } ; @ DataProvider ( name = "<STR_LIT>" ) public static Object [ ] [ ] rankStrategies ( ) { return RANK_STRATEGIES ; } } </s>
|
<s> package edu . ucla . cens . systemsens ; public interface IAdaptiveApplication extends android . os . IInterface { public static abstract class Stub extends android . os . Binder implements edu . ucla . cens . systemsens . IAdaptiveApplication { private static final java . lang . String DESCRIPTOR = "<STR_LIT>" ; public Stub ( ) { this . attachInterface ( this , DESCRIPTOR ) ; } public static edu . ucla . cens . systemsens . IAdaptiveApplication asInterface ( android . os . IBinder obj ) { if ( ( obj == null ) ) { return null ; } android . os . IInterface iin = ( android . os . IInterface ) obj . queryLocalInterface ( DESCRIPTOR ) ; if ( ( ( iin != null ) && ( iin instanceof edu . ucla . cens . systemsens . IAdaptiveApplication ) ) ) { return ( ( edu . ucla . cens . systemsens . IAdaptiveApplication ) iin ) ; } return new edu . ucla . cens . systemsens . IAdaptiveApplication . Stub . Proxy ( obj ) ; } public android . os . IBinder asBinder ( ) { return this ; } @ Override public boolean onTransact ( int code , android . os . Parcel data , android . os . Parcel reply , int flags ) throws android . os . RemoteException { switch ( code ) { case INTERFACE_TRANSACTION : { reply . writeString ( DESCRIPTOR ) ; return true ; } case TRANSACTION_getName : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _result = this . getName ( ) ; reply . writeNoException ( ) ; reply . writeString ( _result ) ; return true ; } case TRANSACTION_identifyList : { data . enforceInterface ( DESCRIPTOR ) ; java . util . List _result = this . identifyList ( ) ; reply . writeNoException ( ) ; reply . writeList ( _result ) ; return true ; } case TRANSACTION_getWork : { data . enforceInterface ( DESCRIPTOR ) ; java . util . List _result = this . getWork ( ) ; reply . writeNoException ( ) ; reply . writeList ( _result ) ; return true ; } case TRANSACTION_setWorkLimit : { data . enforceInterface ( DESCRIPTOR ) ; java . util . List _arg0 ; java . lang . ClassLoader cl = ( java . lang . ClassLoader ) this . getClass ( ) . getClassLoader ( ) ; _arg0 = data . readArrayList ( cl ) ; this . setWorkLimit ( _arg0 ) ; reply . writeNoException ( ) ; return true ; } } return super . onTransact ( code , data , reply , flags ) ; } private static class Proxy implements edu . ucla . cens . systemsens . IAdaptiveApplication { private android . os . IBinder mRemote ; Proxy ( android . os . IBinder remote ) { mRemote = remote ; } public android . os . IBinder asBinder ( ) { return mRemote ; } public java . lang . String getInterfaceDescriptor ( ) { return DESCRIPTOR ; } public java . lang . String getName ( ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; java . lang . String _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; mRemote . transact ( Stub . TRANSACTION_getName , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = _reply . readString ( ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public java . util . List identifyList ( ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; java . util . List _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; mRemote . transact ( Stub . TRANSACTION_identifyList , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; java . lang . ClassLoader cl = ( java . lang . ClassLoader ) this . getClass ( ) . getClassLoader ( ) ; _result = _reply . readArrayList ( cl ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public java . util . List getWork ( ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; java . util . List _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; mRemote . transact ( Stub . TRANSACTION_getWork , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; java . lang . ClassLoader cl = ( java . lang . ClassLoader ) this . getClass ( ) . getClassLoader ( ) ; _result = _reply . readArrayList ( cl ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public void setWorkLimit ( java . util . List workLimit ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeList ( workLimit ) ; mRemote . transact ( Stub . TRANSACTION_setWorkLimit , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } } } static final int TRANSACTION_getName = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:0> ) ; static final int TRANSACTION_identifyList = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:1> ) ; static final int TRANSACTION_getWork = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:2> ) ; static final int TRANSACTION_setWorkLimit = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:3> ) ; } public java . lang . String getName ( ) throws android . os . RemoteException ; public java . util . List identifyList ( ) throws android . os . RemoteException ; public java . util . List getWork ( ) throws android . os . RemoteException ; public void setWorkLimit ( java . util . List workLimit ) throws android . os . RemoteException ; } </s>
|
<s> package edu . ucla . cens . systemsens ; public interface IPowerMonitor extends android . os . IInterface { public static abstract class Stub extends android . os . Binder implements edu . ucla . cens . systemsens . IPowerMonitor { private static final java . lang . String DESCRIPTOR = "<STR_LIT>" ; public Stub ( ) { this . attachInterface ( this , DESCRIPTOR ) ; } public static edu . ucla . cens . systemsens . IPowerMonitor asInterface ( android . os . IBinder obj ) { if ( ( obj == null ) ) { return null ; } android . os . IInterface iin = ( android . os . IInterface ) obj . queryLocalInterface ( DESCRIPTOR ) ; if ( ( ( iin != null ) && ( iin instanceof edu . ucla . cens . systemsens . IPowerMonitor ) ) ) { return ( ( edu . ucla . cens . systemsens . IPowerMonitor ) iin ) ; } return new edu . ucla . cens . systemsens . IPowerMonitor . Stub . Proxy ( obj ) ; } public android . os . IBinder asBinder ( ) { return this ; } @ Override public boolean onTransact ( int code , android . os . Parcel data , android . os . Parcel reply , int flags ) throws android . os . RemoteException { switch ( code ) { case INTERFACE_TRANSACTION : { reply . writeString ( DESCRIPTOR ) ; return true ; } case TRANSACTION_register : { data . enforceInterface ( DESCRIPTOR ) ; edu . ucla . cens . systemsens . IAdaptiveApplication _arg0 ; _arg0 = edu . ucla . cens . systemsens . IAdaptiveApplication . Stub . asInterface ( data . readStrongBinder ( ) ) ; int _arg1 ; _arg1 = data . readInt ( ) ; this . register ( _arg0 , _arg1 ) ; reply . writeNoException ( ) ; return true ; } case TRANSACTION_unregister : { data . enforceInterface ( DESCRIPTOR ) ; edu . ucla . cens . systemsens . IAdaptiveApplication _arg0 ; _arg0 = edu . ucla . cens . systemsens . IAdaptiveApplication . Stub . asInterface ( data . readStrongBinder ( ) ) ; this . unregister ( _arg0 ) ; reply . writeNoException ( ) ; return true ; } case TRANSACTION_setDeadline : { data . enforceInterface ( DESCRIPTOR ) ; int _arg0 ; _arg0 = data . readInt ( ) ; this . setDeadline ( _arg0 ) ; reply . writeNoException ( ) ; return true ; } } return super . onTransact ( code , data , reply , flags ) ; } private static class Proxy implements edu . ucla . cens . systemsens . IPowerMonitor { private android . os . IBinder mRemote ; Proxy ( android . os . IBinder remote ) { mRemote = remote ; } public android . os . IBinder asBinder ( ) { return mRemote ; } public java . lang . String getInterfaceDescriptor ( ) { return DESCRIPTOR ; } public void register ( edu . ucla . cens . systemsens . IAdaptiveApplication app , int horizon ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeStrongBinder ( ( ( ( app != null ) ) ? ( app . asBinder ( ) ) : ( null ) ) ) ; _data . writeInt ( horizon ) ; mRemote . transact ( Stub . TRANSACTION_register , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } } public void unregister ( edu . ucla . cens . systemsens . IAdaptiveApplication app ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeStrongBinder ( ( ( ( app != null ) ) ? ( app . asBinder ( ) ) : ( null ) ) ) ; mRemote . transact ( Stub . TRANSACTION_unregister , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } } public void setDeadline ( int deadline ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeInt ( deadline ) ; mRemote . transact ( Stub . TRANSACTION_setDeadline , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } } } static final int TRANSACTION_register = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:0> ) ; static final int TRANSACTION_unregister = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:1> ) ; static final int TRANSACTION_setDeadline = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:2> ) ; } public void register ( edu . ucla . cens . systemsens . IAdaptiveApplication app , int horizon ) throws android . os . RemoteException ; public void unregister ( edu . ucla . cens . systemsens . IAdaptiveApplication app ) throws android . os . RemoteException ; public void setDeadline ( int deadline ) throws android . os . RemoteException ; } </s>
|
<s> package edu . ucla . cens . accelservice ; import android . content . BroadcastReceiver ; import android . content . Context ; import android . content . Intent ; import android . util . Log ; public class ServiceStarter extends BroadcastReceiver { private static final String TAG = "<STR_LIT>" ; @ Override public void onReceive ( Context context , Intent intent ) { context . startService ( new Intent ( context , AccelService . class ) ) ; Log . i ( TAG , "<STR_LIT>" ) ; } } </s>
|
<s> package edu . ucla . cens . accelservice ; import edu . ucla . cens . systemlog . ISystemLog ; import edu . ucla . cens . systemlog . Log ; import edu . ucla . cens . systemsens . IPowerMonitor ; import edu . ucla . cens . systemsens . IAdaptiveApplication ; import android . app . Service ; import android . app . PendingIntent ; import android . app . AlarmManager ; import android . content . Context ; import android . content . Intent ; import android . content . ComponentName ; import android . content . ServiceConnection ; import android . os . Handler ; import android . os . IBinder ; import android . os . Message ; import android . os . SystemClock ; import android . os . RemoteException ; import android . os . PowerManager ; import android . hardware . SensorManager ; import android . hardware . SensorEventListener ; import android . hardware . SensorEvent ; import android . hardware . Sensor ; import java . util . List ; import java . util . ArrayList ; import java . util . Hashtable ; public class AccelService extends Service { private static final String TAG = "<STR_LIT>" ; private static final String APP_NAME = "<STR_LIT>" ; private static final String ACCEL_UNIT_NAME = "<STR_LIT>" ; private static final int SLEEP_TIMER_MSG = <NUM_LIT:1> ; private static final int READ_TIMER_MSG = <NUM_LIT:2> ; private static final String ACCEL_ALARM_ACTION = "<STR_LIT>" ; private static final int ONE_SECOND = <NUM_LIT:1000> ; private static final int ONE_MINUTE = <NUM_LIT> * ONE_SECOND ; private static final long DEFAULT_WARMUP_INTERVAL = ONE_SECOND ; private static final long DEFAULT_READ_INTERVAL = ONE_SECOND ; private static final long DEFAULT_SLEEP_INTERVAL = ONE_MINUTE ; private static final int DEFAULT_RATE = SensorManager . SENSOR_DELAY_GAME ; private static final int DEFAULT_POWERCYCLE_HORIZON = <NUM_LIT:5> * ONE_MINUTE ; public static final int REGIME_RELAXED = <NUM_LIT:0> ; public static final int REGIME_CONTROLLED = <NUM_LIT:1> ; private int mRate = DEFAULT_RATE ; private long mSleepInterval = DEFAULT_SLEEP_INTERVAL ; private long mWarmupInterval = DEFAULT_WARMUP_INTERVAL ; private long mReadInterval = DEFAULT_READ_INTERVAL ; private boolean mJustStarted = true ; private boolean mRecordSensor = false ; private long mLastTS ; private boolean mIsRunning = false ; private Hashtable < String , ClientInfo > mClientsMap ; private List < Double > mLastForceList ; private List < Double > mTempForceList ; private List < Double > mLastListX ; private List < Double > mTempListX ; private List < Double > mLastListY ; private List < Double > mTempListY ; private List < Double > mLastListZ ; private List < Double > mTempListZ ; private AccelCounter mAccelCounter ; private AlarmManager mAlarmManager ; private PendingIntent mAccelSender ; private PowerManager . WakeLock mCpuLock ; private SensorManager mSensorManager ; private IPowerMonitor mPowerMonitor ; private boolean mPowerMonitorConnected = false ; private final IAdaptiveApplication mAdaptiveControl = new IAdaptiveApplication . Stub ( ) { public String getName ( ) { return APP_NAME ; } public List < String > identifyList ( ) { ArrayList < String > unitNames = new ArrayList < String > ( <NUM_LIT:1> ) ; unitNames . add ( ACCEL_UNIT_NAME ) ; return unitNames ; } public List < Double > getWork ( ) { ArrayList < Double > totalWork = new ArrayList < Double > ( <NUM_LIT:1> ) ; totalWork . add ( mAccelCounter . getCount ( ) ) ; Log . i ( TAG , "<STR_LIT>" + totalWork + "<STR_LIT>" ) ; return totalWork ; } public void setWorkLimit ( List workLimit ) { double accelLimit = ( Double ) workLimit . get ( <NUM_LIT:0> ) ; mAccelCounter . setLimit ( accelLimit ) ; } } ; private ServiceConnection mPowerMonitorConnection = new ServiceConnection ( ) { public void onServiceConnected ( ComponentName className , IBinder service ) { mPowerMonitor = IPowerMonitor . Stub . asInterface ( service ) ; try { mPowerMonitor . register ( mAdaptiveControl , DEFAULT_POWERCYCLE_HORIZON ) ; } catch ( RemoteException re ) { Log . e ( TAG , "<STR_LIT>" , re ) ; } mPowerMonitorConnected = true ; } public void onServiceDisconnected ( ComponentName className ) { try { mPowerMonitor . unregister ( mAdaptiveControl ) ; } catch ( RemoteException re ) { Log . e ( TAG , "<STR_LIT>" , re ) ; } mPowerMonitor = null ; mPowerMonitorConnected = false ; } } ; private final SensorEventListener mSensorListener = new SensorEventListener ( ) { public void onSensorChanged ( SensorEvent se ) { mAccelCounter . count ( ) ; if ( mRecordSensor ) { if ( mJustStarted ) { mTempForceList = new ArrayList < Double > ( ) ; mTempListX = new ArrayList < Double > ( ) ; mTempListY = new ArrayList < Double > ( ) ; mTempListZ = new ArrayList < Double > ( ) ; mHandler . sendMessageAtTime ( mHandler . obtainMessage ( SLEEP_TIMER_MSG ) , SystemClock . uptimeMillis ( ) + mReadInterval ) ; mJustStarted = false ; } double x = se . values [ <NUM_LIT:0> ] ; double y = se . values [ <NUM_LIT:1> ] ; double z = se . values [ <NUM_LIT:2> ] ; double totalForce = <NUM_LIT:0.0> ; double grav = SensorManager . GRAVITY_EARTH ; totalForce += Math . pow ( x / grav , <NUM_LIT> ) ; totalForce += Math . pow ( y / grav , <NUM_LIT> ) ; totalForce += Math . pow ( z / grav , <NUM_LIT> ) ; totalForce = Math . sqrt ( totalForce ) ; mLastTS = System . currentTimeMillis ( ) ; mTempForceList . add ( totalForce ) ; mTempListX . add ( x ) ; mTempListY . add ( y ) ; mTempListZ . add ( z ) ; } } public void onAccuracyChanged ( Sensor sensor , int accuracy ) { String accuracyStr = "<STR_LIT>" ; switch ( accuracy ) { case SensorManager . SENSOR_STATUS_ACCURACY_HIGH : accuracyStr = "<STR_LIT>" ; break ; case SensorManager . SENSOR_STATUS_ACCURACY_MEDIUM : accuracyStr = "<STR_LIT>" ; break ; case SensorManager . SENSOR_STATUS_ACCURACY_LOW : accuracyStr = "<STR_LIT>" ; break ; case <NUM_LIT:0> : accuracyStr = "<STR_LIT>" ; break ; } Log . i ( TAG , "<STR_LIT>" + accuracyStr + "<STR_LIT:U+0020(>" + accuracy + "<STR_LIT:)>" ) ; } } ; private final IAccelService . Stub mBinder = new IAccelService . Stub ( ) { public int suggestRate ( String callerName , int rate ) { if ( callerName == null ) return - <NUM_LIT:1> ; if ( mClientsMap . containsKey ( callerName ) ) { mClientsMap . get ( callerName ) . setRate ( rate ) ; Log . v ( TAG , "<STR_LIT>" + rate + "<STR_LIT>" + callerName ) ; } else { Log . i ( TAG , "<STR_LIT>" + callerName + "<STR_LIT>" ) ; mClientsMap . put ( callerName , new ClientInfo ( ) ) ; mClientsMap . get ( callerName ) . setRate ( rate ) ; } return adjustRate ( ) ; } public long setReadingLength ( String callerName , long length ) { if ( callerName == null ) return - <NUM_LIT:1> ; if ( mClientsMap . containsKey ( callerName ) ) { mClientsMap . get ( callerName ) . setReadInterval ( length ) ; Log . v ( TAG , "<STR_LIT>" + length + "<STR_LIT>" + callerName ) ; } else { Log . i ( TAG , "<STR_LIT>" + callerName + "<STR_LIT>" ) ; mClientsMap . put ( callerName , new ClientInfo ( ) ) ; mClientsMap . get ( callerName ) . setReadInterval ( length ) ; } return adjustReadInterval ( ) ; } public long setWarmupLength ( String callerName , long length ) { if ( callerName == null ) return - <NUM_LIT:1> ; if ( mClientsMap . containsKey ( callerName ) ) { mClientsMap . get ( callerName ) . setWarmupInterval ( length ) ; Log . v ( TAG , "<STR_LIT>" + length + "<STR_LIT>" + callerName ) ; } else { Log . i ( TAG , "<STR_LIT>" + callerName + "<STR_LIT>" ) ; mClientsMap . put ( callerName , new ClientInfo ( ) ) ; mClientsMap . get ( callerName ) . setWarmupInterval ( length ) ; } return adjustWarmupInterval ( ) ; } public long suggestInterval ( String callerName , long interval ) { if ( callerName == null ) return - <NUM_LIT:1> ; if ( mClientsMap . containsKey ( callerName ) ) { mClientsMap . get ( callerName ) . setSleepInterval ( interval ) ; Log . v ( TAG , "<STR_LIT>" + interval + "<STR_LIT>" + callerName ) ; } else { Log . i ( TAG , "<STR_LIT>" + callerName + "<STR_LIT>" ) ; mClientsMap . put ( callerName , new ClientInfo ( ) ) ; mClientsMap . get ( callerName ) . setSleepInterval ( interval ) ; } return adjustSleepInterval ( ) ; } public long getInterval ( ) { return mSleepInterval ; } public int getRate ( ) { return mRate ; } public long getReadingLength ( ) { return mReadInterval ; } public long getWarmupLength ( ) { return mWarmupInterval ; } public List < Double > getLastForce ( ) { synchronized ( mLastListX ) { return mLastForceList ; } } public List < Double > getLastXValues ( ) { synchronized ( mLastListX ) { return mLastListX ; } } public List < Double > getLastYValues ( ) { synchronized ( mLastListX ) { return mLastListY ; } } public List < Double > getLastZValues ( ) { synchronized ( mLastListX ) { return mLastListZ ; } } public long getLastTimeStamp ( ) { synchronized ( mLastListX ) { return mLastTS ; } } public boolean isRunning ( ) { return mIsRunning ; } public void start ( String callerName ) { if ( callerName == null ) return ; Log . i ( TAG , "<STR_LIT>" + callerName ) ; if ( mClientsMap != null ) Log . i ( TAG , "<STR_LIT>" + mClientsMap . keySet ( ) ) ; else Log . i ( TAG , "<STR_LIT>" ) ; if ( ! mClientsMap . containsKey ( callerName ) ) mClientsMap . put ( callerName , new ClientInfo ( ) ) ; if ( mClientsMap != null ) Log . i ( TAG , "<STR_LIT>" + mClientsMap . keySet ( ) ) ; else Log . i ( TAG , "<STR_LIT>" ) ; int clientCount = mClientsMap . size ( ) ; if ( ( clientCount == <NUM_LIT:1> ) && ( ! mIsRunning ) ) { Log . i ( TAG , "<STR_LIT>" ) ; mAlarmManager . cancel ( mAccelSender ) ; mAlarmManager . setRepeating ( AlarmManager . ELAPSED_REALTIME_WAKEUP , SystemClock . elapsedRealtime ( ) , mSleepInterval , mAccelSender ) ; mIsRunning = true ; } else { Log . i ( TAG , "<STR_LIT>" ) ; } } public void stop ( String callerName ) { if ( callerName == null ) return ; Log . i ( TAG , "<STR_LIT>" + callerName ) ; if ( mClientsMap . containsKey ( callerName ) ) mClientsMap . remove ( callerName ) ; else return ; int clientCount = mClientsMap . size ( ) ; Log . i ( TAG , "<STR_LIT>" + clientCount ) ; if ( ( clientCount == <NUM_LIT:0> ) && ( mIsRunning ) ) { Log . i ( TAG , "<STR_LIT>" ) ; mIsRunning = false ; mAlarmManager . cancel ( mAccelSender ) ; mHandler . removeMessages ( SLEEP_TIMER_MSG ) ; mHandler . removeMessages ( READ_TIMER_MSG ) ; mSensorManager . unregisterListener ( mSensorListener , mSensorManager . getDefaultSensor ( Sensor . TYPE_ACCELEROMETER ) ) ; mIsRunning = false ; } else { Log . i ( TAG , "<STR_LIT>" ) ; adjustRate ( ) ; adjustSleepInterval ( ) ; adjustWarmupInterval ( ) ; adjustReadInterval ( ) ; } } } ; @ Override public IBinder onBind ( Intent intent ) { if ( IAccelService . class . getName ( ) . equals ( intent . getAction ( ) ) ) { return mBinder ; } return null ; } private final Handler mHandler = new Handler ( ) { @ Override public void handleMessage ( Message msg ) { if ( ! mIsRunning ) { Log . w ( TAG , "<STR_LIT>" ) ; return ; } if ( msg . what == SLEEP_TIMER_MSG ) { Log . v ( TAG , "<STR_LIT>" ) ; mSensorManager . unregisterListener ( mSensorListener , mSensorManager . getDefaultSensor ( Sensor . TYPE_ACCELEROMETER ) ) ; mRecordSensor = false ; synchronized ( mLastListX ) { mLastForceList = mTempForceList ; mLastListX = mTempListX ; mLastListY = mTempListY ; mLastListZ = mTempListZ ; } if ( mCpuLock . isHeld ( ) ) mCpuLock . release ( ) ; } else if ( msg . what == READ_TIMER_MSG ) { Log . v ( TAG , "<STR_LIT>" + mReadInterval + "<STR_LIT>" ) ; mJustStarted = true ; mRecordSensor = true ; } } } ; private void sensorCycle ( ) { Log . v ( TAG , "<STR_LIT>" + mWarmupInterval + "<STR_LIT>" ) ; if ( mAccelCounter . hasBudget ( ) ) { mSensorManager . registerListener ( mSensorListener , mSensorManager . getDefaultSensor ( Sensor . TYPE_ACCELEROMETER ) , mRate ) ; mHandler . sendMessageAtTime ( mHandler . obtainMessage ( READ_TIMER_MSG ) , SystemClock . uptimeMillis ( ) + mWarmupInterval ) ; mRecordSensor = false ; } else { Log . i ( TAG , "<STR_LIT>" + "<STR_LIT>" ) ; } } @ Override public void onStart ( Intent intent , int startId ) { if ( ! mPowerMonitorConnected ) { Log . i ( TAG , "<STR_LIT>" ) ; bindService ( new Intent ( IPowerMonitor . class . getName ( ) ) , mPowerMonitorConnection , Context . BIND_AUTO_CREATE ) ; } if ( ! Log . isConnected ( ) ) { bindService ( new Intent ( ISystemLog . class . getName ( ) ) , Log . SystemLogConnection , Context . BIND_AUTO_CREATE ) ; } if ( intent != null ) { String action = intent . getAction ( ) ; if ( action != null ) { if ( action . equals ( ACCEL_ALARM_ACTION ) ) { if ( ! mCpuLock . isHeld ( ) ) mCpuLock . acquire ( ) ; sensorCycle ( ) ; } } } super . onStart ( intent , startId ) ; } @ Override public void onCreate ( ) { super . onCreate ( ) ; Log . setAppName ( APP_NAME ) ; bindService ( new Intent ( ISystemLog . class . getName ( ) ) , Log . SystemLogConnection , Context . BIND_AUTO_CREATE ) ; bindService ( new Intent ( IPowerMonitor . class . getName ( ) ) , mPowerMonitorConnection , Context . BIND_AUTO_CREATE ) ; Log . i ( TAG , "<STR_LIT>" ) ; mClientsMap = new Hashtable < String , ClientInfo > ( ) ; resetToDefault ( ) ; mSensorManager = ( SensorManager ) getSystemService ( Context . SENSOR_SERVICE ) ; mAccelCounter = new AccelCounter ( ) ; PowerManager pm = ( PowerManager ) getSystemService ( Context . POWER_SERVICE ) ; mCpuLock = pm . newWakeLock ( PowerManager . PARTIAL_WAKE_LOCK , APP_NAME ) ; mCpuLock . setReferenceCounted ( false ) ; mAlarmManager = ( AlarmManager ) getSystemService ( ALARM_SERVICE ) ; Intent accelAlarmIntent = new Intent ( AccelService . this , AccelService . class ) ; accelAlarmIntent . setAction ( ACCEL_ALARM_ACTION ) ; mAccelSender = PendingIntent . getService ( AccelService . this , <NUM_LIT:0> , accelAlarmIntent , <NUM_LIT:0> ) ; } @ Override public void onDestroy ( ) { Log . i ( TAG , "<STR_LIT>" ) ; Log . i ( TAG , "<STR_LIT>" ) ; mAlarmManager . cancel ( mAccelSender ) ; mHandler . removeMessages ( SLEEP_TIMER_MSG ) ; mHandler . removeMessages ( READ_TIMER_MSG ) ; mSensorManager . unregisterListener ( mSensorListener , mSensorManager . getDefaultSensor ( Sensor . TYPE_ACCELEROMETER ) ) ; super . onDestroy ( ) ; unbindService ( Log . SystemLogConnection ) ; mSensorManager . unregisterListener ( mSensorListener ) ; } private void resetToDefault ( ) { Log . i ( TAG , "<STR_LIT>" ) ; mRate = DEFAULT_RATE ; mSleepInterval = DEFAULT_SLEEP_INTERVAL ; mReadInterval = DEFAULT_READ_INTERVAL ; mWarmupInterval = DEFAULT_WARMUP_INTERVAL ; mLastForceList = new ArrayList < Double > ( ) ; mLastListX = new ArrayList < Double > ( ) ; mLastListY = new ArrayList < Double > ( ) ; mLastListZ = new ArrayList < Double > ( ) ; } private long gcd ( long a , long b ) { if ( b == <NUM_LIT:0> ) return a ; else return gcd ( b , a % b ) ; } private long adjustSleepInterval ( ) { long interval , curInterval = mSleepInterval ; for ( ClientInfo client : mClientsMap . values ( ) ) { interval = client . sleepInterval ; curInterval = gcd ( curInterval , interval ) ; } if ( mSleepInterval != curInterval ) { mSleepInterval = curInterval ; Log . i ( TAG , "<STR_LIT>" + mSleepInterval ) ; } if ( mIsRunning ) { mAlarmManager . cancel ( mAccelSender ) ; mAlarmManager . setRepeating ( AlarmManager . ELAPSED_REALTIME_WAKEUP , SystemClock . elapsedRealtime ( ) , mSleepInterval , mAccelSender ) ; } return mSleepInterval ; } private long adjustWarmupInterval ( ) { long interval , curInterval = - <NUM_LIT:1> ; for ( ClientInfo client : mClientsMap . values ( ) ) { interval = client . warmupInterval ; if ( curInterval < interval ) curInterval = interval ; } if ( mWarmupInterval != curInterval ) { mWarmupInterval = curInterval ; Log . v ( TAG , "<STR_LIT>" + mWarmupInterval ) ; } return mWarmupInterval ; } private long adjustReadInterval ( ) { long interval , curInterval = - <NUM_LIT:1> ; for ( ClientInfo client : mClientsMap . values ( ) ) { interval = client . readInterval ; if ( curInterval < interval ) curInterval = interval ; } if ( mReadInterval != curInterval ) { mReadInterval = curInterval ; Log . i ( TAG , "<STR_LIT>" + mReadInterval ) ; } return mReadInterval ; } private int adjustRate ( ) { int rate , curRate = Integer . MAX_VALUE ; for ( ClientInfo client : mClientsMap . values ( ) ) { rate = client . rate ; if ( curRate > rate ) curRate = rate ; } if ( mRate != curRate ) { mRate = curRate ; Log . i ( TAG , "<STR_LIT>" + mRate ) ; } return mRate ; } class ClientInfo { public int rate ; public long sleepInterval ; public long warmupInterval ; public long readInterval ; ClientInfo ( ) { this . rate = DEFAULT_RATE ; this . sleepInterval = DEFAULT_SLEEP_INTERVAL ; this . readInterval = DEFAULT_READ_INTERVAL ; this . warmupInterval = DEFAULT_WARMUP_INTERVAL ; } public void setReadInterval ( long length ) { if ( length > <NUM_LIT:0> ) readInterval = length ; else warmupInterval = DEFAULT_WARMUP_INTERVAL ; } public void setWarmupInterval ( long length ) { if ( length >= <NUM_LIT:0> ) warmupInterval = length ; else warmupInterval = DEFAULT_WARMUP_INTERVAL ; } public void setRate ( int newrate ) { switch ( newrate ) { case SensorManager . SENSOR_DELAY_FASTEST : mRate = SensorManager . SENSOR_DELAY_FASTEST ; break ; case SensorManager . SENSOR_DELAY_GAME : mRate = SensorManager . SENSOR_DELAY_GAME ; break ; case SensorManager . SENSOR_DELAY_NORMAL : mRate = SensorManager . SENSOR_DELAY_NORMAL ; break ; case SensorManager . SENSOR_DELAY_UI : mRate = SensorManager . SENSOR_DELAY_UI ; break ; default : mRate = DEFAULT_RATE ; break ; } } public void setSleepInterval ( long interval ) { if ( interval < ONE_SECOND ) { this . sleepInterval = DEFAULT_SLEEP_INTERVAL ; } else { mSleepInterval = interval ; } } } class AccelCounter { private double mTotal ; private double mCurTotal ; private double mLimit ; public AccelCounter ( ) { mTotal = mCurTotal = <NUM_LIT:0.0> ; mLimit = Double . NaN ; } public boolean hasBudget ( ) { if ( Double . isNaN ( mLimit ) || ( mCurTotal < mLimit ) ) { return true ; } else if ( ! Double . isNaN ( mLimit ) && ( mCurTotal >= mLimit ) ) { return false ; } return true ; } public boolean count ( ) { if ( hasBudget ( ) ) { mTotal += <NUM_LIT:1> ; mCurTotal += <NUM_LIT:1> ; return true ; } else return false ; } public void setLimit ( double workLimit ) { mLimit = workLimit ; mCurTotal = <NUM_LIT:0.0> ; } public double getCount ( ) { return mTotal ; } } } </s>
|
<s> package edu . ucla . cens . systemlog ; import android . content . ComponentName ; import android . content . ServiceConnection ; import android . os . IBinder ; import android . os . RemoteException ; public class Log { private static final String DEFAULT_APP_NAME = "<STR_LIT:default>" ; private static final String TAG = "<STR_LIT>" ; private static ISystemLog sLogger ; private static boolean sConnected = false ; private static String sAppName = DEFAULT_APP_NAME ; private static String sUserId ; public static void setAppName ( String name ) { sAppName = name ; } public static ServiceConnection SystemLogConnection = new ServiceConnection ( ) { public void onServiceConnected ( ComponentName className , IBinder service ) { sLogger = ISystemLog . Stub . asInterface ( service ) ; sConnected = true ; } public void onServiceDisconnected ( ComponentName className ) { sLogger = null ; sConnected = false ; } } ; public static void register ( String tag ) { if ( sConnected ) { try { sLogger . registerLogger ( tag , sAppName ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" + tag , re ) ; } } else { android . util . Log . i ( TAG , "<STR_LIT>" + tag ) ; } } public static boolean isConnected ( ) { return sConnected ; } public static boolean isRegistered ( String tag ) { boolean res = false ; if ( sConnected ) { try { res = sLogger . isRegistered ( tag ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" , re ) ; res = false ; } } else { android . util . Log . e ( tag , "<STR_LIT>" ) ; res = false ; } return res ; } public static void i ( String tag , String message ) { if ( sConnected ) { try { if ( ! sLogger . isRegistered ( tag ) ) register ( tag ) ; sLogger . info ( tag , message ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" , re ) ; } } else { android . util . Log . i ( tag , message ) ; } } public static void d ( String tag , String message ) { if ( sConnected ) { try { if ( ! sLogger . isRegistered ( tag ) ) register ( tag ) ; sLogger . debug ( tag , message ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" , re ) ; } } else { android . util . Log . d ( tag , message ) ; } } public static void e ( String tag , String message , Exception e ) { if ( sConnected ) { try { if ( ! sLogger . isRegistered ( tag ) ) register ( tag ) ; sLogger . error ( tag , message + e . getMessage ( ) ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" , re ) ; } } else { android . util . Log . e ( tag , message , e ) ; } } public static void e ( String tag , String message ) { if ( sConnected ) { try { if ( ! sLogger . isRegistered ( tag ) ) register ( tag ) ; sLogger . error ( tag , message ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" , re ) ; } } else { android . util . Log . e ( tag , message ) ; } } public static void v ( String tag , String message ) { if ( sConnected ) { try { if ( ! sLogger . isRegistered ( tag ) ) register ( tag ) ; sLogger . verbose ( tag , message ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" , re ) ; } } else { android . util . Log . v ( tag , message ) ; } } public static void w ( String tag , String message ) { if ( sConnected ) { try { if ( ! sLogger . isRegistered ( tag ) ) register ( tag ) ; sLogger . warning ( tag , message ) ; } catch ( RemoteException re ) { android . util . Log . e ( TAG , "<STR_LIT>" , re ) ; } } else { android . util . Log . w ( tag , message ) ; } } } </s>
|
<s> package edu . ucla . cens . systemlog ; public interface ISystemLog extends android . os . IInterface { public static abstract class Stub extends android . os . Binder implements edu . ucla . cens . systemlog . ISystemLog { private static final java . lang . String DESCRIPTOR = "<STR_LIT>" ; public Stub ( ) { this . attachInterface ( this , DESCRIPTOR ) ; } public static edu . ucla . cens . systemlog . ISystemLog asInterface ( android . os . IBinder obj ) { if ( ( obj == null ) ) { return null ; } android . os . IInterface iin = ( android . os . IInterface ) obj . queryLocalInterface ( DESCRIPTOR ) ; if ( ( ( iin != null ) && ( iin instanceof edu . ucla . cens . systemlog . ISystemLog ) ) ) { return ( ( edu . ucla . cens . systemlog . ISystemLog ) iin ) ; } return new edu . ucla . cens . systemlog . ISystemLog . Stub . Proxy ( obj ) ; } public android . os . IBinder asBinder ( ) { return this ; } @ Override public boolean onTransact ( int code , android . os . Parcel data , android . os . Parcel reply , int flags ) throws android . os . RemoteException { switch ( code ) { case INTERFACE_TRANSACTION : { reply . writeString ( DESCRIPTOR ) ; return true ; } case TRANSACTION_registerLogger : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _arg0 ; _arg0 = data . readString ( ) ; java . lang . String _arg1 ; _arg1 = data . readString ( ) ; boolean _result = this . registerLogger ( _arg0 , _arg1 ) ; reply . writeNoException ( ) ; reply . writeInt ( ( ( _result ) ? ( <NUM_LIT:1> ) : ( <NUM_LIT:0> ) ) ) ; return true ; } case TRANSACTION_isRegistered : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _arg0 ; _arg0 = data . readString ( ) ; boolean _result = this . isRegistered ( _arg0 ) ; reply . writeNoException ( ) ; reply . writeInt ( ( ( _result ) ? ( <NUM_LIT:1> ) : ( <NUM_LIT:0> ) ) ) ; return true ; } case TRANSACTION_verbose : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _arg0 ; _arg0 = data . readString ( ) ; java . lang . String _arg1 ; _arg1 = data . readString ( ) ; boolean _result = this . verbose ( _arg0 , _arg1 ) ; reply . writeNoException ( ) ; reply . writeInt ( ( ( _result ) ? ( <NUM_LIT:1> ) : ( <NUM_LIT:0> ) ) ) ; return true ; } case TRANSACTION_info : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _arg0 ; _arg0 = data . readString ( ) ; java . lang . String _arg1 ; _arg1 = data . readString ( ) ; boolean _result = this . info ( _arg0 , _arg1 ) ; reply . writeNoException ( ) ; reply . writeInt ( ( ( _result ) ? ( <NUM_LIT:1> ) : ( <NUM_LIT:0> ) ) ) ; return true ; } case TRANSACTION_debug : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _arg0 ; _arg0 = data . readString ( ) ; java . lang . String _arg1 ; _arg1 = data . readString ( ) ; boolean _result = this . debug ( _arg0 , _arg1 ) ; reply . writeNoException ( ) ; reply . writeInt ( ( ( _result ) ? ( <NUM_LIT:1> ) : ( <NUM_LIT:0> ) ) ) ; return true ; } case TRANSACTION_warning : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _arg0 ; _arg0 = data . readString ( ) ; java . lang . String _arg1 ; _arg1 = data . readString ( ) ; boolean _result = this . warning ( _arg0 , _arg1 ) ; reply . writeNoException ( ) ; reply . writeInt ( ( ( _result ) ? ( <NUM_LIT:1> ) : ( <NUM_LIT:0> ) ) ) ; return true ; } case TRANSACTION_error : { data . enforceInterface ( DESCRIPTOR ) ; java . lang . String _arg0 ; _arg0 = data . readString ( ) ; java . lang . String _arg1 ; _arg1 = data . readString ( ) ; boolean _result = this . error ( _arg0 , _arg1 ) ; reply . writeNoException ( ) ; reply . writeInt ( ( ( _result ) ? ( <NUM_LIT:1> ) : ( <NUM_LIT:0> ) ) ) ; return true ; } } return super . onTransact ( code , data , reply , flags ) ; } private static class Proxy implements edu . ucla . cens . systemlog . ISystemLog { private android . os . IBinder mRemote ; Proxy ( android . os . IBinder remote ) { mRemote = remote ; } public android . os . IBinder asBinder ( ) { return mRemote ; } public java . lang . String getInterfaceDescriptor ( ) { return DESCRIPTOR ; } public boolean registerLogger ( java . lang . String tag , java . lang . String dbTable ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; boolean _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeString ( tag ) ; _data . writeString ( dbTable ) ; mRemote . transact ( Stub . TRANSACTION_registerLogger , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = ( <NUM_LIT:0> != _reply . readInt ( ) ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public boolean isRegistered ( java . lang . String tag ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; boolean _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeString ( tag ) ; mRemote . transact ( Stub . TRANSACTION_isRegistered , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = ( <NUM_LIT:0> != _reply . readInt ( ) ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public boolean verbose ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; boolean _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeString ( tag ) ; _data . writeString ( message ) ; mRemote . transact ( Stub . TRANSACTION_verbose , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = ( <NUM_LIT:0> != _reply . readInt ( ) ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public boolean info ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; boolean _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeString ( tag ) ; _data . writeString ( message ) ; mRemote . transact ( Stub . TRANSACTION_info , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = ( <NUM_LIT:0> != _reply . readInt ( ) ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public boolean debug ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; boolean _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeString ( tag ) ; _data . writeString ( message ) ; mRemote . transact ( Stub . TRANSACTION_debug , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = ( <NUM_LIT:0> != _reply . readInt ( ) ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public boolean warning ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; boolean _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeString ( tag ) ; _data . writeString ( message ) ; mRemote . transact ( Stub . TRANSACTION_warning , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = ( <NUM_LIT:0> != _reply . readInt ( ) ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } public boolean error ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException { android . os . Parcel _data = android . os . Parcel . obtain ( ) ; android . os . Parcel _reply = android . os . Parcel . obtain ( ) ; boolean _result ; try { _data . writeInterfaceToken ( DESCRIPTOR ) ; _data . writeString ( tag ) ; _data . writeString ( message ) ; mRemote . transact ( Stub . TRANSACTION_error , _data , _reply , <NUM_LIT:0> ) ; _reply . readException ( ) ; _result = ( <NUM_LIT:0> != _reply . readInt ( ) ) ; } finally { _reply . recycle ( ) ; _data . recycle ( ) ; } return _result ; } } static final int TRANSACTION_registerLogger = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:0> ) ; static final int TRANSACTION_isRegistered = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:1> ) ; static final int TRANSACTION_verbose = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:2> ) ; static final int TRANSACTION_info = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:3> ) ; static final int TRANSACTION_debug = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:4> ) ; static final int TRANSACTION_warning = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:5> ) ; static final int TRANSACTION_error = ( android . os . IBinder . FIRST_CALL_TRANSACTION + <NUM_LIT:6> ) ; } public boolean registerLogger ( java . lang . String tag , java . lang . String dbTable ) throws android . os . RemoteException ; public boolean isRegistered ( java . lang . String tag ) throws android . os . RemoteException ; public boolean verbose ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException ; public boolean info ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException ; public boolean debug ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException ; public boolean warning ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException ; public boolean error ( java . lang . String tag , java . lang . String message ) throws android . os . RemoteException ; } </s>
|
<s> package org . hbasene . index ; import java . util . List ; import java . util . concurrent . BlockingQueue ; import java . util . concurrent . ConcurrentHashMap ; import jsr166y . RecursiveAction ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . hbase . client . Put ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . util . OpenBitSet ; import org . hbasene . index . util . HBaseneUtil ; public class TermVectorPutTask extends RecursiveAction { private static final Log LOG = LogFactory . getLog ( TermVectorPutTask . class ) ; private static final int THRESHOLD = <NUM_LIT> ; private final long docBase ; private final ConcurrentHashMap < String , Object > termVectorMap ; public TermVectorPutTask ( final String [ ] inputTerms , int low , int high , final ConcurrentHashMap < String , Object > termVectorMap , final long docBase , final BlockingQueue < Put > queuePuts ) { this . termVectorMap = termVectorMap ; this . docBase = docBase ; } @ Override protected void compute ( ) { } Put generatePut ( final String key ) { final Object value = this . termVectorMap . get ( key ) ; Put put = new Put ( Bytes . toBytes ( key ) ) ; byte [ ] docSet = null ; if ( value instanceof OpenBitSet ) { docSet = Bytes . add ( Bytes . toBytes ( '<CHAR_LIT>' ) , HBaseneUtil . toBytes ( ( OpenBitSet ) value ) ) ; } else if ( value instanceof List ) { List < Integer > list = ( List < Integer > ) value ; byte [ ] out = new byte [ ( list . size ( ) + <NUM_LIT:1> ) * Bytes . SIZEOF_INT ] ; Bytes . putInt ( out , <NUM_LIT:0> , list . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < list . size ( ) ; ++ i ) { Bytes . putInt ( out , ( i + <NUM_LIT:1> ) * Bytes . SIZEOF_INT , list . get ( i ) . intValue ( ) ) ; } docSet = Bytes . add ( Bytes . toBytes ( '<CHAR_LIT:A>' ) , out ) ; } put . add ( HBaseneConstants . FAMILY_TERMVECTOR , Bytes . toBytes ( this . docBase ) , docSet ) ; put . setWriteToWAL ( true ) ; return put ; } } </s>
|
<s> package org . hbasene . index ; import java . util . List ; public abstract class AbstractTermPositionsEncoder { abstract byte [ ] encode ( final List < Integer > termPositions ) ; abstract int [ ] decode ( final byte [ ] value ) ; abstract int getTermFrequency ( byte [ ] termFreqRepresentation ) ; } </s>
|
<s> package org . hbasene . index ; import java . util . ArrayList ; import java . util . List ; import java . util . concurrent . ConcurrentHashMap ; import jsr166y . RecursiveAction ; import org . apache . lucene . util . OpenBitSet ; public class TermVectorAppendTask extends RecursiveAction { static final int THRESHOLD = <NUM_LIT> ; private final int termVectorArrayThreshold ; private final long relativeId ; private final ConcurrentHashMap < String , Object > termVectorMap ; public TermVectorAppendTask ( final String [ ] inputTerms , int low , int high , final ConcurrentHashMap < String , Object > termVectorMap , final int termVectorArrayThreshold , final long relativeId ) { this . termVectorMap = termVectorMap ; this . termVectorArrayThreshold = termVectorArrayThreshold ; this . relativeId = relativeId ; } @ Override protected void compute ( ) { } void processAssign ( final String fieldTerm ) { Object docs = this . termVectorMap . get ( fieldTerm ) ; if ( docs == null ) { docs = new ArrayList < Integer > ( ) ; this . termVectorMap . put ( fieldTerm , docs ) ; } if ( docs instanceof List ) { List < Integer > listImpl = ( List < Integer > ) docs ; listImpl . add ( ( int ) relativeId ) ; if ( listImpl . size ( ) > this . termVectorArrayThreshold ) { OpenBitSet bitset = new OpenBitSet ( ) ; for ( Integer value : listImpl ) { bitset . set ( value ) ; } listImpl . clear ( ) ; this . termVectorMap . put ( fieldTerm , bitset ) ; } } else if ( docs instanceof OpenBitSet ) { ( ( OpenBitSet ) docs ) . set ( relativeId ) ; } } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . util . Arrays ; import java . util . Collection ; import java . util . Map ; import java . util . NavigableMap ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . hbase . client . Get ; import org . apache . hadoop . hbase . client . HTable ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . hadoop . hbase . client . Result ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Field ; import org . apache . lucene . document . FieldSelector ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . index . IndexReader ; import org . apache . lucene . index . Term ; import org . apache . lucene . index . TermDocs ; import org . apache . lucene . index . TermEnum ; import org . apache . lucene . index . TermFreqVector ; import org . apache . lucene . index . TermPositions ; import org . apache . lucene . index . TermVectorMapper ; import org . apache . lucene . search . DefaultSimilarity ; public class HBaseIndexReader extends IndexReader { private static final Log LOG = LogFactory . getLog ( HBaseIndexReader . class ) ; private final String indexName ; private final HTablePool tablePool ; static final byte DEFAULT_NORM = DefaultSimilarity . encodeNorm ( <NUM_LIT:1.0f> ) ; private final AbstractTermPositionsEncoder termPositionEncoder = new AlphaTermPositionsEncoder ( ) ; private final byte [ ] primaryKeyField ; public HBaseIndexReader ( final HTablePool tablePool , final String indexName , final String primaryKeyField ) { this . tablePool = tablePool ; this . indexName = indexName ; this . primaryKeyField = Bytes . toBytes ( primaryKeyField ) ; } @ Override protected void doClose ( ) throws IOException { } @ Override protected void doCommit ( Map < String , String > commitUserData ) throws IOException { } @ Override protected void doDelete ( int docNum ) throws CorruptIndexException , IOException { } @ Override protected void doSetNorm ( int doc , String field , byte value ) throws CorruptIndexException , IOException { } @ Override protected void doUndeleteAll ( ) throws CorruptIndexException , IOException { } @ Override public int docFreq ( Term t ) throws IOException { final String rowKey = t . field ( ) + "<STR_LIT:/>" + t . text ( ) ; Get get = new Get ( Bytes . toBytes ( rowKey ) ) ; get . addFamily ( HBaseneConstants . FAMILY_TERMVECTOR ) ; HTable table = this . getTablePool ( ) . getTable ( this . indexName ) ; try { Result result = table . get ( get ) ; if ( result == null ) { return <NUM_LIT:0> ; } NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( HBaseneConstants . FAMILY_TERMVECTOR ) ; if ( map == null ) { return <NUM_LIT:0> ; } return map . size ( ) ; } finally { this . getTablePool ( ) . putTable ( table ) ; } } @ Override public Document document ( int n , FieldSelector fieldSelector ) throws CorruptIndexException , IOException { final long index = ( long ) n ; Document doc = null ; HTable table = this . getTablePool ( ) . getTable ( this . indexName ) ; try { Get get = new Get ( Bytes . toBytes ( index ) ) ; get . addColumn ( HBaseneConstants . FAMILY_FIELDS , this . primaryKeyField ) ; doc = new Document ( ) ; Result result = table . get ( get ) ; byte [ ] docId = result . getValue ( HBaseneConstants . FAMILY_FIELDS , this . primaryKeyField ) ; doc . add ( new Field ( "<STR_LIT:id>" , Bytes . toString ( docId ) , Field . Store . YES , Field . Index . NO ) ) ; } finally { this . getTablePool ( ) . putTable ( table ) ; } return doc ; } @ Override public Collection < String > getFieldNames ( FieldOption fldOption ) { return Arrays . asList ( new String [ ] { } ) ; } @ Override public TermFreqVector getTermFreqVector ( int docNumber , String field ) throws IOException { return null ; } @ Override public void getTermFreqVector ( int docNumber , TermVectorMapper mapper ) throws IOException { } @ Override public void getTermFreqVector ( int docNumber , String field , TermVectorMapper mapper ) throws IOException { } @ Override public TermFreqVector [ ] getTermFreqVectors ( int docNumber ) throws IOException { return null ; } @ Override public boolean hasDeletions ( ) { return false ; } @ Override public boolean isDeleted ( int n ) { return false ; } @ Override public int maxDoc ( ) { return this . numDocs ( ) + <NUM_LIT:1> ; } @ Override public byte [ ] norms ( String field ) throws IOException { byte [ ] result = new byte [ this . maxDoc ( ) ] ; Arrays . fill ( result , DEFAULT_NORM ) ; return result ; } @ Override public void norms ( String field , byte [ ] bytes , int offset ) throws IOException { } @ Override public int numDocs ( ) { HTable table = this . getTablePool ( ) . getTable ( this . indexName ) ; int numDocs = <NUM_LIT:0> ; try { Get get = new Get ( HBaseneConstants . ROW_SEQUENCE_ID ) ; get . addColumn ( HBaseneConstants . FAMILY_SEQUENCE , HBaseneConstants . QUALIFIER_SEQUENCE ) ; Result result = table . get ( get ) ; numDocs = ( int ) Bytes . toLong ( result . getValue ( HBaseneConstants . FAMILY_SEQUENCE , HBaseneConstants . QUALIFIER_SEQUENCE ) ) ; } catch ( IOException e ) { LOG . warn ( "<STR_LIT>" , e ) ; } finally { this . getTablePool ( ) . putTable ( table ) ; } return numDocs ; } @ Override public TermDocs termDocs ( ) throws IOException { return new HBaseTermPositions ( this , this . termPositionEncoder ) ; } @ Override public TermPositions termPositions ( ) throws IOException { return new HBaseTermPositions ( this , this . termPositionEncoder ) ; } @ Override public TermEnum terms ( ) throws IOException { return new HBaseTermEnum ( this ) ; } @ Override public TermEnum terms ( Term t ) throws IOException { HBaseTermEnum termEnum = ( HBaseTermEnum ) terms ( ) ; termEnum . skipTo ( t ) ; return termEnum ; } public HTablePool getTablePool ( ) { return this . tablePool ; } public String getIndexName ( ) { return this . indexName ; } } </s>
|
<s> package org . hbasene . index . search ; import java . io . IOException ; import java . util . Comparator ; import java . util . Map ; import java . util . NavigableMap ; import java . util . PriorityQueue ; import java . util . TreeMap ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . hbase . client . HTable ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . hadoop . hbase . client . Result ; import org . apache . hadoop . hbase . client . ResultScanner ; import org . apache . hadoop . hbase . client . Scan ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . index . IndexReader ; import org . apache . lucene . search . Collector ; import org . apache . lucene . search . ScoreDoc ; import org . apache . lucene . search . Scorer ; import org . apache . lucene . search . Sort ; import org . apache . lucene . search . SortField ; import org . apache . lucene . search . TopFieldDocs ; import org . hbasene . index . HBaseneConstants ; import com . google . common . collect . Sets ; import com . google . common . collect . Sets . SetView ; public final class HBaseTopFieldCollector extends Collector implements HBaseneConstants { private static final Log LOG = LogFactory . getLog ( HBaseTopFieldCollector . class ) ; private static final int DOCS_THRESHOLD = <NUM_LIT:1000> ; private final HTablePool tablePool ; private final String indexName ; private final int nDocs ; private final NavigableMap < byte [ ] , SortFieldDoc > docMap = new TreeMap < byte [ ] , SortFieldDoc > ( new BytesAsLongComparator ( ) ) ; private final PriorityQueue < SortFieldDoc > pq ; private final SortField [ ] fields ; private Scorer scorer ; private int pendingDocs ; private int totalHits ; private static final Comparator < SortFieldDoc > ASCENDING_COMPARATOR = new SortFieldDocComparatorAsc ( ) ; private static final Comparator < SortFieldDoc > DESCENDING_COMPARATOR = new SortFieldDocComparatorDesc ( ) ; public HBaseTopFieldCollector ( final HTablePool tablePool , final String indexName , final int nDocs , final Sort sort ) { this . tablePool = tablePool ; this . indexName = indexName ; this . nDocs = nDocs ; this . fields = sort . getSort ( ) ; this . pendingDocs = <NUM_LIT:0> ; this . totalHits = <NUM_LIT:0> ; this . pq = new PriorityQueue < SortFieldDoc > ( nDocs , this . fields [ <NUM_LIT:0> ] . getReverse ( ) ? DESCENDING_COMPARATOR : ASCENDING_COMPARATOR ) ; if ( fields . length > <NUM_LIT:1> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } @ Override public void collect ( int doc ) throws IOException { float currentScore = <NUM_LIT:1.0f> ; if ( this . scorer != null ) { currentScore = this . scorer . score ( ) ; } byte [ ] key = Bytes . toBytes ( ( long ) doc ) ; docMap . put ( key , new SortFieldDoc ( doc , currentScore , <NUM_LIT:1> ) ) ; ++ pendingDocs ; if ( this . pendingDocs == DOCS_THRESHOLD ) { this . appendToPQ ( ) ; this . pendingDocs = <NUM_LIT:0> ; } ++ this . totalHits ; } @ Override public void setNextReader ( IndexReader reader , int docBase ) throws IOException { } @ Override public void setScorer ( Scorer scorer ) throws IOException { this . scorer = scorer ; } @ Override public boolean acceptsDocsOutOfOrder ( ) { return true ; } TopFieldDocs topDocs ( ) throws IOException { if ( this . pendingDocs > <NUM_LIT:0> ) { this . appendToPQ ( ) ; this . pendingDocs = <NUM_LIT:0> ; } int arraySize = ( this . totalHits >= this . nDocs ) ? this . nDocs : this . totalHits ; ScoreDoc [ ] scoreDocs = new ScoreDoc [ arraySize ] ; for ( int i = <NUM_LIT:0> ; i < this . nDocs ; ++ i ) { scoreDocs [ i ] = this . pq . poll ( ) ; } return new TopFieldDocs ( this . totalHits , scoreDocs , this . fields , <NUM_LIT:0.0f> ) ; } public void appendToPQ ( ) throws IOException { this . doAppendToPQ ( this . docMap , this . pq , this . fields [ <NUM_LIT:0> ] . getField ( ) , <NUM_LIT:0> ) ; } private void doAppendToPQ ( final Map < byte [ ] , SortFieldDoc > docMap , final PriorityQueue < SortFieldDoc > outputPq , final String sortField , final int sortIndex ) throws IOException { HTable table = this . tablePool . getTable ( this . indexName ) ; final String sortFieldPrefix = sortField + "<STR_LIT:/>" ; try { byte [ ] row = Bytes . toBytes ( sortFieldPrefix ) ; Result priorToFirstTerm = table . getRowOrBefore ( row , FAMILY_TERMVECTOR ) ; ResultScanner scanner = table . getScanner ( this . createScan ( ( priorToFirstTerm != null ) ? priorToFirstTerm . getRow ( ) : null ) ) ; try { int index = <NUM_LIT:0> ; Result result = scanner . next ( ) ; while ( result != null ) { String currentRow = Bytes . toString ( result . getRow ( ) ) ; if ( currentRow . startsWith ( sortFieldPrefix ) ) { ++ index ; NavigableMap < byte [ ] , byte [ ] > columnQualifiers = result . getFamilyMap ( FAMILY_TERMVECTOR ) ; SetView < byte [ ] > intersectionSet = Sets . intersection ( columnQualifiers . keySet ( ) , docMap . keySet ( ) ) ; for ( final byte [ ] commonDocId : intersectionSet ) { SortFieldDoc next = docMap . get ( commonDocId ) ; next . indices [ sortIndex ] = index ; outputPq . add ( next ) ; } docMap . keySet ( ) . removeAll ( intersectionSet ) ; LOG . info ( "<STR_LIT>" + currentRow + "<STR_LIT>" + docMap . size ( ) ) ; if ( docMap . isEmpty ( ) ) { break ; } } result = scanner . next ( ) ; } } finally { scanner . close ( ) ; } } finally { this . tablePool . putTable ( table ) ; } } private Scan createScan ( final byte [ ] prefix ) { Scan scan = new Scan ( ) ; if ( prefix != null ) { scan . setStartRow ( prefix ) ; } scan . addFamily ( FAMILY_TERMVECTOR ) ; scan . setCaching ( <NUM_LIT:20> ) ; return scan ; } private static class SortFieldDoc extends ScoreDoc { private int [ ] indices ; public SortFieldDoc ( int doc , float score , int totalLength ) { super ( doc , score ) ; this . indices = new int [ totalLength ] ; for ( int i = <NUM_LIT:0> ; i < totalLength ; ++ i ) { indices [ i ] = - <NUM_LIT:1> ; } } } private static class SortFieldDocComparatorAsc implements Comparator < SortFieldDoc > { @ Override public int compare ( SortFieldDoc lhs , SortFieldDoc rhs ) { if ( lhs . indices . length > rhs . indices . length ) { return <NUM_LIT:1> ; } else if ( lhs . indices . length < rhs . indices . length ) { return - <NUM_LIT:1> ; } else { for ( int i = <NUM_LIT:0> ; i < lhs . indices . length ; ++ i ) { if ( lhs . indices [ i ] > rhs . indices [ i ] ) { return <NUM_LIT:1> ; } else if ( lhs . indices [ i ] < rhs . indices [ i ] ) { return - <NUM_LIT:1> ; } } return Float . compare ( lhs . score , rhs . score ) ; } } } private static class SortFieldDocComparatorDesc implements Comparator < SortFieldDoc > { @ Override public int compare ( SortFieldDoc lhs , SortFieldDoc rhs ) { if ( lhs . indices . length > rhs . indices . length ) { return <NUM_LIT:1> ; } else if ( lhs . indices . length < rhs . indices . length ) { return - <NUM_LIT:1> ; } else { for ( int i = <NUM_LIT:0> ; i < lhs . indices . length ; ++ i ) { if ( lhs . indices [ i ] < rhs . indices [ i ] ) { return <NUM_LIT:1> ; } else if ( lhs . indices [ i ] > rhs . indices [ i ] ) { return - <NUM_LIT:1> ; } } return Float . compare ( lhs . score , rhs . score ) ; } } } private static class BytesAsLongComparator implements Comparator < byte [ ] > { @ Override public int compare ( byte [ ] o1 , byte [ ] o2 ) { long lhs = Bytes . toLong ( o1 ) ; long rhs = Bytes . toLong ( o2 ) ; if ( lhs > rhs ) { return - <NUM_LIT:1> ; } else if ( lhs < rhs ) { return <NUM_LIT:1> ; } else { return <NUM_LIT:0> ; } } } } </s>
|
<s> package org . hbasene . index . search ; import java . io . IOException ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . search . Filter ; import org . apache . lucene . search . IndexSearcher ; import org . apache . lucene . search . Sort ; import org . apache . lucene . search . SortField ; import org . apache . lucene . search . TopFieldDocs ; import org . apache . lucene . search . Weight ; import org . hbasene . index . HBaseIndexReader ; import org . hbasene . index . HBaseneConstants ; public class HBaseIndexSearcher extends IndexSearcher implements HBaseneConstants { @ SuppressWarnings ( "<STR_LIT:unused>" ) private static final Log LOG = LogFactory . getLog ( HBaseIndexSearcher . class ) ; private final HTablePool tablePool ; private final String indexName ; public HBaseIndexSearcher ( HBaseIndexReader indexReader ) throws CorruptIndexException , IOException { super ( indexReader ) ; this . tablePool = indexReader . getTablePool ( ) ; this . indexName = indexReader . getIndexName ( ) ; } @ Override public TopFieldDocs search ( Weight weight , Filter filter , final int nDocs , Sort sort , boolean fillFields ) throws IOException { SortField [ ] fields = sort . getSort ( ) ; return ( fields . length == <NUM_LIT:1> && fields [ <NUM_LIT:0> ] == SortField . FIELD_SCORE ) ? super . search ( weight , filter , nDocs , sort , fillFields ) : doSearch ( weight , filter , nDocs , sort , fillFields ) ; } TopFieldDocs doSearch ( final Weight weight , Filter filter , int nDocs , Sort sort , boolean fillFields ) throws IOException { HBaseTopFieldCollector topFieldCollector = new HBaseTopFieldCollector ( this . tablePool , this . indexName , nDocs , sort ) ; search ( weight , filter , topFieldCollector ) ; return ( TopFieldDocs ) topFieldCollector . topDocs ( ) ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; public abstract class AbstractIndexStore { public abstract void commit ( ) throws IOException ; public abstract void close ( ) throws IOException ; public abstract SegmentInfo indexDocument ( final String key , final DocumentIndexContext documentIndexContext ) throws IOException ; } </s>
|
<s> package org . hbasene . index ; import java . util . List ; import java . util . Map ; public class DocumentIndexContext { final Map < String , List < Integer > > termPositionVectors ; final Map < String , byte [ ] > storeFields ; public DocumentIndexContext ( final Map < String , List < Integer > > termPositionVectors , final Map < String , byte [ ] > storeFields ) { this . termPositionVectors = termPositionVectors ; this . storeFields = storeFields ; } } </s>
|
<s> package org . hbasene . index ; import org . apache . hadoop . hbase . util . Bytes ; public interface HBaseneConstants { static final byte [ ] FAMILY_TERMVECTOR = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] FAMILY_TERMFREQUENCIES = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] FAMILY_PAYLOADS = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] FAMILY_FIELDS = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] FAMILY_DOC_TO_INT = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] QUALIFIER_INT = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] FAMILY_INT_TO_DOC = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] QUALIFIER_DOC = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] FAMILY_SEQUENCE = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] QUALIFIER_SEQUENCE = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] QUALIFIER_SEGMENT = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] ROW_SEQUENCE_ID = Bytes . toBytes ( "<STR_LIT>" ) ; static final byte [ ] ROW_SEGMENT_ID = Bytes . toBytes ( "<STR_LIT>" ) ; static final String TERM_FREQ_PREFIX = "<STR_LIT>" ; static final String CONF_AUTOCOMMIT_MAXDOCS = "<STR_LIT>" ; } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . io . StringReader ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . analysis . Analyzer ; import org . apache . lucene . analysis . TokenStream ; import org . apache . lucene . analysis . tokenattributes . PositionIncrementAttribute ; import org . apache . lucene . analysis . tokenattributes . TermAttribute ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Fieldable ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . store . LockObtainFailedException ; import com . google . common . collect . Lists ; public class HBaseIndexWriter { private static final Log LOG = LogFactory . getLog ( HBaseIndexWriter . class ) ; private final AbstractIndexStore indexStore ; private final String primaryKeyField ; static final List < Integer > EMPTY_TERM_POSITIONS = Arrays . asList ( new Integer [ ] { <NUM_LIT:0> } ) ; public HBaseIndexWriter ( final AbstractIndexStore indexTransactionLog , final String primaryKeyField ) throws IOException { this . indexStore = indexTransactionLog ; this . primaryKeyField = primaryKeyField ; } public void addDocument ( Document doc , Analyzer analyzer ) throws CorruptIndexException , IOException { String docId = doc . get ( this . primaryKeyField ) ; if ( docId == null ) { throw new IllegalArgumentException ( "<STR_LIT>" + this . primaryKeyField + "<STR_LIT>" ) ; } int position = <NUM_LIT:0> ; Map < String , List < Integer > > termPositions = new HashMap < String , List < Integer > > ( ) ; Map < String , byte [ ] > fieldsToStore = new HashMap < String , byte [ ] > ( ) ; for ( Fieldable field : doc . getFields ( ) ) { if ( field . isIndexed ( ) && field . isTokenized ( ) ) { TokenStream tokens = field . tokenStreamValue ( ) ; if ( tokens == null ) { tokens = analyzer . tokenStream ( field . name ( ) , new StringReader ( field . stringValue ( ) ) ) ; } tokens . addAttribute ( TermAttribute . class ) ; tokens . addAttribute ( PositionIncrementAttribute . class ) ; if ( position > <NUM_LIT:0> ) { position += analyzer . getPositionIncrementGap ( field . name ( ) ) ; } while ( tokens . incrementToken ( ) ) { String term = createColumnName ( field . name ( ) , tokens . getAttribute ( TermAttribute . class ) . term ( ) ) ; List < Integer > pvec = termPositions . get ( term ) ; if ( pvec == null ) { pvec = Lists . newArrayList ( ) ; termPositions . put ( term , pvec ) ; } position += ( tokens . getAttribute ( PositionIncrementAttribute . class ) . getPositionIncrement ( ) - <NUM_LIT:1> ) ; pvec . add ( ++ position ) ; } tokens . close ( ) ; } if ( field . isIndexed ( ) && ! field . isTokenized ( ) ) { String term = this . createColumnName ( field . name ( ) , field . stringValue ( ) ) ; String key = term ; termPositions . put ( key , EMPTY_TERM_POSITIONS ) ; } if ( field . isStored ( ) ) { byte [ ] value = field . isBinary ( ) ? field . getBinaryValue ( ) : Bytes . toBytes ( field . stringValue ( ) ) ; final byte [ ] prefix = Bytes . toBytes ( ( field . isBinary ( ) ? '<CHAR_LIT>' : '<CHAR_LIT>' ) ) ; fieldsToStore . put ( field . name ( ) , Bytes . add ( prefix , value ) ) ; } } indexStore . indexDocument ( docId , new DocumentIndexContext ( termPositions , fieldsToStore ) ) ; termPositions . clear ( ) ; fieldsToStore . clear ( ) ; } public void commit ( ) throws IOException { this . indexStore . commit ( ) ; } public void close ( ) throws IOException { this . indexStore . close ( ) ; } String createColumnName ( final String fieldName , final String term ) { return fieldName + "<STR_LIT:/>" + term ; } } </s>
|
<s> package org . hbasene . index ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . lucene . index . TermFreqVector ; public class HBaseTermFreqVector implements TermFreqVector { private HTablePool tablePool ; private String indexName ; public HBaseTermFreqVector ( final HBaseIndexReader indexReader ) { this . tablePool = indexReader . getTablePool ( ) ; this . indexName = indexReader . getIndexName ( ) ; } @ Override public String getField ( ) { return null ; } @ Override public int [ ] getTermFrequencies ( ) { return null ; } @ Override public String [ ] getTerms ( ) { return null ; } @ Override public int indexOf ( String term ) { return <NUM_LIT:0> ; } @ Override public int [ ] indexesOf ( String [ ] terms , int start , int len ) { return null ; } @ Override public int size ( ) { return <NUM_LIT:0> ; } } </s>
|
<s> package org . hbasene . index ; public class SegmentInfo { private final int documentId ; private final long segmentId ; public SegmentInfo ( final long segmentId , final int documentId ) { this . documentId = documentId ; this . segmentId = segmentId ; } public long getSegmentId ( ) { return this . segmentId ; } public int getDocumentId ( ) { return this . documentId ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; import java . util . concurrent . BlockingQueue ; import java . util . concurrent . LinkedBlockingQueue ; import org . apache . hadoop . hbase . HBaseConfiguration ; import org . apache . hadoop . hbase . client . HTable ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . hadoop . hbase . util . Bytes ; public class IndexHTablePool extends HTablePool { private final HBaseConfiguration conf ; private final int maxSize ; private final Map < String , BlockingQueue < HTable > > tables = Collections . synchronizedMap ( new HashMap < String , BlockingQueue < HTable > > ( ) ) ; public IndexHTablePool ( final HBaseConfiguration conf , int maxSize ) { super ( conf , maxSize ) ; this . conf = conf ; this . maxSize = maxSize ; } public void close ( final String tableName ) throws IOException { for ( int i = <NUM_LIT:0> ; i < this . maxSize ; ++ i ) { this . getTable ( tableName ) . close ( ) ; } } @ Override protected HTable newHTable ( String tableName ) { try { HTable table = new HTable ( conf , Bytes . toBytes ( tableName ) ) ; table . setAutoFlush ( false ) ; return table ; } catch ( IOException ioe ) { throw new RuntimeException ( ioe ) ; } } @ Override public HTable getTable ( String tableName ) { BlockingQueue < HTable > queue = tables . get ( tableName ) ; if ( queue == null ) { synchronized ( tables ) { queue = tables . get ( tableName ) ; if ( queue == null ) { queue = new LinkedBlockingQueue < HTable > ( this . maxSize ) ; for ( int i = <NUM_LIT:0> ; i < this . maxSize ; ++ i ) { queue . add ( this . newHTable ( tableName ) ) ; } tables . put ( tableName , queue ) ; } } } try { return queue . take ( ) ; } catch ( Exception ex ) { return null ; } } public HTable getTable ( byte [ ] tableName ) { return getTable ( Bytes . toString ( tableName ) ) ; } @ Override public void putTable ( HTable table ) { BlockingQueue < HTable > queue = tables . get ( Bytes . toString ( table . getTableName ( ) ) ) ; try { queue . put ( table ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . util . ArrayList ; import java . util . List ; import java . util . NavigableMap ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . hbase . client . Get ; import org . apache . hadoop . hbase . client . HTable ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . hadoop . hbase . client . Result ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . index . Term ; import org . apache . lucene . index . TermEnum ; import org . apache . lucene . index . TermPositions ; import com . google . common . base . Function ; public class HBaseTermPositions implements TermPositions { @ SuppressWarnings ( "<STR_LIT:unused>" ) private static final Log LOG = LogFactory . getLog ( HBaseTermPositions . class ) ; public static final Function < byte [ ] , Long > BYTES_TO_DOCID = new Function < byte [ ] , Long > ( ) { @ Override public Long apply ( byte [ ] from ) { return Bytes . toLong ( from ) ; } } ; private final HTable table ; private final HTablePool pool ; private List < byte [ ] > documents ; private int currentIndex ; private byte [ ] currentRow ; private int [ ] currentTermPositions ; private int currentTermPositionIndex ; private AbstractTermPositionsEncoder termPositionsEncoder ; public HBaseTermPositions ( final HBaseIndexReader reader , final AbstractTermPositionsEncoder termPositionsEncoder ) throws IOException { this . pool = reader . getTablePool ( ) ; this . table = this . pool . getTable ( reader . getIndexName ( ) ) ; this . termPositionsEncoder = termPositionsEncoder ; } @ Override public void close ( ) throws IOException { this . documents . clear ( ) ; this . currentIndex = <NUM_LIT:0> ; this . pool . putTable ( table ) ; } @ Override public int doc ( ) { return ( int ) Bytes . toLong ( this . documents . get ( this . currentIndex ) ) ; } @ Override public int freq ( ) { return this . currentTermPositions . length ; } @ Override public boolean next ( ) throws IOException { if ( currentIndex < ( this . documents . size ( ) - <NUM_LIT:1> ) ) { this . currentIndex ++ ; resetTermPositions ( ) ; return true ; } else { return false ; } } void resetTermPositions ( ) throws IOException { Get get = new Get ( this . currentRow ) ; get . addColumn ( HBaseneConstants . FAMILY_TERMVECTOR , this . documents . get ( this . currentIndex ) ) ; Result result = table . get ( get ) ; byte [ ] tfArray = result . getValue ( HBaseneConstants . FAMILY_TERMVECTOR , this . documents . get ( this . currentIndex ) ) ; this . currentTermPositionIndex = <NUM_LIT:0> ; this . currentTermPositions = this . termPositionsEncoder . decode ( tfArray ) ; } @ Override public int read ( int [ ] docs , int [ ] freqs ) throws IOException { int count = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < docs . length ; ++ i ) { if ( next ( ) ) { docs [ i ] = this . doc ( ) ; freqs [ i ] = this . freq ( ) ; ++ count ; } else { break ; } } return count ; } @ Override public void seek ( Term term ) throws IOException { final String rowKey = term . field ( ) + "<STR_LIT:/>" + term . text ( ) ; this . currentRow = Bytes . toBytes ( rowKey ) ; Result result = this . getRowWithTermVectors ( ) ; NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( HBaseneConstants . FAMILY_TERMVECTOR ) ; this . documents = new ArrayList < byte [ ] > ( map . keySet ( ) ) ; this . currentIndex = - <NUM_LIT:1> ; } Result getRowWithTermVectors ( ) throws IOException { Get get = new Get ( this . currentRow ) ; get . addFamily ( HBaseneConstants . FAMILY_TERMVECTOR ) ; return this . table . get ( get ) ; } @ Override public void seek ( TermEnum termEnum ) throws IOException { seek ( termEnum . term ( ) ) ; } @ Override public boolean skipTo ( int target ) throws IOException { for ( int i = <NUM_LIT:0> ; i < this . documents . size ( ) ; ++ i ) { if ( Bytes . toLong ( this . documents . get ( i ) ) >= target ) { currentIndex = i ; return true ; } } return false ; } @ Override public byte [ ] getPayload ( byte [ ] data , int offset ) throws IOException { return null ; } @ Override public int getPayloadLength ( ) { return <NUM_LIT:0> ; } @ Override public boolean isPayloadAvailable ( ) { return false ; } @ Override public int nextPosition ( ) throws IOException { return this . currentTermPositions [ this . currentTermPositionIndex ++ ] ; } } </s>
|
<s> package org . hbasene . index ; import java . util . List ; import org . apache . hadoop . hbase . util . Bytes ; public class AlphaTermPositionsEncoder extends AbstractTermPositionsEncoder { @ Override int [ ] decode ( byte [ ] value ) { int length = ( value . length / Bytes . SIZEOF_INT ) ; int [ ] result = new int [ length ] ; for ( int i = <NUM_LIT:0> ; i < length ; ++ i ) { result [ i ] = Bytes . toInt ( value , i * Bytes . SIZEOF_INT ) ; } return result ; } @ Override byte [ ] encode ( List < Integer > termPositions ) { byte [ ] encoded = new byte [ termPositions . size ( ) * Bytes . SIZEOF_INT ] ; for ( int i = <NUM_LIT:0> ; i < termPositions . size ( ) ; ++ i ) { Bytes . putInt ( encoded , i * Bytes . SIZEOF_INT , termPositions . get ( i ) ) ; } return encoded ; } @ Override int getTermFrequency ( byte [ ] termPositions ) { return ( termPositions . length / Bytes . SIZEOF_INT ) ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Set ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . conf . Configuration ; import org . apache . hadoop . hbase . HBaseConfiguration ; import org . apache . hadoop . hbase . HColumnDescriptor ; import org . apache . hadoop . hbase . HTableDescriptor ; import org . apache . hadoop . hbase . client . HBaseAdmin ; import org . apache . hadoop . hbase . client . HTable ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . hadoop . hbase . client . Put ; import org . apache . hadoop . hbase . io . hfile . Compression . Algorithm ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . util . OpenBitSet ; import org . hbasene . index . util . HBaseneUtil ; import com . google . common . collect . Maps ; public class HBaseIndexStore extends AbstractIndexStore implements HBaseneConstants { private static final Log LOG = LogFactory . getLog ( HBaseIndexStore . class ) ; private final Map < String , Object > termVector = new HashMap < String , Object > ( ) ; private final Map < String , Map < Integer , List < Integer > > > termFrequencies = new HashMap < String , Map < Integer , List < Integer > > > ( ) ; private long segmentId = <NUM_LIT:0> ; private int documentId = - <NUM_LIT:1> ; private final int maxCommitDocs ; private final int arrayThreshold ; private final HTable table ; private final AbstractTermPositionsEncoder termPositionEncoder = new AlphaTermPositionsEncoder ( ) ; public HBaseIndexStore ( final HTablePool tablePool , final Configuration configuration , final String indexName ) throws IOException { this . table = tablePool . getTable ( indexName ) ; this . doIncrementSegmentId ( ) ; this . maxCommitDocs = configuration . getInt ( CONF_AUTOCOMMIT_MAXDOCS , <NUM_LIT:1000> ) ; this . arrayThreshold = OpenBitSet . bits2words ( maxCommitDocs ) ; } @ Override public synchronized void close ( ) throws IOException { commit ( ) ; this . table . close ( ) ; } @ Override public synchronized void commit ( ) throws IOException { this . doCommit ( ) ; } public int getMaxCommitDocs ( ) { return this . maxCommitDocs ; } public synchronized SegmentInfo indexDocument ( final String key , final DocumentIndexContext documentIndexContext ) throws IOException { ++ this . documentId ; final byte [ ] currentRow = this . getCurrentRow ( ) ; this . doAddTermVector ( documentId , documentIndexContext . termPositionVectors . keySet ( ) ) ; this . doAddTermFrequency ( documentId , documentIndexContext . termPositionVectors ) ; this . doStoreFields ( currentRow , documentIndexContext . storeFields ) ; this . doStoreReverseMapping ( key , currentRow ) ; SegmentInfo segmentInfo = new SegmentInfo ( this . segmentId , this . documentId ) ; if ( this . documentId == this . maxCommitDocs ) { doCommit ( ) ; } return segmentInfo ; } void doStoreReverseMapping ( final String key , final byte [ ] currentRow ) { Put put = new Put ( Bytes . toBytes ( key ) ) ; put . add ( FAMILY_DOC_TO_INT , QUALIFIER_INT , currentRow ) ; put . setWriteToWAL ( true ) ; this . table . getWriteBuffer ( ) . add ( put ) ; } void doAddTermFrequency ( final int docId , final Map < String , List < Integer > > termFrequencies ) throws IOException { for ( final Map . Entry < String , List < Integer > > entry : termFrequencies . entrySet ( ) ) { if ( entry . getValue ( ) . size ( ) == <NUM_LIT:1> && entry . getValue ( ) . get ( <NUM_LIT:0> ) == <NUM_LIT:0> ) { continue ; } Map < Integer , List < Integer > > existingFrequencies = this . termFrequencies . get ( entry . getKey ( ) ) ; if ( existingFrequencies == null ) { existingFrequencies = Maps . newHashMap ( ) ; this . termFrequencies . put ( entry . getKey ( ) , existingFrequencies ) ; } existingFrequencies . put ( docId , entry . getValue ( ) ) ; } } void doAddTermVector ( final int docId , final Set < String > fieldTerms ) throws IOException { for ( final String fieldTerm : fieldTerms ) { Object bitset = this . termVector . get ( fieldTerm ) ; if ( bitset == null ) { bitset = new ArrayList < Integer > ( ) ; this . termVector . put ( fieldTerm , bitset ) ; } if ( bitset instanceof List ) { List < Integer > impl = ( List < Integer > ) bitset ; impl . add ( docId ) ; if ( impl . size ( ) >= this . arrayThreshold ) { bitset = new OpenBitSet ( ) ; for ( Integer existingDocId : impl ) { ( ( OpenBitSet ) bitset ) . set ( existingDocId ) ; } this . termVector . put ( fieldTerm , bitset ) ; } } if ( bitset instanceof OpenBitSet ) { ( ( OpenBitSet ) bitset ) . set ( docId ) ; } } } private void doCommit ( ) throws IOException { final int sz = this . termVector . size ( ) ; final long start = System . nanoTime ( ) ; this . doCommitTermVector ( ) ; this . doCommitTermFrequencies ( ) ; LOG . info ( "<STR_LIT>" + sz + "<STR_LIT>" + table + "<STR_LIT>" + ( double ) ( System . nanoTime ( ) - start ) / ( double ) <NUM_LIT> + "<STR_LIT>" ) ; this . documentId = <NUM_LIT:0> ; this . segmentId = doIncrementSegmentId ( ) ; } void doCommitTermVector ( ) throws IOException { for ( final Map . Entry < String , Object > entry : this . termVector . entrySet ( ) ) { final String key = entry . getKey ( ) ; final Object value = entry . getValue ( ) ; Put put = new Put ( Bytes . toBytes ( key ) ) ; byte [ ] docSet = null ; if ( value instanceof OpenBitSet ) { docSet = Bytes . add ( Bytes . toBytes ( '<CHAR_LIT>' ) , HBaseneUtil . toBytes ( ( OpenBitSet ) entry . getValue ( ) ) ) ; } else if ( value instanceof List ) { List < Integer > list = ( List < Integer > ) value ; byte [ ] out = new byte [ ( list . size ( ) + <NUM_LIT:1> ) * Bytes . SIZEOF_INT ] ; Bytes . putInt ( out , <NUM_LIT:0> , list . size ( ) ) ; for ( int i = <NUM_LIT:0> ; i < list . size ( ) ; ++ i ) { Bytes . putInt ( out , ( i + <NUM_LIT:1> ) * Bytes . SIZEOF_INT , list . get ( i ) . intValue ( ) ) ; } docSet = Bytes . add ( Bytes . toBytes ( '<CHAR_LIT:A>' ) , out ) ; } put . add ( HBaseneConstants . FAMILY_TERMVECTOR , Bytes . toBytes ( this . segmentId ) , docSet ) ; put . setWriteToWAL ( true ) ; this . table . getWriteBuffer ( ) . add ( put ) ; } this . table . flushCommits ( ) ; this . termVector . clear ( ) ; } void doCommitTermFrequencies ( ) throws IOException { List < Put > puts = new ArrayList < Put > ( ) ; for ( Map . Entry < String , Map < Integer , List < Integer > > > entry : termFrequencies . entrySet ( ) ) { Put put = new Put ( Bytes . toBytes ( HBaseneConstants . TERM_FREQ_PREFIX + "<STR_LIT:/>" + entry . getKey ( ) + "<STR_LIT:/>" + this . segmentId ) ) ; for ( final Map . Entry < Integer , List < Integer > > termFrequencyEntry : entry . getValue ( ) . entrySet ( ) ) { put . add ( HBaseneConstants . FAMILY_TERMFREQUENCIES , Bytes . toBytes ( termFrequencyEntry . getKey ( ) ) , Bytes . toBytes ( termFrequencyEntry . getValue ( ) . size ( ) ) ) ; } puts . add ( put ) ; if ( puts . size ( ) == <NUM_LIT> ) { this . table . getWriteBuffer ( ) . addAll ( puts ) ; this . table . flushCommits ( ) ; puts . clear ( ) ; } } this . table . getWriteBuffer ( ) . addAll ( puts ) ; this . table . flushCommits ( ) ; puts . clear ( ) ; this . termFrequencies . clear ( ) ; } long doIncrementSegmentId ( ) throws IOException { return this . table . incrementColumnValue ( ROW_SEGMENT_ID , FAMILY_SEQUENCE , QUALIFIER_SEGMENT , <NUM_LIT:1> , true ) ; } void doStoreFields ( final byte [ ] currentRow , final Map < String , byte [ ] > fieldsToStore ) throws IOException { for ( final Map . Entry < String , byte [ ] > entry : fieldsToStore . entrySet ( ) ) { Put put = new Put ( currentRow ) ; put . add ( FAMILY_FIELDS , Bytes . toBytes ( entry . getKey ( ) ) , entry . getValue ( ) ) ; put . setWriteToWAL ( true ) ; this . table . getWriteBuffer ( ) . add ( put ) ; } } byte [ ] getCurrentRow ( ) { return Bytes . toBytes ( "<STR_LIT:s>" + this . segmentId + "<STR_LIT:/>" + this . documentId ) ; } public static void dropLuceneIndexTable ( final String tableName , final HBaseConfiguration configuration ) throws IOException { HBaseAdmin admin = new HBaseAdmin ( configuration ) ; doDropTable ( admin , tableName ) ; } static void doDropTable ( final HBaseAdmin admin , final String tableName ) throws IOException { if ( admin . tableExists ( tableName ) ) { if ( admin . isTableAvailable ( tableName ) ) { admin . disableTable ( tableName ) ; } admin . deleteTable ( tableName ) ; } } public static HTable createLuceneIndexTable ( final String tableName , final HBaseConfiguration configuration , boolean forceRecreate ) throws IOException { HBaseAdmin admin = new HBaseAdmin ( configuration ) ; if ( admin . tableExists ( tableName ) ) { if ( ! forceRecreate ) { throw new IllegalArgumentException ( "<STR_LIT>" + tableName ) ; } else { doDropTable ( admin , tableName ) ; } } HTableDescriptor tableDescriptor = new HTableDescriptor ( Bytes . toBytes ( tableName ) ) ; tableDescriptor . addFamily ( createUniversionLZO ( admin , FAMILY_FIELDS ) ) ; tableDescriptor . addFamily ( createUniversionLZO ( admin , FAMILY_TERMVECTOR ) ) ; tableDescriptor . addFamily ( createUniversionLZO ( admin , FAMILY_TERMFREQUENCIES ) ) ; tableDescriptor . addFamily ( createUniversionLZO ( admin , FAMILY_DOC_TO_INT ) ) ; tableDescriptor . addFamily ( createUniversionLZO ( admin , FAMILY_SEQUENCE ) ) ; tableDescriptor . addFamily ( createUniversionLZO ( admin , FAMILY_PAYLOADS ) ) ; admin . createTable ( tableDescriptor ) ; HTableDescriptor descriptor = admin . getTableDescriptor ( Bytes . toBytes ( tableName ) ) ; if ( descriptor != null ) { HTable table = new HTable ( configuration , tableName ) ; Put put2 = new Put ( ROW_SEGMENT_ID ) ; put2 . add ( FAMILY_SEQUENCE , QUALIFIER_SEGMENT , Bytes . toBytes ( - <NUM_LIT:1L> ) ) ; table . put ( put2 ) ; table . flushCommits ( ) ; return table ; } else { return null ; } } static HColumnDescriptor createUniversionLZO ( final HBaseAdmin admin , final byte [ ] columnFamilyName ) { HColumnDescriptor desc = new HColumnDescriptor ( columnFamilyName ) ; desc . setCompressionType ( Algorithm . GZ ) ; desc . setMaxVersions ( <NUM_LIT:1> ) ; return desc ; } } </s>
|
<s> package org . hbasene . index . util ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . util . OpenBitSet ; public class HBaseneUtil { public static final String QUALIFIER_DOCUMENTS_PREFIX = "<STR_LIT>" ; public static final byte [ ] FAMILY_TERMVECTOR = Bytes . toBytes ( "<STR_LIT>" ) ; private HBaseneUtil ( ) { } public static byte [ ] toBytes ( final OpenBitSet bitset ) { long [ ] bits = bitset . getBits ( ) ; int wlen = bitset . getNumWords ( ) ; byte [ ] output = new byte [ wlen * Bytes . SIZEOF_LONG ] ; for ( int i = <NUM_LIT:0> ; i < wlen ; ++ i ) { Bytes . putBytes ( output , i * Bytes . SIZEOF_LONG , Bytes . toBytes ( bits [ i ] ) , <NUM_LIT:0> , Bytes . SIZEOF_LONG ) ; } return output ; } public static OpenBitSet toOpenBitSet ( final byte [ ] bytes ) { int wlen = bytes . length / Bytes . SIZEOF_LONG ; if ( wlen == <NUM_LIT:0> ) { return null ; } long [ ] bits = new long [ wlen ] ; for ( int i = <NUM_LIT:0> ; i < wlen ; ++ i ) { bits [ i ] = Bytes . toLong ( bytes , i * Bytes . SIZEOF_LONG ) ; } return new OpenBitSet ( bits , wlen ) ; } public static OpenBitSet createDefaultOpenBitSet ( ) { return createDefaultOpenBitSet ( <NUM_LIT> ) ; } public static OpenBitSet createDefaultOpenBitSet ( long numbits ) { return new OpenBitSet ( numbits ) ; } public static byte [ ] createTermVectorQualifier ( int partitionId ) { return Bytes . toBytes ( QUALIFIER_DOCUMENTS_PREFIX ) ; } public static final int MAX_DOCS = <NUM_LIT> ; } </s>
|
<s> package org . hbasene . index . create ; import java . io . ByteArrayInputStream ; import java . io . OutputStream ; import java . io . StringWriter ; import java . util . concurrent . ConcurrentHashMap ; import java . util . Iterator ; import java . util . Map ; import java . util . Properties ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . transform . Transformer ; import javax . xml . transform . TransformerFactory ; import javax . xml . transform . dom . DOMSource ; import javax . xml . transform . stream . StreamResult ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . conf . Configuration ; import org . w3c . dom . Document ; import org . w3c . dom . Element ; import org . w3c . dom . Node ; import org . w3c . dom . NodeList ; import org . w3c . dom . Text ; @ Deprecated public class IndexConfiguration extends Configuration { private static final Log LOG = LogFactory . getLog ( IndexConfiguration . class ) ; static final String HBASE_COLUMN_NAME = "<STR_LIT>" ; static final String HBASE_COLUMN_STORE = "<STR_LIT>" ; static final String HBASE_COLUMN_INDEX = "<STR_LIT>" ; static final String HBASE_COLUMN_TOKENIZE = "<STR_LIT>" ; static final String HBASE_COLUMN_BOOST = "<STR_LIT>" ; static final String HBASE_COLUMN_OMIT_NORMS = "<STR_LIT>" ; static final String HBASE_INDEX_ROWKEY_NAME = "<STR_LIT>" ; static final String HBASE_INDEX_ANALYZER_NAME = "<STR_LIT>" ; static final String HBASE_INDEX_MAX_BUFFERED_DOCS = "<STR_LIT>" ; static final String HBASE_INDEX_MAX_BUFFERED_DELS = "<STR_LIT>" ; static final String HBASE_INDEX_MAX_FIELD_LENGTH = "<STR_LIT>" ; static final String HBASE_INDEX_MAX_MERGE_DOCS = "<STR_LIT>" ; static final String HBASE_INDEX_MERGE_FACTOR = "<STR_LIT>" ; static final String HBASE_INDEX_SIMILARITY_NAME = "<STR_LIT>" ; static final String HBASE_INDEX_USE_COMPOUND_FILE = "<STR_LIT>" ; static final String HBASE_INDEX_OPTIMIZE = "<STR_LIT>" ; public static class ColumnConf extends Properties { private static final long serialVersionUID = <NUM_LIT> ; boolean getBoolean ( String name , boolean defaultValue ) { String valueString = getProperty ( name ) ; if ( "<STR_LIT:true>" . equals ( valueString ) ) return true ; else if ( "<STR_LIT:false>" . equals ( valueString ) ) return false ; else return defaultValue ; } void setBoolean ( String name , boolean value ) { setProperty ( name , Boolean . toString ( value ) ) ; } float getFloat ( String name , float defaultValue ) { String valueString = getProperty ( name ) ; if ( valueString == null ) return defaultValue ; try { return Float . parseFloat ( valueString ) ; } catch ( NumberFormatException e ) { return defaultValue ; } } void setFloat ( String name , float value ) { setProperty ( name , Float . toString ( value ) ) ; } } private Map < String , ColumnConf > columnMap = new ConcurrentHashMap < String , ColumnConf > ( ) ; public Iterator < String > columnNameIterator ( ) { return columnMap . keySet ( ) . iterator ( ) ; } public boolean isIndex ( String columnName ) { return getColumn ( columnName ) . getBoolean ( HBASE_COLUMN_INDEX , true ) ; } public void setIndex ( String columnName , boolean index ) { getColumn ( columnName ) . setBoolean ( HBASE_COLUMN_INDEX , index ) ; } public boolean isStore ( String columnName ) { return getColumn ( columnName ) . getBoolean ( HBASE_COLUMN_STORE , false ) ; } public void setStore ( String columnName , boolean store ) { getColumn ( columnName ) . setBoolean ( HBASE_COLUMN_STORE , store ) ; } public boolean isTokenize ( String columnName ) { return getColumn ( columnName ) . getBoolean ( HBASE_COLUMN_TOKENIZE , true ) ; } public void setTokenize ( String columnName , boolean tokenize ) { getColumn ( columnName ) . setBoolean ( HBASE_COLUMN_TOKENIZE , tokenize ) ; } public float getBoost ( String columnName ) { return getColumn ( columnName ) . getFloat ( HBASE_COLUMN_BOOST , <NUM_LIT:1.0f> ) ; } public void setBoost ( String columnName , float boost ) { getColumn ( columnName ) . setFloat ( HBASE_COLUMN_BOOST , boost ) ; } public boolean isOmitNorms ( String columnName ) { return getColumn ( columnName ) . getBoolean ( HBASE_COLUMN_OMIT_NORMS , true ) ; } public void setOmitNorms ( String columnName , boolean omitNorms ) { getColumn ( columnName ) . setBoolean ( HBASE_COLUMN_OMIT_NORMS , omitNorms ) ; } private ColumnConf getColumn ( String columnName ) { ColumnConf column = columnMap . get ( columnName ) ; if ( column == null ) { column = new ColumnConf ( ) ; columnMap . put ( columnName , column ) ; } return column ; } public String getAnalyzerName ( ) { return get ( HBASE_INDEX_ANALYZER_NAME , "<STR_LIT>" ) ; } public void setAnalyzerName ( String analyzerName ) { set ( HBASE_INDEX_ANALYZER_NAME , analyzerName ) ; } public int getMaxBufferedDeleteTerms ( ) { return getInt ( HBASE_INDEX_MAX_BUFFERED_DELS , <NUM_LIT:1000> ) ; } public void setMaxBufferedDeleteTerms ( int maxBufferedDeleteTerms ) { setInt ( HBASE_INDEX_MAX_BUFFERED_DELS , maxBufferedDeleteTerms ) ; } public int getMaxBufferedDocs ( ) { return getInt ( HBASE_INDEX_MAX_BUFFERED_DOCS , <NUM_LIT:10> ) ; } public void setMaxBufferedDocs ( int maxBufferedDocs ) { setInt ( HBASE_INDEX_MAX_BUFFERED_DOCS , maxBufferedDocs ) ; } public int getMaxFieldLength ( ) { return getInt ( HBASE_INDEX_MAX_FIELD_LENGTH , Integer . MAX_VALUE ) ; } public void setMaxFieldLength ( int maxFieldLength ) { setInt ( HBASE_INDEX_MAX_FIELD_LENGTH , maxFieldLength ) ; } public int getMaxMergeDocs ( ) { return getInt ( HBASE_INDEX_MAX_MERGE_DOCS , Integer . MAX_VALUE ) ; } public void setMaxMergeDocs ( int maxMergeDocs ) { setInt ( HBASE_INDEX_MAX_MERGE_DOCS , maxMergeDocs ) ; } public int getMergeFactor ( ) { return getInt ( HBASE_INDEX_MERGE_FACTOR , <NUM_LIT:10> ) ; } public void setMergeFactor ( int mergeFactor ) { setInt ( HBASE_INDEX_MERGE_FACTOR , mergeFactor ) ; } public String getRowkeyName ( ) { return get ( HBASE_INDEX_ROWKEY_NAME , "<STR_LIT>" ) ; } public void setRowkeyName ( String rowkeyName ) { set ( HBASE_INDEX_ROWKEY_NAME , rowkeyName ) ; } public String getSimilarityName ( ) { return get ( HBASE_INDEX_SIMILARITY_NAME , null ) ; } public void setSimilarityName ( String similarityName ) { set ( HBASE_INDEX_SIMILARITY_NAME , similarityName ) ; } public boolean isUseCompoundFile ( ) { return getBoolean ( HBASE_INDEX_USE_COMPOUND_FILE , false ) ; } public void setUseCompoundFile ( boolean useCompoundFile ) { setBoolean ( HBASE_INDEX_USE_COMPOUND_FILE , useCompoundFile ) ; } public boolean doOptimize ( ) { return getBoolean ( HBASE_INDEX_OPTIMIZE , true ) ; } public void setDoOptimize ( boolean doOptimize ) { setBoolean ( HBASE_INDEX_OPTIMIZE , doOptimize ) ; } public void addFromXML ( String content ) { try { DocumentBuilder builder = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) ; Document doc = builder . parse ( new ByteArrayInputStream ( content . getBytes ( ) ) ) ; Element root = doc . getDocumentElement ( ) ; if ( ! "<STR_LIT>" . equals ( root . getTagName ( ) ) ) { LOG . fatal ( "<STR_LIT>" ) ; } NodeList props = root . getChildNodes ( ) ; for ( int i = <NUM_LIT:0> ; i < props . getLength ( ) ; i ++ ) { Node propNode = props . item ( i ) ; if ( ! ( propNode instanceof Element ) ) { continue ; } Element prop = ( Element ) propNode ; if ( "<STR_LIT>" . equals ( prop . getTagName ( ) ) ) { propertyFromXML ( prop , null ) ; } else if ( "<STR_LIT>" . equals ( prop . getTagName ( ) ) ) { columnConfFromXML ( prop ) ; } else { LOG . warn ( "<STR_LIT>" ) ; } } } catch ( Exception e ) { LOG . fatal ( "<STR_LIT>" + e ) ; throw new RuntimeException ( e ) ; } } private void propertyFromXML ( Element prop , Properties properties ) { NodeList fields = prop . getChildNodes ( ) ; String attr = null ; String value = null ; for ( int j = <NUM_LIT:0> ; j < fields . getLength ( ) ; j ++ ) { Node fieldNode = fields . item ( j ) ; if ( ! ( fieldNode instanceof Element ) ) { continue ; } Element field = ( Element ) fieldNode ; if ( "<STR_LIT:name>" . equals ( field . getTagName ( ) ) ) { attr = ( ( Text ) field . getFirstChild ( ) ) . getData ( ) ; } if ( "<STR_LIT:value>" . equals ( field . getTagName ( ) ) && field . hasChildNodes ( ) ) { value = ( ( Text ) field . getFirstChild ( ) ) . getData ( ) ; } } if ( attr != null && value != null ) { if ( properties == null ) { set ( attr , value ) ; } else { properties . setProperty ( attr , value ) ; } } } private void columnConfFromXML ( Element column ) { ColumnConf columnConf = new ColumnConf ( ) ; NodeList props = column . getChildNodes ( ) ; for ( int i = <NUM_LIT:0> ; i < props . getLength ( ) ; i ++ ) { Node propNode = props . item ( i ) ; if ( ! ( propNode instanceof Element ) ) { continue ; } Element prop = ( Element ) propNode ; if ( "<STR_LIT>" . equals ( prop . getTagName ( ) ) ) { propertyFromXML ( prop , columnConf ) ; } else { LOG . warn ( "<STR_LIT>" ) ; } } if ( columnConf . getProperty ( HBASE_COLUMN_NAME ) != null ) { columnMap . put ( columnConf . getProperty ( HBASE_COLUMN_NAME ) , columnConf ) ; } else { LOG . warn ( "<STR_LIT>" ) ; } } public void write ( OutputStream out ) { try { Document doc = writeDocument ( ) ; DOMSource source = new DOMSource ( doc ) ; StreamResult result = new StreamResult ( out ) ; TransformerFactory transFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transFactory . newTransformer ( ) ; transformer . transform ( source , result ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } private Document writeDocument ( ) { Iterator < Map . Entry < String , String > > iter = iterator ( ) ; try { Document doc = DocumentBuilderFactory . newInstance ( ) . newDocumentBuilder ( ) . newDocument ( ) ; Element conf = doc . createElement ( "<STR_LIT>" ) ; doc . appendChild ( conf ) ; conf . appendChild ( doc . createTextNode ( "<STR_LIT:n>" ) ) ; Map . Entry < String , String > entry ; while ( iter . hasNext ( ) ) { entry = iter . next ( ) ; String name = entry . getKey ( ) ; String value = entry . getValue ( ) ; writeProperty ( doc , conf , name , value ) ; } Iterator < String > columnIter = columnNameIterator ( ) ; while ( columnIter . hasNext ( ) ) { writeColumn ( doc , conf , columnIter . next ( ) ) ; } return doc ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } private void writeProperty ( Document doc , Element parent , String name , String value ) { Element propNode = doc . createElement ( "<STR_LIT>" ) ; parent . appendChild ( propNode ) ; Element nameNode = doc . createElement ( "<STR_LIT:name>" ) ; nameNode . appendChild ( doc . createTextNode ( name ) ) ; propNode . appendChild ( nameNode ) ; Element valueNode = doc . createElement ( "<STR_LIT:value>" ) ; valueNode . appendChild ( doc . createTextNode ( value ) ) ; propNode . appendChild ( valueNode ) ; parent . appendChild ( doc . createTextNode ( "<STR_LIT:n>" ) ) ; } private void writeColumn ( Document doc , Element parent , String columnName ) { Element column = doc . createElement ( "<STR_LIT>" ) ; parent . appendChild ( column ) ; column . appendChild ( doc . createTextNode ( "<STR_LIT:n>" ) ) ; ColumnConf columnConf = getColumn ( columnName ) ; for ( Map . Entry < Object , Object > entry : columnConf . entrySet ( ) ) { if ( entry . getKey ( ) instanceof String && entry . getValue ( ) instanceof String ) { writeProperty ( doc , column , ( String ) entry . getKey ( ) , ( String ) entry . getValue ( ) ) ; } } } @ Override public String toString ( ) { StringWriter writer = new StringWriter ( ) ; try { Document doc = writeDocument ( ) ; DOMSource source = new DOMSource ( doc ) ; StreamResult result = new StreamResult ( writer ) ; TransformerFactory transFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transFactory . newTransformer ( ) ; transformer . transform ( source , result ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return writer . toString ( ) ; } } </s>
|
<s> package org . hbasene . index . create ; import java . io . DataInput ; import java . io . DataOutput ; import org . apache . hadoop . io . Writable ; import org . apache . lucene . document . Document ; public class LuceneDocumentWrapper implements Writable { protected Document doc ; public LuceneDocumentWrapper ( Document doc ) { this . doc = doc ; } public Document get ( ) { return doc ; } public void readFields ( DataInput in ) { } public void write ( DataOutput out ) { } } </s>
|
<s> package org . hbasene . index . create . mapred ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import org . apache . hadoop . conf . Configuration ; import org . apache . hadoop . fs . Path ; import org . apache . hadoop . hbase . HBaseConfiguration ; import org . apache . hadoop . hbase . HConstants ; import org . apache . hadoop . hbase . mapred . IdentityTableMap ; import org . apache . hadoop . mapred . FileOutputFormat ; import org . apache . hadoop . mapred . JobClient ; import org . apache . hadoop . mapred . JobConf ; import org . apache . hadoop . mapred . RunningJob ; import org . hbasene . index . create . IndexConfiguration ; @ Deprecated public class BuildTableIndex { private static final String USAGE = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; private static void printUsage ( String message ) { System . err . println ( message ) ; System . err . println ( USAGE ) ; System . exit ( - <NUM_LIT:1> ) ; } public BuildTableIndex ( ) { super ( ) ; } public void run ( String [ ] args ) throws IOException { if ( args . length < <NUM_LIT:6> ) { printUsage ( "<STR_LIT>" ) ; } int numMapTasks = <NUM_LIT:1> ; int numReduceTasks = <NUM_LIT:1> ; String iconfFile = null ; String indexDir = null ; String tableName = null ; StringBuilder columnNames = null ; for ( int i = <NUM_LIT:0> ; i < args . length - <NUM_LIT:1> ; i ++ ) { if ( "<STR_LIT>" . equals ( args [ i ] ) ) { numMapTasks = Integer . parseInt ( args [ ++ i ] ) ; } else if ( "<STR_LIT>" . equals ( args [ i ] ) ) { numReduceTasks = Integer . parseInt ( args [ ++ i ] ) ; } else if ( "<STR_LIT>" . equals ( args [ i ] ) ) { iconfFile = args [ ++ i ] ; } else if ( "<STR_LIT>" . equals ( args [ i ] ) ) { indexDir = args [ ++ i ] ; } else if ( "<STR_LIT>" . equals ( args [ i ] ) ) { tableName = args [ ++ i ] ; } else if ( "<STR_LIT>" . equals ( args [ i ] ) ) { columnNames = new StringBuilder ( args [ ++ i ] ) ; while ( i + <NUM_LIT:1> < args . length && ! args [ i + <NUM_LIT:1> ] . startsWith ( "<STR_LIT:->" ) ) { columnNames . append ( "<STR_LIT:U+0020>" ) ; columnNames . append ( args [ ++ i ] ) ; } } else { printUsage ( "<STR_LIT>" + args [ i ] ) ; } } if ( indexDir == null || tableName == null || columnNames == null ) { printUsage ( "<STR_LIT>" + "<STR_LIT>" ) ; } Configuration conf = new HBaseConfiguration ( ) ; if ( iconfFile != null ) { String content = readContent ( iconfFile ) ; IndexConfiguration iconf = new IndexConfiguration ( ) ; iconf . addFromXML ( content ) ; conf . set ( "<STR_LIT>" , content ) ; } if ( columnNames != null ) { JobConf jobConf = createJob ( conf , numMapTasks , numReduceTasks , indexDir , tableName , columnNames . toString ( ) ) ; RunningJob runningJob = JobClient . runJob ( jobConf ) ; runningJob . waitForCompletion ( ) ; } } public JobConf createJob ( Configuration conf , int numMapTasks , int numReduceTasks , String indexDir , String tableName , String columnNames ) { JobConf jobConf = new JobConf ( conf , BuildTableIndex . class ) ; jobConf . setJobName ( "<STR_LIT>" + tableName ) ; jobConf . setNumMapTasks ( numMapTasks ) ; jobConf . setNumReduceTasks ( numReduceTasks ) ; IdentityTableMap . initJob ( tableName , columnNames , IdentityTableMap . class , jobConf ) ; jobConf . setReducerClass ( IndexTableReduce . class ) ; FileOutputFormat . setOutputPath ( jobConf , new Path ( indexDir ) ) ; jobConf . setOutputFormat ( IndexOutputFormat . class ) ; jobConf . setJarByClass ( BuildTableIndex . class ) ; return jobConf ; } private String readContent ( String fileName ) throws IOException { File file = new File ( fileName ) ; int length = ( int ) file . length ( ) ; if ( length == <NUM_LIT:0> ) { printUsage ( "<STR_LIT>" + fileName + "<STR_LIT>" ) ; } int bytesRead = <NUM_LIT:0> ; byte [ ] bytes = new byte [ length ] ; FileInputStream fis = new FileInputStream ( file ) ; try { while ( bytesRead < length ) { int read = fis . read ( bytes , bytesRead , length - bytesRead ) ; if ( read > <NUM_LIT:0> ) { bytesRead += read ; } else { break ; } } } finally { fis . close ( ) ; } return new String ( bytes , <NUM_LIT:0> , bytesRead , HConstants . UTF8_ENCODING ) ; } public static void main ( String [ ] args ) throws IOException { BuildTableIndex build = new BuildTableIndex ( ) ; build . run ( args ) ; } } </s>
|
<s> package org . hbasene . index . create . mapred ; import java . io . IOException ; import java . util . Iterator ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . hbase . KeyValue ; import org . apache . hadoop . hbase . client . Result ; import org . apache . hadoop . hbase . io . ImmutableBytesWritable ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . hadoop . mapred . JobConf ; import org . apache . hadoop . mapred . MapReduceBase ; import org . apache . hadoop . mapred . OutputCollector ; import org . apache . hadoop . mapred . Reducer ; import org . apache . hadoop . mapred . Reporter ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Field ; import org . hbasene . index . create . IndexConfiguration ; import org . hbasene . index . create . LuceneDocumentWrapper ; @ Deprecated public class IndexTableReduce extends MapReduceBase implements Reducer < ImmutableBytesWritable , Result , ImmutableBytesWritable , LuceneDocumentWrapper > { private static final Log LOG = LogFactory . getLog ( IndexTableReduce . class ) ; private IndexConfiguration indexConf ; @ Override public void configure ( JobConf job ) { super . configure ( job ) ; indexConf = new IndexConfiguration ( ) ; String content = job . get ( "<STR_LIT>" ) ; if ( content != null ) { indexConf . addFromXML ( content ) ; } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "<STR_LIT>" + indexConf ) ; } } @ Override public void close ( ) throws IOException { super . close ( ) ; } public void reduce ( ImmutableBytesWritable key , Iterator < Result > values , OutputCollector < ImmutableBytesWritable , LuceneDocumentWrapper > output , Reporter reporter ) throws IOException { Document doc = null ; while ( values . hasNext ( ) ) { Result r = values . next ( ) ; if ( doc == null ) { doc = new Document ( ) ; Field keyField = new Field ( indexConf . getRowkeyName ( ) , Bytes . toString ( key . get ( ) , key . getOffset ( ) , key . getLength ( ) ) , Field . Store . YES , Field . Index . NOT_ANALYZED ) ; keyField . setOmitNorms ( true ) ; doc . add ( keyField ) ; } for ( KeyValue kv : r . list ( ) ) { String column = Bytes . toString ( kv . getQualifier ( ) ) ; byte [ ] columnValue = kv . getValue ( ) ; Field . Store store = indexConf . isStore ( column ) ? Field . Store . YES : Field . Store . NO ; Field . Index index = indexConf . isIndex ( column ) ? ( indexConf . isTokenize ( column ) ? Field . Index . ANALYZED : Field . Index . NOT_ANALYZED ) : Field . Index . NO ; Field field = new Field ( column , Bytes . toString ( columnValue ) , store , index ) ; field . setBoost ( indexConf . getBoost ( column ) ) ; field . setOmitNorms ( indexConf . isOmitNorms ( column ) ) ; doc . add ( field ) ; } } output . collect ( key , new LuceneDocumentWrapper ( doc ) ) ; } } </s>
|
<s> package org . hbasene . index . create . mapred ; import java . io . IOException ; import java . io . File ; import java . lang . reflect . Constructor ; import java . util . Random ; import java . util . concurrent . atomic . AtomicBoolean ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import org . apache . hadoop . fs . FileSystem ; import org . apache . hadoop . fs . Path ; import org . apache . hadoop . hbase . io . ImmutableBytesWritable ; import org . apache . hadoop . mapred . JobConf ; import org . apache . hadoop . mapred . FileOutputFormat ; import org . apache . hadoop . mapred . RecordWriter ; import org . apache . hadoop . mapred . Reporter ; import org . apache . hadoop . util . Progressable ; import org . apache . lucene . analysis . Analyzer ; import org . apache . lucene . document . Document ; import org . apache . lucene . index . IndexWriter ; import org . apache . lucene . search . Similarity ; import org . apache . lucene . store . FSDirectory ; import org . apache . lucene . util . Version ; import org . hbasene . index . create . IndexConfiguration ; import org . hbasene . index . create . LuceneDocumentWrapper ; @ Deprecated public class IndexOutputFormat extends FileOutputFormat < ImmutableBytesWritable , LuceneDocumentWrapper > { static final Log LOG = LogFactory . getLog ( IndexOutputFormat . class ) ; private Random random = new Random ( ) ; @ Override public RecordWriter < ImmutableBytesWritable , LuceneDocumentWrapper > getRecordWriter ( final FileSystem fs , JobConf job , String name , final Progressable progress ) throws IOException { final Path perm = new Path ( FileOutputFormat . getOutputPath ( job ) , name ) ; final Path temp = job . getLocalPath ( "<STR_LIT>" + Integer . toString ( random . nextInt ( ) ) ) ; LOG . info ( "<STR_LIT>" + perm ) ; fs . delete ( perm , true ) ; final IndexConfiguration indexConf = new IndexConfiguration ( ) ; String content = job . get ( "<STR_LIT>" ) ; if ( content != null ) { indexConf . addFromXML ( content ) ; } String analyzerName = indexConf . getAnalyzerName ( ) ; Analyzer analyzer ; try { Class < ? extends Analyzer > analyzerClass = Class . forName ( analyzerName ) . asSubclass ( Analyzer . class ) ; Constructor < ? extends Analyzer > analyzerCtor = analyzerClass . getConstructor ( Version . class ) ; analyzer = analyzerCtor . newInstance ( Version . LUCENE_30 ) ; } catch ( Exception e ) { throw new IOException ( "<STR_LIT>" + analyzerName ) ; } final IndexWriter writer = new IndexWriter ( FSDirectory . open ( new File ( fs . startLocalOutput ( perm , temp ) . toString ( ) ) ) , analyzer , true , IndexWriter . MaxFieldLength . LIMITED ) ; writer . setMaxBufferedDocs ( indexConf . getMaxBufferedDocs ( ) ) ; writer . setMaxFieldLength ( indexConf . getMaxFieldLength ( ) ) ; writer . setMaxMergeDocs ( indexConf . getMaxMergeDocs ( ) ) ; writer . setMergeFactor ( indexConf . getMergeFactor ( ) ) ; String similarityName = indexConf . getSimilarityName ( ) ; if ( similarityName != null ) { try { Class < ? extends Similarity > similarityClass = Class . forName ( similarityName ) . asSubclass ( Similarity . class ) ; Constructor < ? extends Similarity > ctor = similarityClass . getConstructor ( Version . class ) ; Similarity similarity = ctor . newInstance ( Version . LUCENE_30 ) ; writer . setSimilarity ( similarity ) ; } catch ( Exception e ) { throw new IOException ( "<STR_LIT>" + similarityName ) ; } } writer . setUseCompoundFile ( indexConf . isUseCompoundFile ( ) ) ; return new RecordWriter < ImmutableBytesWritable , LuceneDocumentWrapper > ( ) { AtomicBoolean closed = new AtomicBoolean ( false ) ; private long docCount = <NUM_LIT:0> ; public void write ( ImmutableBytesWritable key , LuceneDocumentWrapper value ) throws IOException { Document doc = value . get ( ) ; writer . addDocument ( doc ) ; docCount ++ ; progress . progress ( ) ; } public void close ( final Reporter reporter ) throws IOException { Thread prog = new Thread ( ) { @ Override public void run ( ) { while ( ! closed . get ( ) ) { try { reporter . setStatus ( "<STR_LIT>" ) ; Thread . sleep ( <NUM_LIT:1000> ) ; } catch ( InterruptedException e ) { continue ; } catch ( Throwable e ) { return ; } } } } ; try { prog . start ( ) ; if ( indexConf . doOptimize ( ) ) { if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "<STR_LIT>" ) ; } writer . optimize ( ) ; } writer . close ( ) ; if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "<STR_LIT>" + docCount + "<STR_LIT>" ) ; } fs . completeLocalOutput ( perm , temp ) ; if ( LOG . isInfoEnabled ( ) ) { LOG . info ( "<STR_LIT>" ) ; } } finally { closed . set ( true ) ; } } } ; } } </s>
|
<s> package org . hbasene . index ; public class HBaseneConfiguration { public static final String CONF_MAX_TERM_VECTOR = "<STR_LIT>" ; public static final String CONF_TERM_VECTOR_LIST_THRESHOLD = "<STR_LIT>" ; } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . util . NavigableMap ; import org . apache . hadoop . hbase . client . HTable ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . hadoop . hbase . client . Result ; import org . apache . hadoop . hbase . client . ResultScanner ; import org . apache . hadoop . hbase . client . Scan ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . lucene . index . Term ; import org . apache . lucene . index . TermEnum ; public class HBaseTermEnum extends TermEnum { private final HTable table ; private ResultScanner resultScanner ; private Term currentTerm ; private final HTablePool pool ; public HBaseTermEnum ( final HBaseIndexReader reader ) throws IOException { this . pool = reader . getTablePool ( ) ; table = pool . getTable ( reader . getIndexName ( ) ) ; this . resultScanner = table . getScanner ( HBaseneConstants . FAMILY_TERMVECTOR ) ; } @ Override public void close ( ) throws IOException { this . resultScanner . close ( ) ; this . pool . putTable ( table ) ; } @ Override public int docFreq ( ) { Scan get = new Scan ( Bytes . toBytes ( this . currentTerm . field ( ) + "<STR_LIT:/>" + this . currentTerm . text ( ) ) ) ; get . addFamily ( HBaseneConstants . FAMILY_TERMVECTOR ) ; ResultScanner scanner = null ; try { scanner = this . table . getScanner ( HBaseneConstants . FAMILY_TERMVECTOR ) ; final Result result = scanner . next ( ) ; if ( result == null ) { return <NUM_LIT:0> ; } NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( HBaseneConstants . FAMILY_TERMVECTOR ) ; return map . size ( ) ; } catch ( Exception ex ) { return <NUM_LIT:0> ; } finally { scanner . close ( ) ; } } @ Override public boolean next ( ) { try { Result result = resultScanner . next ( ) ; if ( result != null ) { String fieldTerm = Bytes . toString ( result . getRow ( ) ) ; String [ ] fieldTerms = fieldTerm . split ( "<STR_LIT:/>" ) ; this . currentTerm = new Term ( fieldTerms [ <NUM_LIT:0> ] , fieldTerms [ <NUM_LIT:1> ] ) ; return true ; } else { return false ; } } catch ( Exception ex ) { return false ; } } @ Override public Term term ( ) { return this . currentTerm ; } public void skipTo ( Term t ) throws IOException { if ( this . resultScanner != null ) { this . resultScanner . close ( ) ; } Scan scan = new Scan ( ) ; scan . addFamily ( HBaseneConstants . FAMILY_TERMVECTOR ) ; scan . setStartRow ( Bytes . toBytes ( t . field ( ) + "<STR_LIT:/>" + t . text ( ) ) ) ; this . resultScanner = this . table . getScanner ( scan ) ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import org . apache . lucene . document . Document ; import org . apache . lucene . index . Term ; import org . apache . lucene . search . IndexSearcher ; import org . apache . lucene . search . ScoreDoc ; import org . apache . lucene . search . TermQuery ; import org . apache . lucene . search . TopDocs ; import org . hbasene . index . search . HBaseIndexSearcher ; import org . junit . Assert ; import org . junit . Test ; public class TestHBaseIndexReader extends AbstractHBaseneTest { @ Test public void testSearch ( ) throws IOException { IndexSearcher searcher = new HBaseIndexSearcher ( this . indexReader ) ; TopDocs docs = searcher . search ( new TermQuery ( new Term ( "<STR_LIT:content>" , "<STR_LIT>" ) ) , <NUM_LIT:3> ) ; Assert . assertTrue ( docs . totalHits > <NUM_LIT:3> ) ; for ( ScoreDoc scoreDoc : docs . scoreDocs ) { Assert . assertTrue ( scoreDoc . doc >= <NUM_LIT:0> ) ; Assert . assertTrue ( scoreDoc . score > <NUM_LIT:0.0f> ) ; try { Assert . assertNotNull ( this . indexReader . document ( scoreDoc . doc ) ) ; } catch ( Exception ex ) { Assert . assertTrue ( false ) ; } } Document doc = this . indexReader . document ( docs . scoreDocs [ <NUM_LIT:0> ] . doc ) ; Assert . assertEquals ( "<STR_LIT>" , doc . get ( PK_FIELD ) ) ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . util . Map ; import java . util . NavigableMap ; import org . apache . hadoop . hbase . HBaseClusterTestCase ; import org . apache . hadoop . hbase . client . Get ; import org . apache . hadoop . hbase . client . HBaseAdmin ; import org . apache . hadoop . hbase . client . HTable ; import org . apache . hadoop . hbase . client . HTablePool ; import org . apache . hadoop . hbase . client . Result ; import org . apache . hadoop . hbase . client . ResultScanner ; import org . apache . hadoop . hbase . util . Bytes ; import org . apache . log4j . Logger ; import org . apache . lucene . analysis . standard . StandardAnalyzer ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Field ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . util . Version ; import org . junit . Assert ; public class AbstractHBaseneTest extends HBaseClusterTestCase { private static final Logger LOGGER = Logger . getLogger ( AbstractHBaseneTest . class . getName ( ) ) ; protected static final String TEST_INDEX = "<STR_LIT>" ; protected static final String PK_FIELD = "<STR_LIT:id>" ; protected HTablePool tablePool ; protected HBaseIndexWriter indexWriter ; protected HBaseIndexReader indexReader ; protected static final int DEFAULT_POOL_SIZE = <NUM_LIT:20> ; protected AbstractHBaseneTest ( ) { super ( <NUM_LIT:1> ) ; } @ Override public void setUp ( ) throws Exception { super . setUp ( ) ; HBaseIndexStore . dropLuceneIndexTable ( TEST_INDEX , conf ) ; HBaseIndexStore . createLuceneIndexTable ( TEST_INDEX , conf , true ) ; this . tablePool = new HTablePool ( conf , DEFAULT_POOL_SIZE ) ; HBaseIndexStore hbaseIndex = new HBaseIndexStore ( this . tablePool , conf , TEST_INDEX ) ; this . indexWriter = new HBaseIndexWriter ( hbaseIndex , PK_FIELD ) ; doInitDocs ( ) ; this . indexReader = new HBaseIndexReader ( this . tablePool , TEST_INDEX , PK_FIELD ) ; doSetupDerived ( ) ; } protected void doSetupDerived ( ) throws CorruptIndexException , IOException { } protected void doInitDocs ( ) throws CorruptIndexException , IOException { this . addDefaultDocuments ( ) ; } protected void addDefaultDocuments ( ) throws CorruptIndexException , IOException { indexWriter . addDocument ( this . createDocument ( "<STR_LIT>" , "<STR_LIT>" ) , new StandardAnalyzer ( Version . LUCENE_30 ) ) ; indexWriter . addDocument ( this . createDocument ( "<STR_LIT>" , "<STR_LIT>" ) , new StandardAnalyzer ( Version . LUCENE_30 ) ) ; indexWriter . addDocument ( this . createDocument ( "<STR_LIT>" , "<STR_LIT>" ) , new StandardAnalyzer ( Version . LUCENE_30 ) ) ; indexWriter . addDocument ( this . createDocument ( "<STR_LIT>" , "<STR_LIT>" ) , new StandardAnalyzer ( Version . LUCENE_30 ) ) ; Assert . assertTrue ( new HBaseAdmin ( conf ) . tableExists ( TEST_INDEX ) ) ; } @ Override public void tearDown ( ) throws Exception { LOGGER . info ( "<STR_LIT>" ) ; HBaseIndexStore . dropLuceneIndexTable ( TEST_INDEX , conf ) ; this . indexReader . close ( ) ; super . tearDown ( ) ; } protected Document createDocument ( final String id , final String content ) throws CorruptIndexException , IOException { Document doc = new Document ( ) ; doc . add ( new Field ( "<STR_LIT:content>" , content , Field . Store . NO , Field . Index . ANALYZED_NO_NORMS ) ) ; doc . add ( new Field ( "<STR_LIT:id>" , id , Field . Store . YES , Field . Index . NO ) ) ; return doc ; } protected void assertDocumentPresent ( final long docId ) throws IOException { Get get = new Get ( Bytes . toBytes ( docId ) ) ; get . addFamily ( HBaseneConstants . FAMILY_FIELDS ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; try { Result result = table . get ( get ) ; NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( HBaseneConstants . FAMILY_FIELDS ) ; Assert . assertTrue ( map . size ( ) > <NUM_LIT:0> ) ; } finally { table . close ( ) ; } } protected void listAll ( final byte [ ] family ) throws IOException { LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; ResultScanner scanner = table . getScanner ( family ) ; Result result = scanner . next ( ) ; while ( result != null ) { NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( family ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < byte [ ] , byte [ ] > entry : map . entrySet ( ) ) { sb . append ( "<STR_LIT:U+0020(>" + Bytes . toString ( entry . getKey ( ) ) + "<STR_LIT:U+002CU+0020>" + Bytes . toString ( entry . getValue ( ) ) + "<STR_LIT:)>" ) ; } LOGGER . info ( Bytes . toString ( result . getRow ( ) ) + sb . toString ( ) ) ; result = scanner . next ( ) ; } table . close ( ) ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; } protected void listSequence ( ) throws IOException { final byte [ ] family = HBaseneConstants . FAMILY_SEQUENCE ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; ResultScanner scanner = table . getScanner ( family ) ; Result result = scanner . next ( ) ; while ( result != null ) { NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( family ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < byte [ ] , byte [ ] > entry : map . entrySet ( ) ) { sb . append ( "<STR_LIT:U+0020(>" + Bytes . toString ( entry . getKey ( ) ) + "<STR_LIT:U+002CU+0020>" + Bytes . toLong ( entry . getValue ( ) ) + "<STR_LIT:)>" ) ; } LOGGER . info ( Bytes . toString ( result . getRow ( ) ) + sb . toString ( ) ) ; result = scanner . next ( ) ; } table . close ( ) ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; } protected void listLongQualifiers ( final byte [ ] family ) throws IOException { LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; ResultScanner scanner = table . getScanner ( family ) ; Result result = scanner . next ( ) ; while ( result != null ) { NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( family ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < byte [ ] , byte [ ] > entry : map . entrySet ( ) ) { sb . append ( "<STR_LIT:U+0020(>" + Bytes . toString ( entry . getKey ( ) ) + "<STR_LIT:U+002CU+0020>" + Bytes . toLong ( entry . getValue ( ) ) + "<STR_LIT:)>" ) ; } LOGGER . info ( Bytes . toString ( result . getRow ( ) ) + sb . toString ( ) ) ; result = scanner . next ( ) ; } table . close ( ) ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; } protected void listLongRows ( final byte [ ] family ) throws IOException { LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; ResultScanner scanner = table . getScanner ( family ) ; Result result = scanner . next ( ) ; while ( result != null ) { NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( family ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < byte [ ] , byte [ ] > entry : map . entrySet ( ) ) { sb . append ( "<STR_LIT:U+0020(>" + Bytes . toString ( entry . getKey ( ) ) + "<STR_LIT:U+002CU+0020>" + Bytes . toString ( entry . getValue ( ) ) + "<STR_LIT:)>" ) ; } LOGGER . info ( Bytes . toLong ( result . getRow ( ) ) + sb . toString ( ) ) ; result = scanner . next ( ) ; } table . close ( ) ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; } protected void listTermVectors ( ) throws IOException { final byte [ ] family = HBaseneConstants . FAMILY_TERMVECTOR ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; ResultScanner scanner = table . getScanner ( family ) ; Result result = scanner . next ( ) ; while ( result != null ) { NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( family ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < byte [ ] , byte [ ] > entry : map . entrySet ( ) ) { sb . append ( "<STR_LIT:U+0020(>" + Bytes . toLong ( entry . getKey ( ) ) + "<STR_LIT:U+002CU+0020>" + Bytes . toString ( entry . getValue ( ) ) + "<STR_LIT:)>" ) ; } LOGGER . info ( Bytes . toString ( result . getRow ( ) ) + sb . toString ( ) ) ; result = scanner . next ( ) ; } table . close ( ) ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; } protected void listFields ( ) throws IOException { final byte [ ] family = HBaseneConstants . FAMILY_FIELDS ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; ResultScanner scanner = table . getScanner ( family ) ; Result result = scanner . next ( ) ; while ( result != null ) { NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( family ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( Map . Entry < byte [ ] , byte [ ] > entry : map . entrySet ( ) ) { sb . append ( "<STR_LIT:U+0020(>" + Bytes . toString ( entry . getKey ( ) ) + "<STR_LIT:U+002CU+0020>" + Bytes . toString ( entry . getValue ( ) ) + "<STR_LIT:)>" ) ; } LOGGER . info ( Bytes . toLong ( result . getRow ( ) ) + sb . toString ( ) ) ; result = scanner . next ( ) ; } table . close ( ) ; LOGGER . info ( "<STR_LIT>" + Bytes . toString ( family ) + "<STR_LIT>" ) ; } protected void assertTermVectorDocumentMapping ( final String term , final long docId ) throws IOException { byte [ ] internalDocId = Bytes . toBytes ( docId ) ; Get get = new Get ( Bytes . toBytes ( term ) ) ; get . addFamily ( HBaseneConstants . FAMILY_TERMVECTOR ) ; HTable table = new HTable ( conf , TEST_INDEX ) ; try { Result result = table . get ( get ) ; NavigableMap < byte [ ] , byte [ ] > map = result . getFamilyMap ( HBaseneConstants . FAMILY_TERMVECTOR ) ; Assert . assertTrue ( map . size ( ) > <NUM_LIT:0> ) ; Assert . assertNotNull ( map . get ( internalDocId ) ) ; } finally { table . close ( ) ; } } } </s>
|
<s> package org . hbasene . index ; import org . hbasene . index . AbstractTermPositionsEncoder ; import org . junit . Test ; public class AlphaTermPositionsEncoderTest extends AbstractTermPositionsEncoderTest { protected AbstractTermPositionsEncoder createEncoder ( ) { return new AlphaTermPositionsEncoder ( ) ; } @ Test public void testEncodeDecode ( ) { this . assertEncodeDecode ( termPositions ) ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import org . apache . log4j . Logger ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . index . Term ; import org . apache . lucene . store . LockObtainFailedException ; import org . hbasene . index . HBaseTermEnum ; import org . junit . After ; import org . junit . Assert ; import org . junit . Before ; import org . junit . Test ; @ SuppressWarnings ( "<STR_LIT:unused>" ) public class TestHBaseTermEnum extends AbstractHBaseneTest { @ SuppressWarnings ( "<STR_LIT:unused>" ) private static final Logger LOGGER = Logger . getLogger ( TestHBaseTermEnum . class . getName ( ) ) ; private HBaseTermEnum termEnum ; protected void doSetupDerived ( ) throws CorruptIndexException , IOException { termEnum = new HBaseTermEnum ( indexReader ) ; } public void tearDown ( ) throws Exception { termEnum . close ( ) ; } @ Test public void testTermEnum ( ) throws CorruptIndexException , LockObtainFailedException , IOException { while ( termEnum . next ( ) ) { Term term = termEnum . term ( ) ; String field = term . field ( ) ; Assert . assertTrue ( field . contains ( "<STR_LIT:content>" ) || field . contains ( "<STR_LIT:id>" ) ) ; Assert . assertTrue ( termEnum . docFreq ( ) > <NUM_LIT:0> ) ; } } } </s>
|
<s> package org . hbasene . index . search ; import java . io . IOException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . TreeMap ; import junit . framework . Assert ; import org . apache . log4j . Logger ; import org . apache . lucene . analysis . standard . StandardAnalyzer ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Field ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . index . Term ; import org . apache . lucene . search . IndexSearcher ; import org . apache . lucene . search . ScoreDoc ; import org . apache . lucene . search . Sort ; import org . apache . lucene . search . SortField ; import org . apache . lucene . search . TermQuery ; import org . apache . lucene . search . TopDocs ; import org . apache . lucene . util . Version ; import org . hbasene . index . AbstractHBaseneTest ; import org . hbasene . index . search . HBaseIndexSearcher ; import org . junit . Test ; public class TestHBaseIndexSearcher extends AbstractHBaseneTest { private static final Logger LOG = Logger . getLogger ( TestHBaseIndexSearcher . class . getName ( ) ) ; private static final String [ ] AIRPORTS = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; private final Map < String , List < Integer > > airportMap = new TreeMap < String , List < Integer > > ( ) ; private HBaseIndexSearcher indexSearcher ; @ Override protected void doSetupDerived ( ) throws CorruptIndexException , IOException { this . indexSearcher = new HBaseIndexSearcher ( this . indexReader ) ; } @ Override protected void doInitDocs ( ) throws CorruptIndexException , IOException { for ( int i = <NUM_LIT:100> ; i >= <NUM_LIT:0> ; -- i ) { Document doc = this . getDocument ( i ) ; indexWriter . addDocument ( doc , new StandardAnalyzer ( Version . LUCENE_30 ) ) ; } } private Document getDocument ( int i ) { Document doc = new Document ( ) ; doc . add ( new Field ( "<STR_LIT:id>" , "<STR_LIT>" + i , Field . Store . YES , Field . Index . NO ) ) ; int randomIndex = ( int ) ( Math . random ( ) * <NUM_LIT> ) ; doc . add ( new Field ( "<STR_LIT>" , AIRPORTS [ randomIndex ] , Field . Store . NO , Field . Index . ANALYZED_NO_NORMS ) ) ; doc . add ( new Field ( "<STR_LIT>" , Math . random ( ) > <NUM_LIT> ? "<STR_LIT>" : "<STR_LIT>" , Field . Store . NO , Field . Index . ANALYZED_NO_NORMS ) ) ; recordRandomIndex ( <NUM_LIT:100> - i , randomIndex ) ; return doc ; } private void recordRandomIndex ( final int docIndex , final int airportIndex ) { List < Integer > docs = airportMap . get ( AIRPORTS [ airportIndex ] ) ; if ( docs == null ) { docs = new LinkedList < Integer > ( ) ; airportMap . put ( AIRPORTS [ airportIndex ] , docs ) ; } docs . add ( docIndex ) ; } @ Test public void testSortFieldAsc ( ) throws IOException { LOG . info ( this . airportMap . toString ( ) ) ; TermQuery termQuery = new TermQuery ( new Term ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Sort sort = new Sort ( new SortField ( "<STR_LIT>" , SortField . STRING ) ) ; TopDocs docs = this . indexSearcher . search ( termQuery . createWeight ( indexSearcher ) , null , <NUM_LIT> , sort , false ) ; LOG . info ( "<STR_LIT>" + docs . scoreDocs . length ) ; this . printScoreDocs ( docs . scoreDocs , "<STR_LIT>" ) ; assertSortOrderAsc ( docs . scoreDocs ) ; } @ Test public void testSortFieldDesc ( ) throws IOException { LOG . info ( this . airportMap . toString ( ) ) ; TermQuery termQuery = new TermQuery ( new Term ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Sort sort = new Sort ( new SortField ( "<STR_LIT>" , SortField . STRING , true ) ) ; TopDocs docs = this . indexSearcher . search ( termQuery . createWeight ( indexSearcher ) , null , <NUM_LIT> , sort , false ) ; LOG . info ( "<STR_LIT>" + docs . scoreDocs . length ) ; this . printScoreDocs ( docs . scoreDocs , "<STR_LIT>" ) ; assertSortOrderDesc ( docs . scoreDocs ) ; } public void tistNonExistentSortField ( ) throws IOException { LOG . info ( this . airportMap . toString ( ) ) ; IndexSearcher searcher = new IndexSearcher ( this . indexReader ) ; try { TopDocs docs = searcher . search ( new TermQuery ( new Term ( "<STR_LIT>" , "<STR_LIT>" ) ) , <NUM_LIT> ) ; LOG . info ( "<STR_LIT>" + docs . scoreDocs . length ) ; this . printScoreDocs ( docs . scoreDocs , "<STR_LIT>" ) ; } finally { searcher . close ( ) ; } } void printScoreDocs ( final ScoreDoc [ ] scoreDocs , final String prefix ) { List < Integer > originalOrder = new ArrayList < Integer > ( ) ; for ( ScoreDoc scoreDoc : scoreDocs ) { originalOrder . add ( scoreDoc . doc ) ; } LOG . info ( prefix + "<STR_LIT>" + originalOrder ) ; } void assertSortOrderAsc ( final ScoreDoc [ ] result ) { Map < Integer , String > reverseMap = new HashMap < Integer , String > ( ) ; for ( final Map . Entry < String , List < Integer > > entry : this . airportMap . entrySet ( ) ) { for ( final Integer docId : entry . getValue ( ) ) { reverseMap . put ( docId , entry . getKey ( ) ) ; } } String previousAirport = "<STR_LIT>" ; for ( final ScoreDoc scoreDoc : result ) { String currentAirport = reverseMap . get ( scoreDoc . doc ) ; Assert . assertTrue ( currentAirport + "<STR_LIT>" + previousAirport , currentAirport . compareTo ( previousAirport ) >= <NUM_LIT:0> ) ; previousAirport = currentAirport ; } } void assertSortOrderDesc ( final ScoreDoc [ ] result ) { Map < Integer , String > reverseMap = new HashMap < Integer , String > ( ) ; for ( final Map . Entry < String , List < Integer > > entry : this . airportMap . entrySet ( ) ) { for ( final Integer docId : entry . getValue ( ) ) { reverseMap . put ( docId , entry . getKey ( ) ) ; } } String previousAirport = "<STR_LIT>" ; for ( final ScoreDoc scoreDoc : result ) { String currentAirport = reverseMap . get ( scoreDoc . doc ) ; Assert . assertTrue ( currentAirport + "<STR_LIT>" + previousAirport , currentAirport . compareTo ( previousAirport ) <= <NUM_LIT:0> ) ; previousAirport = currentAirport ; } } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import org . apache . log4j . Logger ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . index . Term ; import org . hbasene . index . AbstractTermPositionsEncoder ; import org . hbasene . index . HBaseTermPositions ; import org . junit . After ; import org . junit . Assert ; import org . junit . Before ; import org . junit . Test ; public class TestHBaseTermPositions extends AbstractHBaseneTest { @ SuppressWarnings ( "<STR_LIT:unused>" ) private static final Logger LOGGER = Logger . getLogger ( TestHBaseTermPositions . class . getName ( ) ) ; private HBaseTermPositions termPositions ; private final AbstractTermPositionsEncoder termPositionEncoder = new AlphaTermPositionsEncoder ( ) ; @ Before public void doSetupDerived ( ) throws CorruptIndexException , IOException { termPositions = new HBaseTermPositions ( indexReader , this . termPositionEncoder ) ; } @ After public void doTearDownDerived ( ) throws Exception { termPositions . close ( ) ; } @ Test public void testTermDocs ( ) throws IOException { termPositions . seek ( new Term ( "<STR_LIT:content>" , "<STR_LIT>" ) ) ; int count = <NUM_LIT:0> ; while ( termPositions . next ( ) ) { Assert . assertTrue ( termPositions . doc ( ) >= <NUM_LIT:0> ) ; Assert . assertTrue ( termPositions . freq ( ) > <NUM_LIT:0> ) ; ++ count ; } Assert . assertEquals ( <NUM_LIT:4> , count ) ; } @ Test public void testReadNormal ( ) throws IOException { int [ ] docs = new int [ <NUM_LIT:4> ] ; int [ ] freqs = new int [ <NUM_LIT:4> ] ; termPositions . seek ( new Term ( "<STR_LIT:content>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( <NUM_LIT:4> , termPositions . read ( docs , freqs ) ) ; } @ Test public void testReadOverflowDocs ( ) throws IOException { int [ ] docs = new int [ <NUM_LIT:32> ] ; int [ ] freqs = new int [ <NUM_LIT:32> ] ; termPositions . seek ( new Term ( "<STR_LIT:content>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( <NUM_LIT:4> , termPositions . read ( docs , freqs ) ) ; } @ Test public void testReadUnderflowDocs ( ) throws IOException { int [ ] docs = new int [ <NUM_LIT:3> ] ; int [ ] freqs = new int [ <NUM_LIT:3> ] ; termPositions . seek ( new Term ( "<STR_LIT:content>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( <NUM_LIT:3> , termPositions . read ( docs , freqs ) ) ; } @ Test public void testReadMultipleSplits ( ) throws IOException { termPositions . seek ( new Term ( "<STR_LIT:content>" , "<STR_LIT>" ) ) ; int [ ] docs = new int [ <NUM_LIT:3> ] ; int [ ] freqs = new int [ <NUM_LIT:3> ] ; Assert . assertEquals ( <NUM_LIT:3> , termPositions . read ( docs , freqs ) ) ; docs = new int [ <NUM_LIT:1> ] ; freqs = new int [ <NUM_LIT:1> ] ; Assert . assertEquals ( <NUM_LIT:1> , termPositions . read ( docs , freqs ) ) ; } @ Test public void testReadAtLastBoundary ( ) throws IOException { termPositions . seek ( new Term ( "<STR_LIT:content>" , "<STR_LIT>" ) ) ; int [ ] docs = new int [ <NUM_LIT:3> ] ; int [ ] freqs = new int [ <NUM_LIT:3> ] ; Assert . assertEquals ( <NUM_LIT:3> , termPositions . read ( docs , freqs ) ) ; docs = new int [ <NUM_LIT:1> ] ; freqs = new int [ <NUM_LIT:1> ] ; Assert . assertEquals ( <NUM_LIT:1> , termPositions . read ( docs , freqs ) ) ; Assert . assertEquals ( <NUM_LIT:0> , termPositions . read ( docs , freqs ) ) ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import org . apache . log4j . Logger ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . store . LockObtainFailedException ; import org . junit . Test ; public class TestHBaseIndexStore extends AbstractHBaseneTest { @ SuppressWarnings ( "<STR_LIT:unused>" ) private static final Logger LOGGER = Logger . getLogger ( TestHBaseIndexStore . class . getName ( ) ) ; @ Test public void testAddDocuments ( ) throws CorruptIndexException , LockObtainFailedException , IOException { listLongQualifiers ( HBaseneConstants . FAMILY_DOC_TO_INT ) ; listTermVectors ( ) ; listFields ( ) ; listSequence ( ) ; for ( long i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; ++ i ) { assertDocumentPresent ( i ) ; } assertTermVectorDocumentMapping ( "<STR_LIT>" , <NUM_LIT> ) ; assertTermVectorDocumentMapping ( "<STR_LIT>" , <NUM_LIT:1L> ) ; } } </s>
|
<s> package org . hbasene . index ; import java . io . IOException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . apache . log4j . Logger ; import org . apache . lucene . analysis . standard . StandardAnalyzer ; import org . apache . lucene . document . Document ; import org . apache . lucene . document . Field ; import org . apache . lucene . index . CorruptIndexException ; import org . apache . lucene . util . Version ; import org . junit . AfterClass ; import org . junit . Assert ; import org . junit . BeforeClass ; import org . junit . Test ; public class TestHBaseIndexWriter { private static final Logger LOGGER = Logger . getLogger ( TestHBaseIndexWriter . class . getName ( ) ) ; static HBaseIndexWriter writer ; static MyIndexStore store ; @ BeforeClass public static void setUp ( ) throws IOException { store = new MyIndexStore ( ) ; writer = new HBaseIndexWriter ( store , "<STR_LIT:id>" ) ; } @ AfterClass public static void tearDown ( ) { } @ Test public void testWrite ( ) throws CorruptIndexException , IOException { Document doc = new Document ( ) ; doc . add ( new Field ( "<STR_LIT:content>" , "<STR_LIT>" , Field . Store . NO , Field . Index . ANALYZED_NO_NORMS ) ) ; doc . add ( new Field ( "<STR_LIT:id>" , "<STR_LIT>" , Field . Store . YES , Field . Index . NOT_ANALYZED_NO_NORMS ) ) ; writer . addDocument ( doc , new StandardAnalyzer ( Version . LUCENE_30 ) ) ; boolean contentPresent = false ; for ( final String term : store . tfs . keySet ( ) ) { if ( term . startsWith ( "<STR_LIT>" ) ) { contentPresent = true ; break ; } } Assert . assertTrue ( "<STR_LIT>" , contentPresent ) ; LOGGER . info ( store . tfs . keySet ( ) ) ; } static final class MyIndexStore extends AbstractIndexStore { Map < String , List < Long > > tfs = new HashMap < String , List < Long > > ( ) ; @ Override public void close ( ) throws IOException { } @ Override public void commit ( ) throws IOException { } @ Override public SegmentInfo indexDocument ( String key , DocumentIndexContext documentIndexContext ) throws IOException { return null ; } } } </s>
|
<s> package org . hbasene . index ; import java . util . ArrayList ; import java . util . List ; import org . hbasene . index . AbstractTermPositionsEncoder ; import org . junit . Assert ; import org . junit . Before ; public abstract class AbstractTermPositionsEncoderTest { protected AbstractTermPositionsEncoder encoder ; protected abstract AbstractTermPositionsEncoder createEncoder ( ) ; protected int [ ] termPositions ; @ Before public void setup ( ) { this . encoder = this . createEncoder ( ) ; this . termPositions = new int [ ] { <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:9> , <NUM_LIT:10> } ; } protected void assertEncodeDecode ( final int [ ] inputTermPositions ) { List < Integer > input = new ArrayList < Integer > ( inputTermPositions . length ) ; for ( int i : inputTermPositions ) { input . add ( i ) ; } byte [ ] array = this . encoder . encode ( input ) ; int [ ] result = this . encoder . decode ( array ) ; Assert . assertArrayEquals ( inputTermPositions , result ) ; } } </s>
|
<s> package com . mousefeed . client ; import com . mousefeed . client . collector . ActionDescTest ; import com . mousefeed . client . collector . CollectorTest ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; import org . junit . runners . Suite . SuiteClasses ; @ RunWith ( Suite . class ) @ SuiteClasses ( { AssertEnabledTest . class , MessagesTest . class , OnWrongInvocationModeTest . class , ActionDescTest . class , CollectorTest . class } ) public class AllClientTests { } </s>
|
<s> package com . mousefeed . client ; import static com . mousefeed . client . OnWrongInvocationMode . getLabels ; import static com . mousefeed . client . OnWrongInvocationMode . values ; import static org . apache . commons . lang . StringUtils . isNotBlank ; import static org . junit . Assert . assertEquals ; import org . apache . commons . lang . Validate ; import org . junit . Test ; public class OnWrongInvocationModeTest { @ Test public void general ( ) { assert values ( ) . length > <NUM_LIT:1> ; } @ Test public void getLabel ( ) { for ( OnWrongInvocationMode e : values ( ) ) { assert isNotBlank ( e . getLabel ( ) ) ; assert ! e . name ( ) . equals ( e . getLabel ( ) ) ; } } @ Test public void getLabelsTest ( ) { assertEquals ( getLabels ( ) . length , values ( ) . length ) ; assertEquals ( getLabels ( ) [ <NUM_LIT:0> ] , values ( ) [ <NUM_LIT:0> ] . getLabel ( ) ) ; Validate . noNullElements ( getLabels ( ) ) ; } } </s>
|
<s> package com . mousefeed . client ; import static org . junit . Assert . assertTrue ; import org . junit . Test ; public class AssertEnabledTest { @ Test public void assertsEnabled ( ) { boolean assertsEnabled = false ; assert assertsEnabled = true ; assertTrue ( "<STR_LIT>" , assertsEnabled ) ; } } </s>
|
<s> package com . mousefeed . client ; import static org . apache . commons . lang . StringUtils . isNotBlank ; import static org . junit . Assert . assertEquals ; import java . util . MissingResourceException ; import org . junit . Test ; public class MessagesTest { private static final String SHORT_KEY = "<STR_LIT:message>" ; private static final String FULL_KEY = MessagesTest . class . getSimpleName ( ) + "<STR_LIT:.>" + SHORT_KEY ; @ Test public void get_common ( ) { assertEquals ( "<STR_LIT:OK>" , new Messages ( ) . get ( "<STR_LIT>" ) ) ; } @ Test public void get_class ( ) { final Messages messages = new Messages ( MessagesTest . class ) ; assert isNotBlank ( messages . get ( SHORT_KEY ) ) ; assertEquals ( messages . get ( SHORT_KEY ) , messages . get ( FULL_KEY ) ) ; assert isNotBlank ( new Messages ( ) . get ( FULL_KEY ) ) ; assert isNotBlank ( new Messages ( null ) . get ( FULL_KEY ) ) ; } @ Test ( expected = MissingResourceException . class ) public void get_nonexisting ( ) { new Messages ( ) . get ( SHORT_KEY ) ; } @ Test ( expected = MissingResourceException . class ) public void get_nonexisting2 ( ) { new Messages ( null ) . get ( SHORT_KEY ) ; } @ Test ( expected = NullPointerException . class ) public void get_nullKey ( ) { new Messages ( ) . get ( null ) ; } @ Test ( expected = NullPointerException . class ) public void get_emptyKey ( ) { new Messages ( ) . get ( "<STR_LIT>" ) ; } @ Test ( expected = NullPointerException . class ) public void get_blankKey ( ) { new Messages ( ) . get ( "<STR_LIT>" ) ; } @ Test public void get_withParameters ( ) { final Messages m = new Messages ( MessagesTest . class ) ; final String p1 = "<STR_LIT>" ; final String p2 = "<STR_LIT>" ; final String p3 = "<STR_LIT>" ; assert m . get ( SHORT_KEY ) . contains ( "<STR_LIT>" ) : "<STR_LIT>" ; { final String s = m . get ( SHORT_KEY , p1 ) ; assert s . contains ( p1 ) ; assert ! s . contains ( p2 ) ; } { final String s = m . get ( SHORT_KEY , p1 , p2 ) ; assert s . contains ( p1 ) ; assert s . contains ( p2 ) ; assert ! s . contains ( p3 ) ; } { final String s = m . get ( SHORT_KEY , p1 , p2 , p3 ) ; assert s . contains ( p1 ) ; assert s . contains ( p2 ) ; assert ! s . contains ( p3 ) ; } } } </s>
|
<s> package com . mousefeed . client . collector ; import static junit . framework . Assert . assertEquals ; import static junit . framework . Assert . assertNull ; import org . junit . Test ; public class CollectorTest { private static final String LABEL = "<STR_LIT>" ; private static final String ACCELERATOR = "<STR_LIT>" ; @ Test ( expected = IllegalArgumentException . class ) public void onAction_null ( ) { new Collector ( ) . onAction ( null ) ; } @ Test public void getLastAction ( ) { final Collector c = new Collector ( ) ; assertNull ( c . getLastAction ( ) ) ; final AbstractActionDesc action = new TestActionDesc ( ) ; action . setLabel ( LABEL ) ; action . setAccelerator ( ACCELERATOR ) ; c . onAction ( action ) ; assertEquals ( action , c . getLastAction ( ) ) ; } private static class TestActionDesc extends AbstractActionDesc { } } </s>
|
<s> package com . mousefeed . client . collector ; import static junit . framework . Assert . assertEquals ; import static junit . framework . Assert . assertFalse ; import static junit . framework . Assert . assertNull ; import static junit . framework . Assert . assertTrue ; import org . junit . Test ; public class ActionDescTest { @ Test ( expected = IllegalArgumentException . class ) public void setLabel_blank ( ) { new TestActionDesc ( ) . setLabel ( "<STR_LIT>" ) ; } @ Test public void setLabel ( ) { final AbstractActionDesc d = new TestActionDesc ( ) ; final String s1 = "<STR_LIT:abc>" ; d . setLabel ( s1 ) ; assertEquals ( s1 , d . getLabel ( ) ) ; d . setLabel ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , d . getLabel ( ) ) ; assertEquals ( "<STR_LIT>" , d . getId ( ) ) ; } @ Test public void setAccelerator ( ) { final AbstractActionDesc d = new TestActionDesc ( ) ; assertFalse ( d . hasAccelerator ( ) ) ; d . setAccelerator ( null ) ; assertFalse ( d . hasAccelerator ( ) ) ; assertNull ( d . getAccelerator ( ) ) ; d . setAccelerator ( "<STR_LIT>" ) ; assertTrue ( d . hasAccelerator ( ) ) ; } private static class TestActionDesc extends AbstractActionDesc { } } </s>
|
<s> package com . mousefeed . eclipse ; import static junit . framework . Assert . assertEquals ; import static junit . framework . Assert . assertNull ; import org . junit . Test ; public class ActionDescImplTest { final static String label = "<STR_LIT>" ; final static String className = "<STR_LIT>" ; final static String def = "<STR_LIT>" ; @ Test public void setClassName ( ) { final ActionDescImpl desc = new ActionDescImpl ( ) ; assertNull ( desc . getClassName ( ) ) ; desc . setClassName ( className ) ; assertEquals ( className , desc . getClassName ( ) ) ; desc . setClassName ( "<STR_LIT>" ) ; assertEquals ( className , desc . getClassName ( ) ) ; } @ Test public void setDef ( ) { final ActionDescImpl desc = new ActionDescImpl ( ) ; assertNull ( desc . getDef ( ) ) ; desc . setDef ( def ) ; assertEquals ( def , desc . getDef ( ) ) ; desc . setDef ( "<STR_LIT>" ) ; assertEquals ( def , desc . getDef ( ) ) ; } @ Test public void getId ( ) { final ActionDescImpl desc = new ActionDescImpl ( ) ; assertNull ( desc . getId ( ) ) ; desc . setLabel ( label ) ; assertEquals ( label , desc . getId ( ) ) ; desc . setClassName ( className ) ; assertEquals ( className , desc . getClassName ( ) ) ; assertEquals ( className , desc . getId ( ) ) ; desc . setDef ( def ) ; assertEquals ( def , desc . getDef ( ) ) ; assertEquals ( def , desc . getId ( ) ) ; } } </s>
|
<s> package com . mousefeed . eclipse . preferences ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNull ; import com . mousefeed . client . OnWrongInvocationMode ; import com . mousefeed . client . collector . AbstractActionDesc ; import com . mousefeed . eclipse . ActionDescImpl ; import com . mousefeed . eclipse . preferences . ActionOnWrongInvocationMode . LabelComparator ; import org . apache . commons . lang . builder . EqualsBuilder ; import org . junit . Test ; public class ActionOnWrongInvocationModeTest { private static final String ID = "<STR_LIT>" ; private static final String LABEL = "<STR_LIT>" ; @ Test ( expected = IllegalArgumentException . class ) public void constructor_null ( ) { create ( null ) ; } @ Test public void constructor ( ) { final ActionDescImpl actionDesc = new ActionDescImpl ( ) ; actionDesc . setLabel ( LABEL ) ; actionDesc . setDef ( ID ) ; final ActionOnWrongInvocationMode mode = create ( actionDesc ) ; assertEquals ( LABEL , mode . getLabel ( ) ) ; assertEquals ( ID , mode . getId ( ) ) ; assertNull ( mode . getOnWrongInvocationMode ( ) ) ; } @ Test public void testClone ( ) throws CloneNotSupportedException { final ActionOnWrongInvocationMode mode = new ActionOnWrongInvocationMode ( ) ; mode . setId ( ID ) ; mode . setLabel ( LABEL ) ; mode . setOnWrongInvocationMode ( OnWrongInvocationMode . ENFORCE ) ; final ActionOnWrongInvocationMode mode2 = ( ActionOnWrongInvocationMode ) mode . clone ( ) ; EqualsBuilder . reflectionEquals ( mode , mode2 ) ; } @ Test public void testLabelComparator ( ) throws CloneNotSupportedException { final ActionOnWrongInvocationMode mode1 = new ActionOnWrongInvocationMode ( ) ; mode1 . setId ( ID ) ; mode1 . setLabel ( LABEL ) ; mode1 . setOnWrongInvocationMode ( OnWrongInvocationMode . ENFORCE ) ; final LabelComparator comparator = new LabelComparator ( ) ; final ActionOnWrongInvocationMode mode2 = ( ActionOnWrongInvocationMode ) mode1 . clone ( ) ; assertEquals ( <NUM_LIT:0> , comparator . compare ( mode1 , mode2 ) ) ; mode1 . setLabel ( LABEL + "<STR_LIT:a>" ) ; mode2 . setLabel ( LABEL + "<STR_LIT:b>" ) ; assertEquals ( - <NUM_LIT:1> , comparator . compare ( mode1 , mode2 ) ) ; mode1 . setLabel ( LABEL + "<STR_LIT:b>" ) ; mode2 . setLabel ( LABEL + "<STR_LIT:a>" ) ; assertEquals ( <NUM_LIT:1> , comparator . compare ( mode1 , mode2 ) ) ; } private ActionOnWrongInvocationMode create ( AbstractActionDesc actionDesc ) { return new ActionOnWrongInvocationMode ( actionDesc ) ; } } </s>
|
<s> package com . mousefeed . eclipse . preferences ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import com . mousefeed . client . OnWrongInvocationMode ; import com . mousefeed . eclipse . preferences . ActionInvocationModeControl . Column ; import org . junit . Test ; public class ActionInvocationModeTableLabelProviderTest { private static final String ID = "<STR_LIT>" ; private static final String LABEL = "<STR_LIT>" ; private static final OnWrongInvocationMode MODE = OnWrongInvocationMode . DO_NOTHING ; @ Test public void isLabelProperty ( ) { final ActionInvocationModeTableLabelProvider labelProvider = new ActionInvocationModeTableLabelProvider ( ) ; assertFalse ( labelProvider . isLabelProperty ( null , Column . LABEL . name ( ) ) ) ; assertTrue ( labelProvider . isLabelProperty ( null , Column . MODE . name ( ) ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void isLabelProperty_unknownProperty ( ) { final ActionInvocationModeTableLabelProvider labelProvider = new ActionInvocationModeTableLabelProvider ( ) ; labelProvider . isLabelProperty ( null , "<STR_LIT>" ) ; } @ Test public void getColumnImage ( ) { final ActionInvocationModeTableLabelProvider labelProvider = new ActionInvocationModeTableLabelProvider ( ) ; labelProvider . getColumnImage ( null , Column . LABEL . ordinal ( ) ) ; labelProvider . getColumnImage ( null , Column . MODE . ordinal ( ) ) ; labelProvider . getColumnImage ( null , - <NUM_LIT:100> ) ; } @ Test public void getColumnText ( ) { final ActionInvocationModeTableLabelProvider labelProvider = new ActionInvocationModeTableLabelProvider ( ) ; assertEquals ( LABEL , labelProvider . getColumnText ( getMode ( ) , Column . LABEL . ordinal ( ) ) ) ; assertEquals ( MODE . getLabel ( ) , labelProvider . getColumnText ( getMode ( ) , Column . MODE . ordinal ( ) ) ) ; } @ Test ( expected = IllegalArgumentException . class ) public void getColumnText_unknownColumnIdx ( ) { final ActionInvocationModeTableLabelProvider labelProvider = new ActionInvocationModeTableLabelProvider ( ) ; labelProvider . getColumnText ( getMode ( ) , - <NUM_LIT:100> ) ; } private ActionOnWrongInvocationMode getMode ( ) { final ActionOnWrongInvocationMode mode = new ActionOnWrongInvocationMode ( ) ; mode . setId ( ID ) ; mode . setLabel ( LABEL ) ; mode . setOnWrongInvocationMode ( MODE ) ; return mode ; } } </s>
|
<s> package com . mousefeed . eclipse . preferences ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertNull ; import static org . junit . Assert . assertTrue ; import com . mousefeed . client . OnWrongInvocationMode ; import com . mousefeed . eclipse . ActionDescImpl ; import java . io . File ; import java . io . IOException ; import org . junit . After ; import org . junit . Before ; import org . junit . Test ; public class PreferenceAccessorTest { private static final String ID1 = "<STR_LIT>" ; private static final String ID2 = "<STR_LIT>" ; private File FILE ; @ Before public void initFile ( ) throws IOException { FILE = File . createTempFile ( "<STR_LIT:test>" , null ) ; } @ After public void removeFile ( ) { FILE . delete ( ) ; } @ Test public void getActionsWrongInvocationModeFile ( ) throws IOException { final PreferenceAccessor preferences = new TestPreferenceAccessor ( ) ; assertNull ( preferences . getOnWrongInvocationMode ( ID1 ) ) ; { final ActionOnWrongInvocationMode mode = new ActionOnWrongInvocationMode ( ) ; mode . setLabel ( "<STR_LIT>" ) ; mode . setId ( ID1 ) ; assertEquals ( <NUM_LIT:0> , FILE . length ( ) ) ; mode . setOnWrongInvocationMode ( OnWrongInvocationMode . ENFORCE ) ; preferences . setOnWrongInvocationMode ( mode ) ; } assertTrue ( FILE . length ( ) > <NUM_LIT:0> ) ; assertEquals ( OnWrongInvocationMode . ENFORCE , preferences . getOnWrongInvocationMode ( ID1 ) ) ; { final ActionDescImpl actionDesc = new ActionDescImpl ( ) ; actionDesc . setDef ( ID2 ) ; actionDesc . setLabel ( "<STR_LIT>" ) ; final ActionOnWrongInvocationMode mode = new ActionOnWrongInvocationMode ( actionDesc ) ; mode . setOnWrongInvocationMode ( OnWrongInvocationMode . DO_NOTHING ) ; preferences . setOnWrongInvocationMode ( mode ) ; } { final PreferenceAccessor p = new TestPreferenceAccessor ( ) ; assertEquals ( OnWrongInvocationMode . ENFORCE , p . getOnWrongInvocationMode ( ID1 ) ) ; assertEquals ( OnWrongInvocationMode . DO_NOTHING , p . getOnWrongInvocationMode ( ID2 ) ) ; } assertEquals ( OnWrongInvocationMode . ENFORCE , preferences . getOnWrongInvocationMode ( ID1 ) ) ; preferences . removeOnWrongInvocaitonMode ( ID1 ) ; assertNull ( preferences . getOnWrongInvocationMode ( ID1 ) ) ; { final PreferenceAccessor p = new TestPreferenceAccessor ( ) ; assertNull ( p . getOnWrongInvocationMode ( ID1 ) ) ; assertEquals ( OnWrongInvocationMode . DO_NOTHING , p . getOnWrongInvocationMode ( ID2 ) ) ; } } private class TestPreferenceAccessor extends PreferenceAccessor { @ Override File getActionsWrongInvocationModeFile ( ) { return FILE ; } } } </s>
|
<s> package com . mousefeed . eclipse . preferences ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertNull ; import static org . junit . Assert . assertTrue ; import com . mousefeed . client . OnWrongInvocationMode ; import com . mousefeed . eclipse . preferences . ActionInvocationModeControl . Column ; import org . eclipse . jface . viewers . TableViewer ; import org . junit . Test ; public class ActionInvocationModeTableCellModifierTest { private static final String ID = "<STR_LIT>" ; private static final String LABEL = "<STR_LIT>" ; private static final OnWrongInvocationMode MODE = OnWrongInvocationMode . DO_NOTHING ; private static final OnWrongInvocationMode MODE2 = OnWrongInvocationMode . ENFORCE ; @ Test ( expected = IllegalArgumentException . class ) public void constructor ( ) { new ActionInvocationModeControl ( null ) ; } @ Test public void canModify ( ) { final ActionInvocationModeTableCellModifier m = new TestModifier ( null ) ; assertFalse ( m . canModify ( null , Column . LABEL . name ( ) ) ) ; assertTrue ( m . canModify ( new Object ( ) , Column . MODE . name ( ) ) ) ; } @ Test public void canModify_unknownProperty ( ) { final ActionInvocationModeTableCellModifier m = new TestModifier ( null ) ; assertFalse ( m . canModify ( null , "<STR_LIT>" ) ) ; } @ Test public void getValue ( ) { final ActionInvocationModeTableCellModifier m = new TestModifier ( null ) ; assertEquals ( LABEL , m . getValue ( getMode ( ) , Column . LABEL . name ( ) ) ) ; assertEquals ( MODE . ordinal ( ) , m . getValue ( getMode ( ) , Column . MODE . name ( ) ) ) ; } @ Test public void getValue_unknownProperty ( ) { final ActionInvocationModeTableCellModifier m = new TestModifier ( null ) ; assertNull ( m . getValue ( getMode ( ) , "<STR_LIT>" ) ) ; } @ Test public void modify_mode ( ) { final ActionInvocationModeTableCellModifier m = new TestModifier ( null ) ; final ActionOnWrongInvocationMode mode = getMode ( ) ; assertFalse ( mode . getOnWrongInvocationMode ( ) . equals ( MODE2 ) ) ; m . modify ( mode , Column . MODE . name ( ) , MODE2 . ordinal ( ) ) ; assertEquals ( MODE2 , mode . getOnWrongInvocationMode ( ) ) ; } @ Test public void modify_label ( ) { final ActionInvocationModeTableCellModifier m = new TestModifier ( null ) ; m . modify ( getMode ( ) , Column . LABEL . name ( ) , "<STR_LIT>" ) ; } @ Test public void modify_unknownProperty ( ) { final ActionInvocationModeTableCellModifier m = new TestModifier ( null ) ; m . modify ( getMode ( ) , "<STR_LIT>" , "<STR_LIT>" ) ; } private ActionOnWrongInvocationMode getMode ( ) { final ActionOnWrongInvocationMode mode = new ActionOnWrongInvocationMode ( ) ; mode . setId ( ID ) ; mode . setLabel ( LABEL ) ; mode . setOnWrongInvocationMode ( MODE ) ; return mode ; } private static final class TestModifier extends ActionInvocationModeTableCellModifier { private TestModifier ( TableViewer tableViewer ) { super ( tableViewer ) ; } @ Override void validateTableViewer ( TableViewer tableViewer ) { } @ Override void updateTableViewer ( Object element , String property ) { } } } </s>
|
<s> package com . mousefeed . eclipse ; import com . mousefeed . eclipse . preferences . ActionInvocationModeTableCellModifierTest ; import com . mousefeed . eclipse . preferences . ActionInvocationModeTableLabelProviderTest ; import com . mousefeed . eclipse . preferences . ActionOnWrongInvocationModeTest ; import com . mousefeed . eclipse . preferences . PreferenceAccessorTest ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; import org . junit . runners . Suite . SuiteClasses ; @ RunWith ( Suite . class ) @ SuiteClasses ( { ActionDescImplTest . class , ActionInvocationModeTableCellModifierTest . class , ActionInvocationModeTableLabelProviderTest . class , ActionOnWrongInvocationModeTest . class , PreferenceAccessorTest . class } ) public class AllEclipseTests { } </s>
|
<s> package com . mousefeed ; import com . mousefeed . client . AllClientTests ; import com . mousefeed . eclipse . AllEclipseTests ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; import org . junit . runners . Suite . SuiteClasses ; @ RunWith ( Suite . class ) @ SuiteClasses ( { AllClientTests . class , AllEclipseTests . class } ) public class AllTests { } </s>
|
<s> package com . mousefeed . client ; public enum OnWrongInvocationMode { DO_NOTHING , REMIND , ENFORCE ; public static final OnWrongInvocationMode DEFAULT = REMIND ; private static final Messages MESSAGES = new Messages ( OnWrongInvocationMode . class ) ; public String getLabel ( ) { return MESSAGES . get ( name ( ) ) ; } public static String [ ] getLabels ( ) { final String [ ] labels = new String [ values ( ) . length ] ; for ( int i = <NUM_LIT:0> ; i < values ( ) . length ; i ++ ) { labels [ i ] = values ( ) [ i ] . getLabel ( ) ; } return labels ; } } </s>
|
<s> package com . mousefeed . client ; import static org . apache . commons . lang . StringUtils . isBlank ; import java . text . MessageFormat ; import java . util . MissingResourceException ; import java . util . ResourceBundle ; public class Messages { private static final String MESSAGES_BASE = Messages . class . getPackage ( ) . getName ( ) + "<STR_LIT>" ; private static final ResourceBundle BUNDLE = ResourceBundle . getBundle ( MESSAGES_BASE ) ; private final Class < ? > forClass ; public Messages ( ) { this ( AbstractNoForClassIsSpecified . class ) ; } public Messages ( final Class < ? > forClass ) { this . forClass = forClass == null ? AbstractNoForClassIsSpecified . class : forClass ; } public String get ( final String key , final Object ... arguments ) throws NullPointerException , MissingResourceException { if ( isBlank ( key ) ) { throw new NullPointerException ( "<STR_LIT>" + key + "<STR_LIT:'>" ) ; } try { final String forClassKey = forClass . getSimpleName ( ) + "<STR_LIT:.>" + key ; return getFromBundle ( forClassKey , arguments ) ; } catch ( final MissingResourceException e ) { return getFromBundle ( key , arguments ) ; } } private String getFromBundle ( final String key , final Object ... arguments ) { final String pattern = BUNDLE . getString ( key ) ; return arguments . length == <NUM_LIT:0> ? pattern : MessageFormat . format ( pattern , arguments ) ; } private abstract static class AbstractNoForClassIsSpecified { } } </s>
|
<s> package com . mousefeed . client . collector ; import static org . apache . commons . lang . Validate . notNull ; public class Collector { private AbstractActionDesc lastAction ; public Collector ( ) { } public AbstractActionDesc getLastAction ( ) { return lastAction ; } public void onAction ( final AbstractActionDesc action ) { notNull ( action ) ; lastAction = action ; } } </s>
|
<s> package com . mousefeed . client . collector ; import static org . apache . commons . lang . StringUtils . isNotBlank ; import static org . apache . commons . lang . Validate . isTrue ; public abstract class AbstractActionDesc { private String label ; private String accelerator ; public String getId ( ) { return getLabel ( ) ; } public String getLabel ( ) { return label ; } public void setLabel ( final String label ) { isTrue ( isNotBlank ( label ) ) ; this . label = label . replace ( "<STR_LIT:&>" , "<STR_LIT>" ) ; } public boolean hasAccelerator ( ) { return getAccelerator ( ) != null ; } public String getAccelerator ( ) { return accelerator ; } public void setAccelerator ( final String accelerator ) { this . accelerator = accelerator ; } } </s>
|
<s> package com . mousefeed . eclipse ; public class AcceleratorSearchResult { public AcceleratorSearchResult ( ) { } } </s>
|
<s> package com . mousefeed . eclipse ; import static org . apache . commons . lang . Validate . isTrue ; import static org . apache . commons . lang . Validate . notNull ; import java . lang . reflect . Field ; import java . util . Collections ; import java . util . HashMap ; import java . util . Map ; import org . eclipse . jface . action . IAction ; public class TextActionHandlerActionLocator { private static final String HANDLER_CLASS_NAME = "<STR_LIT>" ; private static final Map < String , String > HANDLER_ACTIONS ; static { final Map < String , String > map = new HashMap < String , String > ( ) ; map . put ( "<STR_LIT>" , "<STR_LIT>" ) ; HANDLER_ACTIONS = Collections . unmodifiableMap ( map ) ; } public TextActionHandlerActionLocator ( ) { } public boolean isSearchable ( final IAction searchTarget ) { notNull ( searchTarget ) ; return searchTarget . getClass ( ) . getName ( ) . startsWith ( HANDLER_CLASS_NAME + "<STR_LIT:$>" ) ; } public String findActionDefinitionId ( final IAction action , final IAction searchTarget ) { try { return doFindActionDefinitionId ( action , searchTarget ) ; } catch ( final SecurityException e ) { throw new AssertionError ( e ) ; } catch ( final NoSuchFieldException e ) { throw new AssertionError ( e ) ; } catch ( final IllegalAccessException e ) { throw new AssertionError ( e ) ; } } private String doFindActionDefinitionId ( final IAction action , final IAction searchTarget ) throws NoSuchFieldException , IllegalAccessException { notNull ( action ) ; notNull ( searchTarget ) ; final Object handler = getTextActionHandler ( searchTarget ) ; for ( final String fieldName : HANDLER_ACTIONS . keySet ( ) ) { final IAction handlerAction = getActionFromField ( handler , fieldName ) ; if ( handlerAction == null ) { continue ; } if ( action . getClass ( ) . equals ( handlerAction . getClass ( ) ) ) { return HANDLER_ACTIONS . get ( fieldName ) ; } } return null ; } private IAction getActionFromField ( final Object o , final String fieldName ) throws NoSuchFieldException , IllegalAccessException { final Field actionField = o . getClass ( ) . getDeclaredField ( fieldName ) ; actionField . setAccessible ( true ) ; return ( IAction ) actionField . get ( o ) ; } private Object getTextActionHandler ( final IAction action ) throws NoSuchFieldException , IllegalAccessException { notNull ( action ) ; final Field handlerField = action . getClass ( ) . getDeclaredField ( "<STR_LIT>" ) ; notNull ( handlerField ) ; handlerField . setAccessible ( true ) ; final Object handler = handlerField . get ( action ) ; notNull ( handler ) ; isTrue ( handler . getClass ( ) . getName ( ) . equals ( HANDLER_CLASS_NAME ) ) ; return handler ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.