idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
128,700
protected void checkRequired ( String key , AnnotatedElement element ) { if ( isRequired ( element ) ) { throw new PropertyLoaderException ( String . format ( "Required property <%s> doesn't exists" , key ) ) ; } }
Throws an exception if given element is required .
128,701
protected String concat ( String first , String second ) { return first == null ? second : String . format ( "%s.%s" , first , second ) ; }
Concat the given prefixes into one .
128,702
public < T > PropertyLoader register ( Converter < T > converter , Class < T > type ) { manager . register ( type , converter ) ; return this ; }
Register custom converter for given type .
128,703
public final static String byteArrayAsHex ( final byte [ ] buf , final int limit ) { final StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < limit ; ++ i ) { if ( ( i % 16 ) == 0 ) { sb . append ( nativeAsHex ( i , 32 ) ) . append ( " " ) ; } else if ( ( ( i ) % 8 ) == 0 ) { sb . append ( " " ) ; } sb ....
Return hexdump of byte - array
128,704
public void clear ( final boolean shrink ) { while ( queue . poll ( ) != null ) { ; } if ( elementCount > 0 ) { elementCount = 0 ; } if ( shrink && ( elementData . length > 1024 ) && ( elementData . length > defaultSize ) ) { elementData = newElementArray ( defaultSize ) ; } else { Arrays . fill ( elementData , null ) ...
Clear the set
128,705
public T get ( final T value ) { expungeStaleEntries ( ) ; final int index = ( value . hashCode ( ) & 0x7FFFFFFF ) % elementData . length ; Entry < T > m = elementData [ index ] ; while ( m != null ) { if ( eq ( value , m . get ( ) ) ) { return m . get ( ) ; } m = m . nextInSlot ; } return null ; }
Returns the specified value .
128,706
public T put ( final T value ) { expungeStaleEntries ( ) ; final int hash = value . hashCode ( ) ; int index = ( hash & 0x7FFFFFFF ) % elementData . length ; Entry < T > entry = elementData [ index ] ; while ( entry != null && ! eq ( value , entry . get ( ) ) ) { entry = entry . nextInSlot ; } if ( entry == null ) { if...
Puts the specified value in the set .
128,707
public T remove ( final T value ) { expungeStaleEntries ( ) ; final Entry < T > entry = removeEntry ( value ) ; if ( entry == null ) { return null ; } final T ret = entry . get ( ) ; return ret ; }
Removes the specified value from this set .
128,708
public void clear ( boolean shrink ) { if ( elementCount > 0 ) { elementCount = 0 ; } if ( shrink && ( ( elementKeys . length > 1024 ) && ( elementKeys . length > defaultSize ) ) ) { elementKeys = newKeyArray ( defaultSize ) ; elementValues = newElementArray ( defaultSize ) ; } else { Arrays . fill ( elementKeys , Inte...
Removes all mappings from this hash map leaving it empty .
128,709
private void computeMaxSize ( ) { threshold = ( int ) ( elementKeys . length * loadFactor ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( this . getClass ( ) . getName ( ) + "::computeMaxSize()=" + threshold + " collisions=" + collisions + " (" + ( collisions * 100 / elementKeys . length ) + ")" ) ; } collisions = ...
Returns a shallow copy of this map .
128,710
protected void createRootNode ( ) { final Node < K , V > node = createLeafNode ( ) ; node . allocId ( ) ; rootIdx = node . id ; height = 1 ; elements = 0 ; putNode ( node ) ; }
Create a Leaf root node and alloc nodeid for this
128,711
private int getMaxStructSize ( ) { final int leafSize = ( createLeafNode ( ) . getStructMaxSize ( ) ) ; final int internalSize = ( createInternalNode ( ) . getStructMaxSize ( ) ) ; return Math . max ( leafSize , internalSize ) ; }
Get the maximal size for a node
128,712
private void findOptimalNodeOrder ( final int block_size ) { final Node < K , V > leaf = createLeafNode ( ) ; final Node < K , V > internal = createInternalNode ( ) ; final int nodeSize = Math . max ( leaf . getStructEstimateSize ( MIN_B_ORDER ) , internal . getStructEstimateSize ( MIN_B_ORDER ) ) ; blockSize = ( ( nod...
Calculate optimal values for b - order to fit in a block of block_size
128,713
private int findOptimalNodeOrder ( final Node < K , V > node ) { int low = MIN_B_ORDER ; int high = ( blockSize / node . getStructEstimateSize ( 1 ) ) << 2 ; while ( low <= high ) { int mid = ( ( low + high ) >>> 1 ) ; mid += ( 1 - ( mid % 2 ) ) ; int nodeSize = node . getStructEstimateSize ( mid ) ; if ( log . isDebug...
Find b - order for a blockSize of this tree
128,714
private final LeafNode < K , V > findLeafNode ( final K key , final boolean tracePath ) { Node < K , V > node = getNode ( rootIdx ) ; if ( tracePath ) { stackNodes . clear ( ) ; stackSlots . clear ( ) ; } while ( ! node . isLeaf ( ) ) { final InternalNode < K , V > nodeInternal = ( InternalNode < K , V > ) node ; int s...
Find node that can hold the key
128,715
public synchronized TreeEntry < K , V > pollFirstEntry ( ) { final TreeEntry < K , V > entry = firstEntry ( ) ; if ( entry != null ) { remove ( entry . getKey ( ) ) ; } return entry ; }
Removes and returns a key - value mapping associated with the least key in this map or null if the map is empty .
128,716
public synchronized TreeEntry < K , V > pollLastEntry ( ) { final TreeEntry < K , V > entry = lastEntry ( ) ; if ( entry != null ) { remove ( entry . getKey ( ) ) ; } return entry ; }
Removes and returns a key - value mapping associated with the greatest key in this map or null if the map is empty .
128,717
private final K getRoundKey ( final K key , final boolean upORdown , final boolean acceptEqual ) { final TreeEntry < K , V > entry = getRoundEntry ( key , upORdown , acceptEqual ) ; if ( entry == null ) { return null ; } return entry . getKey ( ) ; }
Return ceilingKey floorKey higherKey or lowerKey
128,718
public synchronized TreeEntry < K , V > ceilingEntry ( final K key ) { return getRoundEntry ( key , true , true ) ; }
Returns the least key greater than or equal to the given key or null if there is no such key .
128,719
public synchronized TreeEntry < K , V > floorEntry ( final K key ) { return getRoundEntry ( key , false , true ) ; }
Returns the greatest key less than or equal to the given key or null if there is no such key .
128,720
public synchronized TreeEntry < K , V > higherEntry ( final K key ) { return getRoundEntry ( key , true , false ) ; }
Returns the least key strictly greater than the given key or null if there is no such key .
128,721
public synchronized TreeEntry < K , V > lowerEntry ( final K key ) { return getRoundEntry ( key , false , false ) ; }
Returns the greatest key strictly less than the given key or null if there is no such key .
128,722
private final TreeEntry < K , V > getRoundEntry ( final K key , final boolean upORdown , final boolean acceptEqual ) { if ( ! validState ) { throw new InvalidStateException ( ) ; } if ( _isEmpty ( ) ) { return null ; } if ( key == null ) { return null ; } try { LeafNode < K , V > node = findLeafNode ( key , false ) ; i...
Return ceilingEntry floorEntry higherEntry or lowerEntry
128,723
public synchronized V get ( final K key ) { if ( ! validState ) { throw new InvalidStateException ( ) ; } if ( _isEmpty ( ) ) { return null ; } if ( key == null ) { return null ; } try { final LeafNode < K , V > node = findLeafNode ( key , false ) ; if ( node == null ) { return null ; } int slot = node . findSlotByKey ...
Find a Key in the Tree
128,724
public synchronized boolean remove ( final K key ) { if ( readOnly ) { return false ; } if ( ! validState ) { throw new InvalidStateException ( ) ; } if ( key == null ) { return false ; } try { if ( log . isDebugEnabled ( ) ) { log . debug ( "trying remove key=" + key ) ; } submitRedoRemove ( key ) ; if ( removeIterati...
Remove a key from key
128,725
private String toStringIterative ( ) { final String PADDING = " " ; final StringBuilder sb = new StringBuilder ( ) ; int elements_debug_local_recounter = 0 ; Node < K , V > node = null ; int nodeid = rootIdx ; int depth = 0 ; stackSlots . clear ( ) ; stackSlots . push ( rootIdx ) ; boole...
A iterative algorithm for converting this tree into a string
128,726
@ SuppressWarnings ( "unused" ) private String toStringRecursive ( ) { final StringBuilder sb = new StringBuilder ( ) ; int elements_debug_local_recounter = toString ( rootIdx , sb , 0 ) ; sb . append ( "height=" ) . append ( getHeight ( ) ) . append ( " root=" ) . append ( rootIdx ) . append ( " low=" ) . append ( low...
A recursive algorithm for converting this tree into a string
128,727
public Iterator < BplusTree . TreeEntry < K , V > > iterator ( ) { return new TreeIterator < BplusTree . TreeEntry < K , V > > ( this ) ; }
Note that the iterator cannot be guaranteed to be thread - safe as it is generally speaking impossible to make any hard guarantees in the presence of unsynchronized concurrent modification .
128,728
public LeafNode < K , V > prevNode ( ) { if ( leftid == NULL_ID ) { return null ; } return ( LeafNode < K , V > ) tree . getNode ( leftid ) ; }
Return the previous LeafNode in LinkedList
128,729
public LeafNode < K , V > nextNode ( ) { if ( rightid == NULL_ID ) { return null ; } return ( LeafNode < K , V > ) tree . getNode ( rightid ) ; }
Return the next LeafNode in LinkedList
128,730
public synchronized boolean isValid ( ) { if ( ! validState ) { throw new InvalidStateException ( ) ; } final long size = size ( ) ; if ( size == 0 ) { return true ; } try { final long offset = ( size - FOOTER_LEN ) ; if ( offset < 0 ) { return false ; } if ( offset >= offsetOutputCommited ) { if ( bufOutput . position...
Read end of valid and check last magic footer
128,731
public synchronized long readFromEnd ( final long datalen , final ByteBuffer buf ) { if ( ! validState ) { throw new InvalidStateException ( ) ; } final long size = size ( ) ; final long offset = ( size - HEADER_LEN - datalen - FOOTER_LEN ) ; return read ( offset , buf ) ; }
Read desired block of datalen from end of file
128,732
private final void alignBuffer ( final int diff ) throws IOException { if ( bufOutput . remaining ( ) < diff ) { flushBuffer ( ) ; } bufOutput . put ( MAGIC_PADDING ) ; int i = 1 ; for ( ; i + 8 <= diff ; i += 8 ) { bufOutput . putLong ( 0L ) ; } for ( ; i + 4 <= diff ; i += 4 ) { bufOutput . putInt ( 0 ) ; } switch ( ...
Pad output buffer with NULL to complete alignment
128,733
public synchronized boolean flush ( ) { if ( ! validState ) { throw new InvalidStateException ( ) ; } try { flushBuffer ( ) ; return true ; } catch ( Exception e ) { log . error ( "Exception in flush()" , e ) ; } return false ; }
Flush buffer to file
128,734
private final void flushBuffer ( ) throws IOException { if ( bufOutput . position ( ) > 0 ) { bufOutput . flip ( ) ; fcOutput . write ( bufOutput ) ; bufOutput . clear ( ) ; offsetOutputUncommited = offsetOutputCommited = fcOutput . position ( ) ; if ( syncOnFlush ) { fcOutput . force ( false ) ; if ( callback != null ...
Write uncommited data to disk
128,735
private final boolean checkUnderflowWithRight ( final int slot ) { final Node < K , V > nodeLeft = tree . getNode ( childs [ slot ] ) ; if ( nodeLeft . isUnderFlow ( ) ) { final Node < K , V > nodeRight = tree . getNode ( childs [ slot + 1 ] ) ; if ( nodeLeft . canMerge ( nodeRight ) ) { nodeLeft . merge ( this , slot ...
Check if underflow ocurred in child of slot
128,736
public static DatagramPacket getDatagram ( String serviceType ) { StringBuilder sb = new StringBuilder ( "M-SEARCH * HTTP/1.1\r\n" ) ; sb . append ( "HOST: " + SsdpParams . getSsdpMulticastAddress ( ) . getHostAddress ( ) + ":" + SsdpParams . getSsdpMulticastPort ( ) + "\r\n" ) ; sb . append ( "MAN: \"ssdp:discover\"\r...
Get Datagram from serviceType .
128,737
public static void selectAppropriateInterface ( MulticastSocket socket ) throws SocketException { Enumeration e = NetworkInterface . getNetworkInterfaces ( ) ; while ( e . hasMoreElements ( ) ) { NetworkInterface n = ( NetworkInterface ) e . nextElement ( ) ; Enumeration ee = n . getInetAddresses ( ) ; while ( ee . has...
Selects the appropriate interface to use Multicast . This prevents computers with multiple interfaces to select the wrong one by default .
128,738
public static SsdpResponse parse ( DatagramPacket packet ) { Map < String , String > headers = new HashMap < String , String > ( ) ; byte [ ] body = null ; SsdpResponse . Type type = null ; byte [ ] data = packet . getData ( ) ; int endOfHeaders = findEndOfHeaders ( data ) ; if ( endOfHeaders == - 1 ) { endOfHeaders = ...
Parse incoming Datagram into SsdpResponse .
128,739
private static long parseCacheHeader ( Map < String , String > headers ) { if ( headers . get ( "CACHE-CONTROL" ) != null ) { String cacheControlHeader = headers . get ( "CACHE-CONTROL" ) ; Matcher m = CACHE_CONTROL_PATTERN . matcher ( cacheControlHeader ) ; if ( m . matches ( ) ) { return new Date ( ) . getTime ( ) + ...
Parse both Cache - Control and Expires headers to determine if there is any caching strategy requested by service .
128,740
private static int findEndOfHeaders ( byte [ ] data ) { for ( int i = 0 ; i < data . length - 3 ; i ++ ) { if ( data [ i ] != CRLF [ 0 ] || data [ i + 1 ] != CRLF [ 1 ] || data [ i + 2 ] != CRLF [ 0 ] || data [ i + 3 ] != CRLF [ 1 ] ) { continue ; } return i ; } return - 1 ; }
Find the index matching the end of the header data .
128,741
private void reset ( DiscoveryRequest req , DiscoveryListener callback ) { this . callback = callback ; this . state = State . ACTIVE ; this . requests = new ArrayList < DiscoveryRequest > ( ) ; if ( req != null ) { requests . add ( req ) ; } for ( Map . Entry < String , SsdpService > e : this . cache . entrySet ( ) ) ...
Reset all stateful attributes .
128,742
private void handleIncomingPacket ( DatagramPacket packet ) { SsdpResponse response = new ResponseParser ( ) . parse ( packet ) ; if ( response == null ) { return ; } if ( response . getType ( ) . equals ( SsdpResponse . Type . DISCOVERY_RESPONSE ) ) { handleDiscoveryResponse ( response ) ; } else if ( response . getTy...
Thid handler handles incoming SSDP packets .
128,743
private void sendDiscoveryRequest ( ) { try { if ( requests . isEmpty ( ) ) { return ; } for ( DiscoveryRequest req : requests ) { if ( req . getServiceTypes ( ) == null || req . getServiceTypes ( ) . isEmpty ( ) ) { clientSocket . send ( SsdpDiscovery . getDatagram ( null ) ) ; } else { for ( String st : req . getServ...
Send discovery Multicast request .
128,744
private void openAndBindSocket ( ) { try { this . clientSocket = new MulticastSocket ( ) ; Utils . selectAppropriateInterface ( clientSocket ) ; this . clientSocket . joinGroup ( SsdpParams . getSsdpMulticastAddress ( ) ) ; } catch ( IOException e ) { callback . onFailed ( e ) ; } }
Open MulticastSocket and bind to Ssdp port .
128,745
private void handlePresenceAnnouncement ( SsdpResponse response ) { SsdpServiceAnnouncement ssdpServiceAnnouncement = response . toServiceAnnouncement ( ) ; if ( ssdpServiceAnnouncement . getSerialNumber ( ) == null ) { callback . onFailed ( new NoSerialNumberException ( ) ) ; return ; } if ( cache . containsKey ( ssdp...
Handle presence announcement Datagrams .
128,746
private void handleDiscoveryResponse ( SsdpResponse response ) { SsdpService ssdpService = response . toService ( ) ; if ( ssdpService . getSerialNumber ( ) == null ) { callback . onFailed ( new NoSerialNumberException ( ) ) ; return ; } if ( ! cache . containsKey ( ssdpService . getSerialNumber ( ) ) ) { callback . on...
Handle discovery response Datagrams .
128,747
public T get ( T dest , int index ) { checkBounds ( index ) ; copier . copy ( dest , offset ( index ) ) ; return dest ; }
Copies the element at index into dest
128,748
public void swap ( int i , int j ) { checkBounds ( i ) ; checkBounds ( j ) ; if ( i == j ) return ; copier . copy ( tmp , offset ( i ) ) ; unsafe . copyMemory ( null , offset ( j ) , null , offset ( i ) , elementSpacing ) ; unsafe . copyMemory ( tmp , firstFieldOffset , null , offset ( j ) , elementSize ) ; }
Swaps two elements
128,749
public UnsafeCopier build ( Unsafe unsafe ) throws IllegalAccessException , InstantiationException , NoSuchMethodException , InvocationTargetException { checkArgument ( offset >= 0 , "Offset must be set" ) ; checkArgument ( length >= 0 , "Length must be set" ) ; checkNotNull ( unsafe ) ; Class < ? > dynamicType = new B...
Constructs a new Copier using the passed in Unsafe instance
128,750
public static < E extends Comparable < E > > void recursiveQuickSort ( List < E > array , int startIdx , int endIdx ) { int idx = partition ( array , startIdx , endIdx ) ; if ( startIdx < idx - 1 ) { recursiveQuickSort ( array , startIdx , idx - 1 ) ; } if ( endIdx > idx ) { recursiveQuickSort ( array , idx , endIdx ) ...
Recursive quicksort logic .
128,751
public static void printMemoryLayout2 ( ) { Object o1 = new Object ( ) ; Object o2 = new Object ( ) ; Byte b1 = new Byte ( ( byte ) 0x12 ) ; Byte b2 = new Byte ( ( byte ) 0x34 ) ; Byte b3 = new Byte ( ( byte ) 0x56 ) ; Long l = new Long ( 0x0123456789ABCDEFL ) ; Person p = new Person ( "Bob" , 406425600000L , 'M' ) ; S...
Prints the memory layout of various test classes .
128,752
@ Setup ( Level . Trial ) public void setup ( ) throws Exception { test = benchmarks . get ( list + "-" + type ) ; if ( test == null ) { throw new RuntimeException ( "Can't find requested test " + list + " " + type ) ; } test . setSize ( size ) ; test . setRandomSeed ( size ) ; test . setup ( ) ; }
Sets up the benchmark .
128,753
public static void main ( String [ ] args ) throws RunnerException { for ( String benchmark : benchmarks . keySet ( ) ) { String [ ] parts = benchmark . split ( "-" ) ; Options opt = new OptionsBuilder ( ) . include ( ArrayListBenchmark . class . getSimpleName ( ) ) . warmupIterations ( 2 ) . measurementIterations ( 5 ...
Runs the ArrayListBenchmarks .
128,754
public static String memoryUsage ( ) { final Runtime runtime = Runtime . getRuntime ( ) ; runtime . gc ( ) ; final long max = runtime . maxMemory ( ) ; final long total = runtime . totalMemory ( ) ; final long free = runtime . freeMemory ( ) ; final long used = total - free ; return String . format ( "%d\t%d\t%d\t%d" ,...
Calculates the memory usage according to Runtime .
128,755
public static int getPid ( ) throws NoSuchFieldException , IllegalAccessException , NoSuchMethodException , InvocationTargetException { RuntimeMXBean runtime = ManagementFactory . getRuntimeMXBean ( ) ; Field jvm = runtime . getClass ( ) . getDeclaredField ( "jvm" ) ; jvm . setAccessible ( true ) ; VMManagement mgmt = ...
Returns the pid of the current process . This fails on systems without process identifiers .
128,756
public static String pidMemoryUsage ( int pid ) throws IOException { Process process = new ProcessBuilder ( ) . command ( "ps" , "-o" , "pid,rss,vsz" , "-p" , Long . toString ( pid ) ) . start ( ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( process . getInputStream ( ) ) ) ; reader . readLine...
Calculates the memory usage according to ps for a given pid .
128,757
public static long toAddress ( Object obj ) { Object [ ] array = new Object [ ] { obj } ; long baseOffset = unsafe . arrayBaseOffset ( Object [ ] . class ) ; return normalize ( unsafe . getInt ( array , baseOffset ) ) ; }
Returns the address the object is located at
128,758
public static void copyMemory ( final Object src , long srcOffset , final Object dest , final long destOffset , final long len ) { Preconditions . checkNotNull ( src ) ; Preconditions . checkArgument ( len % COPY_STRIDE != 0 , "Length (%d) is not a multiple of stride" , len ) ; Preconditions . checkArgument ( destOffse...
Copies the memory from srcAddress into dest
128,759
public static void copyMemoryFieldByField ( long srcAddress , Object dest ) { Class clazz = dest . getClass ( ) ; while ( clazz != Object . class ) { for ( Field f : clazz . getDeclaredFields ( ) ) { if ( ( f . getModifiers ( ) & Modifier . STATIC ) == 0 ) { final Class type = f . getType ( ) ; Preconditions . checkArg...
Copies from srcAddress to dest one field at a time .
128,760
public static byte [ ] toByteArray ( Object obj ) { int len = ( int ) sizeOf ( obj ) ; byte [ ] bytes = new byte [ len ] ; unsafe . copyMemory ( obj , 0 , bytes , Unsafe . ARRAY_BYTE_BASE_OFFSET , bytes . length ) ; return bytes ; }
Returns the object as a byte array including header padding and all fields .
128,761
private static byte [ ] stringToByteArray ( String str ) { byte [ ] result = new byte [ str . length ( ) + 1 ] ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { result [ i ] = ( byte ) str . charAt ( i ) ; } result [ str . length ( ) ] = 0 ; return result ; }
Returns this java string as a null - terminated byte array
128,762
public void createKey ( HKey hk , String key ) throws RegistryException { int [ ] ret ; try { ret = ReflectedMethods . createKey ( hk . root ( ) , hk . hex ( ) , key ) ; } catch ( Exception e ) { throw new RegistryException ( "Cannot create key " + key , e ) ; } if ( ret . length == 0 ) { throw new RegistryException ( ...
Create key in registry .
128,763
public void deleteKey ( HKey hk , String key ) throws RegistryException { int rc = - 1 ; try { rc = ReflectedMethods . deleteKey ( hk . root ( ) , hk . hex ( ) , key ) ; } catch ( Exception e ) { throw new RegistryException ( "Cannot delete key " + key , e ) ; } if ( rc != RC . SUCCESS ) { throw new RegistryException (...
Delete given key from registry .
128,764
public void close ( ) { File tmp = new File ( webpTmpDir ) ; if ( tmp . exists ( ) && tmp . isDirectory ( ) ) { File [ ] files = tmp . listFiles ( ) ; for ( File file : Objects . requireNonNull ( files ) ) { file . delete ( ) ; } tmp . delete ( ) ; } }
delete temp dir and commands
128,765
private String getOsName ( ) { if ( OS_NAME . contains ( "win" ) ) { boolean is64bit = ( System . getenv ( "ProgramFiles(x86)" ) != null ) ; return "windows_" + ( is64bit ? "x86_64" : "x86" ) ; } else if ( OS_NAME . contains ( "mac" ) ) { return "mac_" + OS_ARCH ; } else if ( OS_NAME . contains ( "nix" ) || OS_NAME . c...
get os name and arch
128,766
private String getExtensionByOs ( String os ) { if ( os == null || os . isEmpty ( ) ) return "" ; else if ( os . contains ( "win" ) ) return ".exe" ; return "" ; }
Return the Os specific extension
128,767
public List < Tag > getInstanceTags ( ) { final DescribeInstancesResult response = ec2 . describeInstances ( new DescribeInstancesRequest ( ) . withInstanceIds ( Collections . singletonList ( instanceIdentity . instanceId ) ) ) ; return response . getReservations ( ) . stream ( ) . flatMap ( reservation -> reservation ...
Returns all of the tags defined on the EC2 current instance instanceId .
128,768
public TagsUtils validateTags ( ) { final List < String > instanceTags = getInstanceTags ( ) . stream ( ) . map ( Tag :: getKey ) . collect ( Collectors . toList ( ) ) ; final List < String > missingTags = getAwsTagNames ( ) . map ( List :: stream ) . orElse ( Stream . empty ( ) ) . filter ( configuredTag -> ! instance...
Configured tags will be validated against the instance tags . If one or more tags are missing on the instance an exception will be thrown .
128,769
private static List < String > parseTagNames ( String tagNames ) { return Arrays . stream ( tagNames . split ( "\\s*,\\s*" ) ) . map ( String :: trim ) . collect ( Collectors . toList ( ) ) ; }
Parses a comma separated list of tag names .
128,770
private static String getIdentityDocument ( final HttpClient client ) throws IOException { try { final HttpGet getInstance = new HttpGet ( ) ; getInstance . setURI ( INSTANCE_IDENTITY_URI ) ; final HttpResponse response = client . execute ( getInstance ) ; if ( response . getStatusLine ( ) . getStatusCode ( ) != HttpSt...
Gets the body of the content returned from a GET request to uri .
128,771
private static void setupAWSExceptionLogging ( AmazonEC2 ec2 ) { boolean accessible = false ; Field exceptionUnmarshallersField = null ; try { exceptionUnmarshallersField = AmazonEC2Client . class . getDeclaredField ( "exceptionUnmarshallers" ) ; accessible = exceptionUnmarshallersField . isAccessible ( ) ; exceptionUn...
Sets up the AmazonEC2Client to log soap faults from the AWS EC2 api server .
128,772
public static boolean isValid ( String kidnummer ) { try { KidnummerValidator . getKidnummer ( kidnummer ) ; return true ; } catch ( IllegalArgumentException e ) { return false ; } }
Return true if the provided String is a valid KID - nummmer .
128,773
public static Kidnummer getKidnummer ( String kidnummer ) throws IllegalArgumentException { validateSyntax ( kidnummer ) ; validateChecksum ( kidnummer ) ; return new Kidnummer ( kidnummer ) ; }
Returns an object that represents a Kidnummer .
128,774
public static List < Organisasjonsnummer > getOrganisasjonsnummerList ( int length ) { List < Organisasjonsnummer > result = new ArrayList < Organisasjonsnummer > ( ) ; int numAddedToList = 0 ; while ( numAddedToList < length ) { StringBuilder orgnrBuffer = new StringBuilder ( LENGTH ) ; for ( int i = 0 ; i < LENGTH ; ...
Returns a List with completely random but syntactically valid Organisasjonsnummer instances .
128,775
public static void main ( String [ ] args ) throws Exception { GeoParser parser = GeoParserFactory . getDefault ( "./IndexDirectory" ) ; File inputFile = new File ( "src/test/resources/sample-docs/Somalia-doc.txt" ) ; String inputString = TextUtils . fileToString ( inputFile ) ; List < ResolvedLocation > resolvedLocati...
Run this after installing & configuring CLAVIN to get a sense of how to use it .
128,776
public static no . bekk . bekkopen . person . Fodselsnummer getFodselsnummer ( String fodselsnummer ) throws IllegalArgumentException { validateSyntax ( fodselsnummer ) ; validateIndividnummer ( fodselsnummer ) ; validateDate ( fodselsnummer ) ; validateChecksums ( fodselsnummer ) ; return new no . bekk . bekkopen . pe...
Returns an object that represents a Fodselsnummer .
128,777
public static boolean isValid ( String fodselsnummer ) { try { FodselsnummerValidator . getFodselsnummer ( fodselsnummer ) ; return true ; } catch ( IllegalArgumentException e ) { return false ; } }
Return true if the provided String is a valid Fodselsnummer .
128,778
public static boolean isValid ( String organisasjonsnummer ) { try { OrganisasjonsnummerValidator . getOrganisasjonsnummer ( organisasjonsnummer ) ; return true ; } catch ( IllegalArgumentException e ) { return false ; } }
Return true if the provided String is a valid Organisasjonsnummer .
128,779
public static Organisasjonsnummer getOrganisasjonsnummer ( String organisasjonsnummer ) throws IllegalArgumentException { validateSyntax ( organisasjonsnummer ) ; validateChecksum ( organisasjonsnummer ) ; return new Organisasjonsnummer ( organisasjonsnummer ) ; }
Returns an object that represents an Organisasjonsnummer .
128,780
public static Organisasjonsnummer getAndForceValidOrganisasjonsnummer ( String organisasjonsnummer ) { validateSyntax ( organisasjonsnummer ) ; try { validateChecksum ( organisasjonsnummer ) ; } catch ( IllegalArgumentException iae ) { Organisasjonsnummer onr = new Organisasjonsnummer ( organisasjonsnummer ) ; int chec...
Returns an object that represents a Organisasjonsnummer . The checksum of the supplied organisasjonsnummer is changed to a valid checksum if the original organisasjonsnummer has an invalid checksum .
128,781
public static Date [ ] getHolidays ( int year ) { Set < Date > days = getHolidaySet ( year ) ; Date [ ] dates = days . toArray ( new Date [ days . size ( ) ] ) ; Arrays . sort ( dates ) ; return dates ; }
Return a sorted array of holidays for a given year .
128,782
private static Set < Date > getHolidaySet ( int year ) { if ( holidays == null ) { holidays = new HashMap < Integer , Set < Date > > ( ) ; } if ( ! holidays . containsKey ( year ) ) { Set < Date > yearSet = new HashSet < Date > ( ) ; yearSet . add ( getDate ( 1 , Calendar . JANUARY , year ) ) ; yearSet . add ( getDate ...
Get a set of holidays for a given year .
128,783
private static boolean isWorkingDay ( Calendar cal ) { return cal . get ( Calendar . DAY_OF_WEEK ) != Calendar . SATURDAY && cal . get ( Calendar . DAY_OF_WEEK ) != Calendar . SUNDAY && ! isHoliday ( cal ) ; }
Will check if the given date is a working day . That is check if the given date is a weekend day or a national holiday .
128,784
private static boolean isHoliday ( Calendar cal ) { int year = cal . get ( Calendar . YEAR ) ; Set < ? > yearSet = getHolidaySet ( year ) ; for ( Object aYearSet : yearSet ) { Date date = ( Date ) aYearSet ; if ( checkDate ( cal , dateToCalendar ( date ) ) ) { return true ; } } return false ; }
Check if given Calendar object represents a holiday .
128,785
private static boolean checkDate ( Calendar cal , Calendar other ) { return checkDate ( cal , other . get ( Calendar . DATE ) , other . get ( Calendar . MONTH ) ) ; }
Check if the given dates match on day and month .
128,786
private static boolean checkDate ( Calendar cal , int date , int month ) { return cal . get ( Calendar . DATE ) == date && cal . get ( Calendar . MONTH ) == month ; }
Check if the given date represents the given date and month .
128,787
private static Calendar dateToCalendar ( Date date ) { Calendar cal = Calendar . getInstance ( ) ; cal . setTime ( date ) ; return cal ; }
Convert the given Date object to a Calendar instance .
128,788
private static Date rollGetDate ( Calendar calendar , int days ) { Calendar easterSunday = ( Calendar ) calendar . clone ( ) ; easterSunday . add ( Calendar . DATE , days ) ; return easterSunday . getTime ( ) ; }
Add the given number of days to the calendar and convert to Date .
128,789
private static Date getDate ( int day , int month , int year ) { Calendar cal = Calendar . getInstance ( ) ; cal . set ( Calendar . YEAR , year ) ; cal . set ( Calendar . MONTH , month ) ; cal . set ( Calendar . DATE , day ) ; return cal . getTime ( ) ; }
Get the date for the given values .
128,790
public String getGroupedValue ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( getRegisternummer ( ) ) . append ( Constants . DOT ) ; sb . append ( getAccountType ( ) ) . append ( Constants . DOT ) ; sb . append ( getPartAfterAccountType ( ) ) ; return sb . toString ( ) ; }
Returns the Kontonummer as a String formatted with . s separating the Registernummer AccountType and end part .
128,791
public static List < Fodselsnummer > getFodselsnummerForDateAndGender ( Date date , KJONN kjonn ) { List < Fodselsnummer > result = getManyFodselsnummerForDate ( date ) ; splitByGender ( kjonn , result ) ; return result ; }
Returns a List with valid Fodselsnummer instances for a given Date and gender .
128,792
public static Fodselsnummer getFodselsnummerForDate ( Date date ) { List < Fodselsnummer > fodselsnummerList = getManyFodselsnummerForDate ( date ) ; Collections . shuffle ( fodselsnummerList ) ; return fodselsnummerList . get ( 0 ) ; }
Return one random valid fodselsnummer on a given date
128,793
public static List < Fodselsnummer > getManyDNumberFodselsnummerForDate ( Date date ) { if ( date == null ) { throw new IllegalArgumentException ( ) ; } DateFormat df = new SimpleDateFormat ( "ddMMyy" ) ; String centuryString = getCentury ( date ) ; String dateString = df . format ( date ) ; dateString = new StringBuil...
Returns a List with with VALID DNumber Fodselsnummer instances for a given Date .
128,794
public static List < Fodselsnummer > getManyFodselsnummerForDate ( Date date ) { if ( date == null ) { throw new IllegalArgumentException ( ) ; } DateFormat df = new SimpleDateFormat ( "ddMMyy" ) ; String centuryString = getCentury ( date ) ; String dateString = df . format ( date ) ; return generateFodselsnummerForDat...
Returns a List with with VALID Fodselsnummer instances for a given Date .
128,795
public static GeoParser getDefault ( String pathToLuceneIndex , int maxHitDepth , int maxContentWindow ) throws ClavinException { return getDefault ( pathToLuceneIndex , maxHitDepth , maxContentWindow , false ) ; }
Get a GeoParser with defined values for maxHitDepth and maxContentWindow .
128,796
public static GeoParser getDefault ( String pathToLuceneIndex , int maxHitDepth , int maxContentWindow , boolean fuzzy ) throws ClavinException { try { LocationExtractor extractor = new ApacheExtractor ( ) ; return getDefault ( pathToLuceneIndex , extractor , maxHitDepth , maxContentWindow , fuzzy ) ; } catch ( IOExcep...
Get a GeoParser with defined values for maxHitDepth and maxContentWindow and fuzzy matching explicitly turned on or off .
128,797
public static GeoParser getDefault ( String pathToLuceneIndex , LocationExtractor extractor , int maxHitDepth , int maxContentWindow , boolean fuzzy ) throws ClavinException { Gazetteer gazetteer = new LuceneGazetteer ( new File ( pathToLuceneIndex ) ) ; return new GeoParser ( extractor , gazetteer , maxHitDepth , maxC...
Get a GeoParser with defined values for maxHitDepth and maxContentWindow fuzzy matching explicitly turned on or off and a specific LocationExtractor to use .
128,798
public static Kidnummer mod10Kid ( String baseNumber , int targetLength ) { if ( baseNumber . length ( ) >= targetLength ) throw new IllegalArgumentException ( "baseNumber too long" ) ; String padded = String . format ( "%0" + ( targetLength - 1 ) + "d" , new BigInteger ( baseNumber ) ) ; Kidnummer k = new Kidnummer ( ...
Create a valid KID numer of the wanted length using MOD10 . Input is padded with leading zeros to reach wanted target length
128,799
public static Kidnummer mod11Kid ( String baseNumber , int targetLength ) { if ( baseNumber . length ( ) >= targetLength ) throw new IllegalArgumentException ( "baseNumber too long" ) ; String padded = String . format ( "%0" + ( targetLength - 1 ) + "d" , new BigInteger ( baseNumber ) ) ; Kidnummer k = new Kidnummer ( ...
Create a valid KID numer of the wanted length using MOD11 . Input is padded with leading zeros to reach wanted target length