idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
41,000
public static AirlineCheckinTemplateBuilder addAirlineCheckinTemplate ( String introMessage , String locale , String pnrNumber , String checkinUrl ) { return new AirlineCheckinTemplateBuilder ( introMessage , locale , pnrNumber , checkinUrl ) ; }
Adds an Airline Checkin Template to the response .
41,001
public static AirlineFlightUpdateTemplateBuilder addAirlineFlightUpdateTemplate ( String introMessage , String locale , String pnrNumber , UpdateType updateType ) { return new AirlineFlightUpdateTemplateBuilder ( introMessage , locale , pnrNumber , updateType ) ; }
Adds an Airline Flight Update Template to the response .
41,002
public static byte [ ] i2cConfigRequest ( int delayInMicroseconds ) { if ( delayInMicroseconds < 0 ) { throw new IllegalArgumentException ( "Delay cannot be less than 0 microseconds." ) ; } if ( delayInMicroseconds > 255 ) { throw new IllegalArgumentException ( "Delay cannot be greater than 255 microseconds." ) ; } byte delayLsb = ( byte ) ( delayInMicroseconds & 0x7F ) ; byte delayMsb = 0 ; if ( delayInMicroseconds > 128 ) { delayMsb = 1 ; } return new byte [ ] { START_SYSEX , I2C_CONFIG , delayLsb , delayMsb , END_SYSEX } ; }
Creates SysEx message that configures I2C setup .
41,003
public static byte [ ] analogReport ( boolean enable ) { byte [ ] result = new byte [ 32 ] ; byte flag = ( byte ) ( enable ? 1 : 0 ) ; for ( byte i = 0 , j = 0 ; i < 16 ; i ++ ) { result [ j ++ ] = ( byte ) ( REPORT_ANALOG | i ) ; result [ j ++ ] = flag ; } return result ; }
Builds message to enable or disable reporting from Firmata device on change of analog input .
41,004
public static byte [ ] digitalReport ( boolean enable ) { byte [ ] result = new byte [ 32 ] ; byte flag = ( byte ) ( enable ? 1 : 0 ) ; for ( byte i = 0 , j = 0 ; i < 16 ; i ++ ) { result [ j ++ ] = ( byte ) ( REPORT_DIGITAL | i ) ; result [ j ++ ] = flag ; } return result ; }
Builds message to enable or disable reporting from Firmata device on change of digital input .
41,005
public static byte [ ] setMode ( byte pinId , Pin . Mode mode ) { if ( mode == Pin . Mode . UNSUPPORTED ) { throw new IllegalArgumentException ( "Cannot set unsupported mode to pin " + pinId ) ; } return new byte [ ] { SET_PIN_MODE , pinId , ( byte ) mode . ordinal ( ) } ; }
Creates the message that assigns particular mode to specified pin .
41,006
public static byte [ ] stringMessage ( String message ) { byte [ ] bytes = message . getBytes ( ) ; byte [ ] result = new byte [ bytes . length * 2 + 3 ] ; result [ 0 ] = START_SYSEX ; result [ 1 ] = STRING_DATA ; result [ result . length - 1 ] = END_SYSEX ; for ( int i = 0 ; i < bytes . length ; i ++ ) { byte b = bytes [ i ] ; result [ i * 2 + 2 ] = ( byte ) ( b & 0x7F ) ; result [ i * 2 + 3 ] = ( byte ) ( ( b >> 7 ) & 0x7F ) ; } return result ; }
Encodes the string as a SysEx message .
41,007
public static byte [ ] setDisplayClock ( byte divideRatio , byte oscillatorFrequency ) { if ( divideRatio < 0 || oscillatorFrequency < 0 ) { throw new IllegalArgumentException ( "Divide ratio and oscillator frequency must be non-negative." ) ; } byte param = ( byte ) ( ( oscillatorFrequency << 4 ) & divideRatio ) ; return new byte [ ] { COMMAND_CONTROL_BYTE , SET_DISPLAY_CLOCK , COMMAND_CONTROL_BYTE , param } ; }
timing configuration commands
41,008
protected void bufferize ( byte b ) { if ( index == buffer . length ) { byte [ ] newBuffer = new byte [ buffer . length * 2 ] ; System . arraycopy ( buffer , 0 , newBuffer , 0 , index ) ; buffer = newBuffer ; } buffer [ index ++ ] = b ; }
Stores the byte to the internal buffer in order to get a chunk of data latter .
41,009
private void shutdown ( ) throws IOException { ready . set ( false ) ; sendMessage ( FirmataMessageFactory . analogReport ( false ) ) ; sendMessage ( FirmataMessageFactory . digitalReport ( false ) ) ; parser . stop ( ) ; transport . stop ( ) ; }
Tries to release all resources and properly terminate the connection to the hardware .
41,010
public void init ( ) { turnOff ( ) ; command ( setDisplayClock ( ( byte ) 0 , ( byte ) 8 ) ) ; command ( setMultiplexRatio ( size . height ) ) ; command ( setDisplayOffset ( 0 ) ) ; command ( setDisplayStartLine ( 0 ) ) ; command ( setMemoryAddressingMode ( MemoryAddressingMode . HORIZONTAL ) ) ; command ( setHorizontalFlip ( false ) ) ; command ( setVerticalFlip ( false ) ) ; if ( vccState == VCC . EXTERNAL ) { command ( setChargePump ( false ) ) ; } else { command ( setChargePump ( true ) ) ; } int contrast = 0 ; boolean sequentialPins = true ; boolean leftRightPinsRemap = false ; if ( size == Size . SSD1306_128_32 ) { contrast = 0x8F ; } else if ( size == Size . SSD1306_128_64 ) { if ( vccState == VCC . EXTERNAL ) { contrast = 0x9F ; } else { contrast = 0xCF ; } sequentialPins = false ; } else if ( size == Size . SSD1306_96_16 ) { if ( vccState == VCC . EXTERNAL ) { contrast = 0x10 ; } else { contrast = 0xAF ; } } command ( setCOMPinsConfig ( sequentialPins , leftRightPinsRemap ) ) ; command ( setContrast ( ( byte ) contrast ) ) ; if ( vccState == VCC . EXTERNAL ) { command ( setPrechargePeriod ( ( byte ) 2 , ( byte ) 2 ) ) ; } else { command ( setPrechargePeriod ( ( byte ) 1 , ( byte ) 15 ) ) ; } command ( setVcomhDeselectLevel ( ( byte ) 3 ) ) ; command ( DISPLAY_RESUME ) ; command ( setDisplayInverse ( false ) ) ; stopScrolling ( ) ; display ( ) ; turnOn ( ) ; }
Prepares the device to operation .
41,011
public void dim ( boolean dim ) { byte contrast ; if ( dim ) { contrast = 0 ; } else { if ( vccState == VCC . EXTERNAL ) { contrast = ( byte ) 0x9F ; } else { contrast = ( byte ) 0xCF ; } } command ( setContrast ( contrast ) ) ; }
Dims the display
41,012
public void process ( byte b ) { if ( b == END_SYSEX ) { byte [ ] buffer = convertI2CBuffer ( getBuffer ( ) ) ; byte address = buffer [ 0 ] ; byte register = buffer [ 1 ] ; byte [ ] message = new byte [ buffer . length - 2 ] ; System . arraycopy ( buffer , 2 , message , 0 , buffer . length - 2 ) ; Event event = new Event ( I2C_MESSAGE ) ; event . setBodyItem ( I2C_ADDRESS , address ) ; event . setBodyItem ( I2C_REGISTER , register ) ; event . setBodyItem ( I2C_MESSAGE , message ) ; transitTo ( WaitingForMessageState . class ) ; publish ( event ) ; } else { bufferize ( b ) ; } }
Collects I2C message from individual bytes .
41,013
public void drawRect ( int x , int y , int w , int h , Color color ) { drawHorizontalLine ( x , y , w , color ) ; drawHorizontalLine ( x , y + h - 1 , w , color ) ; drawVerticalLine ( x , y , h , color ) ; drawVerticalLine ( x + w - 1 , y , h , color ) ; }
Draw a rectangle
41,014
public void drawBitmap ( int x , int y , byte [ ] [ ] bitmap , boolean opaque ) { int h = bitmap . length ; if ( h == 0 ) { return ; } int w = bitmap [ 0 ] . length ; if ( w == 0 ) { return ; } for ( int i = 0 ; i < h ; i ++ ) { if ( y + i >= 0 && y + i < height ) { for ( int j = 0 ; j < w ; j ++ ) { if ( x + j * 8 >= 0 && x + j * 8 < width ) { byte b = bitmap [ i ] [ j ] ; for ( int shift = 7 ; shift >= 0 ; shift -- ) { int mask = 1 << shift ; if ( ( b & mask ) != 0 ) { setPixel ( x + j * 8 + ( 7 - shift ) , y + i , color ) ; } else if ( opaque ) { setPixel ( x + j * 8 + ( 7 - shift ) , y + i , bgcolor ) ; } } } } } } }
Draws a bitmap . Each byte of data contains values for 8 consecutive pixels in a row .
41,015
public void drawImage ( int x , int y , BufferedImage image , boolean opaque , boolean invert ) { drawBitmap ( x , y , convertToBitmap ( image , invert ) , opaque ) ; }
Draws an image . The image is grayscalled before drawing .
41,016
public final void bsf ( Register dst , Register src ) { assert ( ! dst . isRegType ( REG_GPB ) ) ; emitX86 ( INST_BSF , dst , src ) ; }
Bit Scan Forward .
41,017
public final void bsr ( Register dst , Mem src ) { assert ( ! dst . isRegType ( REG_GPB ) ) ; emitX86 ( INST_BSR , dst , src ) ; }
Bit Scan Reverse .
41,018
public final void call ( Register dst ) { assert ( dst . isRegType ( is64 ( ) ? REG_GPQ : REG_GPD ) ) ; emitX86 ( INST_CALL , dst ) ; }
Call Procedure .
41,019
public final void cmov ( CONDITION cc , Register dst , Register src ) { emitX86 ( conditionToCMovCC ( cc ) , dst , src ) ; }
Conditional Move .
41,020
public final void mov_ptr ( Register dst , long src ) { assert dst . index ( ) == 0 ; emitX86 ( INST_MOV_PTR , dst , Immediate . imm ( src ) ) ; }
Move byte word dword or qword from absolute address
41,021
public final void pop ( Register dst ) { assert ( dst . isRegType ( REG_GPW ) || dst . isRegType ( is64 ( ) ? REG_GPQ : REG_GPD ) ) ; emitX86 ( INST_POP , dst ) ; }
! or segment register .
41,022
public final void shld ( Mem dst , Register src1 , Immediate src2 ) { emitX86 ( INST_SHLD , dst , src1 , src2 ) ; }
Double Precision Shift Left .
41,023
public final void fild ( Mem src ) { assert ( src . size ( ) == 2 || src . size ( ) == 4 || src . size ( ) == 8 ) ; emitX86 ( INST_FILD , src ) ; }
! preserved .
41,024
public final void fstp ( Mem dst ) { assert ( dst . size ( ) == 4 || dst . size ( ) == 8 || dst . size ( ) == 10 ) ; emitX86 ( INST_FSTP , dst ) ; }
! and pop register stack .
41,025
public final void extractps ( XMMRegister dst , XMMRegister src , Immediate imm8 ) { emitX86 ( INST_EXTRACTPS , dst , src , imm8 ) ; }
Extract Packed SP - FP Value
41,026
public final void roundps ( XMMRegister dst , XMMRegister src , Immediate imm8 ) { emitX86 ( INST_ROUNDPS , dst , src , imm8 ) ; }
! Round Packed SP - FP Values
41,027
static void writeTrampoline ( ByteBuffer buf , long target ) { buf . put ( ( byte ) 0xFF ) ; buf . put ( ( byte ) 0x25 ) ; buf . putInt ( 0 ) ; buf . putLong ( target ) ; }
Write trampoline into code at address
41,028
private static void mergeWildcardTypes ( final List < Type > types , final Type ... addition ) { if ( types . isEmpty ( ) ) { Collections . addAll ( types , addition ) ; return ; } for ( Type add : addition ) { final Class < ? > addClass = GenericsUtils . resolveClass ( add ) ; final Iterator < Type > it = types . iterator ( ) ; boolean additionApproved = true ; while ( it . hasNext ( ) ) { final Type type = it . next ( ) ; final Class < ? > typeClass = GenericsUtils . resolveClass ( type ) ; if ( addClass . isAssignableFrom ( typeClass ) ) { if ( TypeUtils . isMoreSpecific ( add , type ) ) { it . remove ( ) ; } else { additionApproved = false ; } break ; } } if ( additionApproved ) { types . add ( add ) ; } } }
Adds new types to wildcard if types are not already contained . If added type is more specific then already contained type then it replace such type .
41,029
private static void removeDuplicateContracts ( final Class < ? > type , final Set < Class < ? > > contracts ) { if ( contracts . isEmpty ( ) ) { return ; } Iterator < Class < ? > > it = contracts . iterator ( ) ; while ( it . hasNext ( ) ) { if ( it . next ( ) . isAssignableFrom ( type ) ) { it . remove ( ) ; } } it = contracts . iterator ( ) ; while ( it . hasNext ( ) ) { final Class < ? > current = it . next ( ) ; for ( Class < ? > iface : contracts ) { if ( ! current . equals ( iface ) && current . isAssignableFrom ( iface ) ) { it . remove ( ) ; break ; } } } }
After common types resolution we have some base class and set of common interfaces . These interfaces may contain duplicates or be already covered by base class .
41,030
public static Map < Class < ? > , LinkedHashMap < String , Type > > resolve ( final Class < ? > type , final LinkedHashMap < String , Type > rootGenerics , final Class < ? > ... ignoreClasses ) { return resolve ( type , rootGenerics , Collections . < Class < ? > , LinkedHashMap < String , Type > > emptyMap ( ) , Arrays . asList ( ignoreClasses ) ) ; }
Analyze class hierarchy and resolve actual generic values for all composing types . Root type generics are known .
41,031
@ SuppressWarnings ( "PMD.LooseCoupling" ) public static LinkedHashMap < String , Type > createGenericsMap ( final Class < ? > type , final List < ? extends Type > generics ) { final TypeVariable < ? extends Class < ? > > [ ] params = type . getTypeParameters ( ) ; if ( params . length != generics . size ( ) ) { throw new IllegalArgumentException ( String . format ( "Can't build generics map for %s with %s because of incorrect generics count" , type . getSimpleName ( ) , Arrays . toString ( generics . toArray ( ) ) ) ) ; } final LinkedHashMap < String , Type > res = new LinkedHashMap < String , Type > ( ) ; int i = 0 ; for ( TypeVariable var : params ) { res . put ( var . getName ( ) , generics . get ( i ++ ) ) ; } return GenericsResolutionUtils . fillOuterGenerics ( type , res , null ) ; }
LinkedHashMap indicates stored order important for context
41,032
private static Type resolveGenericArrayTypeVariables ( final GenericArrayType type , final Map < String , Type > generics , final boolean countPreservedVariables ) { final Type componentType = resolveTypeVariables ( type . getGenericComponentType ( ) , generics , countPreservedVariables ) ; return ArrayTypeUtils . toArrayType ( componentType ) ; }
May produce array class instead of generic array type . This is possible due to wildcard or parameterized type shrinking .
41,033
public static Type getMoreSpecificType ( final Type one , final Type two ) { return isMoreSpecific ( one , two ) ? one : two ; }
Not resolved type variables are resolved to Object .
41,034
public static void walk ( final Type one , final Type two , final TypesVisitor visitor ) { final Map < String , Type > oneKnownGenerics = new IgnoreGenericsMap ( GenericsResolutionUtils . resolveGenerics ( one , IGNORE_VARS ) ) ; final Map < String , Type > twoKnownGenerics = new IgnoreGenericsMap ( GenericsResolutionUtils . resolveGenerics ( two , IGNORE_VARS ) ) ; doWalk ( GenericsUtils . resolveTypeVariables ( one , oneKnownGenerics ) , oneKnownGenerics , GenericsUtils . resolveTypeVariables ( two , twoKnownGenerics ) , twoKnownGenerics , visitor ) ; }
Walk will stop if visitor tells it s enough or when hierarchy incompatibility will be found .
41,035
private static boolean isLowerBoundCompatible ( final WildcardType type , final Class ... with ) { boolean res = true ; if ( type . getLowerBounds ( ) . length > 0 ) { final Class < ? > lower = GenericsUtils . resolveClassIgnoringVariables ( type . getLowerBounds ( ) [ 0 ] ) ; for ( Class < ? > target : with ) { if ( ! target . isAssignableFrom ( lower ) ) { res = false ; break ; } } } return res ; }
Check that wildcard s lower bound type is not less then any of provided types .
41,036
public UnknownGenericException rethrowWithType ( final Class < ? > type ) { final boolean sameType = contextType != null && contextType . equals ( type ) ; if ( ! sameType && contextType != null ) { throw new IllegalStateException ( "Context type can't be changed" ) ; } return sameType ? this : new UnknownGenericException ( type , genericName , genericSource , this ) ; }
Throw more specific exception .
41,037
private Schema getSchema ( Resolver pResolver , ValidationSet pValidationSet ) throws MojoExecutionException { String schemaLanguage = pValidationSet . getSchemaLanguage ( ) ; if ( schemaLanguage == null || "" . equals ( schemaLanguage ) ) { schemaLanguage = XMLConstants . W3C_XML_SCHEMA_NS_URI ; } final String publicId = pValidationSet . getPublicId ( ) ; final String systemId = pValidationSet . getSystemId ( ) ; if ( ( publicId == null || "" . equals ( publicId ) ) && ( systemId == null || "" . equals ( systemId ) ) && ! INTRINSIC_NS_URI . equals ( schemaLanguage ) ) { return null ; } final SAXSource saxSource ; if ( INTRINSIC_NS_URI . equals ( schemaLanguage ) && ( publicId == null || "" . equals ( publicId ) ) && ( systemId == null || "" . equals ( systemId ) ) ) { saxSource = null ; } else { getLog ( ) . debug ( "Loading schema with public Id " + publicId + ", system Id " + systemId ) ; InputSource inputSource = null ; if ( pResolver != null ) { try { inputSource = pResolver . resolveEntity ( publicId , systemId ) ; } catch ( SAXException e ) { throw new MojoExecutionException ( e . getMessage ( ) , e ) ; } catch ( IOException e ) { throw new MojoExecutionException ( e . getMessage ( ) , e ) ; } } if ( inputSource == null ) { inputSource = new InputSource ( ) ; inputSource . setPublicId ( pResolver . filterPossibleURI ( publicId ) ) ; inputSource . setSystemId ( pResolver . filterPossibleURI ( systemId ) ) ; } saxSource = new SAXSource ( inputSource ) ; } try { SchemaFactory schemaFactory = SchemaFactory . newInstance ( schemaLanguage ) ; if ( pResolver != null ) { schemaFactory . setResourceResolver ( pResolver ) ; } return saxSource == null ? schemaFactory . newSchema ( ) : schemaFactory . newSchema ( saxSource ) ; } catch ( SAXException e ) { throw new MojoExecutionException ( "Failed to load schema with public ID " + publicId + ", system ID " + systemId + ": " + e . getMessage ( ) , e ) ; } }
Reads a validation sets schema .
41,038
private void validate ( final Resolver pResolver , ValidationSet pValidationSet , Schema pSchema , File pFile , ValidationErrorHandler errorHandler ) throws MojoExecutionException { errorHandler . setContext ( pFile ) ; try { if ( pSchema == null ) { getLog ( ) . debug ( "Parsing " + pFile . getPath ( ) ) ; parse ( pResolver , pValidationSet , pFile , errorHandler ) ; } else { getLog ( ) . debug ( "Validating " + pFile . getPath ( ) ) ; Validator validator = pSchema . newValidator ( ) ; validator . setErrorHandler ( errorHandler ) ; if ( pResolver != null ) { validator . setResourceResolver ( pResolver ) ; } if ( pValidationSet . isXincludeAware ( ) ) { SAXParserFactory spf = SAXParserFactory . newInstance ( ) ; spf . setNamespaceAware ( true ) ; spf . setXIncludeAware ( pValidationSet . isXincludeAware ( ) ) ; InputSource isource = new InputSource ( pFile . toURI ( ) . toASCIIString ( ) ) ; XMLReader xmlReader = spf . newSAXParser ( ) . getXMLReader ( ) ; xmlReader . setEntityResolver ( pResolver ) ; validator . validate ( new SAXSource ( xmlReader , isource ) ) ; } else { validator . validate ( new StreamSource ( pFile ) ) ; } } } catch ( SAXParseException e ) { try { errorHandler . fatalError ( e ) ; } catch ( SAXException se ) { throw new MojoExecutionException ( "While parsing " + pFile + ": " + e . getMessage ( ) , se ) ; } } catch ( Exception e ) { throw new MojoExecutionException ( "While parsing " + pFile + ": " + e . getMessage ( ) , e ) ; } }
Called for parsing or validating a single file .
41,039
private void parse ( Resolver pResolver , ValidationSet pValidationSet , File pFile , ErrorHandler errorHandler ) throws IOException , SAXException , ParserConfigurationException { XMLReader xr = newSAXParserFactory ( pValidationSet ) . newSAXParser ( ) . getXMLReader ( ) ; if ( pResolver != null ) { xr . setEntityResolver ( pResolver ) ; } xr . setErrorHandler ( errorHandler ) ; xr . parse ( pFile . toURI ( ) . toURL ( ) . toExternalForm ( ) ) ; }
Called for validating a single file .
41,040
private void validate ( Resolver pResolver , ValidationSet pValidationSet , ValidationErrorHandler errorHandler ) throws MojoExecutionException , MojoFailureException { final Schema schema = getSchema ( pResolver , pValidationSet ) ; final File [ ] files = getFiles ( pValidationSet . getDir ( ) , pValidationSet . getIncludes ( ) , getExcludes ( pValidationSet . getExcludes ( ) , pValidationSet . isSkipDefaultExcludes ( ) ) ) ; if ( files . length == 0 ) { getLog ( ) . info ( "No matching files found for ValidationSet with public ID " + pValidationSet . getPublicId ( ) + ", system ID " + pValidationSet . getSystemId ( ) + "." ) ; } for ( int i = 0 ; i < files . length ; i ++ ) { validate ( pResolver , pValidationSet , schema , files [ i ] , errorHandler ) ; } }
Called for validating a set of XML files against a common schema .
41,041
public static TransformerFactory newTransformerFactory ( String factoryClassName , ClassLoader classLoader ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { Class < ? > [ ] methodTypes = new Class [ ] { String . class , ClassLoader . class } ; Method method = TransformerFactory . class . getDeclaredMethod ( "newInstance" , methodTypes ) ; Object [ ] methodArgs = new Object [ ] { factoryClassName , classLoader } ; return ( TransformerFactory ) method . invoke ( null , methodArgs ) ; }
public for use by unit test
41,042
public void execute ( ) throws MojoExecutionException , MojoFailureException { if ( isSkipping ( ) ) { getLog ( ) . debug ( "Skipping execution, as demanded by user." ) ; return ; } if ( transformationSets == null || transformationSets . length == 0 ) { throw new MojoFailureException ( "No TransformationSets configured." ) ; } checkCatalogHandling ( ) ; Object oldProxySettings = activateProxy ( ) ; try { Resolver resolver = getResolver ( ) ; for ( int i = 0 ; i < transformationSets . length ; i ++ ) { TransformationSet transformationSet = transformationSets [ i ] ; resolver . setXincludeAware ( transformationSet . isXincludeAware ( ) ) ; resolver . setValidating ( transformationSet . isValidating ( ) ) ; transform ( resolver , transformationSet ) ; } } finally { passivateProxy ( oldProxySettings ) ; } }
Called by Maven to run the plugin .
41,043
public void characters ( char [ ] ch , int start , int length ) throws SAXException { charBuffer . append ( ch , start , length ) ; charLineNumber = locator . getLineNumber ( ) ; }
Stores the passed characters into a character buffer .
41,044
public void endElement ( String uri , String localName , String qName ) throws SAXException { flushCharacters ( ) ; if ( stack . isEmpty ( ) ) { throw new IllegalStateException ( "Stack must not be empty when closing the element " + qName + " around line " + locator . getLineNumber ( ) + " and column " + locator . getColumnNumber ( ) ) ; } IndentCheckSaxHandler . ElementEntry startEntry = stack . pop ( ) ; int indentDiff = lastIndent . size - startEntry . expectedIndent . size ; int expectedIndent = startEntry . expectedIndent . size ; if ( lastIndent . lineNumber != startEntry . foundIndent . lineNumber && indentDiff != 0 ) { int opValue = expectedIndent - lastIndent . size ; String op = opValue > 0 ? "Insert" : "Delete" ; String units = opValue == 1 ? "space" : "spaces" ; String message = op + " " + Math . abs ( opValue ) + " " + units + ". Expected " + expectedIndent + " found " + lastIndent . size + " spaces before end element </" + qName + ">" ; XmlFormatViolation violation = new XmlFormatViolation ( file , locator . getLineNumber ( ) , locator . getColumnNumber ( ) , message ) ; violationHandler . handle ( violation ) ; } }
Checks indentation for an end element .
41,045
public void startElement ( String uri , String localName , String qName , Attributes attributes ) throws SAXException { flushCharacters ( ) ; IndentCheckSaxHandler . ElementEntry currentEntry = new ElementEntry ( qName , lastIndent ) ; if ( ! stack . isEmpty ( ) ) { IndentCheckSaxHandler . ElementEntry parentEntry = stack . peek ( ) ; int indentDiff = currentEntry . foundIndent . size - parentEntry . expectedIndent . size ; int expectedIndent = parentEntry . expectedIndent . size + indentSize ; if ( indentDiff == 0 && currentEntry . foundIndent . lineNumber == parentEntry . foundIndent . lineNumber ) { } else if ( indentDiff != indentSize ) { int opValue = expectedIndent - currentEntry . foundIndent . size ; String op = opValue > 0 ? "Insert" : "Delete" ; String message = op + " " + Math . abs ( opValue ) + " spaces. Expected " + expectedIndent + " found " + currentEntry . foundIndent . size + " spaces before start element <" + currentEntry . elementName + ">" ; XmlFormatViolation violation = new XmlFormatViolation ( file , locator . getLineNumber ( ) , locator . getColumnNumber ( ) , message ) ; violationHandler . handle ( violation ) ; currentEntry = new ElementEntry ( qName , lastIndent , new Indent ( lastIndent . lineNumber , expectedIndent ) ) ; } } stack . push ( currentEntry ) ; }
Checks indentation for a start element .
41,046
protected File asAbsoluteFile ( File f ) { if ( f . isAbsolute ( ) ) { return f ; } return new File ( getBasedir ( ) , f . getPath ( ) ) ; }
Converts the given file into an file with an absolute path .
41,047
protected void setCatalogs ( List < File > pCatalogFiles , List < URL > pCatalogUrls ) throws MojoExecutionException { if ( catalogs == null || catalogs . length == 0 ) { return ; } for ( int i = 0 ; i < catalogs . length ; i ++ ) { try { URL url = new URL ( catalogs [ i ] ) ; pCatalogUrls . add ( url ) ; } catch ( MalformedURLException e ) { File absoluteCatalog = asAbsoluteFile ( new File ( catalogs [ i ] ) ) ; if ( ! absoluteCatalog . exists ( ) || ! absoluteCatalog . isFile ( ) ) { throw new MojoExecutionException ( "That catalog does not exist:" + absoluteCatalog . getPath ( ) , e ) ; } pCatalogFiles . add ( absoluteCatalog ) ; } } }
Returns the plugins catalog files .
41,048
protected Resolver getResolver ( ) throws MojoExecutionException { List < File > catalogFiles = new ArrayList < File > ( ) ; List < URL > catalogUrls = new ArrayList < URL > ( ) ; setCatalogs ( catalogFiles , catalogUrls ) ; return new Resolver ( getBasedir ( ) , catalogFiles , catalogUrls , getLocator ( ) , catalogHandling , getLog ( ) . isDebugEnabled ( ) ) ; }
Creates a new resolver .
41,049
protected String [ ] getFileNames ( File pDir , String [ ] pIncludes , String [ ] pExcludes ) throws MojoFailureException , MojoExecutionException { if ( pDir == null ) { throw new MojoFailureException ( "A ValidationSet or TransformationSet" + " requires a nonempty 'dir' child element." ) ; } final File dir = asAbsoluteFile ( pDir ) ; if ( ! dir . isDirectory ( ) ) { throw new MojoExecutionException ( "The directory " + dir . getPath ( ) + ", which is a base directory of a ValidationSet or TransformationSet, does not exist." ) ; } final DirectoryScanner ds = new DirectoryScanner ( ) ; ds . setBasedir ( dir ) ; if ( pIncludes != null && pIncludes . length > 0 ) { ds . setIncludes ( pIncludes ) ; } if ( pExcludes != null && pExcludes . length > 0 ) { ds . setExcludes ( pExcludes ) ; } ds . scan ( ) ; return ds . getIncludedFiles ( ) ; }
Scans a directory for files and returns a set of path names .
41,050
protected String [ ] getExcludes ( String [ ] origExcludes , boolean skipDefaultExcludes ) { if ( skipDefaultExcludes ) { return origExcludes ; } String [ ] defaultExcludes = FileUtils . getDefaultExcludes ( ) ; if ( origExcludes == null || origExcludes . length == 0 ) { return defaultExcludes ; } String [ ] result = new String [ origExcludes . length + defaultExcludes . length ] ; System . arraycopy ( origExcludes , 0 , result , 0 , origExcludes . length ) ; System . arraycopy ( defaultExcludes , 0 , result , origExcludes . length , defaultExcludes . length ) ; return result ; }
Calculates the exclusions to use when searching files .
41,051
protected Object activateProxy ( ) { if ( settings == null ) { return null ; } final Proxy proxy = settings . getActiveProxy ( ) ; if ( proxy == null ) { return null ; } final List < String > properties = new ArrayList < String > ( ) ; final String protocol = proxy . getProtocol ( ) ; final String prefix = isEmpty ( protocol ) ? "" : ( protocol + "." ) ; final String host = proxy . getHost ( ) ; final String hostProperty = prefix + "proxyHost" ; final String hostValue = isEmpty ( host ) ? null : host ; setProperty ( properties , hostProperty , hostValue ) ; final int port = proxy . getPort ( ) ; final String portProperty = prefix + "proxyPort" ; final String portValue = ( port == 0 || port == - 1 ) ? null : String . valueOf ( port ) ; setProperty ( properties , portProperty , portValue ) ; final String username = proxy . getUsername ( ) ; final String userProperty = prefix + "proxyUser" ; final String userValue = isEmpty ( username ) ? null : username ; setProperty ( properties , userProperty , userValue ) ; final String password = proxy . getPassword ( ) ; final String passwordProperty = prefix + "proxyPassword" ; final String passwordValue = isEmpty ( password ) ? null : password ; setProperty ( properties , passwordProperty , passwordValue ) ; final String nonProxyHosts = proxy . getNonProxyHosts ( ) ; final String nonProxyHostsProperty = prefix + "nonProxyHosts" ; final String nonProxyHostsValue = isEmpty ( nonProxyHosts ) ? null : nonProxyHosts . replace ( ',' , '|' ) ; setProperty ( properties , nonProxyHostsProperty , nonProxyHostsValue ) ; getLog ( ) . debug ( "Proxy settings: " + hostProperty + "=" + hostValue + ", " + portProperty + "=" + portValue + ", " + userProperty + "=" + userValue + ", " + passwordProperty + "=" + ( passwordValue == null ? "null" : "<PasswordNotLogged>" ) + ", " + nonProxyHostsProperty + "=" + nonProxyHostsValue ) ; return properties ; }
Called to install the plugins proxy settings .
41,052
protected void passivateProxy ( Object pProperties ) { if ( pProperties == null ) { return ; } @ SuppressWarnings ( "unchecked" ) final List < String > properties = ( List < String > ) pProperties ; for ( Iterator < String > iter = properties . iterator ( ) ; iter . hasNext ( ) ; ) { final String key = iter . next ( ) ; final String value = iter . next ( ) ; setProperty ( null , key , value ) ; } }
Called to restore the proxy settings which have been installed when the plugin was invoked .
41,053
private void addQueryParameters ( HttpRequestBase request , Map < String , String > params ) { if ( params != null ) { URIBuilder builder = new URIBuilder ( request . getURI ( ) ) ; for ( Map . Entry < String , String > param : params . entrySet ( ) ) { builder . addParameter ( param . getKey ( ) , param . getValue ( ) ) ; } try { request . setURI ( builder . build ( ) ) ; } catch ( URISyntaxException e ) { throw new RuntimeException ( "Unable to construct API URI" , e ) ; } } }
Modifies request in place to add on any query parameters
41,054
private static AlgorithmException wrapException ( Throwable throwable ) { if ( throwable == null ) { return null ; } else if ( throwable instanceof AlgorithmException ) { return ( AlgorithmException ) throwable ; } else { return new AlgorithmException ( throwable . getMessage ( ) , wrapException ( throwable . getCause ( ) ) , wrapStackTrace ( throwable ) ) ; } }
Constructs a new algorithm exception from an existing throwable . This replaces all Exceptions in the cause hierarchy to be replaced with AlgorithmException for inter - jvm communication safety .
41,055
public DataFile putFile ( File file ) throws APIException , FileNotFoundException { DataFile dataFile = new DataFile ( client , trimmedPath + "/" + file . getName ( ) ) ; dataFile . put ( file ) ; return dataFile ; }
Convenience wrapper for putting a File
41,056
public void create ( ) throws APIException { CreateDirectoryRequest reqObj = new CreateDirectoryRequest ( this . getName ( ) , null ) ; Gson gson = new Gson ( ) ; JsonElement inputJson = gson . toJsonTree ( reqObj ) ; String url = this . getParent ( ) . getUrl ( ) ; HttpResponse response = this . client . post ( url , new StringEntity ( inputJson . toString ( ) , ContentType . APPLICATION_JSON ) ) ; HttpClientHelpers . throwIfNotOk ( response ) ; }
Creates this directory via the Algorithmia Data API
41,057
public void delete ( boolean forceDelete ) throws APIException { HttpResponse response = client . delete ( getUrl ( ) + "?force=" + forceDelete ) ; HttpClientHelpers . throwIfNotOk ( response ) ; }
Creates this directory vi the Algorithmia Data API
41,058
protected DirectoryListResponse getPage ( String marker , Boolean getAcl ) throws APIException { String url = getUrl ( ) ; Map < String , String > params = new HashMap < String , String > ( ) ; if ( marker != null ) { params . put ( "marker" , marker ) ; } if ( getAcl ) { params . put ( "acl" , getAcl . toString ( ) ) ; } return client . get ( url , new TypeToken < DirectoryListResponse > ( ) { } , params ) ; }
Gets a single page of the directory listing . Subsquent pages are fetched with the returned marker value .
41,059
private static String getTrimmedPath ( String path ) { String result = path ; if ( result . endsWith ( "/" ) ) { result = result . substring ( 0 , result . length ( ) - 1 ) ; } return result ; }
a slash and those that don t .
41,060
public boolean exists ( ) throws APIException { HttpResponse response = client . head ( getUrl ( ) ) ; int status = response . getStatusLine ( ) . getStatusCode ( ) ; if ( status != 200 && status != 404 ) { throw APIException . fromHttpResponse ( response ) ; } return ( 200 == status ) ; }
Returns whether the file exists in the Data API
41,061
public File getFile ( ) throws APIException , IOException { String filename = getName ( ) ; int extensionIndex = filename . lastIndexOf ( '.' ) ; String body ; String ext ; if ( extensionIndex <= 0 ) { body = filename ; ext = "" ; } else { body = filename . substring ( 0 , extensionIndex ) ; ext = filename . substring ( extensionIndex ) ; } if ( body . length ( ) < 3 || body . length ( ) > 127 ) { body = "algodata" ; } File tempFile = File . createTempFile ( body , ext ) ; client . getFile ( getUrl ( ) , tempFile ) ; return tempFile ; }
Gets the data for this file and saves it to a local temporary file
41,062
public InputStream getInputStream ( ) throws APIException , IOException { final HttpResponse response = client . get ( getUrl ( ) ) ; HttpClientHelpers . throwIfNotOk ( response ) ; return response . getEntity ( ) . getContent ( ) ; }
Gets the data for this file as an InputStream
41,063
public void put ( String data , Charset charset ) throws APIException { HttpResponse response = client . put ( getUrl ( ) , new StringEntity ( data , charset ) ) ; HttpClientHelpers . throwIfNotOk ( response ) ; }
Upload string data to this file as text using a custom Charset
41,064
public void put ( byte [ ] data ) throws APIException { HttpResponse response = client . put ( getUrl ( ) , new ByteArrayEntity ( data , ContentType . APPLICATION_OCTET_STREAM ) ) ; HttpClientHelpers . throwIfNotOk ( response ) ; }
Upload raw data to this file as binary
41,065
public void put ( InputStream is ) throws APIException { HttpResponse response = client . put ( getUrl ( ) , new InputStreamEntity ( is , - 1 , ContentType . APPLICATION_OCTET_STREAM ) ) ; HttpClientHelpers . throwIfNotOk ( response ) ; }
Upload raw data to this file as an input stream
41,066
public AlgoResponse pipe ( Object input ) throws APIException { if ( input instanceof String ) { return pipeRequest ( ( String ) input , ContentType . Text ) ; } else if ( input instanceof byte [ ] ) { return pipeBinaryRequest ( ( byte [ ] ) input ) ; } else { return pipeRequest ( gson . toJsonTree ( input ) . toString ( ) , ContentType . Json ) ; } }
Calls the Algorithmia API for a given input . Attempts to automatically serialize the input to JSON .
41,067
public FutureAlgoResponse pipeAsync ( Object input ) { final Gson gson = new Gson ( ) ; final JsonElement inputJson = gson . toJsonTree ( input ) ; return pipeJsonAsync ( inputJson . toString ( ) ) ; }
Calls the Algorithmia API asynchronously for a given input . Attempts to automatically serialize the input to JSON . The future response will complete when the algorithm has completed or errored
41,068
public < R > R execute ( MailChimpMethod < R > method ) throws IOException , MailChimpException { final Gson gson = MailChimpGsonFactory . createGson ( ) ; JsonElement result = execute ( buildUrl ( method ) , gson . toJsonTree ( method ) , method . getMetaInfo ( ) . version ( ) ) ; if ( result . isJsonObject ( ) ) { JsonElement error = result . getAsJsonObject ( ) . get ( "error" ) ; if ( error != null ) { JsonElement code = result . getAsJsonObject ( ) . get ( "code" ) ; throw new MailChimpException ( code . getAsInt ( ) , error . getAsString ( ) ) ; } } return gson . fromJson ( result , method . getResultType ( ) ) ; }
Execute MailChimp API method .
41,069
public void close ( ) { try { connection . close ( ) ; } catch ( IOException e ) { log . log ( Level . WARNING , "Could not close connection" , e ) ; } }
Release resources associated with the connection to MailChimp API service point .
41,070
public Object remove ( Object key ) { if ( key instanceof String && reflective . containsKey ( ( String ) key ) ) { throw new ReflectiveValueRemovalException ( ( String ) key ) ; } else { return regular . remove ( key ) ; } }
Removes a regular mapping for a key from this map if it is present .
41,071
public static < T extends MailChimpObject > T fromJson ( String json , Class < T > clazz ) { try { return MailChimpGsonFactory . createGson ( ) . fromJson ( json , clazz ) ; } catch ( JsonParseException e ) { throw new IllegalArgumentException ( e ) ; } }
Deserializes an object from JSON .
41,072
public final Method getMetaInfo ( ) { for ( Class < ? > c = getClass ( ) ; c != null ; c = c . getSuperclass ( ) ) { Method a = c . getAnnotation ( Method . class ) ; if ( a != null ) { return a ; } } throw new IllegalArgumentException ( "Neither " + getClass ( ) + " nor its superclasses are annotated with " + Method . class ) ; }
Get the MailChimp API method meta - info .
41,073
public final Type getResultType ( ) { Type type = resultTypeToken . getType ( ) ; if ( type instanceof Class || type instanceof ParameterizedType || type instanceof GenericArrayType ) { return type ; } else { throw new IllegalArgumentException ( "Cannot resolve result type: " + resultTypeToken ) ; } }
Get the method result type .
41,074
private void postCreatedOrEnabledUser ( UserDetails userDetails , Map < String , Object > userInfo ) { if ( oAuth2PostCreatedOrEnabledUserService != null ) { oAuth2PostCreatedOrEnabledUserService . postCreatedOrEnabledUser ( userDetails , userInfo ) ; } }
Extension point to allow sub classes to optionally do some processing after a user has been created or enabled . For example they could set something in the session so that the authentication success handler can treat the first log in differently .
41,075
public void afterPropertiesSet ( ) throws Exception { Assert . notNull ( userAuthorisationUri , "The userAuthorisationUri must be set" ) ; Assert . notNull ( redirectUri , "The redirectUri must be set" ) ; Assert . notNull ( accessTokenUri , "The accessTokenUri must be set" ) ; Assert . notNull ( clientId , "The clientId must be set" ) ; Assert . notNull ( clientSecret , "The clientSecret must be set" ) ; Assert . notNull ( userInfoUri , "The userInfoUri must be set" ) ; }
Check whether all required properties have been set
41,076
protected void checkStateParameter ( HttpSession session , Map < String , String [ ] > parameters ) throws AuthenticationException { String originalState = ( String ) session . getAttribute ( oAuth2ServiceProperties . getStateParamName ( ) ) ; String receivedStates [ ] = parameters . get ( oAuth2ServiceProperties . getStateParamName ( ) ) ; if ( receivedStates == null || receivedStates . length == 0 || ! receivedStates [ 0 ] . equals ( originalState ) ) { String errorMsg = String . format ( "Received states %s was not equal to original state %s" , receivedStates , originalState ) ; LOG . error ( errorMsg ) ; throw new AuthenticationServiceException ( errorMsg ) ; } }
Check the state parameter to ensure it is the same as was originally sent . Subclasses can override this behaviour if they so choose but it is not recommended .
41,077
public void afterPropertiesSet ( ) { super . afterPropertiesSet ( ) ; Assert . notNull ( oAuth2ServiceProperties ) ; Assert . isTrue ( oAuth2ServiceProperties . getRedirectUri ( ) . toString ( ) . endsWith ( super . getFilterProcessesUrl ( ) ) , "The filter must be configured to be listening on the redirect_uri in OAuth2ServiceProperties" ) ; }
Check properties are set
41,078
public void bind ( Object item ) { this . item = item ; if ( onItemBindListener != null ) { onItemBindListener . onItemBind ( itemView , item , getAdapterPosition ( ) ) ; } }
Called to update view
41,079
public static boolean startsWithPrefix ( final String input ) { boolean ret = false ; if ( input != null ) { ret = input . toLowerCase ( ) . startsWith ( PREFIX_BIGINT_DASH_CHECKSUM ) ; } else { ret = false ; } return ret ; }
Utility to test if the input string can even - possibly - be a BigIntStringChecksum encoded . This is check is necessary but not sufficient for the input string to parse correctly .
41,080
public static BigIntStringChecksum fromString ( String bics ) { boolean returnIsNegative = false ; BigIntStringChecksum ret = null ; if ( bics == null ) { createThrow ( "Input cannot be null" , bics ) ; } if ( startsWithPrefix ( bics ) ) { String noprefix = bics . substring ( PREFIX_BIGINT_DASH_CHECKSUM . length ( ) ) ; String noprefixnosign = noprefix ; if ( noprefixnosign . startsWith ( "-" ) ) { returnIsNegative = true ; noprefixnosign = noprefixnosign . substring ( 1 ) ; } String [ ] split = noprefixnosign . split ( "-" ) ; if ( split . length <= 1 ) { createThrow ( "Missing checksum section" , bics ) ; } else { String asHex = "" ; if ( returnIsNegative ) { asHex = "-" ; } for ( int i = 0 , n = split . length - 1 ; i < n ; i ++ ) { asHex += split [ i ] ; } String computedMd5sum = computeMd5ChecksumLimit6 ( asHex ) ; String givenMd5sum = split [ split . length - 1 ] ; if ( computedMd5sum . equalsIgnoreCase ( givenMd5sum ) ) { ret = new BigIntStringChecksum ( asHex , computedMd5sum ) ; } else { createThrow ( "Mismatch checksum given='" + givenMd5sum + "' computed='" + computedMd5sum + "'" , bics ) ; } } } else { createThrow ( "Input must start with '" + PREFIX_BIGINT_DASH_CHECKSUM + "'" , bics ) ; } ret . asBigInteger ( ) ; return ret ; }
Take input string and create the instance . As of version 1 . 3 . 2 forward the case of the INPUT is not relevant . Note however that when the Checksum CCCCCC is computed the hex hhhhhh - string is LOWER CASE .
41,081
public static BigIntStringChecksum fromStringOrNull ( String bics ) { BigIntStringChecksum ret ; if ( bics == null ) { ret = null ; } else if ( ! startsWithPrefix ( bics ) ) { ret = null ; } else { try { ret = fromString ( bics ) ; if ( ret . asBigInteger ( ) == null ) { throw new SecretShareException ( "Programmer error converting '" + bics + "' to BigInteger" ) ; } } catch ( SecretShareException e ) { ret = null ; } } return ret ; }
Take string as input and either return an instance or return null .
41,082
public static void setOptOut ( final Context context , boolean optOut ) { SharedPreferences pref = context . getSharedPreferences ( PREF_NAME , Context . MODE_PRIVATE ) ; Editor editor = pref . edit ( ) ; editor . putBoolean ( KEY_OPT_OUT , optOut ) ; editor . apply ( ) ; }
Set opt out flag . If it is true the rate dialog will never shown unless app data is cleared .
41,083
public static EasyLinearEquation createForPolynomial ( final BigInteger [ ] xarray , final BigInteger [ ] fofxarray ) { if ( xarray . length != fofxarray . length ) { throw new SecretShareException ( "Unequal length arrays are not allowed" ) ; } final int numRows = xarray . length ; final int numCols = xarray . length + 1 ; BigInteger [ ] [ ] cvt = new BigInteger [ numRows ] [ ] ; for ( int row = 0 ; row < numRows ; row ++ ) { cvt [ row ] = new BigInteger [ numCols ] ; fillInPolynomial ( cvt [ row ] , fofxarray [ row ] , xarray [ row ] ) ; } return create ( cvt ) ; }
Create solver for polynomial equations .
41,084
public static EasyLinearEquation create ( BigInteger [ ] [ ] inMatrix ) { EasyLinearEquation ret = null ; final int width = inMatrix [ 0 ] . length ; for ( BigInteger [ ] row : inMatrix ) { if ( width != row . length ) { throw new SecretShareException ( "All rows must be " + width + " wide" ) ; } } List < Row > rows = new ArrayList < Row > ( ) ; for ( BigInteger [ ] row : inMatrix ) { Row add = Row . create ( row ) ; rows . add ( add ) ; } ret = new EasyLinearEquation ( rows ) ; return ret ; }
Most typical factory for BigInteger arrays .
41,085
public static BigInteger getPrimeUsedFor8192bigSecretPayload ( ) { BigInteger p8192one = new BigInteger ( "279231522718570477942523966651848412786" + "755625471035569262549193264568660953374" + "539575363644038451708729333066699816198" + "469916126929965359120284410819859854028" + "564200012503601405321884115258380340520" + "882394013079459378373602954907987087391" + "050381798882893060582464649164778803202" + "580377606793174221031756238305523801728" + "417330041767401217359965327363800941065" + "035149118936045803200708786247512086542" + "238084017753586024109523236048614557723" + "115585648257171971411582352854028094056" + "289905359934753668545924906214201949630" + "392942663006227207072738059572864458946" + "995442098987135298017199066044684799206" + "646046852007692829583685501822083927579" + "071735457164040393298305467092078136746" + "232403045411490624416360836139009389471" + "599615055083953010222383976037199530343" + "650749295317216621610856318814974339038" + "401628152419869957586845887861406968283" + "393603484693172919144488209043235143942" + "917711597456617030850345093344845985897" + "228637329601259767634683509551299437410" + "250309746800132742906307824914615196564" + "591280851829591037942122046141801113374" + "061071502459843521616519068508840608866" + "142367016446371333344905644939606218218" + "417724015092650576657942326665080385451" + "599873057465726933634139504551380207635" + "732730508948201719784282311694063519119" + "639243736364276253689069434848647101071" + "362100254351086081223103674307034576258" + "686423188956569254966171125838939239921" + "106224566793694393912187263674266535325" + "772507180754537736572272329042950336363" + "370798851143956021690701705567437971039" + "256378548127430749169994462670402156122" + "918017938186142563187105245902896325033" + "680839207188324653847844773975235005076" + "945808128766572234433268495689937486958" + "100390065467437864644075017104695336221" + "543165982790695835615515631994231511431" + "260924853427059238919995356824115989937" + "622769832207704636596283910866202357492" + "467506454291595823775435851401331614913" + "666393860839942086098314120390709421306" + "518971383380559076685994283375663380057" + "764241494257799693167997775692501598019" + "901080423655494004717753331078458159262" + "055518170817180281440517060614547611105" + "545747781301175793208826135138672277976" + "088445981721562249959417511860209657110" + "039278232822620356487671024234137135540" + "726721167743323091920287701321960015105" + "097732434284751017974443861383170363586" + "137823503261214393288044057973810845631" + "331034904805398832430192982926982354654" + "090524982435531180945318487132920328174" + "085989844087121548092990523399171888560" + "553067218681856208752028326977093161880" + "486624111065893663542842180250983316936" + "056087246483576051350441471279745450361" + "783242982069" ) ; String bigintcs = "bigintcs:010000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "000000-000000-000000-000000-000000-000000-000000-" + "0002b5-1E18FD" ; return checkAndReturn ( "8192bit prime" , p8192one , bigintcs ) ; }
All primes were tested with 100 000 iterations of Miller - Rabin
41,086
private static BigInteger checkAndReturn ( String which , BigInteger expected , String asbigintcs ) { BigInteger other = BigIntStringChecksum . fromString ( asbigintcs ) . asBigInteger ( ) ; if ( expected . equals ( other ) ) { return expected ; } else { throw new SecretShareException ( which + " failure" ) ; } }
Guard against accidental changes to the strings .
41,087
public SplitSecretOutput split ( final BigInteger secret , final Random random ) { if ( secret == null ) { throw new SecretShareException ( "Secret cannot be null" ) ; } if ( secret . signum ( ) <= 0 ) { throw new SecretShareException ( "Secret cannot be negative" ) ; } if ( publicInfo . getPrimeModulus ( ) != null ) { checkThatModulusIsAppropriate ( publicInfo . getPrimeModulus ( ) , secret ) ; } BigInteger [ ] coeffs = new BigInteger [ publicInfo . getK ( ) ] ; randomizeCoeffs ( coeffs , random , publicInfo . getPrimeModulus ( ) , secret ) ; coeffs [ 0 ] = secret ; final PolyEquationImpl equation = new PolyEquationImpl ( coeffs ) ; SplitSecretOutput ret = new SplitSecretOutput ( this . publicInfo , equation ) ; for ( int x = 1 , n = publicInfo . getNforSplit ( ) + 1 ; x < n ; x ++ ) { final BigInteger fofx = equation . calculateFofX ( BigInteger . valueOf ( x ) ) ; BigInteger data = fofx ; if ( publicInfo . primeModulus != null ) { data = data . mod ( publicInfo . primeModulus ) ; } final ShareInfo share = new ShareInfo ( x , data , this . publicInfo ) ; if ( publicInfo . primeModulus != null ) { if ( data . compareTo ( publicInfo . getPrimeModulus ( ) ) > 0 ) { throw new RuntimeException ( "" + data + "\n" + publicInfo . getPrimeModulus ( ) + "\n" ) ; } } ret . sharesInfo . add ( share ) ; } return ret ; }
Split the secret into pieces where the caller controls the random instance .
41,088
public CombineOutput combine ( final List < ShareInfo > usetheseshares ) { CombineOutput ret = null ; sanityCheckPublicInfos ( publicInfo , usetheseshares ) ; if ( true ) { println ( " SOLVING USING THESE SHARES, mod=" + publicInfo . getPrimeModulus ( ) ) ; for ( ShareInfo si : usetheseshares ) { println ( " " + si . share ) ; } println ( "end SOLVING USING THESE SHARES" ) ; } if ( publicInfo . getK ( ) > usetheseshares . size ( ) ) { throw new SecretShareException ( "Must have " + publicInfo . getK ( ) + " shares to solve. Only provided " + usetheseshares . size ( ) ) ; } checkForDuplicatesOrThrow ( usetheseshares ) ; final int size = publicInfo . getK ( ) ; BigInteger [ ] xarray = new BigInteger [ size ] ; BigInteger [ ] fofxarray = new BigInteger [ size ] ; for ( int i = 0 , n = size ; i < n ; i ++ ) { xarray [ i ] = usetheseshares . get ( i ) . getXasBigInteger ( ) ; fofxarray [ i ] = usetheseshares . get ( i ) . getShare ( ) ; } EasyLinearEquation ele = EasyLinearEquation . createForPolynomial ( xarray , fofxarray ) ; if ( publicInfo . getPrimeModulus ( ) != null ) { ele = ele . createWithPrimeModulus ( publicInfo . getPrimeModulus ( ) ) ; } BigInteger solveSecret = null ; if ( false ) { EasyLinearEquation . EasySolve solve = ele . solve ( ) ; solveSecret = solve . getAnswer ( 1 ) ; } else { BigInteger [ ] [ ] matrix = ele . getMatrix ( ) ; NumberMatrix . print ( "SS.java" , matrix , out ) ; println ( "CVT matrix.height=" + matrix . length + " width=" + matrix [ 0 ] . length ) ; BigRationalMatrix brm = BigRationalMatrix . create ( matrix ) ; NumberMatrix . print ( "SS.java brm" , brm . getArray ( ) , out ) ; NumberSimplex < BigRational > simplex = new NumberSimplex < BigRational > ( brm , 0 ) ; simplex . initForSolve ( out ) ; simplex . solve ( out ) ; BigRational answer = simplex . getAnswer ( 0 ) ; if ( publicInfo . getPrimeModulus ( ) != null ) { solveSecret = answer . computeBigIntegerMod ( publicInfo . getPrimeModulus ( ) ) ; } else { solveSecret = answer . bigIntegerValue ( ) ; } } if ( publicInfo . getPrimeModulus ( ) != null ) { solveSecret = solveSecret . mod ( publicInfo . getPrimeModulus ( ) ) ; } ret = new CombineOutput ( solveSecret ) ; return ret ; }
Combine the shares generated by the split to recover the secret .
41,089
public ParanoidOutput combineParanoid ( List < ShareInfo > shares , ParanoidInput paranoidInput ) { ParanoidOutput ret = performParanoidCombines ( shares , paranoidInput ) ; if ( paranoidInput != null ) { if ( ret . getReconstructedMap ( ) . size ( ) != 1 ) { throw new SecretShareException ( "Paranoid combine failed, on combination at count=" + ret . getCount ( ) ) ; } } return ret ; }
This version does the combines and throws an exception if there is not 100% agreement .
41,090
public ParanoidOutput performParanoidCombines ( List < ShareInfo > shares , ParanoidInput paranoidInput ) { if ( paranoidInput == null ) { return ParanoidOutput . createEmpty ( ) ; } else { return performParanoidCombinesNonNull ( shares , paranoidInput ) ; } }
This version just collects all of the reconstructed secrets .
41,091
public static PolyEquationImpl create ( final int ... args ) { BigInteger [ ] bigints = new BigInteger [ args . length ] ; for ( int i = 0 , n = args . length ; i < n ; i ++ ) { bigints [ i ] = BigInteger . valueOf ( args [ i ] ) ; } return new PolyEquationImpl ( bigints ) ; }
Helper factory to create instances . Accepts int converts them to BigInteger and calls the constructor .
41,092
public E [ ] [ ] addMatrix ( E [ ] [ ] matrix1 , E [ ] [ ] matrix2 ) { if ( ( matrix1 . length != matrix2 . length ) || ( matrix1 [ 0 ] . length != matrix2 [ 0 ] . length ) ) { throw new SecretShareException ( "The matrices do not have the same size" ) ; } E [ ] [ ] result = create ( matrix1 . length , matrix1 [ 0 ] . length ) ; for ( int i = 0 ; i < result . length ; i ++ ) { for ( int j = 0 ; j < result [ i ] . length ; j ++ ) { result [ i ] [ j ] = add ( matrix1 [ i ] [ j ] , matrix2 [ i ] [ j ] ) ; } } return result ; }
Add two matrices .
41,093
public E [ ] [ ] multiplyMatrix ( E [ ] [ ] matrix1 , E [ ] [ ] matrix2 ) { if ( matrix1 [ 0 ] . length != matrix2 . length ) { throw new SecretShareException ( "The matrices do not have compatible size" ) ; } E [ ] [ ] result = create ( matrix1 . length , matrix2 [ 0 ] . length ) ; for ( int i = 0 ; i < result . length ; i ++ ) { for ( int j = 0 ; j < result [ 0 ] . length ; j ++ ) { result [ i ] [ j ] = zero ( ) ; for ( int k = 0 ; k < matrix1 [ 0 ] . length ; k ++ ) { result [ i ] [ j ] = add ( result [ i ] [ j ] , multiply ( matrix1 [ i ] [ k ] , matrix2 [ k ] [ j ] ) ) ; } } } return result ; }
Multiply two matrices .
41,094
public E determinant ( E [ ] [ ] matrix , int r , int s , int i , int j ) { E a , b , c , d ; a = matrix [ r ] [ s ] ; b = matrix [ r ] [ j ] ; c = matrix [ i ] [ s ] ; d = matrix [ i ] [ j ] ; E ad = multiply ( a , d ) ; E bc = multiply ( b , c ) ; E ret = subtract ( ad , bc ) ; return ret ; }
Return the determinant .
41,095
public static void print ( String string , Number [ ] [ ] matrix2 , PrintStream out ) { if ( out == null ) { return ; } out . println ( string ) ; printResult ( matrix2 , out ) ; }
Print this array - array .
41,096
public static void printResult ( Number [ ] [ ] m1 , PrintStream out ) { if ( out == null ) { return ; } for ( int i = 0 ; i < m1 . length ; i ++ ) { for ( int j = 0 ; j < m1 [ 0 ] . length ; j ++ ) { out . print ( " " + m1 [ i ] [ j ] ) ; } out . println ( "" ) ; } }
Print array - array .
41,097
public static void printResult ( Number [ ] [ ] m1 , Number [ ] [ ] m2 , Number [ ] [ ] m3 , char op , PrintStream out ) { for ( int i = 0 ; i < m1 . length ; i ++ ) { for ( int j = 0 ; j < m1 [ 0 ] . length ; j ++ ) { out . print ( " " + m1 [ i ] [ j ] ) ; } if ( i == m1 . length / 2 ) { out . print ( " " + op + " " ) ; } else { out . print ( " " ) ; } for ( int j = 0 ; j < m2 . length ; j ++ ) { out . print ( " " + m2 [ i ] [ j ] ) ; } if ( i == m1 . length / 2 ) { out . print ( " = " ) ; } else { out . print ( " " ) ; } for ( int j = 0 ; j < m3 . length ; j ++ ) { out . print ( m3 [ i ] [ j ] + " " ) ; } out . println ( ) ; } }
Print matrices the operator and their operation result .
41,098
public synchronized static Index createIndex ( Class < ? > type ) { Index index = indices . get ( type ) ; if ( index == null ) { try { Indexer indexer = new Indexer ( ) ; Class < ? > currentType = type ; while ( currentType != null ) { String className = currentType . getName ( ) . replace ( "." , "/" ) + ".class" ; InputStream stream = type . getClassLoader ( ) . getResourceAsStream ( className ) ; indexer . index ( stream ) ; currentType = currentType . getSuperclass ( ) ; } index = indexer . complete ( ) ; indices . put ( type , index ) ; } catch ( IOException e ) { throw new RuntimeException ( "Failed to initialize Indexer" , e ) ; } } return index ; }
Creates an annotation index for the given entity type
41,099
public ModelNode fromChangeset ( Map < String , Object > changeSet , String ... wildcards ) { ClassInfo clazz = null ; Class < ? > currentType = getType ( ) ; while ( clazz == null ) { clazz = index . getClassByName ( DotName . createSimple ( currentType . getCanonicalName ( ) ) ) ; if ( clazz == null ) { currentType = currentType . getSuperclass ( ) ; if ( currentType == null ) { throw new RuntimeException ( "Unable to determine ClassInfo" ) ; } } } Address addressMeta = currentType . getDeclaredAnnotation ( Address . class ) ; AddressTemplate address = AddressTemplate . of ( addressMeta . value ( ) ) ; ModelNode protoType = new ModelNode ( ) ; protoType . get ( ADDRESS ) . set ( address . resolve ( NOOP_CTX , wildcards ) ) ; protoType . get ( OP ) . set ( WRITE_ATTRIBUTE_OPERATION ) ; ModelNode operation = new ModelNode ( ) ; operation . get ( OP ) . set ( COMPOSITE ) ; operation . get ( ADDRESS ) . setEmptyList ( ) ; List < ModelNode > steps = new ArrayList < ModelNode > ( ) ; for ( MethodInfo method : clazz . methods ( ) ) { if ( method . hasAnnotation ( IndexFactory . BINDING_META ) ) { try { Method target = currentType . getMethod ( method . name ( ) ) ; Class < ? > propertyType = target . getReturnType ( ) ; ModelNodeBinding binding = target . getDeclaredAnnotation ( ModelNodeBinding . class ) ; String detypedName = binding . detypedName ( ) ; String javaPropName = method . name ( ) ; Object value = changeSet . get ( javaPropName ) ; if ( value == null ) continue ; ModelNode step = protoType . clone ( ) ; step . get ( NAME ) . set ( javaPropName ) ; ModelNode modelNode = step . get ( VALUE ) ; try { ModelType dmrType = Types . resolveModelType ( propertyType ) ; if ( dmrType == ModelType . LIST ) { new ListTypeAdapter ( ) . toDmr ( modelNode . get ( detypedName ) , ( List ) value ) ; } else if ( dmrType == ModelType . OBJECT ) { new MapTypeAdapter ( ) . toDmr ( modelNode . get ( detypedName ) , ( Map ) value ) ; } else { new SimpleTypeAdapter ( ) . toDmr ( modelNode . get ( detypedName ) , dmrType , value ) ; } } catch ( RuntimeException e ) { throw new RuntimeException ( "Failed to adopt value " + propertyType . getName ( ) , e ) ; } steps . add ( step ) ; } catch ( NoSuchMethodException e ) { e . printStackTrace ( ) ; } } } operation . get ( STEPS ) . set ( steps ) ; return operation ; }
Turns a changeset into a composite write attribute operation . The keys to the changeset are the java property names of the attributes that have been modified .