idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
5,800
public static final String defaultToString ( Object object ) { if ( object == null ) return "null" ; else return object . getClass ( ) . getName ( ) + '@' + Integer . toHexString ( System . identityHashCode ( object ) ) ; }
The default toString implementation of an object
5,801
public static long parseTimePeriod ( String period ) { try { String s = period . toLowerCase ( ) ; long factor ; if ( s . endsWith ( "msec" ) ) { s = s . substring ( 0 , s . lastIndexOf ( "msec" ) ) ; factor = MSEC ; } else if ( s . endsWith ( "sec" ) ) { s = s . substring ( 0 , s . lastIndexOf ( "sec" ) ) ; factor = S...
Parses a time period into a long .
5,802
public static String trimLeadingCharacter ( String str , final char leadingCharacter ) { return trimLeadingCharacter ( str , new CharacterFilter ( ) { public boolean isCharacterLegal ( char character ) { return character == leadingCharacter ; } } ) ; }
Trim all occurences of the supplied leading character from the given String .
5,803
public static String readOutput ( BufferedReader in ) throws IOException { StringBuffer output = new StringBuffer ( ) ; String line = "" ; while ( ( line = in . readLine ( ) ) != null ) { output . append ( line ) ; output . append ( "\n" ) ; } return output . toString ( ) ; }
Reads the output of the reader and delivers it at string .
5,804
public static TextClassifier getClassifier ( File resourceDirectoryFile ) throws Exception { if ( resourceDirectoryFile . toString ( ) . endsWith ( ".zip" ) && resourceDirectoryFile . isFile ( ) ) { resourceDirectoryFile = UnZip . unzip ( resourceDirectoryFile ) ; } if ( resourceDirectoryFile . exists ( ) == false ) th...
Returns a specific instance of a Text Classifier given a resource Directory
5,805
public Map < Integer , Integer > compact ( ) { Map < Integer , Integer > equiv = new HashMap < Integer , Integer > ( ) ; TreeMap < Integer , int [ ] > newIndex2docfreq = new TreeMap < Integer , int [ ] > ( ) ; Iterator < Entry < String , int [ ] > > iter = tokenForm2index . entrySet ( ) . iterator ( ) ; nextAttributeID...
Adjust the indices of the attributes so that maxAttributeID == getAttributesNum . Returns a Map containing the mapping between the old indices and the new ones .
5,806
public WeightingMethod getMethod ( String fieldName ) { WeightingMethod method = this . customWeights . get ( fieldName ) ; if ( method != null ) return method ; return this . method_used ; }
Returns the weighting scheme used for a specific field or the default one if nothing has been specified for it
5,807
public int getIndex ( String tokenForm ) { int [ ] index = ( int [ ] ) tokenForm2index . get ( tokenForm ) ; if ( index == null ) return - 1 ; return index [ 0 ] ; }
returns the position of a given tokenform or - 1 if the tokenform is unknown or has been filtered out
5,808
public int createIndex ( String tokenForm ) { int [ ] index = ( int [ ] ) tokenForm2index . get ( tokenForm ) ; if ( index == null ) { index = new int [ ] { nextAttributeID } ; tokenForm2index . put ( tokenForm , index ) ; nextAttributeID ++ ; } Integer integ = Integer . valueOf ( index [ 0 ] ) ; int [ ] docfreq = ( in...
called from Document
5,809
public void addDocument ( Document doc ) throws IOException { String serial = doc . getStringSerialization ( ) ; raw_file_buffer . write ( serial ) ; }
there is exactly one document per line
5,810
public static void getAttributeScores ( String modelPath , String lexiconF , int topAttributesNumber ) throws IOException { Lexicon lexicon = new Lexicon ( lexiconF ) ; Model liblinearModel = Model . load ( new File ( modelPath ) ) ; double [ ] weights = liblinearModel . getFeatureWeights ( ) ; int numClasses = libline...
Prints out the attributes and their weights from the models generated by liblinear . This is different from CorpusUtils . dumpBestAttributes which computes a score for the attributes regardless of the model .
5,811
public int compareTo ( WeightedAttribute att ) { double absoltarget = att . weight ; double absolsource = this . weight ; double diff = absolsource - absoltarget ; if ( diff < 0 ) return - 1 ; if ( diff > 0 ) return + 1 ; return 0 ; }
rank the attributes based on weight
5,812
public static boolean isSnapshot ( Version version ) { Assert . notNull ( version , "Version must not be null." ) ; return version . toString ( ) . endsWith ( SNAPSHOT_SUFFIX ) ; }
Returns if the version specified is a SNAPSHOT
5,813
private boolean isCanonical ( final FileDescriptor file ) { final FileDescriptorProto proto = file . toProto ( ) ; if ( proto . hasOptions ( ) && proto . getOptions ( ) . getUninterpretedOptionCount ( ) > 0 ) { return false ; } for ( final FieldDescriptorProto field : proto . getExtensionList ( ) ) { if ( ! isFieldCano...
very consuming and problematic!
5,814
private void ensureBuilders ( ) { if ( this . builders == null ) { this . builders = new ArrayList < SingleFieldBuilder < MType , BType , IType > > ( messages . size ( ) ) ; for ( int i = 0 ; i < messages . size ( ) ; i ++ ) { builders . add ( null ) ; } } }
Ensures that the list of builders is not null . If it s null the list is created and initialized to be the same size as the messages list with null entries .
5,815
public RepeatedFieldBuilder < MType , BType , IType > addAllMessages ( final Iterable < ? extends MType > values ) { for ( final MType value : values ) { if ( value == null ) { throw new NullPointerException ( ) ; } } if ( values instanceof Collection ) { @ SuppressWarnings ( "unchecked" ) final Collection < MType > co...
Appends all of the messages in the specified collection to the end of this list in the order that they are returned by the specified collection s iterator .
5,816
public BType addBuilder ( final MType message ) { ensureMutableMessageList ( ) ; ensureBuilders ( ) ; final SingleFieldBuilder < MType , BType , IType > builder = newSingleFieldBuilder ( message , this , isClean ) ; messages . add ( null ) ; builders . add ( builder ) ; onChanged ( ) ; incrementModCounts ( ) ; return b...
Appends a new builder to the end of this list and returns the builder .
5,817
public List < MType > getMessageList ( ) { if ( externalMessageList == null ) { externalMessageList = new MessageExternalList < MType , BType , IType > ( this ) ; } return externalMessageList ; }
Gets a view of the builder as a list of messages . The returned list is live and will reflect any changes to the underlying builder .
5,818
public List < BType > getBuilderList ( ) { if ( externalBuilderList == null ) { externalBuilderList = new BuilderExternalList < MType , BType , IType > ( this ) ; } return externalBuilderList ; }
Gets a view of the builder as a list of builders . This returned list is live and will reflect any changes to the underlying builder .
5,819
public List < IType > getMessageOrBuilderList ( ) { if ( externalMessageOrBuilderList == null ) { externalMessageOrBuilderList = new MessageOrBuilderExternalList < MType , BType , IType > ( this ) ; } return externalMessageOrBuilderList ; }
Gets a view of the builder as a list of MessageOrBuilders . This returned list is live and will reflect any changes to the underlying builder .
5,820
private void incrementModCounts ( ) { if ( externalMessageList != null ) { externalMessageList . incrementModCount ( ) ; } if ( externalBuilderList != null ) { externalBuilderList . incrementModCount ( ) ; } if ( externalMessageOrBuilderList != null ) { externalMessageOrBuilderList . incrementModCount ( ) ; } }
Increments the mod counts so that an ConcurrentModificationException can be thrown if calling code tries to modify the builder while its iterating the list .
5,821
private void collectRequiredAddons ( AddonInfo addonInfo , List < AddonInfo > addons ) { addons . remove ( addonInfo ) ; addons . add ( 0 , addonInfo ) ; for ( AddonId addonId : addonInfo . getRequiredAddons ( ) ) { if ( ! addons . contains ( addonId ) && ( ! isDeployed ( addonId ) || ! isEnabled ( addonId ) ) ) { Addo...
Collect all required addons for a specific addon .
5,822
public void parse ( String str ) { if ( buffer . length ( ) > 0 ) { str = buffer . toString ( ) . concat ( str ) ; buffer = new StringBuilder ( ) ; } Reader reader = new StringReader ( str ) ; try { try { parse ( reader ) ; } finally { reader . close ( ) ; } } catch ( IOException ex ) { } }
Parses the specified string .
5,823
private void parse ( Reader reader ) throws IOException { StringBuilder text = new StringBuilder ( ) ; int character ; while ( ( character = reader . read ( ) ) != - 1 ) { boolean introducedControlSequence = false ; if ( character == SINGLE_CSI ) { introducedControlSequence = true ; } else if ( character == MULTI_CSI [...
Parses characters from the specified character reader .
5,824
private void parseControlSequence ( Reader reader ) throws IOException { boolean finishedSequence = false ; StringBuilder parameters = new StringBuilder ( ) ; int character ; while ( ( character = reader . read ( ) ) != - 1 ) { if ( ( character >= 'a' && character <= 'z' ) || ( character >= 'A' && character <= 'Z' ) ) ...
Parses a control sequence .
5,825
public static < T > ArgumentProcessor < T > newInstance ( Class < ? extends T > beanType , CommandLineParser parser ) { return ArgumentProcessorFactory . getInstance ( ) . newProcessor ( beanType , parser ) ; }
Create new instance with given bean type and command line parser that describes command line sytnax .
5,826
public T process ( String [ ] arguments , T bean ) { return process ( Arrays . asList ( arguments ) , bean ) ; }
Process argument array and pass values to given bean
5,827
public void onBindViewHolder ( EfficientViewHolder < T > viewHolder , int position , EfficientAdapter < T > adapter ) { T object = get ( position ) ; viewHolder . onBindView ( object , position ) ; viewHolder . setAdapter ( adapter ) ; setClickListenerOnView ( viewHolder ) ; setLongClickListenerOnView ( viewHolder ) ; ...
Called by the view to display the data at the specified position .
5,828
int remove ( T object ) { int positionOfRemove = mObjects . indexOf ( object ) ; if ( positionOfRemove >= 0 ) { T objectRemoved = removeAt ( positionOfRemove ) ; if ( objectRemoved != null ) { return positionOfRemove ; } } return - 1 ; }
Remove the specified object of the array .
5,829
public void addPoint ( Point p ) { if ( p == null ) throw new NullPointerException ( ) ; points . add ( new Point ( p ) ) ; repaint ( ) ; }
Adds a point to the list of pixels marked by this overlay .
5,830
public void setPoint ( Point p ) { points . clear ( ) ; if ( p != null ) { points . add ( new Point ( p ) ) ; } repaint ( ) ; }
Sets the argument as the only point marked by this overlay .
5,831
public void setPoints ( Iterable < Point > points ) { if ( points == null ) throw new NullPointerException ( ) ; this . points . clear ( ) ; for ( Point p : points ) { this . points . add ( new Point ( p ) ) ; } repaint ( ) ; }
Sets the marked pixels .
5,832
public static void setVisibility ( EfficientCacheView cacheView , int viewId , int visibility ) { View view = cacheView . findViewByIdEfficient ( viewId ) ; if ( view != null ) { view . setVisibility ( visibility ) ; } }
Equivalent to calling View . setVisibility
5,833
public static void setBackground ( EfficientCacheView cacheView , int viewId , Drawable drawable ) { View view = cacheView . findViewByIdEfficient ( viewId ) ; if ( view != null ) { if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . JELLY_BEAN ) { view . setBackgroundDrawable ( drawable ) ; } else { view . setBac...
Equivalent to calling View . setBackground
5,834
public static void setImageDrawable ( EfficientCacheView cacheView , int viewId , Drawable drawable ) { View view = cacheView . findViewByIdEfficient ( viewId ) ; if ( view instanceof ImageView ) { ( ( ImageView ) view ) . setImageDrawable ( drawable ) ; } }
Equivalent to calling ImageView . setImageDrawable
5,835
public static void setImageBitmap ( EfficientCacheView cacheView , int viewId , Bitmap bm ) { View view = cacheView . findViewByIdEfficient ( viewId ) ; if ( view instanceof ImageView ) { ( ( ImageView ) view ) . setImageBitmap ( bm ) ; } }
Equivalent to calling ImageView . setImageBitmap
5,836
private void init ( ) { setLayout ( new BorderLayout ( 0 , 0 ) ) ; int rows = model . getRows ( ) ; int bufferSize = model . getBufferSize ( ) ; if ( bufferSize > rows ) { scrollBar = new JScrollBar ( JScrollBar . VERTICAL , 0 , rows , 0 , bufferSize + 1 ) ; scrollBar . addAdjustmentListener ( new AdjustmentListener ( ...
Initializes the terminal .
5,837
public void clearViewCached ( int parentId , int viewId ) { SparseArray < View > sparseArrayViewsParent = mSparseSparseArrayView . get ( parentId ) ; if ( sparseArrayViewsParent != null ) { sparseArrayViewsParent . remove ( viewId ) ; } }
Clear the cache for the view specify
5,838
public CommandLineBuilder withLongOption ( String name , String value ) { cl . addOptionValue ( name , value , false ) ; return this ; }
Add an option with its long name
5,839
public CommandLineBuilder withShortOption ( String name , String value ) { cl . addOptionValue ( name , value , true ) ; return this ; }
Add an option with its short name
5,840
@ SuppressWarnings ( "unchecked" ) < P > void setValues ( T bean , List < String > values ) { Collection < P > col ; try { col = ( Collection < P > ) listType . newInstance ( ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( "Can't instantiate " + listType , e ) ; } catch ( IllegalAccessException ...
Write multi value to bean
5,841
private static < A extends Annotation > A getAnnotation ( PropertyDescriptor descriptor , Class < A > type ) { A a = null ; if ( descriptor . getWriteMethod ( ) != null ) { a = descriptor . getWriteMethod ( ) . getAnnotation ( type ) ; } if ( a == null && descriptor . getReadMethod ( ) != null ) { a = descriptor . getR...
Get annotation from either writer or reader of a Java property
5,842
public final void setModel ( PixelModel newModel ) { if ( newModel == null ) throw new NullPointerException ( ) ; if ( model != newModel ) { if ( model != null ) model . removeChangeListener ( modelListener ) ; model = newModel ; model . addChangeListener ( modelListener ) ; update ( ) ; } }
Sets the model dictating the pixel shown by this status bar .
5,843
protected final void update ( ) { BufferedImage image = getImageViewer ( ) == null ? null : getImageViewer ( ) . getImage ( ) ; if ( image == null || model . isInvalid ( ) || model . getX ( ) >= image . getWidth ( ) || model . getY ( ) >= image . getHeight ( ) ) updateLabelNoData ( ) ; else updateLabel ( image , model ...
Updates the info label . This function is called when either the selected pixel or the image shown in the viewer is changed . You can call this method to indicate that the message should be updated for some different reason .
5,844
public void setPosition ( int pos ) { if ( pos < 0 || pos >= number ) throw new IllegalArgumentException ( "Position " + pos + " out of range" ) ; position = pos ; updateLocationDefinition ( position ) ; forwardButton . setEnabled ( position < number - 1 ) ; backwardButton . setEnabled ( position > 0 ) ; if ( panel . g...
Sets the position of the viewer .
5,845
public void setStatusBarVisible ( boolean statusBarVisible ) { if ( this . statusBarVisible == statusBarVisible ) return ; if ( statusBar != null ) { if ( statusBarVisible ) panel . add ( statusBar . getComponent ( ) , BorderLayout . SOUTH ) ; else panel . remove ( statusBar . getComponent ( ) ) ; panel . revalidate ( ...
Sets whether the status bar is visible . The status bar is hidden by default .
5,846
public View . OnClickListener getOnClickListener ( boolean adapterHasListener ) { if ( isClickable ( ) && adapterHasListener ) { if ( mViewHolderClickListener == null ) { mViewHolderClickListener = new ViewHolderClickListener < > ( this ) ; } } else { mViewHolderClickListener = null ; } return mViewHolderClickListener ...
Get the OnClickListener to call when the user click on the item .
5,847
public View . OnLongClickListener getOnLongClickListener ( boolean adapterHasListener ) { if ( isLongClickable ( ) && adapterHasListener ) { if ( mViewHolderLongClickListener == null ) { mViewHolderLongClickListener = new ViewHolderLongClickListener < > ( this ) ; } } else { mViewHolderLongClickListener = null ; } retu...
Get the OnLongClickListener to call when the user long - click on the item .
5,848
Reference < T > lookupReference ( String name , boolean isLongName ) { if ( isLongName ) { for ( Reference < T > r : referenceMap . values ( ) ) { if ( r . longName . equals ( name ) ) { return r ; } } return null ; } return referenceMap . get ( name ) ; }
Find reference with given name of option or argument
5,849
void end ( ) { switch ( state ) { case OPTION : currentOption = context . optionWithShortName ( currentValue . substring ( 1 ) ) ; case LONG_OPTION : if ( state == ArgumentsInspectorState . LONG_OPTION ) { currentOption = context . optionWithLongName ( currentValue . substring ( 2 ) ) ; } if ( currentOption != null && ...
End the process
5,850
void setValue ( T bean , String value ) { ref . writeValue ( converter . fromCharacters ( value ) , bean ) ; }
Set a string value to bean based on known conversion rule and value reference
5,851
protected void fireChange ( ) { Object [ ] listeners = listenerList . getListenerList ( ) ; ChangeEvent event = new ChangeEvent ( this ) ; for ( int i = listeners . length - 2 ; i >= 0 ; i -= 2 ) { if ( listeners [ i ] == ChangeListener . class ) { ( ( ChangeListener ) listeners [ i + 1 ] ) . stateChanged ( event ) ; }...
Notifies the registered listeners that the model has changed .
5,852
public void addOverlay ( Overlay overlay , int layer ) { if ( overlay == null ) throw new NullPointerException ( ) ; OverlayComponent c = new OverlayComponent ( overlay , theImage ) ; overlay . addOverlayComponent ( c ) ; layeredPane . add ( c , Integer . valueOf ( layer ) ) ; layeredPane . revalidate ( ) ; layeredPane...
Adds an overlay as the specified layer .
5,853
public void removeOverlay ( Overlay overlay ) { if ( overlay == null ) throw new NullPointerException ( ) ; for ( Component c : layeredPane . getComponents ( ) ) { if ( c instanceof OverlayComponent && ( ( OverlayComponent ) c ) . overlay == overlay ) { overlay . removeOverlayComponent ( ( OverlayComponent ) c ) ; laye...
Removes an overlay from the image viewer .
5,854
protected Map < String , Role > parseDefinedRoles ( Config config ) { Map < String , Role > roleMap = new HashMap < > ( ) ; if ( ! config . hasPath ( "roles" ) ) { log . trace ( "'{}' has no roles" , config ) ; } else if ( config . hasPath ( "roles" ) ) { log . trace ( "Parsing Role definitions" ) ; Config roleConfig =...
Parse the Roles specified in the Config object .
5,855
public static Collection < Class < ? > > getClasses ( String ... packageNames ) { List < Class < ? > > classes = new ArrayList < > ( ) ; for ( String packageName : packageNames ) { final String packagePath = packageName . replace ( '.' , '/' ) ; final String packagePrefix = packageName + '.' ; List < URL > packageUrls ...
Returns the list of all classes within a package .
5,856
public static < T extends Annotation > T getAnnotation ( Method method , Class < T > annotationClass ) { T t = method . getAnnotation ( annotationClass ) ; if ( t == null ) { t = getAnnotation ( method . getDeclaringClass ( ) , annotationClass ) ; } return t ; }
Extract the annotation from the method or the declaring class .
5,857
protected void executeScript ( String scriptPath ) { URL scriptUrl = null ; try { if ( scriptPath . startsWith ( "classpath:" ) ) { String script = scriptPath . substring ( "classpath:" . length ( ) ) ; scriptUrl = ClassUtil . getResource ( script ) ; if ( scriptUrl == null ) { log . warn ( "Script '{}' not found!" , s...
Execute a script located either in the classpath or on the filesystem .
5,858
private byte [ ] berEncodedValue ( ) { final ByteBuffer buff = ByteBuffer . allocate ( 5 ) ; buff . put ( ( byte ) 0x30 ) ; buff . put ( ( byte ) 0x03 ) ; buff . put ( ( byte ) 0x02 ) ; buff . put ( ( byte ) 0x01 ) ; buff . put ( NumberFacility . leftTrim ( NumberFacility . getBytes ( flags ) ) ) ; return buff . array ...
BER encode the flags .
5,859
public static String getEscaped ( byte ... bytes ) { final StringBuilder bld = new StringBuilder ( ) ; for ( byte b : bytes ) { bld . append ( "\\" ) . append ( Hex . get ( b ) ) ; } return bld . toString ( ) ; }
Gets escaped hex string corresponding to the given bytes .
5,860
public static byte [ ] reverse ( byte ... bytes ) { byte [ ] res = new byte [ bytes . length ] ; int j = 0 ; for ( int i = bytes . length - 1 ; i >= 0 ; i -- ) { res [ j ] = bytes [ i ] ; j ++ ; } return res ; }
Reverses bytes .
5,861
public static SID newInstance ( final byte [ ] identifier ) { final SID sid = new SID ( ) ; sid . setRevision ( ( byte ) 0x01 ) ; sid . setIdentifierAuthority ( identifier ) ; return sid ; }
Instances a new SID with the given identifier authority .
5,862
public static SID parse ( final byte [ ] src ) { final ByteBuffer sddlBuffer = ByteBuffer . wrap ( src ) ; final SID sid = new SID ( ) ; sid . parse ( sddlBuffer . asIntBuffer ( ) , 0 ) ; return sid ; }
Instances a SID instance of the given byte array .
5,863
int parse ( final IntBuffer buff , final int start ) { int pos = start ; final byte [ ] sidHeader = NumberFacility . getBytes ( buff . get ( pos ) ) ; revision = sidHeader [ 0 ] ; int subAuthorityCount = NumberFacility . getInt ( sidHeader [ 1 ] ) ; identifierAuthority = new byte [ 6 ] ; System . arraycopy ( sidHeader ...
Load the SID from the buffer returning the last SID segment position into the buffer .
5,864
public static boolean isUserCannotChangePassword ( final SDDL sddl ) { boolean res = false ; final List < ACE > aces = sddl . getDacl ( ) . getAces ( ) ; for ( int i = 0 ; ! res && i < aces . size ( ) ; i ++ ) { final ACE ace = aces . get ( i ) ; if ( ace . getType ( ) == AceType . ACCESS_DENIED_OBJECT_ACE_TYPE && ace ...
Check if user canot change password .
5,865
protected final boolean isAuthenticated ( Context context ) { Account account = context . getSession ( AuthConstants . ACCOUNT_ATTRIBUTE ) ; if ( account == null ) { account = context . getLocal ( AuthConstants . ACCOUNT_ATTRIBUTE ) ; } return account != null && account . isAuthenticated ( ) ; }
Determines if the current Context has already been authenticated .
5,866
private byte [ ] berEncodedValue ( ) { final byte [ ] cookieSize = NumberFacility . leftTrim ( NumberFacility . getBytes ( cookie . length ) ) ; final byte [ ] size = NumberFacility . leftTrim ( NumberFacility . getBytes ( 14 + cookieSize . length + cookie . length ) ) ; final ByteBuffer buff = ByteBuffer . allocate ( ...
BER encode the cookie value .
5,867
private int parse ( final IntBuffer buff , final int start ) { int pos = start ; final byte [ ] header = NumberFacility . getBytes ( buff . get ( pos ) ) ; revision = header [ 0 ] ; controlFlags = new byte [ ] { header [ 3 ] , header [ 2 ] } ; final boolean [ ] controlFlag = NumberFacility . getBits ( controlFlags ) ; ...
Load the SDDL from the buffer returning the last SDDL segment position into the buffer .
5,868
public int getSize ( ) { return 20 + ( sacl == null ? 0 : sacl . getSize ( ) ) + ( dacl == null ? 0 : dacl . getSize ( ) ) + ( owner == null ? 0 : owner . getSize ( ) ) + ( group == null ? 0 : group . getSize ( ) ) ; }
Gets size in terms of number of bytes .
5,869
public byte [ ] toByteArray ( ) { final ByteBuffer buff = ByteBuffer . allocate ( getSize ( ) ) ; buff . put ( revision ) ; buff . put ( ( byte ) 0x00 ) ; buff . put ( controlFlags [ 1 ] ) ; buff . put ( controlFlags [ 0 ] ) ; buff . position ( 4 ) ; int nextAvailablePosition = 20 ; if ( owner == null ) { buff . putInt...
Serializes SDDL as byte array .
5,870
private void setAdminAttribute ( Account account ) { if ( adminGroups != null ) { for ( String adminGroup : adminGroups ) { if ( adminGroup . startsWith ( "@" ) && account . getUsername ( ) . equalsIgnoreCase ( adminGroup . substring ( 1 ) ) ) { account . getAuthorizations ( ) . addPermission ( "*" ) ; } else if ( acco...
Set the admin attribute from group memberships retrieved from LDAP .
5,871
public void setAllowOrigin ( String ... origin ) { allowOriginSet . clear ( ) ; allowOriginSet . addAll ( Arrays . asList ( origin ) ) ; allowOrigin = Joiner . on ( "," ) . join ( origin ) ; }
Set the list of request origins that are permitted to access the protected routes .
5,872
public void setAllowMethods ( String ... methods ) { allowMethodsSet . clear ( ) ; for ( String method : methods ) { allowMethodsSet . add ( method . toUpperCase ( ) ) ; } allowMethods = Joiner . on ( "," ) . join ( allowMethodsSet ) ; }
Set the list of request methods that may be sent by the browser for a CORS request .
5,873
public void setAllowHeaders ( String ... headers ) { allowHeadersSet . clear ( ) ; for ( String header : headers ) { allowHeadersSet . add ( header . toLowerCase ( ) ) ; } allowHeaders = Joiner . on ( "," ) . join ( headers ) ; }
Set the list of headers that may be sent by the browser for a CORS request .
5,874
protected Collection < Method > sortMethods ( Collection < Method > methods ) { List < Method > list = new ArrayList < > ( methods ) ; Collections . sort ( list , ( m1 , m2 ) -> { int o1 = Integer . MAX_VALUE ; Order order1 = ClassUtil . getAnnotation ( m1 , Order . class ) ; if ( order1 != null ) { o1 = order1 . value...
Sort the methods by their preferred order if specified .
5,875
@ SuppressWarnings ( "empty-statement" ) public static byte [ ] leftTrim ( final byte ... bytes ) { int pos = 0 ; for ( ; pos < bytes . length && bytes [ pos ] == 0x00 ; pos ++ ) ; if ( pos < bytes . length ) { return Arrays . copyOfRange ( bytes , pos , bytes . length ) ; } else { return new byte [ ] { 0x00 } ; } }
Remove 0x00 bytes from left side .
5,876
public static boolean [ ] getBits ( final byte ... bytes ) { if ( bytes . length > 4 ) { throw new InvalidParameterException ( "Invalid number of bytes" ) ; } final boolean [ ] res = new boolean [ bytes . length * 8 ] ; int pos = 0 ; for ( byte b : bytes ) { for ( boolean bool : getBits ( b ) ) { res [ pos ] = bool ; p...
Gets bits as boolean array from a given byte array .
5,877
public static boolean [ ] getBits ( final byte b ) { final boolean [ ] res = new boolean [ 8 ] ; for ( int i = 0 ; i < 8 ; i ++ ) { res [ 7 - i ] = ( b & ( 1 << i ) ) != 0 ; } return res ; }
Gets bits as boolean array from a given byte .
5,878
public static long getUInt ( final byte ... bytes ) { if ( bytes . length > 4 ) { throw new InvalidParameterException ( "Invalid number of bytes" ) ; } long res = 0 ; for ( int i = 0 ; i < bytes . length ; i ++ ) { res |= bytes [ i ] & 0xFF ; if ( i < bytes . length - 1 ) { res <<= 8 ; } } return res ; }
Gets unsigned integer value corresponding to the given bytes .
5,879
private Set < String > toSet ( String value , String delimiter ) { if ( Strings . isNullOrEmpty ( value ) ) { return Collections . emptySet ( ) ; } else { Set < String > stringSet = new LinkedHashSet < > ( ) ; String [ ] values = value . split ( delimiter ) ; for ( String stringValue : values ) { if ( ! Strings . isNul...
Creates an ordered set from a comma or semi - colon delimited string . Empty values are discarded .
5,880
int parse ( final IntBuffer buff , final int start ) { int pos = start ; byte [ ] bytes = NumberFacility . getBytes ( buff . get ( pos ) ) ; revision = AclRevision . parseValue ( bytes [ 0 ] ) ; pos ++ ; bytes = NumberFacility . getBytes ( buff . get ( pos ) ) ; final int aceCount = NumberFacility . getInt ( bytes [ 1 ...
Load the ACL from the buffer returning the last ACL segment position into the buffer .
5,881
public static boolean allowInstance ( Settings settings , Object object ) { Preconditions . checkNotNull ( object , "Can not check runtime permissions on a null instance!" ) ; if ( object instanceof Method ) { return allowMethod ( settings , ( Method ) object ) ; } return allowClass ( settings , object . getClass ( ) )...
Determines if this object may be used in the current runtime environment . Fathom settings are considered as well as runtime modes .
5,882
public static boolean allowClass ( Settings settings , Class < ? > aClass ) { if ( aClass . isAnnotationPresent ( RequireSettings . class ) ) { RequireSetting [ ] requireSettings = aClass . getAnnotation ( RequireSettings . class ) . value ( ) ; StringJoiner joiner = new StringJoiner ( ", " ) ; Arrays . asList ( requir...
Determines if this class may be used in the current runtime environment . Fathom settings are considered as well as runtime modes .
5,883
public static String getGuidAsString ( byte [ ] GUID ) { final StringBuilder res = new StringBuilder ( ) ; res . append ( AddLeadingZero ( ( int ) GUID [ 3 ] & 0xFF ) ) ; res . append ( AddLeadingZero ( ( int ) GUID [ 2 ] & 0xFF ) ) ; res . append ( AddLeadingZero ( ( int ) GUID [ 1 ] & 0xFF ) ) ; res . append ( AddLea...
Gets GUID as string .
5,884
public static byte [ ] getGuidAsByteArray ( final String GUID ) { final UUID uuid = UUID . fromString ( GUID ) ; final ByteBuffer buff = ByteBuffer . wrap ( new byte [ 16 ] ) ; buff . putLong ( uuid . getMostSignificantBits ( ) ) ; buff . putLong ( uuid . getLeastSignificantBits ( ) ) ; byte [ ] res = new byte [ ] { bu...
Gets GUID as byte array .
5,885
public Authorizations setRoles ( Set < Role > roles ) { this . roles . clear ( ) ; this . aggregatePermissions = null ; addRoles ( roles ) ; return this ; }
Sets the roles assigned to the Account .
5,886
public Authorizations addRoles ( String ... roles ) { for ( String role : roles ) { addRole ( new Role ( role ) ) ; } return this ; }
Adds roles to the Account Authorizations .
5,887
public Collection < Permission > getAggregatePermissions ( ) { if ( aggregatePermissions == null ) { Set < Permission > perms = new LinkedHashSet < > ( ) ; perms . addAll ( permissions ) ; for ( Role role : roles ) { perms . addAll ( role . getPermissions ( ) ) ; } if ( perms . isEmpty ( ) ) { aggregatePermissions = Co...
Gets the collection of permissions including the role permissions and discrete permissions .
5,888
protected Method findMethod ( Class < ? > controllerClass , String name ) { Method controllerMethod = null ; for ( Method method : controllerClass . getMethods ( ) ) { if ( method . getName ( ) . equals ( name ) ) { if ( controllerMethod == null ) { controllerMethod = method ; } else { throw new FatalException ( "Found...
Finds the named controller method .
5,889
protected Set < String > configureContentTypeSuffixes ( ContentTypeEngines engines ) { if ( null == ClassUtil . getAnnotation ( method , ContentTypeBySuffix . class ) ) { return Collections . emptySet ( ) ; } Set < String > suffixes = new TreeSet < > ( ) ; for ( String suffix : engines . getContentTypeSuffixes ( ) ) { ...
Configures the content - type suffixes
5,890
protected void configureMethodArgs ( Injector injector ) { Class < ? > [ ] types = method . getParameterTypes ( ) ; extractors = new ArgumentExtractor [ types . length ] ; patterns = new String [ types . length ] ; for ( int i = 0 ; i < types . length ; i ++ ) { final Parameter parameter = method . getParameters ( ) [ ...
Configures the controller method arguments .
5,891
public void validateMethodArgs ( String uriPattern ) { Set < String > namedParameters = new LinkedHashSet < > ( ) ; for ( ArgumentExtractor extractor : extractors ) { if ( extractor instanceof NamedExtractor ) { NamedExtractor namedExtractor = ( NamedExtractor ) extractor ; namedParameters . add ( namedExtractor . getN...
Validate that the parameters specified in the uri pattern are declared in the method signature .
5,892
protected void validateConsumes ( Collection < String > fathomContentTypes ) { Set < String > ignoreConsumes = new TreeSet < > ( ) ; ignoreConsumes . add ( Consumes . ALL ) ; ignoreConsumes . add ( Consumes . HTML ) ; ignoreConsumes . add ( Consumes . XHTML ) ; ignoreConsumes . add ( Consumes . FORM ) ; ignoreConsumes ...
Validates that the declared consumes can actually be processed by Fathom .
5,893
protected void validateProduces ( Collection < String > fathomContentTypes ) { Set < String > ignoreProduces = new TreeSet < > ( ) ; ignoreProduces . add ( Produces . TEXT ) ; ignoreProduces . add ( Produces . HTML ) ; ignoreProduces . add ( Produces . XHTML ) ; for ( String produces : declaredProduces ) { if ( ignoreP...
Validates that the declared content - types can actually be generated by Fathom .
5,894
protected void validateDeclaredReturns ( ) { boolean returnsObject = void . class != method . getReturnType ( ) ; if ( returnsObject ) { for ( Return declaredReturn : declaredReturns ) { if ( declaredReturn . code ( ) >= 200 && declaredReturn . code ( ) < 300 ) { return ; } } throw new FatalException ( "{} returns an o...
Validates the declared Returns of the controller method . If the controller method returns an object then it must also declare a successful
5,895
public static String getVersion ( ) { String FATHOM_PROPERTIES = "fathom/version.properties" ; String version = null ; URL url = ClassUtil . getResource ( FATHOM_PROPERTIES ) ; Preconditions . checkNotNull ( url , "Failed to find " + FATHOM_PROPERTIES ) ; try ( InputStream stream = url . openStream ( ) ) { Properties p...
Returns the running Fathom version .
5,896
public void clearCache ( ) { if ( accountCache != null ) { accountCache . invalidateAll ( ) ; } for ( Realm realm : allRealms ) { if ( realm instanceof CachingRealm ) { CachingRealm cachingRealm = ( CachingRealm ) realm ; cachingRealm . clearCache ( ) ; } } }
Clears the SecurityManager account cache and any CachingRealm s cache . MemoryRealms are not affected by this call .
5,897
protected Collection < Realm > parseDefinedRealms ( Config config ) { List < Realm > realms = new ArrayList < > ( ) ; if ( config . hasPath ( "realms" ) ) { log . trace ( "Parsing Realm definitions" ) ; for ( Config realmConfig : config . getConfigList ( "realms" ) ) { String realmType = Strings . emptyToNull ( realmCo...
Parse the Realms from the Config object .
5,898
public String generateJSON ( Collection < Route > routes ) { Swagger swagger = build ( routes ) ; String json = Json . pretty ( swagger ) ; return json ; }
Generates a Swagger 2 . 0 JSON specification from the collection of routes .
5,899
protected boolean canRegister ( Route route , ControllerHandler handler ) { if ( ! METHODS . contains ( route . getRequestMethod ( ) . toUpperCase ( ) ) ) { log . debug ( "Skip {} {}, {} Swagger does not support specified HTTP method" , route . getRequestMethod ( ) , route . getUriPattern ( ) , Util . toString ( handle...
Determines if this controller handler can be registered in the Swagger specification .