How does creating and initializing a map in Java using an anonymous class potentially cause memory leak issues?

I’ve seen code that creates and initializes a map by extending HashMap (via an anonymous class) and initialization block as follows:

   final Map<String, String> headers = new HashMap<String, String>() {{
        put(SOME_HEADER1, SOME_HEADER1_VALUE);
        put(SOME_HEADER2, SOME_HEADER2_VALUE);
    }};

According to https://www.baeldung.com/java-initialize-hashmap

Note that, we must try to avoid this initialization technique as it
creates an anonymous extra class at every usage, and also holds hidden
references to the enclosing object and might cause memory leak issues

Why might this cause a memory leak issue?

Need to write junit for configuration class

Public class config implements WebMvcConfigurer {

Public void Converters (List<httpMsgConverter<?>> converters) {
Builder builder = new Builder();
Builder.indentOutput(true);
Converters.add(new MappingConverter(builder.build)));
}

Public void addResourceHandlers(final RHRegistry Registry) {
Registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}

I am new at this. Any solution would be very much helpful.

Thanks in advance.

Selling – Start Online Business by Selling Top Class Niches Blog

This Website is Specially Design For Premade Websites Turnkey Business .Fully Automatic and Easy to handle. Very little time required to operate & totally newbie friendly.

This Website consisting of :

1. More than 126 Premade Niche Blog Websites Price US$15.95 each(100% Profit)
2. 26 Amazon Affiliate Review Niche Websites Price US$49.99 each (100% Profit)
3. Premade 22 DropShip Websites
4. 9 Premade Free Blog Website
5. 19 Hot Premade Blog Websites

Total Blog Websites : 208

The Premade Blog industry is one of the most fastest growing service industry. There are more than 5 million new businesses are started every year worldwide. Many business owners, bloggers and internet marketers . They simply do not have the time or the expertise to do it themselves. These people are willing to pay top dollar for Premade Blogs .

This industry has been booming for quite some time now and there are crazy amounts of money to be made. The best part of this is, you don’t even have to perform the services yourself!

You don’t need to be an expert to run this business. All of the work is Fully Auto, you just have to focus on getting traffic to the website which you can do following my marketing strategies.

How This Business Work :
SEMrush

Customer Buy Premade Blog or Place Order
You receive a new order notification straight to your email inbox.
Payment is received instantly to your Paypal Account.
Then Customer Automatically get Download Links of Premade Blog Website File and Database with installation guide.
You will email your customer to inform them their order is complete!

How Do You Drive Traffic To The Website?

1. Facebook Marketing

2. Social Media Marketing

3. SEO Mrketing

Complete Features of “Premade Niche Blog”

We only build well selected niche blogs based on current market trends.

Fully Responsive & Support for Mobile Viewing
Multi Theme Layout (2 Columns / 3 columns)
High Quality Contents Loaded.
Boxed & Full Width style
Social Media users profiles
Already Loaded High Quality articles
Professional looking, Clean and Elegant design
Powerful & User Friendly Theme Option
Unlimited Colors Scheme
Ultra Flexible Banner Ads
Contact us, Privacy Policy, Advertise with us, and TOS Pages
SEO Friendly Website
500+ Google Web Fonts
Monetized with Adsense,Clickbank and Amazon
No Maintenance Needed

Complete Features of “Amazon Affiliate Websites”

We only build well selected niche blogs based on current market trends.

WordPress with WooCommerce
Install Amazon Woocommerce Plugin
Fully Responsive & Support for Mobile Viewing
Multi Theme Layout (2 Columns / 3 columns)
Boxed & Full Width style
Social Media users profiles
50+ Already Loaded Top Selling Amazon Products
Professional looking, Clean and Elegant design
Powerful & User Friendly Theme Option
Unlimited Colors Scheme
Ultra Flexible Banner Ads
Contact us, Privacy Policy, Advertise with us, and TOS Pages
SEO Friendly Website
500+ Google Web Fonts
Monetized with Adsense,Clickbank and Amazon
No Maintenance Needed

WHAT WILL THE NEW OWNER GET?

