lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
Java | I 'm trying to parse Year String values in the range from 0 to 1000 with java.time.Year.parse ( ) , however parsing fails with java.time.format.DateTimeParseException : Text '999 ' could not be parsed at index 0.The javadoc of Year.parse states : Example test to reproduce this issue : The test throws the exception when... | Obtains an instance of Year from a text string such as 2007 . The string must represent a valid year . Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol . @ Testpublic void parse_year ( ) { for ( int i = 2000 ; i > = 0 ; i -- ) { System.out.println ( `` Parsing year : `` + i ) ; Year.par... | JSR310 Year.parse ( ) throws DateTimeParseException with values < 1000 |
Java | I am trying to get my head around how to approach what initially seems a `` simple '' problem.I have UserAccounts that can have MANY Purcahses BUT business logic dictates can only have one Purchase in a PurchaseState.IDLE state ( a field on the entity ) . A purchase is IDLE when first created.I have a repo with a metho... | boolean existsByPurchaseStateInAndUserAccount_Id ( List < PurchaseState > purchaseState , long userAccountId ) ; | Concurrent requests transaction to prevent unwanted persistence |
Java | I came across a problem with generics which keeps me puzzled of how the compiler actually deals with generic types . Consider the following : The following will not compile because both generic types are reduced to Object when calling thenComparing : But if I break them up like the following example , everything compil... | // simple interface to make it a MCVEstatic interface A < F , S > { public F getF ( ) ; public S getS ( ) ; } static < V , S > Comparator < A < V , S > > wrap ( Comparator < S > c ) { return ( L , R ) - > c.compare ( L.getS ( ) , R.getS ( ) ) ; } Comparator < A < String , Integer > > c = wrap ( ( L , R ) - > Integer.co... | Generics - compiler inconsistency [ jdk 1.8.0_162 ] |
Java | I was exploring Fork/Join framework and its possible speed benefits through factorial counting , when discovered that my sequential recursive algorithm breaks at a certain point . To be precise , when I try to count 46342 ! the result from RecursiveCounter is wrong , but before that value it is always right and is the ... | public class RecursiveCounter implements FactorialCounter , RangeFactorialCounter { @ Override public BigInteger count ( int number ) { return count ( 1 , number ) ; } @ Override public BigInteger count ( int from , int to ) { int middle = ( from + to ) > > 1 ; BigInteger left ; BigInteger right ; if ( middle - from > ... | Recursive algorithm stops working after certain depth |
Java | I 'm developing a website for my company , and I use Spring as my backend.There is a situation now , where I need to use one of my Utils method twice , but for different DAOs.In order to avoid code duplication , I was wondering how can I use Java Generics in order to make this method usable for both cases . The method ... | SeverityCount calculateSeveritiesCount ( List < ? > events ) { if ( null == events ) { return new SeverityCount ( ) ; } if ( events.get ( 1 ) instanceof EventDAO ) { events = ( List < EventDAO > ) events ; } else if ( events.get ( 1 ) instanceof EventsByAreaDAO ) { events = ( List < EventsByAreaDAO > ) events ; } Map <... | Accept generic List as parameter and use it base on its type |
Java | I 'm writing an Eclipse plugin that creates an alternative IDetailPane for the debugger.I created an implementation of IDetailPaneFactory that returns my IDetailPane 's ID and it 's .getDetailPaneTypes ( ... ) method gets called.However , now the field DetailPaneManager.fPreferredDetailPanes is a Map < Set < String > ,... | { [ DefaultDetailPane ] =DefaultDetailPane [ DefaultDetailPane , MyDetailPane ] =DefaultDetailPane } | How can I change the default IDetailPane in an Eclipse plugin ? |
Java | I have Answer entity which has values like thisI need to get answers group by questions I could get List < Answer > like thisbut I ca n't find a way to get it as List < String > rather than List < Answer > ? | question answer 1 x2 y3 z4 p1 x2 q3 r Map < Integer , List < String > > < 1 , [ x , x ] 2 , [ y , p ] 3 , [ z , r ] 4 , [ p ] > Map < Integer , List < Answer > > collect = answers .stream ( ) .collect ( Collectors.groupingBy ( Answer : :getQuestion ) ) ; | How to use group by to get a list of new column in an entity |
Java | The question is : Suppose o is a reference of type Object that is pointing to a type A object that contains a f method and a toString method . Both toString and f have no parameters . show the statement that calls the toString method and the statement that calls the f method.is the answer : | f ( ) ; toString ( ) ; | exam sample , curious if i got it right |
Java | I 'm writing an application ( for personal use ) that allows me to send a string over usb to an Arduino.I wrote this method for sending the data : sending is a boolean value that I use to indicate whether a Thread is sending data . The transmissionCooldown is simply to enforce a certain waiting period before data can b... | /** * Sends the data to the Arduino . * A new Thread is created for sending the data . * A transmission cool-down is started before send ( ) method can be used again . * @ param data the data to send to the Arduino */ public void send ( String data ) { if ( connected & & ! sending ) { // Set 'sending ' to true so only ... | How to wait for the end of a long process ( on another thread ) ? |
Java | Take a HashSet in Java . Put a string in it . Serialize it . You end up with some bytes - bytesA.Take bytesA , deserialize it back as an Object - fromBytes . Now reserialize fromBytes and you 've got yourself another array of bytes - bytesB.Strangely enough , these two byte arrays are not equal . One byte is different ... | Set < String > stringSet = new HashSet < > ( ) ; stringSet.add ( `` aaaaaaaaaa '' ) ; //Serialize itbyte [ ] bytesA ; try ( ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ) { ObjectOutputStream out = new ObjectOutputStream ( bos ) ; out.writeObject ( stringSet ) ; out.flush ( ) ; bytesA = bos.toByteArray ( )... | Why do HashSets not have a stable serialization ? |
Java | ... where v is an object of a certain class.When I try to compile this , I get : error : can not find symbol Method m = c.getMethod ( `` something '' ) ; ^Method is a type which resides in java.lang.reflect.Method . By my knowledge java.lang and anything subsequent is imported by default , but I even did so explicitly ... | Class c = v.getClass ( ) ; try { Method m = c.getMethod ( `` something '' ) ; if ( ! m.getReturnType ( ) .equals ( Boolean.TYPE ) ) { return false ; } } catch ( NoSuchMethodException e ) { return false ; } import java.lang . * ; | Error on storing a method in a variable |
Java | On a recent question I came accross the use of the Number abstract class.Now since Java 8 is here , there are default methods , so Number could be an interface and written as : Would old code using the Number abstract class still compile if this were the case ? Are there any actual benefits in making Number an interfac... | public interface Number { public int intValue ( ) ; public long longValue ( ) ; public float floatValue ( ) ; public double doubleValue ( ) ; default public byte byteValue ( ) { return ( byte ) intValue ( ) ; } default public short shortValue ( ) { return ( short ) intValue ( ) ; } } | Would it create issues if Number were to be implemented as an interface ? Are there benefits ? |
Java | I am making a language app for my learning purposes and to practice in Android I want to store all lessons audio in an array and i have an activity for each lesson when i press for example Audio 1 it popups a new activity with a player ( AudioPopup.java ) but the problem i dont't want to make a popup to play certain au... | public class AudioPopup extends AppCompatActivity { SeekBar seek_bar ; ImageView play_button , pause_button ; MediaPlayer player ; ImageView exitPlayer ; Handler seekHandler = new Handler ( ) ; private int [ ] audioFiles ; @ Override public void onCreate ( Bundle savedInstanceState ) { super.onCreate ( savedInstanceSta... | How to play an Audio file when a certain button is clicked from previous activiy |
Java | I used StringTokenizer to get the tokens of a string . But I get two different outputs when I tried to print all the tokens in that StringTokenizer , using a for-loop and a while-loop.when I tried to print all the tokens using a for loopoutputShe is an attractive girlwhen I tried to print all the tokens using a while l... | String string= '' She is an attractive girl , is n't she ? `` ; StringTokenizer stringTokenizer=new StringTokenizer ( string , '' , '' ) ; for ( int i=0 ; i < stringTokenizer.countTokens ( ) ; i++ ) System.out.println ( stringTokenizer.nextToken ( ) ) ; while ( stringTokenizer.hasMoreElements ( ) ) System.out.println (... | Why is StringTokenizer giving different outputs when used in a while loop and a for loop |
Java | I 'm having problems getting a method from one class to work if I put the objects into a set . So I have ... There is lots of other code which I can post if needed but I 'm not allowed to change the Employee class.So for my code I have to create a class for a Set of Employees which I 've done withNow I need a method th... | public class Employee { /* instance variables */ private String firstName ; private String employeeNumber ; public Employee ( String employNum ) { super ( ) ; this.employeeNumber = employNum ; } public String getFirstName ( ) { return this.firstName ; } public class Records { public Set < Employee > employeeSet = new H... | Using a method from one class into a set |
Java | When I execute an unsigned right shift as follows : I get 1111111111111111.So , the value is shifted right , but filled with 1s , which seems to be the same behavior as > > However , I was expecting it to fill with 0s regardless of sign , yielding the following:0000011111111111Here is a relevant REPL to play with my co... | short value = ( short ) 0b1111111111100000 ; System.out.println ( wordToString ( value ) ) ; value > > > = 5 ; | Why is my Java short getting filled with 1s with an unsigned right shift ? |
Java | I have a StringI want to split this string in java from all commas before @ Team appears . The result should look like : My java code uses regex ( ? < = ) ( ? = @ Team ) : It does the job but there 's a lot of boilerplate . Is there any regex so that I can do all this stuff in one shot ? Thanks . | Jon , Kim , Hem , David , Gary , Bryan , Otis , Neil , Blake , Greg , @ Team=Cowboys , Chargers , Panthersm , Royals , Kings , Warriors JonKimHemDavidGaryBryanOtisNeilBlakeGreg @ Team=Cowboys , Chargers , Panthersm , Royals , Kings , Warriors String data = `` Jon , Kim , Hem , David , Gary , Bryan , Otis , Neil , Blake... | Split Everything before a particular pattern |
Java | Related to that question.I know about wildcard capturing . For instance , the following could be used for reversing a list : Now I 'm trying to write the same thing for that kind of situation : I expected that it was compiled fine as well . Is it possible to capture wildacrds for methods with two or more parameters tha... | public static void reverse ( List < ? > list ) { rev ( list ) ; } //capturing the wildcardprivate static < T > void rev ( List < T > list ) { List < T > tmp = new ArrayList < T > ( list ) ; for ( int i = 0 ; i < list.size ( ) ; i++ ) { list.set ( i , tmp.get ( list.size ( ) -i-1 ) ) ; } } private int compare ( Comparab... | Why ca n't we capture wildcards for the method with two parameters ? |
Java | I came across this thing which I havent noticed before.Here is a normal expressionso this just prints 9 as an int . Now If I put the first value String instead of an int 0 Here the value 9 is printed as a string and not as an int . To confirm this just try to add this with another integerNow this results in 13 but if y... | int a = 5 ; System.out.println ( ( ( a < 5 ) ? 0 : 9 ) ) ; int a = 5 ; System.out.println ( ( ( a < 5 ) ? `` asd '' : 9 ) ) ; int a = 5 ; System.out.println ( ( ( ( a < 5 ) ? 0 : 9 ) + 4 ) ) ; `` The operator + is undefined for the argument type ( s ) Object & Serializable & Comparable < ? > , int '' . | Java ternary operator datatype conversion based on the first value ? |
Java | In a Java application I 'm working on , I have a number of enums which ended up having a static fromString method in them for converting a string to its actual enum value.So , I thought I could have a `` base '' class from which all my enums can extend without have to repeat that code all the time . Since enums can not... | public interface IBaseEnum { String enumVal = null ; public static < T extends Enum < T > & IBaseEnum > Enum < T > fromString ( String strVal ) { if ( strVal == null ) return null ; // T.values ( ) has error because T is not recognised to have the method values ( ) for ( T myEnum : T.values ( ) ) { if ( myEnum.enumVal.... | How to inherit functionalities to reduce repeating codes in enums ? |
Java | I know that float arithmetic is tricky , but I am not sure if it is possible to get a mistake if you have a division followed by the inverse multiplication . Written in code , is it possible , that this method will return false : | public boolean calculate ( float a , float b ) { float c = a / b ; return ( a == ( c * b ) ) ; } | Is it possible to get floating point error in this case ? |
Java | Is there a way to template astract methods so that a parameter to an abstract method will be typed the same as the implementing subclass ? In other words if we have : Then each subclass takes its own type as a parameter to this method . I would like to avoid using an interface or reflection . | class Super { abstract void a_method ( < Sub > param ) ; } class Sub_A extends Super { void a_method ( Sub_A param ) { ... } class Sub_B extends Super { void a_method ( Sub_B param ) { ... } } | Is there a way to template astract methods so that a parameter to an abstract method will be typed the same as the implementing subclass ? |
Java | How do I write following code in a simple for loop : | int asInt = ( valueAsBytes [ 3 ] & 0xFF ) | ( ( valueAsBytes [ 2 ] & 0xFF ) < < 8 ) | ( ( valueAsBytes [ 1 ] & 0xFF ) < < 16 ) | ( ( valueAsBytes [ 0 ] & 0xFF ) < < 24 ) ; | How to write attached code block in a for loop |
Java | list.toArray ( ) returns Object [ ] and it contains only int [ ] .So i thought i can cast it directly into int [ ] [ ] .But actually i was wrong , it will lead to a cast exception.it 's ok this way , but i 'm still confused.Why does it throw that exception ? | list.toArray ( new int [ list.size ( ) ] [ ] ) ; List < int [ ] > list = new ArrayList < > ( ) ; //some code//cast exceptionreturn ( int [ ] [ ] ) list.toArray ( ) ; //this way is okreturn list.toArray ( new int [ list.size ( ) ] [ ] ) ; | confused , why Object [ ] objs ( type of objs [ i ] is int [ ] ) cant cast into int [ ] [ ] |
Java | when I am running this code I am getting the following results : expected is : Does anyone know why I am getting these results ? | public class Container { private int value ; public Container ( int value ) { this.value=value ; } public int getValue ( ) { return this.value ; } public int sum ( Container c ) { return this.value+c.getValue ( ) ; } public void main ( ) { Container c1=new Container ( 1 ) ; Container c2=new Container ( 2 ) ; System.out... | Wrong answer with Addition |
Java | As per the question , let 's say you have the following code : Does k get compared to rand.nextInt ( 10 ) only once , when the loop starts running , so that there 's an equal chance of the loop running at every interval between 0 and 9 ? Or does it get compared each iteration of the loop , making it more likely for low... | Random rand = new Random ( ) ; for ( int k = 0 ; k < rand.nextInt ( 10 ) ; k++ ) { //Do stuff here } | When using a random parameter in a loop 's qualifying comparison , does it call the randomization function once or each time the loops runs ? |
Java | I have an interface called A : I then have two subclasses ( B and C ) that implement this interface , but each of them pass a different type to X lets say B passes type foo and C passes type bar : What am I doing wrong and why does n't this work ? The compiler keeps telling me that `` Method does not override method fr... | public interface A { void X ( T t ) ; } public class B implements A { @ Override public < T extends foo > void X ( T type1 ) } public class C implements A { @ Override public < T extends bar > void X ( T type2 ) } | How can I override this method in this interface ( see code ) ? |
Java | This is my code : I expected the output to print values from 0 to 999,999 with spaces in between . However , my output is : Why is my for loop skipping hundreds of thousands of values ? I tried replacing int with long and double . Both skip values when running . Any help ? I am just trying to create an ArrayList of val... | import java.util.List ; import java.util.ArrayList ; public static void main ( String [ ] args ) { List < Integer > possible = new ArrayList < Integer > ( ) ; for ( int i=0 ; i < 1000000 ; i++ ) { possible.add ( i ) ; } for ( int i : possible ) { System.out.println ( i ) ; } } 208850209850210850211 ... all the way to 9... | For-loop not evaluating all entries |
Java | ClassLoaderHelper has no meaningI did n't find any usages for mapAlternativeName which ca n't be overridden ( static ) Also comment has no real meaningIs it just leftover from previous version or just a designating Helper class for future use ? EDITI found a relevant bug ( Resolution : Unresolved ) JDK-7157665 : Use Cl... | class ClassLoaderHelper { private ClassLoaderHelper ( ) { } static File mapAlternativeName ( File lib ) { return null ; } /** * Returns an alternate path name for the given file * such that if the original pathname did not exist , then the * file may be located at the alternate location . * For most platforms , this be... | JDK 's ClassLoaderHelper has no usage |
Java | I have few Maps with the same key name and different value types . What I want to achieve is to , out of this three different maps , compose a new Map : Where Foo is a class : Is it possible to do it with Streams API ? | Map < String , Long > map1 = ... Map < String , Long > map2 = ... Map < String , String > map3 = ... Map < String , Foo > fooMap = ... class Foo { long val1 ; long val2 ; String val3 ; } | Mapping few streams |
Java | Hi I am working with java 8 . Below is the case : I have an empty interface AsyncResponse like below : And I have a model APIResponseAnd finally I have a service using Retrofit2 to make my API response : Now when I call the APIRepository like below : I get an error : java : incompatible types : retrofit2.Call ( com.per... | package com.personal.carrot.core.models ; public interface AsyncResponse { } package com.personal.carrot.core.models ; import org.codehaus.jackson.annotate.JsonProperty ; public class APIResponse implements AsyncResponse { @ JsonProperty ( `` numberOfFeatures '' ) public Long numberOfFeatures ; } public interface APIRe... | Ca n't use parent as variable types and yet receive child types |
Java | I 'm trying to find a element in selenium with this XPATH . I get this in firefox web browser.HTML codeMy Selenium CodeBut it 's not working . Help me . | /html/body/div [ 5 ] /div [ 2 ] /div [ 9 ] /div [ 1 ] /div [ 2 ] /div/div [ 2 ] /div [ 2 ] /div/div/div [ 1 ] /div [ 2 ] /div [ 1 ] /a < a href= '' /url ? sa=t & amp ; rct=j & amp ; q= & amp ; esrc=s & amp ; source=web & amp ; cd= & amp ; cad=rja & amp ; uact=8 & amp ; ved=2ahUKEwiw7cbBv6LqAhVMAHIKHbbFCUYQFjAAegQIBxAB ... | Find Xpath for element in Selenium Java |
Java | I have some stings in the styles/string.xml as below : and I have a textView and a button in my current activity . When I click the button , the text in the textView has to change ( to the next sting ) according to what is currently shown . That is , if the current text in textView is string1 , then it should change to... | < string name= '' string1 '' > something < /string > < string name= '' string2 '' > some other thisn < /string > < string name= '' string3 '' > asdfgh jkl < /string > < string name= '' string4 '' > qwerty uiop < /string > ... count = 0 ; public void onClick ( View v ) { count++ ; str= '' R.string.string '' + count ; te... | Android studio - Change string in textView |
Java | Given the following list if IP address ranges.Assuming that iterating all the addresses within all the ranges and storing them in a HashSet will use too much memory.So we need to maintain the ranges , which are actually just shifted numbers anyway ( low and high ) .How would one store the ranges in a tree and then use ... | LOW HIGH192.168.10.34 192.168.11.200200.50.1.1 200.50.2.2 | What is the correct java data structure and search algorithm to search a set of ip ranges for inclusion |
Java | I have an object where the type of generic T is lost at some point through a giant interface chain . I was wondering if it is possible to use a function to regain some type safety by checking the types : However , this implementation produces an `` Unchecked cast : 'T ' to ' R ' '' warning . Is there an implementation ... | private T metaData ; // type of T is lostpublic < R > R getMetaData ( Class < R > className ) { assert className.isInstance ( metaData ) ; return ( R ) metaData ; } | Solving peculiar 'unchecked cast ' warning |
Java | I was reading through one of Oracle 's lambda expression tutorials , and came across the following code : http : //www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.htmlMy question is why did n't they implement Runnable when creating the class ? Since they overrode the run method when init... | public class RunnableTest { public static void main ( String [ ] args ) { System.out.println ( `` === RunnableTest === '' ) ; // Anonymous Runnable Runnable r1 = new Runnable ( ) { @ Override public void run ( ) { System.out.println ( `` Hello world one ! `` ) ; } } ; // Lambda Runnable Runnable r2 = ( ) - > System.out... | Can you implement an interface during initialization ? |
Java | Let 's say I have an abstract class Animal with an abstract methodthe problem is , if I create subclasses Snake and Armadillo , a call like this would then be legal : But I only want snakes to be able to mate with snakes . I need to be able to define something like this : Is this possible in Java ? | public abstract Animal mateWith ( Animal mate ) ; mySnake.mateWith ( myArmadillo ) ; public abstract Animal_Of_My_Class mateWith ( Animal_Of_My_Class mate ) ; | How can I have an abstract method that accepts an argument of type `` my type '' ? |
Java | CASE 1Output : 7CASE 2Output : Compilation error : method fun ( byte ) is not applicable for the argument ( int ) .My question is : How come in case 1 , 7 is implicitly cast to byte from an int , while in case 2 it is forcing the programmer to cast it explicitly ? 7 is still in the range of byte.Please suggest . | byte b = 7 ; // why do n't I need to cast 7 to byte in this case ? byte b = ( byte ) 7 ; System.out.println ( b ) ; static void fun ( byte b ) { System.out.println ( b ) ; } public static void main ( String [ ] args ) { fun ( 7 ) ; // Compiler gives error because a cast is missing here . } | Java Assignments query |
Java | I noticed I can do : ... and set this class as parent of another and set the same constant with another value like : Since compiler does not complaing , this lead me to the questions above : Are these variables really the same ? I would say it gets the most specific , so in that case from the Ack class . Is that true ?... | public class Message { public static final int MIN_BYTES = 5 ; } public class Ack extends Message { public static final int MIN_BYTES = 1 ; } | Java Constants inheritance |
Java | BackgroundDeveloping a rudimentary , open-source keyboard and mouse on-screen display desktop application for screen casting , called KmCaster : The application uses the JNativeHook library to receive global keyboard and mouse events , because Swing 's Key and Mouse listeners are restricted to receiving events directed... | import org.jnativehook.GlobalScreen ; import org.jnativehook.NativeHookException ; import org.jnativehook.keyboard.NativeKeyEvent ; import org.jnativehook.keyboard.NativeKeyListener ; import javax.swing . * ; import static java.util.logging.Level.OFF ; import static java.util.logging.Logger.getLogger ; import static ja... | Case of the confounding key press caper |
Java | §5.1.2 and §5.6.2 do not mention how numeric promotion and widening work for constants.The following gives an error as expected : But if they are declared final , it compiles without error : Why is that ? And which section of the specs explains that ? My guess is that they are compile time constants and therefore treat... | short a = 2 ; short b = 3 ; short s = a + b ; // error : incompatible types : possible lossy conversion from int to short final short a = 2 ; final short b = 3 ; short s = a + b ; // no error | Does numeric promotion apply to constants in Java ? |
Java | input : he is a good , person.desired output : { `` he '' , '' is '' , '' a '' , '' good '' , '' person '' } program output : { `` he '' , '' is '' , '' a '' , '' good '' , '' `` , '' person '' } am asking for first time here . need pointers for next time | import java.io . * ; import java.util . * ; public class Solution { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System.in ) ; String s = scan.nextLine ( ) ; String [ ] ace = s.trim ( ) .split ( `` [ \\s+ ! , ? ._ ' @ ] '' ) ; scan.close ( ) ; System.out.println ( ace.length ) ; for ( Stri... | Java split function reading space after a character as an empty string |
Java | I translated a word by getting HTML Code from translation website.the translation is right while running the code with NetBeans , but while running with jar file , I see unknown language ... any help , please ... ..From netbeans : From jar file : the code : | ` /* * To change this license header , choose License Headers in Project Properties . * To change this template file , choose Tools | Templates * and open the template in the editor . */package javaapplication5 ; import java.util.ArrayList ; import java.util.Scanner ; import javax.swing.JOptionPane ; public class Main ... | Translation showing strange characters |
Java | If I have this , Since we do n't know what the element type of c stands for , we can not add integers to it . But if I do like , Why the addition in the 2nd example is allowed ? | Collection < ? extends Number > c = new ArrayList < > ( ) ; c.add ( new Integer ( 1 ) ) ; // Compile time error List < List < ? extends Number > > history = new ArrayList < > ( ) ; List < Integer > integers = new ArrayList < > ( ) ; integers.add ( new Integer ( 1 ) ) ; List < Double > doubles = new ArrayList < > ( ) ; ... | List of List of Numbers with a Bounded wildcard type |
Java | In the above code , there is no class defined but the program is still getting executed . But as far as I know , there can not be any static method inside an Interface . And , every program should contain at least one main function . | interface Main { public static void main ( String [ ] args ) { System.out.println ( `` Inside main '' ) ; int a = 4 , b = 6 ; System.out.println ( a+b ) ; } } | Why is the following code working with an interface but without any class defined ? |
Java | I need to make a Java class which can receive a single enum value out of many . For example : Since enums ca n't be extended , how can I define a single member which must be one of the enums ? | public class MyClass { public enum enumA { .. } public enum enumB { .. } public enum enumC { .. } public enum enumD { .. } private OneOfTheEnumsAboveMember enumMember ; } | Save a single enum value out of many types possible |
Java | In this code example , what 's the static type of e in the catch block ? It seems to be effectively Exception , but when I hover over it in my IDE it says IOException | NumberFormatException . Is this a special type that only applies to multiple exceptions in catch blocks or does it generalize to other types ? | try { ... . } catch ( IOException | NumberFormatException e ) { //what 's the static type of e in here ? Is it Exception ? System.out.println ( e.getClass ( ) ) ; } | What 's the static type of an exception in a multiple exception catch clause ? |
Java | I am reading a book 'Java Network Programming ( Elliotte Rusty Harold ) '.And I met the following sentence , after this code . ... intermixing calls to different streams connected to the same source may violate several implicit contracts of the filter streams.And the following code came out.I understand that this simpl... | FileInputStream fin = new FileInputStream ( `` data.txt '' ) ; BufferedInputStream bin = new BufferedInputStream ( fin ) ; InputStream in = new FileInputStream ( `` data.txt '' ) ; in = new BufferedInputStream ( in ) ; | What 's implicit contracts of the filter streams in java ? |
Java | I tried to install pyCOMPSs ( v1.4 ) on a Cluster system using theinstallation script for Supercomputers.The script terminates with the following error : | libtool : link : ranlib .libs/libcbindings.alibtool : link : ( cd `` .libs '' & & rm -f `` libcbindings.la '' & & ln -s '' ../libcbindings.la '' `` libcbindings.la '' ) make [ 1 ] : Entering directory ` /home/xxx/repos/pycompss/COMPSs/Bindings/c/src/bindinglib ' /usr/bin/mkdir -p'/home/cramonco/svn/compss/framework/tru... | Autoreconf failing when installing ( py ) COMPSs in a clusters |
Java | I think that , for the most part , I understand bounded types , and the differences between , for example , List < ? extends MyClass > , List < ? super MyClass > and List < MyClass > . But when it comes to the implementation of classes and generic methods , I do not understand what < T extends MyClass > brings to the t... | public class Box < T > { private T t ; public void set ( T t ) { this.t = t ; } public T get ( ) { return t ; } public < U extends Number > void inspect ( U u ) { System.out.println ( `` T : `` + t.getClass ( ) .getName ( ) ) ; System.out.println ( `` U : `` + u.getClass ( ) .getName ( ) ) ; } public static void main (... | What 's the practical difference between ` class < T extends A > { } ` and a ` class { } ` that uses A ? |
Java | I have once read the following code from a book about method references.When I look up from the File API for the listFiles method , I see it only has the following methods : I have tried the code and it works . But while the API states it accepts either FileFilter or FilenameFilter , why the code can work ? My understa... | File [ ] hiddenFiles = new File ( `` . `` ) .listFiles ( File : :isHidden ) listFiles ( FileFilter filter ) listFiles ( FilenameFilter filter ) ( File file ) - > file.isHidden ( ) boolean accept ( File pathname ) File [ ] hiddenFiles = new File ( `` . `` ) .listFiles ( new FileFilter ( ) { public boolean accept ( File ... | Method references of listFiles |
Java | I have a list of Objects of ClassA ( fields for example : id , name , phone ) and need to set each of those fields in to another list of Objects of ClassB ( fields : studentId , studentName and studentPhone ) . is there a simple way in Java 8 ? Basically , ClassA is my DTO and ClassB is DAO object . For example : here ... | List < ClassA > list1 = new ArrayList < > ( ) ; list1.add ( new ClassA ( 12 , '' John '' , '' 1111111111 '' ) ) List < ClassB > list2 = new ArrayList < > ( ) ; | copying each field of an object of Class A to each field of an object of classB in list |
Java | I am trying to format a date inside a Functional Interface but I do n't know if it is possible | SimpleDateFormat dt1 = new SimpleDateFormat ( `` ddmmyyyyy '' ) ; List < MenuPrice > menuPrices = findAll ( restaurant ) ; menuPrices.parallelStream ( ) .collect ( Collectors.groupingBy ( dt1.format ( MenuPrice : :getUpdateDate ) ) ) ; | Formatting dates inside a Function < T , R > |
Java | I have built a small JavaFX with 2 scenes . The user can input 3 fields ( text ) and upload some documents for an object.So I was thinking when the user clicks save a json object is created and appended to a list of Json objects . Those Json objects are then written into a file.This is of what I was thinking : These wi... | { `` objects '' : { `` object1 '' : { `` field1 '' : `` foo '' `` field2 '' : `` foo '' `` field3 '' : `` foo '' `` folderwithfileslocation '' : `` C : /ProgramFiles/myapp/foobar/ '' } , `` object2 '' : { `` field1 '' : `` foobar '' `` field2 '' : `` foobar '' `` field3 '' : `` foobar '' `` folderwithfileslocation '' :... | Java Database Correct Approach |
Java | So I have a custom Button , that runs good , no errors.Here is the code : Here is my main problem- when ever I click ANYWHERE on the JFrame , it says the button was clicked , but the only part I want to have the action listener on is the blue rectangle I have on the JFrame . ( You 'll under stand my issue if you run my... | import java.awt . * ; import java.awt.event . * ; import java.awt.geom . * ; import java.util.ArrayList ; import javax.swing.JButton ; import javax.swing.JComponent ; import javax.swing.JFrame ; public class LukeButton extends JComponent implements MouseListener { public static void main ( String [ ] args ) { JFrame fr... | How can I size my custom component appropriately ? |
Java | I am using retrofit to post text data , single image and multiple image in single POST request . I tried some method but they did not work form me . I 've attached PostMan screenshot and previous code I have done below.Postman screenshotSample code i 've tried : apiInterface class : method to post data : Please help me... | public interface PostSurveyFormApiInterface { @ Multipart @ POST ( `` Shared/InsertDirectSurveyAsync '' ) Call < ResponseBody > postDirectSurveyForm ( @ Header ( `` Authorization '' ) String auth , @ Header ( `` Content-Type '' ) String contentType , @ Part ( `` CompanyName '' ) RequestBody companyName , @ Part ( `` Ad... | How to post text data , single image and multiple image in single POST method using retrofit in Android ? |
Java | So what I am trying to do is create this : I am using a gridbag layout and here is what I have so far : It creates something like : How would I push up the panels so they are touching each other like in my first picture . I looked through the GridBagConstraints but I could not find anything that looked like it would wo... | public class board { public static void addComponentsToPane ( Container pane ) { pane.setLayout ( new GridBagLayout ( ) ) ; GridBagConstraints c = new GridBagConstraints ( ) ; JPanel leftTop = new JPanel ( ) ; leftTop.setPreferredSize ( new Dimension ( 251,300 ) ) ; leftTop.setBackground ( Color.black ) ; c.fill = Grid... | trouble with GridBagLayout and panels |
Java | I have implemented an application with COMP Superscalar and I got task failed . Looking at the standard error file ( job1_NEW.err ) file I got a File Not Found exception but the file exists in my computer . Any idea what could be the error ? EDIT : Added the resources and the project filesResources.xmlProject.xmlMethod... | < Resource Name= '' 172.16.8.2 '' > < Capabilities > < Host > < TaskCount > 0 < /TaskCount > < Queue > short < /Queue > < Queue/ > < /Host > < Processor > < Architecture > x86_64 < /Architecture > < Speed > 3.0 < /Speed > < CoreCount > 4 < /CoreCount > < /Processor > < OS > < OSType > Linux < /OSType > < MaxProcessesPe... | File not found in task defined in COMPSs |
Java | When I try to convert hexadecimal number to integer type , negative numbers with parseInt or valueOf methods , the method throws NumberFormatException for negative numbers . I could n't find the answer anywhere . | System.out.println ( Integer.parseInt ( `` 7FFFFFFF '' , 16 ) ) ; //this is ok.System.out.println ( Integer.parseInt ( `` FFFFFFFF '' , 16 ) ) ; //this throws ExceptionSystem.out.println ( Integer.valueOf ( `` FFFFFFFF '' , 16 ) ) ; //this throws Exception | numeric type parse functions exception with negative numbers |
Java | Need help for a case on Stream with groupingByI would like to be able to group by 2 different fields and have the sum of other BigDecimal fields , according to the different groupings . Here is my entity : Let 's suppose I have as input this list : The result should beI have a beginning of solution , below , but I bloc... | public class Customer { private String name ; private String type ; private BigDecimal total ; private BigDecimal balance ; // Setter , getter } Customer custa = new Customer ( `` A '' , `` STANDARD '' , new BigDecimal ( `` 1000 '' ) , new BigDecimal ( `` 1500 '' ) ) ; Customer custa1 = new Customer ( `` A '' , `` VIP ... | Java Stream group by 02 fields and aggregate by sum on 2 BigDecimal fields |
Java | Please see this Java ClassThe output of this code is `` string called '' but I am not able to understand that how compiler is able to resolve between Object and String.Moreover , examine this code fragmentHere we get a compile time error related to ambiguous call ( which is quite obvious ) .Any good explanations for th... | class Demo { public static void a ( String s ) { System.out.println ( `` string called '' ) ; } public static void a ( Object a ) { System.out.println ( `` Object called '' ) ; } public static void main ( String ... asrgs ) { a ( null ) ; } } class Demo { public static void a ( String s ) { System.out.println ( `` stri... | Call seems ambiguous , but runs perfectly with unexpected output |
Java | I am trying to create regexp to find duplicated commas , like here : For now my pattern is : \w*\ ( [ \w\ [ \ ] , ? + ] +\ ) which is not working.How can one specify quantity for items in character class ? | baz ( uint32 , ,bool ) | regexp specify counter in character class |
Java | I do n't understand something , I have this code : This generate and exception : But if I change the pattern to have a separator between date part and time part : `` yyyyMMdd_HHmmssSSS '' it works as expected.Why is a formatter ca n't parse its own result ? | DateTimeFormatter fmt = DateTimeFormatter.ofPattern ( `` yyyyMMddHHmmssSSS '' ) ; System.out.println ( LocalDateTime.parse ( LocalDateTime.now ( ) .format ( fmt ) , fmt ) ) ; Exception in thread `` main '' java.time.format.DateTimeParseException : Text '20200605102607066 ' could not be parsed at index 0 at java.time.fo... | DateTimeFormatter exception parsing its own print result |
Java | I have two Java LongStreams and I want to remove values which are present in one stream from the other.The LongStream does not have a contains method and I dont know how to use anyMatch in this case because the value to be checked is coming from another stream and is not in a variable or constant . | LongStream stream 1 = ... LongStream stream 2 = ... stream2 = stream2.filter ( e- > stream1.contains ( e ) ) ; | LongStream filtering |
Java | I ` d like to find some statements in a file . And I need to print out element and sub element name.The statement likeIf a element or sub element name includes one or more spaces , the entire string must be enclosed within double quotes . Double quotes are dispensable if there is no space in a element or sub element na... | set element elemName subElem sumElemName set element `` aaa bbb '' subElem `` ccc '' set element `` aaa bbb '' subElem cccset element `` aaa '' subElem `` ccc '' String regex = `` ^\\s*set\\s+element\\s+\ '' ( .* ) \ '' \\s+subElem\\s+\ '' ( . * ) \ '' \\s* $ '' ; String regex = `` ^\\s*set\\s+element\\s+ ( ? < ! \ '' ... | How to write one regular expression to meet all cases and print specified variable |
Java | I decided to remove the throws ArithmeticException in the code below and I still got the same result when I divided by zero and the stack trace appeared . Is throws ArithmeticException in the method definition optional ? What is its purpose ? | public static int quotient ( int numerator , int denominator ) throws ArithmeticException { return numerator / denominator ; } public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System.in ) ; try { int denominator = scanner.nextInt ( ) ; System.out.println ( quotient ( 10 , denominator ) ) ; ... | Is `` throws ArithmeticException '' only cosmetic in the method definiton ? |
Java | I 'm working with bit shifting in Java and have the following piece of code that works as expected : This produces the value 2 as expected . If however I attempt to extract this into a method like so : This results in a compilation error : The question is what is it about the method that causes this to fail ? | final byte value = 1 ; final int shift = 1 ; byte result = value < < shift ; private void shiftAndCheck ( final byte value , final int shift ) { byte result = value < < shift ; } java : incompatible types : possible lossy conversion from int to byte | Differing behaviour when shifting bits in java |
Java | If I clone an instance of the following class , and overridde a method when instancing , will the clone have the overridden method ? I have n't found anything regarding this behavior inhttps : //docs.oracle.com/javase/7/docs/api/java/lang/Cloneable.html nor https : //docs.oracle.com/javase/7/docs/api/java/lang/Object.h... | public class ToBeCloned implements Cloneable { public int returnInt ( ) { return 1 ; } public void printTest ( ) { System.out.println ( `` returnInt ( ) : '' +returnInt ( ) + '' \nToBeCloned Original '' ) ; } @ Override public ToBeCloned clone ( ) throws CloneNotSupportedException { return ( ToBeCloned ) super.clone ( ... | Does the clone method clone overridden methods ? |
Java | Pardon me if I 'm missing some core Java here.I was searching through HashSet 's javadocs for the specification of it 's implementation of Collection.containsAll ( ) and it apparently inherits the implementation by AbstractCollection which according to the JDK 8 source code documentation goes like this : My question st... | public boolean containsAll ( Collection < ? > c ) { for ( Object e : c ) if ( ! contains ( e ) ) return false ; return true ; } public boolean contains ( Object o ) { return map.containsKey ( o ) ; } public boolean contains ( Object o ) { Iterator < E > it = iterator ( ) ; if ( o==null ) { while ( it.hasNext ( ) ) if (... | Which instance method is called when super type method calls method present in both super type and subtype |
Java | In my gradle build file , I have the following plugin blockNone of these specify a version but everything works . Assume that a project is using gradle 6.0 with the gradle wrapper but the system has gradle 5.0 installed.Questions : If I run gradle wrapper ./gradlew build the java plugin from gradle 6.0 will be executed... | plugins { ` java-library ` jacoco checkstyle } | What are the version numbers of bulit-in gradle plugins ? |
Java | I am trying to do something like this in Kotlin : In Java it looks like this : The Java version works just fine , in Kotlin I get an error : Does anyone have an idea on how to do it ? Thanks in advance . | val top : Long = 1000000_1000000_1000000_1000000_1000000_1000000_1000000 long TOP = 1000000_1000000_1000000_1000000_1000000_1000000_1000000L ; The value is out of range | How do I manually assign bytes to a long in Kotlin ? |
Java | So to my knowledge duplicates are not allowed in a Java set . Why then in this code snippet does the code seem to try to take account of duplicates ? Why not just have keywordsToCover.put ( keyword,1 ) inside the for loop ? | public static Subarray findSmallestSubarrayCoveringSet ( List < String > paragraph , Set < String > keywords ) { Map < String , Integer > keywordsToCover = new HashMap < > ( ) ; for ( String keyword : keywords ) { keywordsToCover.put ( keyword , keywordsToCover.containsKey ( keyword ) ? keywordsToCover.get ( keyword ) ... | Inserting into hashmap , accounting for duplicates in Set ? |
Java | I have a list of class that I want to sort : And I want to make a helper class ( with static methods ) that can be used to sort the Student list : However , the above method only takes Double - but I 'd like to pass all Number object to the method : When I use Number instead of Double , it gives an error The method com... | class Student { private Integer studentId ; private Double scoreA ; private Integer scoreB ; private Long scoreC ; // ... getter/setter ... } public class SortHelper { public static < T > void Sort ( List < T > list , Function < T , Double > fn ) { // Double Collections.sort ( list , Comparator.comparing ( fn ) ) ; } }... | How to use generic ` Number ` for ` Comparator.comparing ` |
Java | I have a class like thisI have saved in a database some serialized instances of MyClass.Now , I 'm adding a new function to MyInterface so it becomes : And I have implemented C ( ) in MyClass.Will my previously serialized instances deserialize as the new class with no problem ? I think yes but wanted to confirm , if po... | class MyClass implements MyInterface , Serializable { private static final serialVersionUID = 42 ; ... } interface MyInterface { void A ( ) ; void B ( ) ; } interface MyInterface { void A ( ) ; void B ( ) ; void C ( ) ; } | Will I be able to successfully deserialize a previous version of my class ? |
Java | Basically I want only a menuitem icon for Edit to show up in the action bar if the current ParseUser is viewing their own post.I figure I could check if their viewing their own post simply by grabbing the current parse user like so ( postedBy simply being a string from intent passed from listview activity ) : Problem i... | ParseUser currentUser = ParseUser.getCurrentUser ( ) ; if ( currentUser.username == postedBy ) { } | have menuitem only appear in action bar if ParseUser is viewing own post |
Java | I try to merge two mapsbut when current has 0 elements , the lambda is not executed.Is n't merge should do union in case no merge is possible ? I want : | private void mergeMaps ( HashMap < String , FailureExample > current , HashMap < String , FailureExample > other ) { current.forEach ( ( k , v ) - > other.merge ( k , v , ( v1 , v2 ) - > { FailureExample answer = new FailureExample ( ) ; addFromListWithSizeLimit ( v1 , answer ) ; addFromListWithSizeLimit ( v2 , answer ... | mergeMaps does n't work when first map has no elements ? |
JS | You can horizontally scroll my demo page by pressing Space Bar , Page Up / Page Down and Left Arrow / Right Arrow keys . You can also snap scroll with a mouse or trackpad.But only one or the other works.Is there a way that keyboard events and CSS scroll snapping can coexist ? What am I missing ? Any help would be reall... | import animate from `` https : //cdn.jsdelivr.net/npm/animateplus @ 2/animateplus.js '' const sections = Array.from ( document.querySelectorAll ( `` section '' ) ) .sort ( ( s1 , s2 ) = > { return s1.getBoundingClientRect ( ) .left - s2.getBoundingClientRect ( ) .left } ) const getSectionInView = ( ) = > { const halfWi... | Conflict when simultaneously using keyboard events for scrolling and CSS scroll snapping |
JS | I 'm going through the MDN docs on arrays and when we want to test whether or not an object is an array we use isArray ( ) . However , it 's usage is very different to most of the other methods . When you use the regular syntax an error pops up : Whereas this does work : I do n't understand why isArray ( ) ( and a coup... | console.log ( [ 1,2,3 ] .isArray ( ) ) ; // TypeError : [ 1 , 2 , 3 ] .isArray is not a function console.log ( Array.isArray ( [ 1,2,3 ] ) ) | Why do some array methods rely on the global Array object ? |
JS | Using the below line of code , like most websites do I wonder , is it possible to have a backup alternative for this ? For example , if googleapis.com~ is down , use this other script src instead ? Thanks in advance , Anders | < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js '' type= '' text/javascript '' > < /script > | JQuery backup alternative |
JS | I 'm struggling to understand some basic concepts of unit testing in Vue.js using Karma , Mocha and Chai.This is my component : VueExample.vueThis is how I 'm trying to test it : VueExample.spec.jsI use Karma to run the tests and Chai as assertion library . Everything is properly configured in karma.conf.js . When I ru... | < template > < div > < p > { { name } } < /p > < input v-model= '' name '' > < /div > < /template > < script > export default { name : 'VueExample ' , data ( ) { return { name : 'Bruce Lee ' } ; } } < /script > import Vue from 'vue ' ; import VueExample from `` ../../../components/VueExample '' ; describe ( 'VueExample... | How to test DOM update in Vue.js with Mocha ? |
JS | For a client side search tool I need to find the Levenshtein distance of a word with millions of other words . A user should be able to compare a short text of about twenty words with a book . The user could do this by finding locations of the most characterizing words of the text in the book . 'Finding locations'does ... | var rowA = new Uint16Array ( 1e6 ) ; var rowB = new Uint16Array ( 1e6 ) ; function levenshtein ( s1 , s2 ) { var s1_len = s1.length , s2_len = s2.length , i1 , i2 = 0 , a , b , c , c2 , i = 0 ; if ( s1_len === 0 ) return s2_len ; if ( s2_len === 0 ) return s1_len ; while ( i < s1_len ) rowA [ i ] = ++i ; while ( i2 < s... | What is the fastest levenshtein algorithm for high frequent use |
JS | I have 2 interface declarations : And 2 classes which implements each : I want my method to be given the return type as a constraint of `` must be IStore '' , so I did this : OKTesting : This works as expected : But this also works - not as expected : Question : How can I force my method to accept a return type which m... | interface IStore { } interface SomethingElse { a : number ; } class AppStoreImplemetion implements IStore { } class SomethingImplementation implements SomethingElse { a : 4 ; } class Foo { selectSync < T extends IStore > ( ) : T { return < T > { /* omitted*/ } ; // I set the return type ( ` T ` ) when invoking } } new ... | Using Typescript to force generic constraint for interface ? |
JS | Possible Duplicate : What is the difference between these ( bCondition == NULL ) and ( NULL==bCondition ) ? Javascript minification of comparison statements Ive been writing my if statements like this : But I remember reading somewhere ( unfortunately I cant find that page anymore ) , that if statements are better off ... | if ( variable1 === 1 ) { } if ( variable2 > 10 ) { } if ( variable3 == `` a '' ) { } if ( 1 === variable1 ) { } if ( 10 < variable2 ) { } if ( `` a '' == variable3 ) { } | The order of expressions in an if statement |
JS | I have a d3 radial chart created using some community sample and stack-overflow posts.Here the two bottom labels and numbers are in mirrored form ( A13 and A14 ) . Looking for some snippets to transform only this two in counter-clockwise with numbers top ( next to the chart ) then label so that it will be in better rea... | var data = [ { `` name '' : '' A11 '' , '' value '' :217 , '' color '' : '' # fad64b '' } , { `` name '' : '' A12 '' , '' value '' :86 , '' color '' : '' # f15d5d '' } , { `` name '' : '' A13 '' , '' value '' :79 , '' color '' : '' # f15d5d '' } , { `` name '' : '' A14 '' , '' value '' :82 , '' color '' : '' # f15d5d '... | Transform label in reverse order d3 radial chart |
JS | In my react App , I have the functionality to create Folders and Files . A folder can have any number of folders inside it.like soand it can get deeper up to any level.Currently , What I am doing is . There 's a component that loads the root folder Folder-1 , When you click on Folder-1 . I change the route and load ano... | Folder-1 |_Folder-1-1 |_Folder-1-2 |_Folder-1-2-1 |_Folder-1-2-2 |_Folder-1-2-2-1 . . . | dynamically pass unknown number of parameters to react router |
JS | it 's my first question here . I tried to find an answer but could n't , honestly , figure out which terms should I use , so sorry if it has been asked before.Here it goes : I have thousands of records in a .txt file , in this format : ... and so on . The first value is the PK , the other 3 are Foreign Keys , the 5th i... | ( 1 , 3 , 2 , 1 , 'John ( Finances ) ' ) , ( 2 , 7 , 2 , 1 , 'Mary Jane ' ) , ( 3 , 7 , 3 , 2 , 'Gerald ( Janitor ) , Broflowski ' ) , | Parse semi-structured values |
JS | I have nested click event handlers within a component : ( Complete , minimal example at the bottom of this post . ) This component is used as a `` list item '' within a containing component . When I click on the ( Delete ) it fires the onDeleteClick as expected , which makes a callback to the parent which results in th... | class ListItem extends React.Component { ... render ( ) { return ( < div onClick= { this.save } > ... Content ... < span onClick= { this.onDeleteClick } > ( Delete ) < /span > < /div > ) ; } ... } -- - orig.jsx+++ new.jsx @ @ -32,6 +32,7 @ @ } onDeleteClick ( e ) { + e.stopPropagation ( ) ; this.props.onDeleteClick ( e... | React click event bubbling `` sideways '' , not just `` up '' |
JS | The general question I suppose is : when does || return the item on the left , and when does it return the item on the right ? The specific question , is why does n't this work : | var fibonacci = ( function ( ) { var cache = [ 0 , 1 ] ; function fibonacci ( number ) { return cache [ number ] = cache [ number ] || ( fibnonacci ( number - 1 ) + fibonacci ( number - 2 ) ) ; } return fibonacci ; } ) ( ) ; var $ div = $ ( 'div ' ) ; for ( var index = 0 ; index < 10 ; index++ ) { $ ( ' < span / > ' ) ... | Proper use of || |
JS | I 'm trying to wrap the following prices and text together , all in one div.This is what I have : This is what I am trying to get : This does n't work but you get the idea of what I 'm doing wrong : Perhaps I should be using SLICE ? | < table cellspacing= '' 0 '' cellpadding= '' 0 '' border= '' 0 '' class= '' thePrices '' > < tbody > < tr > < td > < font class= '' text colors_text '' > < b > MSRP : < span class= '' priceis '' > $ 90.00 < /span > < /b > < /font > < br > < b > < font class= '' pricecolor colors_productprice '' > < font class= '' text ... | jQuery add first part of div , then add last part of div seperatley |
JS | I have coded a script ( with the help of a user here ) which allows me to expand a selected div and make the other divs behave accordingly by stretching equally to fit the remaining space ( except the first one which width is fixed ) .And here is a picture of what I want to achieve : For that I use flex and transitions... | var expanded = `` ; $ ( document ) .on ( `` click '' , `` .div : not ( : first-child ) '' , function ( e ) { var thisInd = $ ( this ) .index ( ) ; if ( expanded ! = thisInd ) { //fit clicked fluid div to its content and reset the other fluid divs $ ( this ) .css ( `` width '' , `` 400 % '' ) ; $ ( '.div ' ) .not ( ' : ... | Flex transition : Stretch ( or shrink ) to fit content |
JS | The backbone.js source code uses a function wrapper like this : as seen at http : //backbonejs.org/docs/backbone.html # section-185.Much more often , I 've seen the following used instead : When does the behavior of these two differ ? I was under the impression that they were equivalent , but I assume that there must b... | ( function ( ) { ... } ) .call ( this ) ; ( function ( ) { ... } ) ( ) ; | Wrapping a file with ( function ( ) { … } ) .call ( this ) versus a call with simply ( ) |
JS | My code receives a RegExp object ( out of my control ) . It is n't global but I need it to be . At the moment I 'm doing this : ... because I ca n't figure out any other way . regex.global does n't have a setter . regex.compile ( new_pattern ) is deprecated in favour of new RegExp ( new_pattern ) regex.flags is n't a t... | if ( ! regex.global ) { var flags = ' g ' ; if ( regex.ignoreCase ) flags += ' i ' ; if ( regex.multiline ) flags += 'm ' ; if ( regex.sticky ) flags += ' y ' ; regex = new RegExp ( regex.source , flags ) ; } | Is it possible to modify flags on an existing RegExp ? |
JS | I have a json and inside this json there is an array that I want to iterate in < td > .My functionality is like I have to create a table based on user input . User provides input for number of rows , input columns and output columns . So I have three arrays i.e $ rootScope.input_columns , $ rootScope.output_columns and... | var app = angular.module ( 'rulesApp ' ) ; app.controller ( 'myController2 ' , [ ' $ scope ' , ' $ rootScope ' , function ( $ scope , $ rootScope ) { var inputcol= [ ] ; $ rootScope.input_col= $ scope.no_of_input ; $ rootScope.output_col= $ scope.no_of_output ; $ rootScope.rows= $ scope.no_of_row ; for ( var i=0 ; i < ... | How to use two ng-repeat inside a particular tag |
JS | I have an unordered list which contains 3 list items ( represented in my example as 3 green boxes ) . Each box has an image and 3 divs ( title , location , price ) . I 'm only concerned with each box 's title div.If the title is long enough so that it produces 2 lines , I want the top line to always be shorter than the... | < li class= '' list__item '' > < figure class= '' list__item__inner '' > < p class= '' vignette '' style= '' background-image : url ( http : //www.ht-real-estate.com/template/ht2014/images/landscape/05.jpg ) '' > < /p > < div class= '' titlebox '' > This line is longer than this line < /div > < div class= '' locationbo... | How to make top line shorter than bottom line ( within div ) |
JS | Some time ago , I started to refactor my code of the main project , decoupling the business logic from controllers to services , according to guidelines . Everything went well , until I faced the problem of circular dependency ( CD ) . I read some resources about this problem : Question 1 on Stack OverflowQuestion 2 on... | self.loadRowData = function ( ) { // implementation here } $ interval ( function ( ) { var rowToAdd = { make : `` VW `` + index , model : `` Golf `` + index , price : 10000 * index } ; var newItems = [ rowToAdd ] ; // here I need to get access to the gridMainService var gridMainService = $ injector.get ( 'gridMainServi... | Angular : circular dependency of specific case |
JS | I 'm enthusiastic about Deno so I 'm giving it a try . Found a tutorial on building a REST API here.So , when I 'm trying to run it , I get this InvalidData error : Now , it looks to me that something is wrong when trying to connect to the database , but I ca n't really figure out what . What does this InvalidData erro... | error : Uncaught InvalidData : data did not match any variant of untagged enum ArgsEnum at unwrapResponse ( $ deno $ /ops/dispatch_json.ts:43:11 ) at Object.sendAsync ( $ deno $ /ops/dispatch_json.ts:98:10 ) at async Object.connect ( $ deno $ /net.ts:216:11 ) at async Connection.startup ( https : //deno.land/x/postgres... | Uncaught InvalidData : data did not match any variant of untagged enum ArgsEnum |
JS | I was reading about Javascript recently and ran into some syntax which seemed foreign to me : What exactly does | > mean in such a scenario ? | const max = { a : 1 , b : 2 , c : 3 } | > Object.values | > ( _ = > Math.max ( ... _ ) ) | What does the `` | > '' operator do in Javascript ? |
JS | I do n't understand why resoved Promise delay .then ( ) argument call ? example : console return : If myPromise is fulfilled , why .then ( ) do n't call imediatly resolve function ? | var myPromise = Promise.resolve ( ) ; console.log ( myPromise ) ; myPromise.then ( ( ) = > console.log ( ' a ' ) ) ; console.log ( ' b ' ) ; > Promise { < state > : `` fulfilled '' , < value > : undefined } > `` b '' > `` a '' | Why Promise.resolve ( ) .then ( ) is delayed ? |
JS | Newbie to JavaScript here.How do I reference member foo from within member foobar , given that foobar 's in a closure ? The code above fails . In it , this.foo is undefined . If I change this.foo to priv.foo , it 's still undefined . How do I reference priv.foo from within the foobar closure ? | var priv = { foo : `` bar '' , foobar : ( function ( ) { return this.foo === `` bar '' ; } ) ( ) } ; | JavaScript scope : referencing parent object member from child member 's closure |
JS | New to Riot.js trying to create a custom tooltip tag and only one tooltip will be active at a time . Trying to use show toggling show_message value to display and hide the tooltips . But show_message is within the context of that particular elements click event . Onclick of a particular tooltip , how can I access other... | < tooltip message= '' Click Tooltip '' content= '' Click tooltip preview '' > < /tooltip > < tooltip message= '' Click Tooltip 1 '' class= '' repeat-tooltip '' content= '' Click tooltip 1 preview '' > < /tooltip > < tooltip trigger= '' hover '' class= '' repeat-tooltip '' message= '' Hover Tooltip '' content= '' Hover ... | Riot.js - Accessing context of tag elements to hide/show that element |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.