Premium,Brandable & Memorable domain name (We will push this domain free of cost to your Account.)
Setup of All Websites Files with database in your Hosting Except Dropship Websites.
FREE Websites Transfer into your hosting
Professionally designed WordPress website with clean and elegant look.
Mobile compatible.
FREE After sales support

Requirements for this Business :

Cpanel Linux Hosting Access For Website Files and Database Transfer

WHY I’M SELLING THIS WEBSITE

I am a web designer & developer by profession and more than 8+ years Experience. I develop high quality websites by keeping in mind hot trends of internet world.

ONLY SERIOUS Buyers Contact VIA SKYPE : adsensemarket

 

integration – General class of functions satisfying growth condition on a given functional

The question is inspired by Abel Plana summation formula :

Is there a general class of functions $f$ that are positive valued on the positive real axis, and which satisfy the following

$$int_0^infty frac{f(x + iy) − f(x − iy)}{e^{2pi y}-1} dy=oleft(int_1^x f(t) dtright)?$$
(I’m really looking for the subcase of bounded $f$.)

(Sorry for such a generality, and the straight-forwardness of the question.)

magento2 – Short array syntax must be used to define arrays Use ::class notation instead

I had things like that

  90 | WARNING | ( ) Use ::class notation instead.
  92 | WARNING | (x) Short array syntax must be used to define arrays
  94 | WARNING | ( ) Use ::class notation instead.
  96 | WARNING | (x) Short array syntax must be used to define arrays
  98 | WARNING | ( ) Use ::class notation instead.
 100 | WARNING | (x) Short array syntax must be used to define arrays
 102 | WARNING | ( ) Use ::class notation instead.

'value' => array(
                        array(
                            'label' => __('Is New (by a period)'),
                            'value' => 'AmastyXlandingModelRuleConditionIsNewByPeriod',
                        ),
                        array(
                            'label' => __('Is New (by 'is_new' attribute)'),
                            'value' => 'AmastyXlandingModelRuleConditionIsNew',
                        ),
                        array(
                            'label' => __('Created (in days)'),
                            'value' => 'AmastyXlandingModelRuleConditionCreated',
                        ),
                        array(
                            'label' => __('In Stock'),
                            'value' => 'AmastyXlandingModelRuleConditionInStock',
                        ),

and modified them like that

(
                            'label' => __('Is New (by a period)'),
                            'value' => 'AmastyXlandingModelRuleConditionIsNewByPeriod',
                        ),
                        (
                            'label' => __('Is New (by 'is_new' attribute)'),
                            'value' => 'AmastyXlandingModelRuleConditionIsNew',
                        ),
                        (
                            'label' => __('Created (in days)'),
                
            'value' => 'AmastyXlandingModelRuleConditionCreated',
                        ),

but still have those warnings and can’t pass pipeline

  88 | WARNING | ( ) Use ::class notation instead.
  92 | WARNING | ( ) Use ::class notation instead.
  96 | WARNING | ( ) Use ::class notation instead.

how can I fix this?

8 – How do I add a class to a views row in a hook?

I am building a view on my website that lists all currently pending user registrations. (They need to be approved by administrators). I also have a taxonomy that lists ‘banned’ names. The view lists the users username, email, discord name and twitch handle. I am trying to build a feature that takes any of those fields, and compares them to the ‘banned’ names list, and if a match is found on any or all of the fields, it adds a special class to the views row.

I can’t find the appropriate hook to tie into that allows me to check these values, but also set a new style/class on the row if a match is found. I already have a function that takes the appropriate value and compares it to the taxonomy and returns a result, but I am not sure what hook to place this function in so that I can do if, for example:

MatchFound() goes through each provided value in the array, and if a match is found returns TRUE, or FALSE if not found at all.

$search = ('name','email','discord','twitch');

if (MatchFound($search)) {
  'return flagged style for row'
}

Is there anybody that could help me?

winforms – Questions about class objects and its new initializations, static (c#)

I’m new to programming and for last couple of weeks I’m working a project. In this project I stumbled on a problem and questions related to it, because i couldn’t find the right answer (most of them were close to it and so on).
In this program you can search for a movie, save it to MySQL database, view its info and so on. So my problems and questions are:

  1. Initial problem was class objects. At the start user logins in the program and I give the username to DBConnection class in which it determines what userID it has and saves to a variable (it is needed to correctly save, delete the new movie for that specific user), but from courses and so on I learned and everyone showed that in new classes or forms in order to access other classes you have to create a new instance of it, but because of that a new problem occurred – every time I made a new instance then the saved userID would be 0
    ( 1.1) I assume its because new instance creates the same class but without new variable, so if I create new class object, with it change values then create new instance, then the values will be the default ones, not like the ones created from previous instance? -> Did I understand the new class initializing correctly or does it work differently? ) to ecape that problem (if I understood it correctly) I made the variable userID static and from basic tests I understood that it saved and had the new value in it even if later on in program I made new instance of that class in different UserControl. (It should work like that, correct? Or did I not understand it..
  2. second question is related to the previous. Because of this problem I made some methods static (later I realized I don’t need it, but this raised some misunderstandings too) so I could access like DBConnection.MyMethod but does this mean that with this type of access I never initialize constructor, correct? This question is important because in the constructor I have the basic info and set the values to variable with which I have necessary data to connect to my MySQL database. So for example, if I do the DBConnection.MyMethod in a different class and within that method I need the information which is set in Constructor does that mean that the method won’t work because the values are not set or it will if the class is initialized sometime previously within the program but from different class?
  3. When does one would want to use class object and initializing it as a new instead of just using the example of DBConnection.MyMethod and using static? Like at what point would I really want/need class objects? Whenever I have anything in the constructor within there are needed values for some methods? Or other aspects (I know it is a broad question and have seen some abstract answers, but maybe you could give some examples)

I know the post is long, but as I said these are more of clarification questions more than anything so I could finally wrap my head around, because for the last hours, even a day, I tried to solve this problem and had these questions.

P.S.
I know I didn’t post any code, because it’s really long and messy in my program, but if anyone wants to see it to understand more it’s available at https://github.com/KarlisAG/Movie-Project/tree/master/Project_Movie/Project_Movie (the following DBConnection is in Database folder in the said .cs). Only when I finish the program and it works like I want it, then I will make it a lot shorter and hopefully cleaner (atm it repeats a lot and many parts are probably un-needed, but this is a first big project that’s why it is really messy).

P.S.S.
Additional question to a problem I’m trying to solve now. I have a listview and when user clicks on columns it sorts it, but the problem is it only does it for the title and not other parameters if the user clicks on different columns ( ) and whenever user opens different UserControl and returns to the one with listview then the table is still sorted (by title) but the other columns are shown as blank spaces -> how and why does this happen?

private void SortColumn(object sender, ColumnClickEventArgs e)
        {
            if (asc)
            {
                listView1.Sorting = SortOrder.Descending;
                asc = !asc;
            }
            else
            {
                listView1.Sorting = SortOrder.Ascending;
                asc = !asc;
            }

(asc is a bool with which the program knows if it is in ascending order at that time or now)

Thank you to anyone in advance!

object oriented – PHP Building customer class with extends, am I doing it correctly?

I am trying to build my own customer class. Customer data is separated in 4 MySql tables. I am not sure if this is idiotic or not yet.

The tables are securities, customer, address and contact. The 4 tables are related by Customer_ID

I created securities class and I created a customer class extending on securities class.

<?php
//create user object
class securities{
    private $con;
    private $table = "securities";

    //properties required
    public $Security_ID;
    public $Customer_ID;
    public $Username;
    public $password;
    public $PSW_Hint;
    public $Verification;
    public $reg_date;

    //constructor
    public function __construct($db){
      $this->con = $db;
    }
    //check if username exists
    function userNameExists(){

      //query to check if username exists
      $query = "SELECT  Security_ID, Customer_ID, Username, PSW, PSW_Hint, Verification
                FROM " . $this->table .
                " WHERE Username = ?,
                LIMIT 0,1";
      //prepare query
      $stmt = $this->con->prepare($query);
      //sanitize
      $this->username=htmlspecialchars(strip_tags($this->username));
      //bind given username
      $stmt->bindParam(1, $this->username);
      //execute the queery
      $stmt->execute();
      //count returning number of rows
      $num=$stmt->rowCount();

      //if username exists
      if($num>0){

          $row=$stmt->fetch(PDO::FETCH_ASSOC);

          $this->Security_ID = $row('Security_ID');
          $this->Customer_ID = $row('Customer_ID');
          $this->Username = $row('Username');
          $this->password = $row('PSW');
          $this->PSW_Hint = $row('PSW_Hint');
          $this->Verification = $row('Verification');
          //return true if user exists
          return true;
      }
      //return false if username does not exists
      return false;
    }

  }

  class customer extends securities {

    private $table = "customer";

    //properties required
    public $firstname;
    public $lastname;
    public $fullname;
    public $Gender;
    public $Birthdate;
    public $Verification;
    public $reg_date;

    //constructor
    public function __construct($db){
      $this->con = $db;
    }

    public customerExists(){

      //query to check if username exists
      $query = "SELECT  Customer_ID, firstname, lastname, fullname, Gender, Birthdate, Verification
                FROM " . $this->table .
                " WHERE Customer_ID = ?
                LIMIT 0,1";
      //prepare query
      $stmt = $this->con->prepare($query);
      //sanitize
      $this->Customer_ID=htmlspecialchars(strip_tags($this->Customer_ID));
      //bind given username
      $stmt->bindParam(1, $this->Customer_ID);
      //execute the queery
      $stmt->execute();
      //count returning number of rows
      $num=$stmt->rowCount();

      if($num>0){

          $row=$stmt->fetch(PDO::FETCH_ASSOC);

          $this->Customer_ID = $row('Customer_ID');
          $this->firstname = $row('firstname');
          $this->lastname = $row('lastname');
          $this->fullname = $row('firstname' + 'lastname');
          $this->Gender = $row('Gender');
          $this->Birthdate = $row('Birthdate');
          $this->Verification = $row('Verification');
          //return true if user exists
          return true;
      }
      //return false if username does not exists
      return false;
    }
  }

?>

What I am wondering right now is:

  • Should I abandon the thought of spreading customer data over 4 different tables and put all customer data into 1 table?
  • How do I refer in my customer class to the Customer_ID in securities class
  • Should I build 2 more extend classes for the other tables or changed the query in the Customer class by using LEFT JOINING the other 2 tables?

sales order – How to add new column in sales_order_grid.xml dynamically or direct from class?

enter image description here

I have created a configuration for selecting fields from sales_order table to join with sales_order_grid table. I need to show these selected extra fields on the sales order listing page. like the screenshot below.

enter image description here

When enabling the fields from configuration it will be shown in the order listing page. Could you please help me to sort out this issue.

I have tried below code in app/code/Vendor/OrderGrid/view/adminhtml/ui_component/sales_order_grid.xmlsales_order_grid.xml

<columns name="sales_order_columns">
    <column name="customer_id" class="VenorOrderGridComponentFields">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
                <item name="label" xsi:type="string" translate="true">Customer id</item>
                <item name="sortOrder" xsi:type="number">60</item>
                <item name="align" xsi:type="string">left</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="visible" xsi:type="boolean">false</item>
                <item name="filter" xsi:type="string">text</item>
            </item>
        </argument>
    </column>
</columns>

And extend Column class by Fields VendorOrderGridComponentFields.

    public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource('data')('items'))) {
            foreach ($dataSource('data')('items') as & $item) {
               $item('componentDisabled') = 1;
               $item('visible') = 0;
            }
        }
    return $dataSource;
    }

javascript – In-memory database class

I built this basic in-memory database that can support some basic operations, like SET, GET, DELETE, COUNT, etc. As well as support transactions. Some of the constraints are as follows: GET​,​ SET​,​ DELETE​, and C​OUNT​ should have a runtime of less than O​ (log n),​ if not better (where ​n​ is the number of items in the database). The memory usage shouldn’t be doubled for every transaction.

One improvement I was thinking to apply is to use a data structure like Map() to store the data — shouldn’t that provide a runtime of O(1) for all basic operations?

I appreciate any advice on how to improve this code.

export class Database {

    constructor() {
        this.database = {valuesCount: {}, names: {}};
        this.transactions = ();
    }

    /**
     * Set the name of the database entry
     *
     * @param {string} name The name to set
     * @param {string} value The value to set the name to
     */
    set(name,value) {
        if(this.database.names(name) === undefined) {
            this.updateValueCount(value);
            this.database.names(name) = value;
        } else if(!!this.database.names(name)) {
            if(this.database.names(name) !== value) {
                this.updateValueCountForExistingName(name, value);
                this.database.names(name) = value;
            }
        }
    }

    /**
     * Update the value count for a new name
     *
     * @param {string} value The value count to update
     */
    updateValueCount(value){
        this.setCountForValue(value);
    }

    /**
     * Update the value count for an existing name
     *
     * @param {string} name The name of the value count to update
     * @param {string} value The value count to update
     */
    updateValueCountForExistingName(name, value){
        this.deleteValuePropertyForName(name);
        this.setCountForValue(value);
    }

    /**
     * Sets the count of a particular value
     *
     * @param {string} value The value to set the count for
     */
    setCountForValue(value) {
        if(!!this.database.valuesCount(value)) {
            this.database.valuesCount(value)++;
        } else {
            this.database.valuesCount(value) = 1;
        }
    }

    /**
     * Get the name of the database entry
     *
     * @param {string} name The name to get
     */
    get(name) {
        console.log(!!this.database.names(name) ? this.database.names(name) : null);
    }

    /**
     * Delete entry from database
     *
     * @param {string} name The name to delete
     */
    deleteFromDatabase(name) {
        if(!!this.database.names(name)) {
            this.deleteValuePropertyForName(name);
        }
    }

    /**
     * Counts the number of occurrences val is found in the database
     *
     * @param {string} value The value to count
     */
    count(value) {
        if(!!this.database.valuesCount(value)) {
            console.log(this.database.valuesCount(value));
        } else {
            console.log(0);
        }
    }

    /**
     * Begins a transaction
     */
    beginTransaction() {
        if(this.transactions.length === 0) {
            this.transactions.push(this.database);
        }
        let shallowCopy = {valuesCount: {...this.database.valuesCount}, names: {...this.database.names}};
        this.transactions.push(shallowCopy);
        this.database = this.transactions(this.transactions.length-1);
    }

    /**
     * Rollback a transaction
     */
    rollback() {
        if(this.transactions.length > 1) {
            this.transactions.pop();
            this.database = this.transactions(this.transactions.length-1);
        } else {
            console.log('TRANSACTION NOT FOUND');
        }
    }

    /**
     * Commit a transaction
     */
    commit() {
        this.database = this.transactions(this.transactions.length-1);
        this.transactions = ();
    }

    /**
     * Delete value property for a particular name
     *
     * @param {string} name The value to delete
     */
    deleteValuePropertyForName(name) {
        this.database.valuesCount(this.database.names(name))--;
        if(this.database.valuesCount(this.database.names(name)) === 0) {
            delete this.database.valuesCount(this.database.names(name));
        }

        delete this.database.names(name);
    }

    /**
     * Handle User Input for Various Database Commands
     *
     * @param {string} input User command line input
     * @returns {boolean}
     */
    handleInput(input) {
        const inputRaw = input.split(' ');
        const action = inputRaw(0);
        const arg1 = inputRaw(1);
        const arg2 = inputRaw(2);
        let name = '';
        let value = '';

        switch(action) {
            case 'SET':
                if(!!arg1 && !!arg2) {
                    name = arg1;
                    value = arg2;
                    this.set(name, value);
                } else {
                    console.log('Invalid Input: the SET command must include a name and a value.');
                }
                break;
            case 'GET':
                name = inputRaw(1);

                if(!!name) {
                    this.get(name);
                } else {
                    console.log('Invalid Input: the GET command must include a name.');
                }
                break;
            case 'DELETE':
                name = inputRaw(1);

                if(!!name) {
                    this.deleteFromDatabase(name);
                } else {
                    console.log('Invalid Input: the DELETE command requires a name.');
                }
                break;
            case 'COUNT':
                value = inputRaw(1);

                if(!!value) {
                    this.count(value);
                } else {
                    console.log('Invalid Input: the COUNT command requires a value to count.');
                }
                break;
            case 'BEGIN':
                this.beginTransaction();
                break;
            case 'ROLLBACK':
                this.rollback();
                break;
            case 'COMMIT':
                this.commit();
                break;
            case 'END':
                return true;
            default:
                console.log('Function is not valid.');
        }
    }
}