kandi background
Explore Kits

plum | plum -

 by   fitzyyf Java Version: Current License: No License

 by   fitzyyf Java Version: Current License: No License

Download this library from

kandi X-RAY | plum Summary

plum is a Java library. plum has no vulnerabilities, it has build file available and it has low support. However plum has 7 bugs. You can download it from GitHub.
plum
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • plum has a low active ecosystem.
  • It has 12 star(s) with 10 fork(s). There are 3 watchers for this library.
  • It had no major release in the last 12 months.
  • plum has no issues reported. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of plum is current.
plum Support
Best in #Java
Average in #Java
plum Support
Best in #Java
Average in #Java

quality kandi Quality

  • plum has 7 bugs (0 blocker, 0 critical, 7 major, 0 minor) and 247 code smells.
plum Quality
Best in #Java
Average in #Java
plum Quality
Best in #Java
Average in #Java

securitySecurity

  • plum has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • plum code analysis shows 0 unresolved vulnerabilities.
  • There are 1 security hotspots that need review.
plum Security
Best in #Java
Average in #Java
plum Security
Best in #Java
Average in #Java

license License

  • plum does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
plum License
Best in #Java
Average in #Java
plum License
Best in #Java
Average in #Java

buildReuse

  • plum releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • plum saves you 2085 person hours of effort in developing the same functionality from scratch.
  • It has 4575 lines of code, 459 functions and 79 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
plum Reuse
Best in #Java
Average in #Java
plum Reuse
Best in #Java
Average in #Java
Top functions reviewed by kandi - BETA

kandi has reviewed plum and discovered the below as its top functions. This is intended to give you an instant insight into plum implemented functionality, and help decide if they suit your requirements.

  • Load properties from an input stream .
    • Process query arguments .
      • Resolve a pagination parameter .
        • Returns paging query string for pagination
          • Executes the query .
            • Get the count of a SQL statement
              • Find the criteria from an object
                • Perform the actual log .
                  • Generate a list of page numbers .
                    • Gets the super class .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      plum Key Features

                      plum

                      plum Examples and Code Snippets

                      See all related Code Snippets

                      Cannot read properties of null (reading 'value')

                      copy iconCopydownload iconDownload
                      var num1;
                      var num2;
                      var answer;
                      
                      num1 = document.getElementById("fornum1").value;
                      num2 = document.getElementById("fornum2").value;
                      
                      function addition() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 + num2;
                          document.getElementById("sum").value = answer;
                      }
                      
                      function subtraction() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 - num2;
                          document.getElementById("minus").value = answer;
                      }
                      
                      function multiplication() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 * num2;
                          document.getElementById("product").value = answer;
                      }
                      
                      function division() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 / num2;
                          document.getElementById("divs").value = answer;
                      }
                      <!DOCTYPE html>
                      <html>
                          <head>
                              <title>Four Basic Operators</title>
                              <style>
                                  #div1 {
                                      height: 300px;
                                      width: 500px;
                                      background-color: plum;
                                      margin: auto;
                                      padding: 5%;
                                  }
                                  body {
                                      font-family: Courier;
                                  }
                                  label {
                                      width: 300px;
                                      display: inline-block;
                                  }
                                  #div2 input {
                                      width: 120px;
                                  }
                              </style>
                          </head>
                          <body>
                              <div id="div1">
                                  <p style="text-align: center;">FOUR BASIC OPERATIONS</p>
                                  
                                  <label for="number1">Enter the First number :</label>
                                  <input type="number" value="0" id="fornum1">
                                  <br><br>
                      
                                  <label for="number2">Enter the Second number:</label>
                                  <input type="number" value="0" id="fornum2">
                                  <br><br><br><br>
                      
                                  <div align="center" id="div2">
                                      <button type="button" onclick="addition()">Add</button>
                                      <input type="text" id="sum" readonly>
                                      <button type="button" >Subtraction </button>
                                      <input type="text" id="minus" onclick="subtraction()" readonly>
                                      <br><br><br>
                      
                                      <button type="button">Multiplication</button>
                                      <input type="text" id="product" onclick="multiplication()" readonly>
                                      <button type="button">Division</button>
                                      <input type="text" id="divs" onclick="division()" readonly>
                                  </div>
                                 
                                  
                              </div>
                          </body>
                              <script src="script.js"></script>
                      </html>
                      var num1;
                      var num2;
                      var answer;
                      
                      num1 = document.getElementById("fornum1").value;
                      num2 = document.getElementById("fornum2").value;
                      
                      function addition() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 + num2;
                          document.getElementById("sum").value = answer;
                      }
                      
                      function subtraction() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 - num2;
                          document.getElementById("minus").value = answer;
                      }
                      
                      function multiplication() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 * num2;
                          document.getElementById("product").value = answer;
                      }
                      
                      function division() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 / num2;
                          document.getElementById("divs").value = answer;
                      }
                      <!DOCTYPE html>
                      <html>
                          <head>
                              <title>Four Basic Operators</title>
                              <style>
                                  #div1 {
                                      height: 300px;
                                      width: 500px;
                                      background-color: plum;
                                      margin: auto;
                                      padding: 5%;
                                  }
                                  body {
                                      font-family: Courier;
                                  }
                                  label {
                                      width: 300px;
                                      display: inline-block;
                                  }
                                  #div2 input {
                                      width: 120px;
                                  }
                              </style>
                          </head>
                          <body>
                              <div id="div1">
                                  <p style="text-align: center;">FOUR BASIC OPERATIONS</p>
                                  
                                  <label for="number1">Enter the First number :</label>
                                  <input type="number" value="0" id="fornum1">
                                  <br><br>
                      
                                  <label for="number2">Enter the Second number:</label>
                                  <input type="number" value="0" id="fornum2">
                                  <br><br><br><br>
                      
                                  <div align="center" id="div2">
                                      <button type="button" onclick="addition()">Add</button>
                                      <input type="text" id="sum" readonly>
                                      <button type="button" >Subtraction </button>
                                      <input type="text" id="minus" onclick="subtraction()" readonly>
                                      <br><br><br>
                      
                                      <button type="button">Multiplication</button>
                                      <input type="text" id="product" onclick="multiplication()" readonly>
                                      <button type="button">Division</button>
                                      <input type="text" id="divs" onclick="division()" readonly>
                                  </div>
                                 
                                  
                              </div>
                          </body>
                              <script src="script.js"></script>
                      </html>
                      <script defer src="myscripts.js" defer/>
                      
                      window.addEventListener("DOMContentLoaded", () => {/\*code here\*/}
                      
                      <script src="myscripts.js" defer></script>
                      
                      window.addEventListener("DOMContentLoaded", () => {
                          let value = document.getElementById("fornum1").value;
                          console.log(value);
                      }
                      
                      <script defer src="myscripts.js" defer/>
                      
                      window.addEventListener("DOMContentLoaded", () => {/\*code here\*/}
                      
                      <script src="myscripts.js" defer></script>
                      
                      window.addEventListener("DOMContentLoaded", () => {
                          let value = document.getElementById("fornum1").value;
                          console.log(value);
                      }
                      
                      <script defer src="myscripts.js" defer/>
                      
                      window.addEventListener("DOMContentLoaded", () => {/\*code here\*/}
                      
                      <script src="myscripts.js" defer></script>
                      
                      window.addEventListener("DOMContentLoaded", () => {
                          let value = document.getElementById("fornum1").value;
                          console.log(value);
                      }
                      
                      <script defer src="myscripts.js" defer/>
                      
                      window.addEventListener("DOMContentLoaded", () => {/\*code here\*/}
                      
                      <script src="myscripts.js" defer></script>
                      
                      window.addEventListener("DOMContentLoaded", () => {
                          let value = document.getElementById("fornum1").value;
                          console.log(value);
                      }
                      

                      Separate column on a space after keyword

                      copy iconCopydownload iconDownload
                      library(dplyr)
                      library(tidyr)
                      library(stringr)
                      df %>% 
                         separate(fruit, into = c("Delicious", "Tasty"), 
                           sep = str_c(sprintf("(?<=%s) ", fruit_key), collapse = "|"), 
                               extra = "merge", remove = FALSE)
                      
                                             fruit  Delicious              Tasty
                      1       Apple Orange Pineapple      Apple   Orange Pineapple
                      2         Plum Good Watermelon  Plum Good         Watermelon
                      3               Plum Good Kiwi  Plum Good               Kiwi
                      4          Plum Good Plum Good  Plum Good          Plum Good
                      5             Cantaloupe Melon Cantaloupe              Melon
                      6 Blueberry Blackberry Cobbler  Blueberry Blackberry Cobbler
                      7          Peach Pie Apple Pie  Peach Pie          Apple Pie
                      
                      library(dplyr)
                      library(tidyr)
                      library(stringr)
                      df %>% 
                         separate(fruit, into = c("Delicious", "Tasty"), 
                           sep = str_c(sprintf("(?<=%s) ", fruit_key), collapse = "|"), 
                               extra = "merge", remove = FALSE)
                      
                                             fruit  Delicious              Tasty
                      1       Apple Orange Pineapple      Apple   Orange Pineapple
                      2         Plum Good Watermelon  Plum Good         Watermelon
                      3               Plum Good Kiwi  Plum Good               Kiwi
                      4          Plum Good Plum Good  Plum Good          Plum Good
                      5             Cantaloupe Melon Cantaloupe              Melon
                      6 Blueberry Blackberry Cobbler  Blueberry Blackberry Cobbler
                      7          Peach Pie Apple Pie  Peach Pie          Apple Pie
                      
                      library(tidyr)
                      df %>%
                        extract(fruit,
                                into = c("Delicious", "Tasty"),
                                regex = paste0("(", paste0(fruit_key, collapse = "|"), ")\\s(.*)"),
                                remove = FALSE)
                                               fruit  Delicious              Tasty
                      1       Apple Orange Pineapple      Apple   Orange Pineapple
                      2         Plum Good Watermelon  Plum Good         Watermelon
                      3               Plum Good Kiwi  Plum Good               Kiwi
                      4          Plum Good Plum Good  Plum Good          Plum Good
                      5             Cantaloupe Melon Cantaloupe              Melon
                      6 Blueberry Blackberry Cobbler  Blueberry Blackberry Cobbler
                      7          Peach Pie Apple Pie  Peach Pie          Apple Pie
                      

                      Add column to pandas df of order per category in another column

                      copy iconCopydownload iconDownload
                      df_fruits['order'] = df_fruits.groupby('fruit')['price'].rank()
                      print(df_fruits)
                      #    fruit garden     price  order
                      # 0  peach      A  4.359949    2.0
                      # 1  peach      B  0.259262    1.0
                      # 2  peach      C  5.496625    3.0
                      # 3  apple      A  4.353224    3.0
                      # 4  apple      B  4.203678    2.0
                      # 5  apple      C  3.303348    1.0
                      # 6   plum      A  2.046486    1.0
                      # 7   plum      B  6.192710    3.0
                      # 8   plum      C  2.996547    2.0
                      

                      sort rdd by two values and get top 10 per group

                      copy iconCopydownload iconDownload
                      from pyspark.sql import SparkSession
                      from pyspark.sql.window import Window
                      from pyspark.sql.functions import rank, col
                      spark = (SparkSession.builder.appName("foo").getOrCreate())
                      
                      initial_list = [["foo", "apple"], ["foo", "orange"],
                                  ["foo", "apple"], ["foo", "apple"],
                                  ["foo", "grape"], ["foo", "grape"],
                                  ["foo", "plum"], ["bar", "orange"],
                                  ["bar", "orange"], ["bar", "orange"],
                                  ["bar", "grape"], ["bar", "apple"],
                                  ["bar", "apple"], ["bar", "plum"],
                                  ["scrog", "apple"], ["scrog", "apple"],
                                  ["scrog", "orange"], ["scrog", "orange"],
                                  ["scrog", "grape"], ["scrog", "plum"]]
                      # creating rdd
                      rdd = spark.sparkContext.parallelize(initial_list)
                      # converting rdd to dataframe
                      df = rdd.toDF()
                      
                      # group by index 0 and index 1 to get count of each
                      df2 = df.groupby(df._1, df._2).count()
                      
                      window = Window.partitionBy(df2['_1']).orderBy(df2['count'].desc())
                      # picking only first 3 from decreasing order of count
                      df3 = df2.select('*',         rank().over(window).alias('rank')).filter(col('rank') <= 3)
                      # display the reqruired dataframe
                      df3.select('_1', '_2', 'count').orderBy('_1', col('count').desc()).show()
                      
                      rdd = sc.parallelize([
                          ["foo", "apple"], ["foo", "orange"], ["foo", "apple"], ["foo", "apple"],
                          ["foo", "grape"], ["foo", "grape"], ["foo", "plum"], ["bar", "orange"],
                          ["bar", "orange"], ["bar", "orange"], ["bar", "grape"], ["bar", "apple"],
                          ["bar", "apple"], ["bar", "plum"], ["scrog", "apple"], ["scrog", "apple"],
                          ["scrog", "orange"], ["scrog", "orange"], ["scrog", "grape"], ["scrog", "plum"]
                      ])
                      
                      from operator import add
                      from heapq import nlargest
                      
                      n = 3
                      
                      results = rdd.map(lambda x: ((x[0], x[1]), 1)).reduceByKey(add) \
                                   .map(lambda x: (x[0][0], (x[1], x[0][1]))).groupByKey() \
                                   .map(lambda x: (x[0], nlargest(n, x[1])))
                      
                      print( results.collect() )
                      # [('bar', [(3, 'orange'), (2, 'apple'), (1, 'plum')]),
                      #  ('scrog', [(2, 'orange'), (2, 'apple'), (1, 'plum')]),
                      #  ('foo', [(3, 'apple'), (2, 'grape'), (1, 'plum')])]
                      
                      data = [
                          ["foo", "apple"], ["foo", "orange"], ["foo", "apple"], ["foo", "apple"],
                          ["foo", "grape"], ["foo", "grape"], ["foo", "plum"], ["bar", "orange"],
                          ["bar", "orange"], ["bar", "orange"], ["bar", "grape"], ["bar", "apple"],
                          ["bar", "apple"], ["bar", "plum"], ["scrog", "apple"], ["scrog", "apple"],
                          ["scrog", "orange"], ["scrog", "orange"], ["scrog", "grape"], ["scrog", "plum"]
                      ]
                      
                      from heapq import nlargest
                      from operator import itemgetter
                      
                      d = {}
                      for k,v in data:
                          d.setdefault(k, {})
                          d[k][v] = d[k].get(v, 0) + 1
                      print(d)
                      # {'foo': {'apple': 3, 'orange': 1, 'grape': 2, 'plum': 1}, 'bar': {'orange': 3, 'grape': 1, 'apple': 2, 'plum': 1}, 'scrog': {'apple': 2, 'orange': 2, 'grape': 1, 'plum': 1}}
                      
                      n = 3
                      results = [(k,v,c) for k,subd in d.items()
                                         for v,c in nlargest(n, subd.items(), key=itemgetter(1))]
                      print(results)
                      # [('foo', 'apple', 3), ('foo', 'grape', 2), ('foo', 'orange', 1), ('bar', 'orange', 3), ('bar', 'apple', 2), ('bar', 'grape', 1), ('scrog', 'apple', 2), ('scrog', 'orange', 2), ('scrog', 'grape', 1)]
                      
                      rdd = sc.parallelize([
                          ["foo", "apple"], ["foo", "orange"], ["foo", "apple"], ["foo", "apple"],
                          ["foo", "grape"], ["foo", "grape"], ["foo", "plum"], ["bar", "orange"],
                          ["bar", "orange"], ["bar", "orange"], ["bar", "grape"], ["bar", "apple"],
                          ["bar", "apple"], ["bar", "plum"], ["scrog", "apple"], ["scrog", "apple"],
                          ["scrog", "orange"], ["scrog", "orange"], ["scrog", "grape"], ["scrog", "plum"]
                      ])
                      
                      from operator import add
                      from heapq import nlargest
                      
                      n = 3
                      
                      results = rdd.map(lambda x: ((x[0], x[1]), 1)).reduceByKey(add) \
                                   .map(lambda x: (x[0][0], (x[1], x[0][1]))).groupByKey() \
                                   .map(lambda x: (x[0], nlargest(n, x[1])))
                      
                      print( results.collect() )
                      # [('bar', [(3, 'orange'), (2, 'apple'), (1, 'plum')]),
                      #  ('scrog', [(2, 'orange'), (2, 'apple'), (1, 'plum')]),
                      #  ('foo', [(3, 'apple'), (2, 'grape'), (1, 'plum')])]
                      
                      data = [
                          ["foo", "apple"], ["foo", "orange"], ["foo", "apple"], ["foo", "apple"],
                          ["foo", "grape"], ["foo", "grape"], ["foo", "plum"], ["bar", "orange"],
                          ["bar", "orange"], ["bar", "orange"], ["bar", "grape"], ["bar", "apple"],
                          ["bar", "apple"], ["bar", "plum"], ["scrog", "apple"], ["scrog", "apple"],
                          ["scrog", "orange"], ["scrog", "orange"], ["scrog", "grape"], ["scrog", "plum"]
                      ]
                      
                      from heapq import nlargest
                      from operator import itemgetter
                      
                      d = {}
                      for k,v in data:
                          d.setdefault(k, {})
                          d[k][v] = d[k].get(v, 0) + 1
                      print(d)
                      # {'foo': {'apple': 3, 'orange': 1, 'grape': 2, 'plum': 1}, 'bar': {'orange': 3, 'grape': 1, 'apple': 2, 'plum': 1}, 'scrog': {'apple': 2, 'orange': 2, 'grape': 1, 'plum': 1}}
                      
                      n = 3
                      results = [(k,v,c) for k,subd in d.items()
                                         for v,c in nlargest(n, subd.items(), key=itemgetter(1))]
                      print(results)
                      # [('foo', 'apple', 3), ('foo', 'grape', 2), ('foo', 'orange', 1), ('bar', 'orange', 3), ('bar', 'apple', 2), ('bar', 'grape', 1), ('scrog', 'apple', 2), ('scrog', 'orange', 2), ('scrog', 'grape', 1)]
                      

                      excel dwindling dynamic drop downs - need a springboard to get started

                      copy iconCopydownload iconDownload
                      =IF(COUNTIF($B$1:$B$5,A1)>=1,"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(H$1:H$5),"",INDEX(A:A,SMALL(H$1:H$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($I$1,0,0,COUNTA($I$1:$I$5)-COUNTBLANK($I$1:$I$5),1)
                      
                      =IF(OR(COUNTIF($C$1:$C$5,A1)>=1,COUNTIF($B$1:$B$5,A1)>=1),"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(J$1:J$5),"",INDEX(A:A,SMALL(J$1:J$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($K$1,0,0,COUNTA($K$1:$K$5)-COUNTBLANK($K$1:$K$5),1)
                      
                      B1 --> Plums,
                      
                      C1 --> Apples,
                      
                      D1 --> • Bananas • Grapes • Cherries
                      
                      =IF(COUNTIF($B$1:$B$5,A1)>=1,"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(H$1:H$5),"",INDEX(A:A,SMALL(H$1:H$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($I$1,0,0,COUNTA($I$1:$I$5)-COUNTBLANK($I$1:$I$5),1)
                      
                      =IF(OR(COUNTIF($C$1:$C$5,A1)>=1,COUNTIF($B$1:$B$5,A1)>=1),"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(J$1:J$5),"",INDEX(A:A,SMALL(J$1:J$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($K$1,0,0,COUNTA($K$1:$K$5)-COUNTBLANK($K$1:$K$5),1)
                      
                      B1 --> Plums,
                      
                      C1 --> Apples,
                      
                      D1 --> • Bananas • Grapes • Cherries
                      
                      =IF(COUNTIF($B$1:$B$5,A1)>=1,"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(H$1:H$5),"",INDEX(A:A,SMALL(H$1:H$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($I$1,0,0,COUNTA($I$1:$I$5)-COUNTBLANK($I$1:$I$5),1)
                      
                      =IF(OR(COUNTIF($C$1:$C$5,A1)>=1,COUNTIF($B$1:$B$5,A1)>=1),"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(J$1:J$5),"",INDEX(A:A,SMALL(J$1:J$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($K$1,0,0,COUNTA($K$1:$K$5)-COUNTBLANK($K$1:$K$5),1)
                      
                      B1 --> Plums,
                      
                      C1 --> Apples,
                      
                      D1 --> • Bananas • Grapes • Cherries
                      
                      =IF(COUNTIF($B$1:$B$5,A1)>=1,"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(H$1:H$5),"",INDEX(A:A,SMALL(H$1:H$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($I$1,0,0,COUNTA($I$1:$I$5)-COUNTBLANK($I$1:$I$5),1)
                      
                      =IF(OR(COUNTIF($C$1:$C$5,A1)>=1,COUNTIF($B$1:$B$5,A1)>=1),"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(J$1:J$5),"",INDEX(A:A,SMALL(J$1:J$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($K$1,0,0,COUNTA($K$1:$K$5)-COUNTBLANK($K$1:$K$5),1)
                      
                      B1 --> Plums,
                      
                      C1 --> Apples,
                      
                      D1 --> • Bananas • Grapes • Cherries
                      
                      =IF(COUNTIF($B$1:$B$5,A1)>=1,"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(H$1:H$5),"",INDEX(A:A,SMALL(H$1:H$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($I$1,0,0,COUNTA($I$1:$I$5)-COUNTBLANK($I$1:$I$5),1)
                      
                      =IF(OR(COUNTIF($C$1:$C$5,A1)>=1,COUNTIF($B$1:$B$5,A1)>=1),"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(J$1:J$5),"",INDEX(A:A,SMALL(J$1:J$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($K$1,0,0,COUNTA($K$1:$K$5)-COUNTBLANK($K$1:$K$5),1)
                      
                      B1 --> Plums,
                      
                      C1 --> Apples,
                      
                      D1 --> • Bananas • Grapes • Cherries
                      
                      =IF(COUNTIF($B$1:$B$5,A1)>=1,"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(H$1:H$5),"",INDEX(A:A,SMALL(H$1:H$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($I$1,0,0,COUNTA($I$1:$I$5)-COUNTBLANK($I$1:$I$5),1)
                      
                      =IF(OR(COUNTIF($C$1:$C$5,A1)>=1,COUNTIF($B$1:$B$5,A1)>=1),"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(J$1:J$5),"",INDEX(A:A,SMALL(J$1:J$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($K$1,0,0,COUNTA($K$1:$K$5)-COUNTBLANK($K$1:$K$5),1)
                      
                      B1 --> Plums,
                      
                      C1 --> Apples,
                      
                      D1 --> • Bananas • Grapes • Cherries
                      
                      =IF(COUNTIF($B$1:$B$5,A1)>=1,"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(H$1:H$5),"",INDEX(A:A,SMALL(H$1:H$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($I$1,0,0,COUNTA($I$1:$I$5)-COUNTBLANK($I$1:$I$5),1)
                      
                      =IF(OR(COUNTIF($C$1:$C$5,A1)>=1,COUNTIF($B$1:$B$5,A1)>=1),"",ROW())
                      
                      =IF(ROW(A1)-ROW($A$1)+1>COUNT(J$1:J$5),"",INDEX(A:A,SMALL(J$1:J$5,1+ROW(A1)-ROW($A$1))))
                      
                      =OFFSET($K$1,0,0,COUNTA($K$1:$K$5)-COUNTBLANK($K$1:$K$5),1)
                      
                      B1 --> Plums,
                      
                      C1 --> Apples,
                      
                      D1 --> • Bananas • Grapes • Cherries
                      

                      VBA Compare single row values and highlight the entire row if different

                      copy iconCopydownload iconDownload
                      Option Explicit
                      
                      Sub Fulfillment()
                      '
                      ' Fulfillment Macro
                      ' Format the order number in column A as plum
                      
                          Const CriteriaColumn As Long = 1
                      
                          Dim wb As Workbook: Set wb = ThisWorkbook
                          Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet1") ' adjust
                          
                          Dim rg As Range: Set rg = ws.Range("A1").CurrentRegion
                          
                          Set rg = rg.Resize(rg.Rows.Count - 2).Offset(2) ' exclude first two rows
                          
                          Application.ScreenUpdating = False
                          
                          rg.Interior.Color = xlNone
                          
                          Dim Col As Long: Col = 1
                          
                          Dim cell As Range
                          Dim r As Long
                          
                          For Each cell In rg.Columns(CriteriaColumn).Cells
                              r = r + 1
                              If cell.Value <> cell.Offset(-1).Value Then Col = Col Mod 2 + 1
                              If Col = 2 Then rg.Rows(r).Interior.Color = RGB(221, 160, 221)
                          Next cell
                          
                          Application.ScreenUpdating = True
                          
                          MsgBox "Fulfillment accomplished.", vbInformation
                      
                      End Sub
                      

                      Better solution to find and return duplicates in an array - VBA

                      copy iconCopydownload iconDownload
                      Sub FindDuplicates()
                          Dim VarDat As Variant
                          Dim lngz As Long, lngz2 As Long, lngF As Long
                          Dim objDict As Object
                          Dim b As Boolean
                              
                          With Sheet1
                              Set objDict = CreateObject("Scripting.Dictionary")
                              VarDat = .Range("A1:A20").Value2
                            
                              For lngz = 1 To UBound(VarDat, 1)
                                  For lngz2 = lngz + 1 To UBound(VarDat, 1)
                                      If VarDat(lngz, 1) = VarDat(lngz2, 1) Then
                                          b = True
                                          Exit For
                                      End If
                                  Next lngz2
                                  If b = True Then
                                      If objDict.Exists(VarDat(lngz, 1)) = False Then
                                          objDict.Add VarDat(lngz, 1), 0
                                      End If
                                      b = False
                                  End If
                              Next lngz
                          
                              .Range("D:D").Clear
                              .Range("D1:D" & objDict.Count) = Application.Transpose(objDict.keys)
                          End With
                      End Sub
                      
                      Sub test1()
                          Dim allFruits(9) As String, manyFruits() As String
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = Duplicates1(allFruits())
                          Debug.Print Join(manyFruits, vbLf)
                      End Sub
                      
                      Function Duplicates1(StringArray() As String) As String()
                          
                          Dim sDict As Object: Set sDict = CreateObject("Scripting.Dictionary")
                          sDict.CompareMode = vbTextCompare
                          Dim dDict As Object: Set dDict = CreateObject("Scripting.Dictionary")
                          dDict.CompareMode = vbTextCompare
                          
                          Dim n As Long
                          For n = LBound(StringArray) To UBound(StringArray)
                              If sDict.Exists(StringArray(n)) Then
                                  dDict(StringArray(n)) = Empty
                              Else
                                  sDict(StringArray(n)) = Empty
                              End If
                          Next n
                          If dDict.Count = 0 Then Exit Function
                          Set sDict = Nothing
                          
                          Dim arr() As String: ReDim arr(0 To dDict.Count - 1)
                          Dim Key As Variant
                          n = 0
                           
                          For Each Key In dDict.Keys
                              arr(n) = Key
                              n = n + 1
                          Next Key
                          
                          Duplicates1 = arr
                      
                      End Function
                      
                      Sub test2()
                          Dim allFruits(9) As String, manyFruits() As Variant ' *** here
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = Duplicates2(allFruits())
                          Debug.Print Join(manyFruits, vbLf)
                      End Sub
                      
                      Function Duplicates2(StringArray() As String) As Variant ' *** here
                          
                          Dim sDict As Object: Set sDict = CreateObject("Scripting.Dictionary")
                          sDict.CompareMode = vbTextCompare
                          Dim dDict As Object: Set dDict = CreateObject("Scripting.Dictionary")
                          dDict.CompareMode = vbTextCompare
                          
                          Dim n As Long
                          For n = LBound(StringArray) To UBound(StringArray)
                              If sDict.Exists(StringArray(n)) Then
                                  dDict(StringArray(n)) = Empty
                              Else
                                  sDict(StringArray(n)) = Empty
                              End If
                          Next n
                          
                          Duplicates2 = dDict.Keys
                      
                      End Function
                      
                      Sub test1()
                          Dim allFruits(9) As String, manyFruits() As String
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = Duplicates1(allFruits())
                          Debug.Print Join(manyFruits, vbLf)
                      End Sub
                      
                      Function Duplicates1(StringArray() As String) As String()
                          
                          Dim sDict As Object: Set sDict = CreateObject("Scripting.Dictionary")
                          sDict.CompareMode = vbTextCompare
                          Dim dDict As Object: Set dDict = CreateObject("Scripting.Dictionary")
                          dDict.CompareMode = vbTextCompare
                          
                          Dim n As Long
                          For n = LBound(StringArray) To UBound(StringArray)
                              If sDict.Exists(StringArray(n)) Then
                                  dDict(StringArray(n)) = Empty
                              Else
                                  sDict(StringArray(n)) = Empty
                              End If
                          Next n
                          If dDict.Count = 0 Then Exit Function
                          Set sDict = Nothing
                          
                          Dim arr() As String: ReDim arr(0 To dDict.Count - 1)
                          Dim Key As Variant
                          n = 0
                           
                          For Each Key In dDict.Keys
                              arr(n) = Key
                              n = n + 1
                          Next Key
                          
                          Duplicates1 = arr
                      
                      End Function
                      
                      Sub test2()
                          Dim allFruits(9) As String, manyFruits() As Variant ' *** here
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = Duplicates2(allFruits())
                          Debug.Print Join(manyFruits, vbLf)
                      End Sub
                      
                      Function Duplicates2(StringArray() As String) As Variant ' *** here
                          
                          Dim sDict As Object: Set sDict = CreateObject("Scripting.Dictionary")
                          sDict.CompareMode = vbTextCompare
                          Dim dDict As Object: Set dDict = CreateObject("Scripting.Dictionary")
                          dDict.CompareMode = vbTextCompare
                          
                          Dim n As Long
                          For n = LBound(StringArray) To UBound(StringArray)
                              If sDict.Exists(StringArray(n)) Then
                                  dDict(StringArray(n)) = Empty
                              Else
                                  sDict(StringArray(n)) = Empty
                              End If
                          Next n
                          
                          Duplicates2 = dDict.Keys
                      
                      End Function
                      
                           "fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                      Function MoreThanOne(arr)
                      'Purp: get only fruits with multiple occurrencies
                      'Note: reads top to bottom returning the last(!) attribute @nm
                      '      based on the condition of no following fruit sibling,
                      'a) create a wellformed xml content string
                          Dim content As String
                          content = _
                              "<fruits><fruit nm='" & _
                              Join(arr, "'/><fruit nm='") & _
                              "'/></fruits>"
                      'b) define XPath expression
                          Dim XPth As String
                          XPth = "/fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"       ' multiple occurrencies
                      'c) apply FilterXML function
                          Dim x: x = Application.FilterXML(content, XPth)
                      'd) return result(s)
                          MoreThanOne = Application.Transpose(x)
                          Select Case VarType(x)
                              Case vbError
                                  MoreThanOne = Array("Nothing found")
                              Case vbString
                                  MoreThanOne = Array(x)
                              Case Else
                                  MoreThanOne = Application.Transpose(x)
                          End Select
                      End Function
                      
                      Sub testMoreThanOne()
                          Dim allFruits(9) As String, manyFruits() As Variant
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = MoreThanOne(allFruits)
                          Debug.Print Join(manyFruits, vbLf)     ' ~~> plum|apple
                      End Sub
                      
                         <fruits>
                             <fruit nm='plum'/>
                             <fruit nm='apple'/>
                             <fruit nm='orange'/>
                             <fruit nm='banana'/>
                             <fruit nm='melon'/>
                             <fruit nm='plum'/>
                             <fruit nm='kiwi'/>
                             <fruit nm='nectarine'/>
                             <fruit nm='apple'/>
                             <fruit nm='grapes'/>
                         </fruits>
                      
                          XPth = "/fruits/fruit[not(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                           "fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                      Function MoreThanOne(arr)
                      'Purp: get only fruits with multiple occurrencies
                      'Note: reads top to bottom returning the last(!) attribute @nm
                      '      based on the condition of no following fruit sibling,
                      'a) create a wellformed xml content string
                          Dim content As String
                          content = _
                              "<fruits><fruit nm='" & _
                              Join(arr, "'/><fruit nm='") & _
                              "'/></fruits>"
                      'b) define XPath expression
                          Dim XPth As String
                          XPth = "/fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"       ' multiple occurrencies
                      'c) apply FilterXML function
                          Dim x: x = Application.FilterXML(content, XPth)
                      'd) return result(s)
                          MoreThanOne = Application.Transpose(x)
                          Select Case VarType(x)
                              Case vbError
                                  MoreThanOne = Array("Nothing found")
                              Case vbString
                                  MoreThanOne = Array(x)
                              Case Else
                                  MoreThanOne = Application.Transpose(x)
                          End Select
                      End Function
                      
                      Sub testMoreThanOne()
                          Dim allFruits(9) As String, manyFruits() As Variant
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = MoreThanOne(allFruits)
                          Debug.Print Join(manyFruits, vbLf)     ' ~~> plum|apple
                      End Sub
                      
                         <fruits>
                             <fruit nm='plum'/>
                             <fruit nm='apple'/>
                             <fruit nm='orange'/>
                             <fruit nm='banana'/>
                             <fruit nm='melon'/>
                             <fruit nm='plum'/>
                             <fruit nm='kiwi'/>
                             <fruit nm='nectarine'/>
                             <fruit nm='apple'/>
                             <fruit nm='grapes'/>
                         </fruits>
                      
                          XPth = "/fruits/fruit[not(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                           "fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                      Function MoreThanOne(arr)
                      'Purp: get only fruits with multiple occurrencies
                      'Note: reads top to bottom returning the last(!) attribute @nm
                      '      based on the condition of no following fruit sibling,
                      'a) create a wellformed xml content string
                          Dim content As String
                          content = _
                              "<fruits><fruit nm='" & _
                              Join(arr, "'/><fruit nm='") & _
                              "'/></fruits>"
                      'b) define XPath expression
                          Dim XPth As String
                          XPth = "/fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"       ' multiple occurrencies
                      'c) apply FilterXML function
                          Dim x: x = Application.FilterXML(content, XPth)
                      'd) return result(s)
                          MoreThanOne = Application.Transpose(x)
                          Select Case VarType(x)
                              Case vbError
                                  MoreThanOne = Array("Nothing found")
                              Case vbString
                                  MoreThanOne = Array(x)
                              Case Else
                                  MoreThanOne = Application.Transpose(x)
                          End Select
                      End Function
                      
                      Sub testMoreThanOne()
                          Dim allFruits(9) As String, manyFruits() As Variant
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = MoreThanOne(allFruits)
                          Debug.Print Join(manyFruits, vbLf)     ' ~~> plum|apple
                      End Sub
                      
                         <fruits>
                             <fruit nm='plum'/>
                             <fruit nm='apple'/>
                             <fruit nm='orange'/>
                             <fruit nm='banana'/>
                             <fruit nm='melon'/>
                             <fruit nm='plum'/>
                             <fruit nm='kiwi'/>
                             <fruit nm='nectarine'/>
                             <fruit nm='apple'/>
                             <fruit nm='grapes'/>
                         </fruits>
                      
                          XPth = "/fruits/fruit[not(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                           "fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                      Function MoreThanOne(arr)
                      'Purp: get only fruits with multiple occurrencies
                      'Note: reads top to bottom returning the last(!) attribute @nm
                      '      based on the condition of no following fruit sibling,
                      'a) create a wellformed xml content string
                          Dim content As String
                          content = _
                              "<fruits><fruit nm='" & _
                              Join(arr, "'/><fruit nm='") & _
                              "'/></fruits>"
                      'b) define XPath expression
                          Dim XPth As String
                          XPth = "/fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"       ' multiple occurrencies
                      'c) apply FilterXML function
                          Dim x: x = Application.FilterXML(content, XPth)
                      'd) return result(s)
                          MoreThanOne = Application.Transpose(x)
                          Select Case VarType(x)
                              Case vbError
                                  MoreThanOne = Array("Nothing found")
                              Case vbString
                                  MoreThanOne = Array(x)
                              Case Else
                                  MoreThanOne = Application.Transpose(x)
                          End Select
                      End Function
                      
                      Sub testMoreThanOne()
                          Dim allFruits(9) As String, manyFruits() As Variant
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = MoreThanOne(allFruits)
                          Debug.Print Join(manyFruits, vbLf)     ' ~~> plum|apple
                      End Sub
                      
                         <fruits>
                             <fruit nm='plum'/>
                             <fruit nm='apple'/>
                             <fruit nm='orange'/>
                             <fruit nm='banana'/>
                             <fruit nm='melon'/>
                             <fruit nm='plum'/>
                             <fruit nm='kiwi'/>
                             <fruit nm='nectarine'/>
                             <fruit nm='apple'/>
                             <fruit nm='grapes'/>
                         </fruits>
                      
                          XPth = "/fruits/fruit[not(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                           "fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"
                      
                      Function MoreThanOne(arr)
                      'Purp: get only fruits with multiple occurrencies
                      'Note: reads top to bottom returning the last(!) attribute @nm
                      '      based on the condition of no following fruit sibling,
                      'a) create a wellformed xml content string
                          Dim content As String
                          content = _
                              "<fruits><fruit nm='" & _
                              Join(arr, "'/><fruit nm='") & _
                              "'/></fruits>"
                      'b) define XPath expression
                          Dim XPth As String
                          XPth = "/fruits/fruit[(@nm = following-sibling::fruit/@nm)]/@nm"       ' multiple occurrencies
                      'c) apply FilterXML function
                          Dim x: x = Application.FilterXML(content, XPth)
                      'd) return result(s)
                          MoreThanOne = Application.Transpose(x)
                          Select Case VarType(x)
                              Case vbError
                                  MoreThanOne = Array("Nothing found")
                              Case vbString
                                  MoreThanOne = Array(x)
                              Case Else
                                  MoreThanOne = Application.Transpose(x)
                          End Select
                      End Function
                      
                      Sub testMoreThanOne()
                          Dim allFruits(9) As String, manyFruits() As Variant
                          allFruits(0) = "plum"
                          allFruits(1) = "apple"
                          allFruits(2) = "orange"
                          allFruits(3) = "banana"
                          allFruits(4) = "melon"
                          allFruits(5) = "plum"
                          allFruits(6) = "kiwi"
                          allFruits(7) = "nectarine"
                          allFruits(8) = "apple"
                          allFruits(9) = "grapes"
                          manyFruits = MoreThanOne(allFruits)
                          Debug.Print Join(manyFruits, vbLf)     ' ~~> plum|apple
                      End Sub
                      
                         <fruits>
                             <fruit nm='plum'/>
                             <fruit nm='apple'/>
                             <fruit nm='orange'/>
                             <fruit nm='banana'/>
                             <fruit nm='melon'/>
                             <fruit nm='plum'/>
                             <fruit nm='kiwi'/>
                             <fruit nm='nectarine'/>
                             <fruit nm='apple'/>
                             <fruit nm='grapes'/>
                         </fruits>
                      
                          XPth = "/fruits/fruit[not(@nm = following-sibling::fruit/@nm)]/@nm"
                      

                      How to bind each array item to its element node representation and make the nodes watch the array?

                      copy iconCopydownload iconDownload
                      function sanitizeInputValue(value) {
                        return value
                          .trim()
                          .replace(/\s+/g, ' ')
                          .replace(/(?:\stree)+$/i, '');
                      }
                      
                      function createItemNode(id, value) {
                        const itemRoot = document.createElement('div');
                      
                        itemRoot.dataset.itemId = id;
                        itemRoot.classList.add('item');
                      
                        let contentNode = document.createElement('span');
                        contentNode.textContent = `${ value } Tree`;
                      
                        itemRoot.appendChild(contentNode);
                      
                        return itemRoot;
                      }
                      function createItemViewModel(id, value) {
                        return {
                          id,
                          value,
                          elm: createItemNode(id, value),
                        };
                      }
                      
                      function createItemListViewModel(itemList) {
                        const registry = new Map;
                      
                        const register = value => {
                          let viewModel;
                      
                          value = sanitizeInputValue(value);
                          const id = value.toLowerCase();
                      
                          if (!registry.has(id)) {
                            viewModel = createItemViewModel(id, value);
                      
                            registry.set(id, viewModel);
                          }
                          return viewModel;
                        };
                        const deregister = id => {
                          let viewModel;
                      
                          if (registry.has(id)) {
                            viewModel = registry.get(id);
                      
                            registry.delete(id);
                          }
                          return viewModel;
                        };
                        const getViewModels = () =>
                          [...registry.values()];
                        const getValueList = () =>
                          [...registry].map(([id, viewModel]) => viewModel.value);
                      
                        // default register items from initial list.
                        itemList.forEach(register);
                      
                        return {
                          register,
                          deregister,
                          getViewModels,
                          getValueList,
                        }
                      }
                      
                      
                      function main/*Controller*/(itemList) {
                        // create a view-model of the provided items by programmatically
                        // adding each items own view-model to the overall items registry.
                        const itemsRegistry = createItemListViewModel(itemList);
                      
                        let itemsRoot = document.querySelector("#item-list");
                        let itemInput = document.querySelector("#item-input");
                        
                        // initial rendering of the provided items from each items's view model.
                        itemsRegistry
                          .getViewModels()
                          .forEach(viewModel =>
                            itemsRoot.appendChild(viewModel.elm)
                          );
                      
                        // register controller logic for a list item's double-click handling.
                        itemsRoot.addEventListener('dblclick', evt => {
                          const target = evt.target.closest('.item');
                          const itemId = target?.dataset.itemId;
                      
                          if (itemId) {
                            // remove view-model from registry in case it does exist.
                            const viewModel = itemsRegistry.deregister(itemId);
                      
                            if (viewModel) {
                              // remove element node of a successfully removed view-model from DOM.
                              viewModel.elm.remove();
                      
                              console.clear();
                              console.log(itemsRegistry.getValueList());
                            }
                          }
                        });
                      
                        // register controller logic for handling a potential new list item.
                        itemInput.addEventListener('keyup', evt => {
                          if (evt.code === "Enter") {
                      
                            // add view-model to registry in case it does not already exist.
                            const viewModel = itemsRegistry.register(evt.currentTarget.value);
                      
                            if (viewModel) {
                              // append element node of newly registered view-model to DOM.
                              itemsRoot.appendChild(viewModel.elm);
                      
                              // sanitize any submitted input value.
                              itemInput.value = viewModel.value;
                      
                              console.clear();
                              console.log(itemsRegistry.getValueList());
                            }
                          }
                        });
                      };
                      
                      
                      let fruits = [
                        "Apple", "Pear", "Oak", "Orange", "Tangerine", "Melon",
                        "Ananas", "Strawberry", "Cherry", "Sour Cherry","Banana",
                        "Plum", "Pomegranate", "Apricot", "Peach", "Nectarine",
                        "Kiwi", "Mulberry", "Fig", "Grapefruit", "Grape",
                      ];
                      main/*Controller*/(fruits);
                      @import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,wght@0,200;0,300;0,400;0,600;0,700;1,200;1,300;1,400;1,600&display=swap');
                      
                      body {
                        background: linear-gradient(135deg,rgb(204, 64, 64),rgb(204, 64, 118));
                        margin: 0 0 100px 0;
                        background-attachment: fixed;
                        zoom: .7;
                      }
                      .as-console-wrapper { height: 100px!important; }
                      
                      #container {
                        width: 100%;
                        margin: auto;
                        padding: 10px;
                      }
                      #input-wrapper {
                        width: 93%;
                      }
                      
                      #input-wrapper input {
                        border:none;
                        padding: 17px 20px;
                        margin: 0;
                        border-radius: 15px;
                        display: block;
                        width: 100%;
                        font-size: 14pt;
                        font-family: 'Nunito Sans', sans-serif;
                        font-weight: 300;
                        box-shadow: 0 10px 10px rgba(0,0,0,0.1);
                      }
                      #input-wrapper input::placeholder {
                        font-family: 'Nunito Sans', sans-serif;
                        font-size: 14pt;
                        font-style: italic;
                      }
                      #input-wrapper input:focus {
                        outline: none;
                      }
                      
                      #item-list {
                        display: flex;
                        margin-top: 15px;
                        flex-wrap: wrap;
                        width: 100%;
                        justify-content: center;
                      }
                      #item-list .item {
                        padding: 10px;
                        background: rgba(255,255,255,1);
                        margin: 7px;
                        border-radius: 10px;
                        cursor: pointer;
                        transition: background .3s;
                        user-select: none;
                      }
                      #item-list .item:hover {
                        background: rgba(255,255,255,.1);
                      }
                      #item-list .item:hover span {
                        color: #fff;
                      }
                      #item-list .item span {
                        font-family: 'Nunito Sans', sans-serif;
                        font-weight: 600;
                        color: rgb(204, 64, 64);
                        transition: color .3s;
                      }
                      <div id="container">
                        <div id="input-wrapper">
                          <input placeholder="Enter a tree and press 'Enter'" type="text" id="item-input">
                        </div>
                        <div id="item-list">
                        </div>
                      </div>
                      function sanitizeInputValue(value) {
                        return value
                          .trim()
                          .replace(/\s+/g, ' ')
                          .replace(/(?:\stree)+$/i, '');
                      }
                      
                      function createItemNode(id, value) {
                        const itemRoot = document.createElement('div');
                      
                        itemRoot.dataset.itemId = id;
                        itemRoot.classList.add('item');
                      
                        let contentNode = document.createElement('span');
                        contentNode.textContent = `${ value } Tree`;
                      
                        itemRoot.appendChild(contentNode);
                      
                        return itemRoot;
                      }
                      function createItemViewModel(id, value) {
                        return {
                          id,
                          value,
                          elm: createItemNode(id, value),
                        };
                      }
                      
                      function createItemListViewModel(itemList) {
                        const registry = new Map;
                      
                        const register = value => {
                          let viewModel;
                      
                          value = sanitizeInputValue(value);
                          const id = value.toLowerCase();
                      
                          if (!registry.has(id)) {
                            viewModel = createItemViewModel(id, value);
                      
                            registry.set(id, viewModel);
                          }
                          return viewModel;
                        };
                        const deregister = id => {
                          let viewModel;
                      
                          if (registry.has(id)) {
                            viewModel = registry.get(id);
                      
                            registry.delete(id);
                          }
                          return viewModel;
                        };
                        const getViewModels = () =>
                          [...registry.values()];
                        const getValueList = () =>
                          [...registry].map(([id, viewModel]) => viewModel.value);
                      
                        // default register items from initial list.
                        itemList.forEach(register);
                      
                        return {
                          register,
                          deregister,
                          getViewModels,
                          getValueList,
                        }
                      }
                      
                      
                      function main/*Controller*/(itemList) {
                        // create a view-model of the provided items by programmatically
                        // adding each items own view-model to the overall items registry.
                        const itemsRegistry = createItemListViewModel(itemList);
                      
                        let itemsRoot = document.querySelector("#item-list");
                        let itemInput = document.querySelector("#item-input");
                        
                        // initial rendering of the provided items from each items's view model.
                        itemsRegistry
                          .getViewModels()
                          .forEach(viewModel =>
                            itemsRoot.appendChild(viewModel.elm)
                          );
                      
                        // register controller logic for a list item's double-click handling.
                        itemsRoot.addEventListener('dblclick', evt => {
                          const target = evt.target.closest('.item');
                          const itemId = target?.dataset.itemId;
                      
                          if (itemId) {
                            // remove view-model from registry in case it does exist.
                            const viewModel = itemsRegistry.deregister(itemId);
                      
                            if (viewModel) {
                              // remove element node of a successfully removed view-model from DOM.
                              viewModel.elm.remove();
                      
                              console.clear();
                              console.log(itemsRegistry.getValueList());
                            }
                          }
                        });
                      
                        // register controller logic for handling a potential new list item.
                        itemInput.addEventListener('keyup', evt => {
                          if (evt.code === "Enter") {
                      
                            // add view-model to registry in case it does not already exist.
                            const viewModel = itemsRegistry.register(evt.currentTarget.value);
                      
                            if (viewModel) {
                              // append element node of newly registered view-model to DOM.
                              itemsRoot.appendChild(viewModel.elm);
                      
                              // sanitize any submitted input value.
                              itemInput.value = viewModel.value;
                      
                              console.clear();
                              console.log(itemsRegistry.getValueList());
                            }
                          }
                        });
                      };
                      
                      
                      let fruits = [
                        "Apple", "Pear", "Oak", "Orange", "Tangerine", "Melon",
                        "Ananas", "Strawberry", "Cherry", "Sour Cherry","Banana",
                        "Plum", "Pomegranate", "Apricot", "Peach", "Nectarine",
                        "Kiwi", "Mulberry", "Fig", "Grapefruit", "Grape",
                      ];
                      main/*Controller*/(fruits);
                      @import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,wght@0,200;0,300;0,400;0,600;0,700;1,200;1,300;1,400;1,600&display=swap');
                      
                      body {
                        background: linear-gradient(135deg,rgb(204, 64, 64),rgb(204, 64, 118));
                        margin: 0 0 100px 0;
                        background-attachment: fixed;
                        zoom: .7;
                      }
                      .as-console-wrapper { height: 100px!important; }
                      
                      #container {
                        width: 100%;
                        margin: auto;
                        padding: 10px;
                      }
                      #input-wrapper {
                        width: 93%;
                      }
                      
                      #input-wrapper input {
                        border:none;
                        padding: 17px 20px;
                        margin: 0;
                        border-radius: 15px;
                        display: block;
                        width: 100%;
                        font-size: 14pt;
                        font-family: 'Nunito Sans', sans-serif;
                        font-weight: 300;
                        box-shadow: 0 10px 10px rgba(0,0,0,0.1);
                      }
                      #input-wrapper input::placeholder {
                        font-family: 'Nunito Sans', sans-serif;
                        font-size: 14pt;
                        font-style: italic;
                      }
                      #input-wrapper input:focus {
                        outline: none;
                      }
                      
                      #item-list {
                        display: flex;
                        margin-top: 15px;
                        flex-wrap: wrap;
                        width: 100%;
                        justify-content: center;
                      }
                      #item-list .item {
                        padding: 10px;
                        background: rgba(255,255,255,1);
                        margin: 7px;
                        border-radius: 10px;
                        cursor: pointer;
                        transition: background .3s;
                        user-select: none;
                      }
                      #item-list .item:hover {
                        background: rgba(255,255,255,.1);
                      }
                      #item-list .item:hover span {
                        color: #fff;
                      }
                      #item-list .item span {
                        font-family: 'Nunito Sans', sans-serif;
                        font-weight: 600;
                        color: rgb(204, 64, 64);
                        transition: color .3s;
                      }
                      <div id="container">
                        <div id="input-wrapper">
                          <input placeholder="Enter a tree and press 'Enter'" type="text" id="item-input">
                        </div>
                        <div id="item-list">
                        </div>
                      </div>
                      function sanitizeInputValue(value) {
                        return value
                          .trim()
                          .replace(/\s+/g, ' ')
                          .replace(/(?:\stree)+$/i, '');
                      }
                      
                      function createItemNode(id, value) {
                        const itemRoot = document.createElement('div');
                      
                        itemRoot.dataset.itemId = id;
                        itemRoot.classList.add('item');
                      
                        let contentNode = document.createElement('span');
                        contentNode.textContent = `${ value } Tree`;
                      
                        itemRoot.appendChild(contentNode);
                      
                        return itemRoot;
                      }
                      function createItemViewModel(id, value) {
                        return {
                          id,
                          value,
                          elm: createItemNode(id, value),
                        };
                      }
                      
                      function createItemListViewModel(itemList) {
                        const registry = new Map;
                      
                        const register = value => {
                          let viewModel;
                      
                          value = sanitizeInputValue(value);
                          const id = value.toLowerCase();
                      
                          if (!registry.has(id)) {
                            viewModel = createItemViewModel(id, value);
                      
                            registry.set(id, viewModel);
                          }
                          return viewModel;
                        };
                        const deregister = id => {
                          let viewModel;
                      
                          if (registry.has(id)) {
                            viewModel = registry.get(id);
                      
                            registry.delete(id);
                          }
                          return viewModel;
                        };
                        const getViewModels = () =>
                          [...registry.values()];
                        const getValueList = () =>
                          [...registry].map(([id, viewModel]) => viewModel.value);
                      
                        // default register items from initial list.
                        itemList.forEach(register);
                      
                        return {
                          register,
                          deregister,
                          getViewModels,
                          getValueList,
                        }
                      }
                      
                      
                      function main/*Controller*/(itemList) {
                        // create a view-model of the provided items by programmatically
                        // adding each items own view-model to the overall items registry.
                        const itemsRegistry = createItemListViewModel(itemList);
                      
                        let itemsRoot = document.querySelector("#item-list");
                        let itemInput = document.querySelector("#item-input");
                        
                        // initial rendering of the provided items from each items's view model.
                        itemsRegistry
                          .getViewModels()
                          .forEach(viewModel =>
                            itemsRoot.appendChild(viewModel.elm)
                          );
                      
                        // register controller logic for a list item's double-click handling.
                        itemsRoot.addEventListener('dblclick', evt => {
                          const target = evt.target.closest('.item');
                          const itemId = target?.dataset.itemId;
                      
                          if (itemId) {
                            // remove view-model from registry in case it does exist.
                            const viewModel = itemsRegistry.deregister(itemId);
                      
                            if (viewModel) {
                              // remove element node of a successfully removed view-model from DOM.
                              viewModel.elm.remove();
                      
                              console.clear();
                              console.log(itemsRegistry.getValueList());
                            }
                          }
                        });
                      
                        // register controller logic for handling a potential new list item.
                        itemInput.addEventListener('keyup', evt => {
                          if (evt.code === "Enter") {
                      
                            // add view-model to registry in case it does not already exist.
                            const viewModel = itemsRegistry.register(evt.currentTarget.value);
                      
                            if (viewModel) {
                              // append element node of newly registered view-model to DOM.
                              itemsRoot.appendChild(viewModel.elm);
                      
                              // sanitize any submitted input value.
                              itemInput.value = viewModel.value;
                      
                              console.clear();
                              console.log(itemsRegistry.getValueList());
                            }
                          }
                        });
                      };
                      
                      
                      let fruits = [
                        "Apple", "Pear", "Oak", "Orange", "Tangerine", "Melon",
                        "Ananas", "Strawberry", "Cherry", "Sour Cherry","Banana",
                        "Plum", "Pomegranate", "Apricot", "Peach", "Nectarine",
                        "Kiwi", "Mulberry", "Fig", "Grapefruit", "Grape",
                      ];
                      main/*Controller*/(fruits);
                      @import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:ital,wght@0,200;0,300;0,400;0,600;0,700;1,200;1,300;1,400;1,600&display=swap');
                      
                      body {
                        background: linear-gradient(135deg,rgb(204, 64, 64),rgb(204, 64, 118));
                        margin: 0 0 100px 0;
                        background-attachment: fixed;
                        zoom: .7;
                      }
                      .as-console-wrapper { height: 100px!important; }
                      
                      #container {
                        width: 100%;
                        margin: auto;
                        padding: 10px;
                      }
                      #input-wrapper {
                        width: 93%;
                      }
                      
                      #input-wrapper input {
                        border:none;
                        padding: 17px 20px;
                        margin: 0;
                        border-radius: 15px;
                        display: block;
                        width: 100%;
                        font-size: 14pt;
                        font-family: 'Nunito Sans', sans-serif;
                        font-weight: 300;
                        box-shadow: 0 10px 10px rgba(0,0,0,0.1);
                      }
                      #input-wrapper input::placeholder {
                        font-family: 'Nunito Sans', sans-serif;
                        font-size: 14pt;
                        font-style: italic;
                      }
                      #input-wrapper input:focus {
                        outline: none;
                      }
                      
                      #item-list {
                        display: flex;
                        margin-top: 15px;
                        flex-wrap: wrap;
                        width: 100%;
                        justify-content: center;
                      }
                      #item-list .item {
                        padding: 10px;
                        background: rgba(255,255,255,1);
                        margin: 7px;
                        border-radius: 10px;
                        cursor: pointer;
                        transition: background .3s;
                        user-select: none;
                      }
                      #item-list .item:hover {
                        background: rgba(255,255,255,.1);
                      }
                      #item-list .item:hover span {
                        color: #fff;
                      }
                      #item-list .item span {
                        font-family: 'Nunito Sans', sans-serif;
                        font-weight: 600;
                        color: rgb(204, 64, 64);
                        transition: color .3s;
                      }
                      <div id="container">
                        <div id="input-wrapper">
                          <input placeholder="Enter a tree and press 'Enter'" type="text" id="item-input">
                        </div>
                        <div id="item-list">
                        </div>
                      </div>

                      In Java Swing (using swingx) how to sort rows in one table in same order as another table

                      copy iconCopydownload iconDownload
                      import javax.swing.*;
                      import javax.swing.table.AbstractTableModel;
                      import javax.swing.table.TableColumn;
                      import javax.swing.table.TableRowSorter;
                      import java.awt.*;
                      
                      public class TablesExample extends JPanel {
                          static class MyTableModel extends AbstractTableModel {
                              private String[] columnNames = {"Row Id",
                                      "Person",
                                      "Fruit"};
                              private Object[][] data = {
                                      {"1", "Tom", "Orange"},
                                      {"2", "Jane", "Apple"},
                                      {"3", "Fred", "Pear"},
                                      {"4", "Steve", "Lemon"},
                                      {"5", "Jim", "Plum"}
                              };
                      
                              public int getColumnCount() {
                                  return columnNames.length;
                              }
                      
                              public int getRowCount() {
                                  return data.length;
                              }
                      
                              public String getColumnName(int col) {
                                  return columnNames[col];
                              }
                      
                              public Object getValueAt(int row, int col) {
                                  return data[row][col];
                              }
                          }
                      
                          public static void main(String[] args) {
                              JFrame frame = new JFrame("Tables Example");
                              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      
                              JTabbedPane tabbedPane = new JTabbedPane();
                              tabbedPane.setPreferredSize(new Dimension(500, 100));
                      
                              TablesExample newContentPane = new TablesExample();
                              newContentPane.setOpaque(true);
                      
                              MyTableModel model = new MyTableModel();
                              TableRowSorter<MyTableModel> sorter = new TableRowSorter<>(model);
                              JTable table = new JTable(model);
                              table.setRowSorter(sorter);
                              TableColumn column2 = table.getColumnModel().getColumn(2);
                              column2.setMinWidth(0);
                              column2.setMaxWidth(0);
                              column2.setWidth(0);
                      
                              JScrollPane scrollPane = new JScrollPane();
                              scrollPane.setViewportView(table);
                              tabbedPane.add("Persons", scrollPane);
                      
                              JTable table2 = new JTable(model);
                              table2.setRowSorter(sorter);
                              TableColumn column1 = table2.getColumnModel().getColumn(1);
                              column1.setMinWidth(0);
                              column1.setMaxWidth(0);
                              column1.setWidth(0);
                      
                              JScrollPane scrollPane2 = new JScrollPane();
                              scrollPane2.setViewportView(table2);
                              tabbedPane.add("Fruits", scrollPane2);
                      
                              frame.setContentPane(tabbedPane);
                      
                              frame.pack();
                              frame.setVisible(true);
                          }
                      }
                      
                              public void toggleSortOrder(int column)
                              {
                                  .........
                                  setSortKeys(newKeys);
                              
                                  for(int i=0; i < getModelWrapper().getRowCount(); i++)
                                  {
                                      SecondTable.instanceOf().getRealModel()
                                          .setValueAt(convertRowIndexToView(i), i, ID3TagNames.INDEX_SYNC_SORT);
                                  }
                              
                                  newKeys = new ArrayList<>();
                                  SecondTable.instanceOf().getTable().getRowSorter().setSortKeys(newKeys);
                              
                                  newKeys.add(new SortKey(ID3TagNames.INDEX_SYNC_SORT, this.getFirstInCycle()));
                                  SecondTable.instanceOf().getTable().getRowSorter().setSortKeys(newKeys);
                      
                              }
                      
                              if (!this.sortKeys.equals(old)) {
                                  fireSortOrderChanged();
                                  if (viewToModel == null) {
                                      // Currently unsorted, use sort so that internal fields
                                      // are correctly set.
                                      sort();
                                  } else {
                                      sortExistingData();
                                  }
                              }
                      
                              public void toggleSortOrder(int column)
                              {
                                  .........
                                  setSortKeys(newKeys);
                              
                                  for(int i=0; i < getModelWrapper().getRowCount(); i++)
                                  {
                                      SecondTable.instanceOf().getRealModel()
                                          .setValueAt(convertRowIndexToView(i), i, ID3TagNames.INDEX_SYNC_SORT);
                                  }
                              
                                  newKeys = new ArrayList<>();
                                  SecondTable.instanceOf().getTable().getRowSorter().setSortKeys(newKeys);
                              
                                  newKeys.add(new SortKey(ID3TagNames.INDEX_SYNC_SORT, this.getFirstInCycle()));
                                  SecondTable.instanceOf().getTable().getRowSorter().setSortKeys(newKeys);
                      
                              }
                      
                              if (!this.sortKeys.equals(old)) {
                                  fireSortOrderChanged();
                                  if (viewToModel == null) {
                                      // Currently unsorted, use sort so that internal fields
                                      // are correctly set.
                                      sort();
                                  } else {
                                      sortExistingData();
                                  }
                              }
                      
                          TableOneModel tableOneData = new TableOneModel( /* omitted */ );
                          JTable tableOne = new JTable(tableOneData);
                          TableRowSorter<TableOneModel> sorterOne = new TableRowSorter<>(tableOneData);
                          tableOne.setRowSorter(sorterOne);
                      
                          TableTwoModel tableTwoData = new TableTwoModel(
                                  /* omitted */,
                                  sorterOne);
                          JTable tableTwo = new JTable(tableTwoData);
                      
                      private static class TableOneModel extends AbstractTableModel {
                          private final String[] columnNames;
                          private final Object[][] data;
                      
                          public TableOneModel(String[] columnNames, Object[][] data) {
                              this.columnNames = columnNames;
                              this.data = data;
                          }
                      
                          public int getRowCount() { return data.length; }
                      
                          public int getColumnCount() { return columnNames.length; }
                      
                          public Object getValueAt(int rowIndex, int columnIndex) {
                              return data[rowIndex][columnIndex];
                          }
                      }
                      
                      private static class TableTwoModel extends TableOneModel
                              implements RowSorterListener {
                      
                          private final RowSorter<? extends TableModel> otherSorter;
                      
                          public TableTwoModel(String[] columnNames, Object[][] data,
                                               RowSorter<? extends TableModel> sorter) {
                              super(columnNames, data);
                              this.otherSorter = sorter;
                              installListeners();
                          }
                      
                          @Override
                          public Object getValueAt(int rowIndex, int columnIndex) {
                              return super.getValueAt(
                                      otherSorter.convertRowIndexToModel(rowIndex),
                                      columnIndex);
                          }
                      
                          private void installListeners() {
                              otherSorter.addRowSorterListener(this);
                          }
                      
                          @Override
                          public void sorterChanged(RowSorterEvent e) {
                              fireTableDataChanged();
                          }
                      }
                      
                          TableOneModel tableOneData = new TableOneModel( /* omitted */ );
                          JTable tableOne = new JTable(tableOneData);
                          TableRowSorter<TableOneModel> sorterOne = new TableRowSorter<>(tableOneData);
                          tableOne.setRowSorter(sorterOne);
                      
                          TableTwoModel tableTwoData = new TableTwoModel(
                                  /* omitted */,
                                  sorterOne);
                          JTable tableTwo = new JTable(tableTwoData);
                      
                      private static class TableOneModel extends AbstractTableModel {
                          private final String[] columnNames;
                          private final Object[][] data;
                      
                          public TableOneModel(String[] columnNames, Object[][] data) {
                              this.columnNames = columnNames;
                              this.data = data;
                          }
                      
                          public int getRowCount() { return data.length; }
                      
                          public int getColumnCount() { return columnNames.length; }
                      
                          public Object getValueAt(int rowIndex, int columnIndex) {
                              return data[rowIndex][columnIndex];
                          }
                      }
                      
                      private static class TableTwoModel extends TableOneModel
                              implements RowSorterListener {
                      
                          private final RowSorter<? extends TableModel> otherSorter;
                      
                          public TableTwoModel(String[] columnNames, Object[][] data,
                                               RowSorter<? extends TableModel> sorter) {
                              super(columnNames, data);
                              this.otherSorter = sorter;
                              installListeners();
                          }
                      
                          @Override
                          public Object getValueAt(int rowIndex, int columnIndex) {
                              return super.getValueAt(
                                      otherSorter.convertRowIndexToModel(rowIndex),
                                      columnIndex);
                          }
                      
                          private void installListeners() {
                              otherSorter.addRowSorterListener(this);
                          }
                      
                          @Override
                          public void sorterChanged(RowSorterEvent e) {
                              fireTableDataChanged();
                          }
                      }
                      
                          TableOneModel tableOneData = new TableOneModel( /* omitted */ );
                          JTable tableOne = new JTable(tableOneData);
                          TableRowSorter<TableOneModel> sorterOne = new TableRowSorter<>(tableOneData);
                          tableOne.setRowSorter(sorterOne);
                      
                          TableTwoModel tableTwoData = new TableTwoModel(
                                  /* omitted */,
                                  sorterOne);
                          JTable tableTwo = new JTable(tableTwoData);
                      
                      private static class TableOneModel extends AbstractTableModel {
                          private final String[] columnNames;
                          private final Object[][] data;
                      
                          public TableOneModel(String[] columnNames, Object[][] data) {
                              this.columnNames = columnNames;
                              this.data = data;
                          }
                      
                          public int getRowCount() { return data.length; }
                      
                          public int getColumnCount() { return columnNames.length; }
                      
                          public Object getValueAt(int rowIndex, int columnIndex) {
                              return data[rowIndex][columnIndex];
                          }
                      }
                      
                      private static class TableTwoModel extends TableOneModel
                              implements RowSorterListener {
                      
                          private final RowSorter<? extends TableModel> otherSorter;
                      
                          public TableTwoModel(String[] columnNames, Object[][] data,
                                               RowSorter<? extends TableModel> sorter) {
                              super(columnNames, data);
                              this.otherSorter = sorter;
                              installListeners();
                          }
                      
                          @Override
                          public Object getValueAt(int rowIndex, int columnIndex) {
                              return super.getValueAt(
                                      otherSorter.convertRowIndexToModel(rowIndex),
                                      columnIndex);
                          }
                      
                          private void installListeners() {
                              otherSorter.addRowSorterListener(this);
                          }
                      
                          @Override
                          public void sorterChanged(RowSorterEvent e) {
                              fireTableDataChanged();
                          }
                      }
                      

                      Combine two freemarker hash with same key inside table

                      copy iconCopydownload iconDownload
                      <#assign map1 = { "1": "Potato", "2": "Chilly" } >
                      <#assign map2 = { "1": "Apple", "2": "Plum", "3": "Extra" } >
                      <#list (map1 + map2)?keys as key>
                      <tr>
                          <td>${key}</td>
                          <td>${map1[key]!}</td>
                          <td>${map2[key]!}</td>
                      </tr>
                      </#list>
                      

                      See all related Code Snippets

                      Community Discussions

                      Trending Discussions on plum
                      • Cannot read properties of null (reading 'value')
                      • Separate column on a space after keyword
                      • Add column to pandas df of order per category in another column
                      • sort rdd by two values and get top 10 per group
                      • excel dwindling dynamic drop downs - need a springboard to get started
                      • VBA Compare single row values and highlight the entire row if different
                      • Better solution to find and return duplicates in an array - VBA
                      • How to bind each array item to its element node representation and make the nodes watch the array?
                      • In Java Swing (using swingx) how to sort rows in one table in same order as another table
                      • Combine two freemarker hash with same key inside table
                      Trending Discussions on plum

                      QUESTION

                      Cannot read properties of null (reading 'value')

                      Asked 2022-Mar-19 at 08:41

                      I am trying to get the value of the input number field but it returns me the said error.

                      HTML: <label for="number1">Enter the First number :</label> <input type="number" value="0" id="fornum1">

                      JavaScript: var num1 = document.getElementById("fornum1").value;

                      The whole point of the website is to create a basic calculator that uses buttons to display outputs on a input field.

                      var num1;
                      var num2;
                      var answer;
                      
                      num1 = document.getElementById("fornum1").value;
                      num2 = document.getElementById("fornum2").value;
                      
                      console.log(num1)
                      
                      function addition() {
                        answer = num1 + num2;
                        document.getElementById("sum").value = answer;
                      }
                      
                      function subtraction() {
                        answer = num1 - num2;
                        document.getElementById("minus").value = answer;
                      }
                      
                      function multiplication() {
                        answer = num1 * num2;
                        document.getElementById("product").value = answer;
                      }
                      
                      function division() {
                        answer = num1 / num2;
                        document.getElementById("divs").value = answer;
                      }
                      #div1 {
                        height: 300px;
                        width: 500px;
                        background-color: plum;
                        margin: auto;
                        padding: 5%;
                      }
                      
                      body {
                        font-family: Courier;
                      }
                      
                      label {
                        width: 300px;
                        display: inline-block;
                      }
                      
                      #div2 input {
                        width: 120px;
                      }
                      <script src="myscripts.js"></script>
                      <div id="div1">
                        <p style="text-align: center;">FOUR BASIC OPERATIONS</p>
                      
                        <label for="number1">Enter the First number :</label>
                        <input type="number" value="0" id="fornum1">
                        <br><br>
                      
                        <label for="number2">Enter the Second number:</label>
                        <input type="number" value="0" id="fornum2">
                        <br><br><br><br>
                      
                        <div align="center" id="div2">
                          <button type="button" onclick="addition()">Add</button>
                          <input type="text" id="sum" readonly>
                          <button type="button">Subtraction </button>
                          <input type="text" id="minus" onclick="subtraction()" readonly>
                          <br><br><br>
                      
                          <button type="button">Multiplication</button>
                          <input type="text" id="product" onclick="multiplication()" readonly>
                          <button type="button">Division</button>
                          <input type="text" id="divs" onclick="division()" readonly>
                        </div>
                      
                      
                      </div>

                      ANSWER

                      Answered 2022-Mar-19 at 08:37

                      First of all, as @mplungjan suggested in the comments, move the script:src to after the </body> tag. Next, you declare num1 and num2 in the start of the script, meaning if the input's values will change the program will still have num1 and num2 set to 0. So all you need to do is when the button is clicked, check the input's values again for a change. Lastly, the checking the input's values returns a string, not a number as you would want in a calculator. So all you need to do is convert the string into a number, using ParseInt.

                      var num1;
                      var num2;
                      var answer;
                      
                      num1 = document.getElementById("fornum1").value;
                      num2 = document.getElementById("fornum2").value;
                      
                      function addition() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 + num2;
                          document.getElementById("sum").value = answer;
                      }
                      
                      function subtraction() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 - num2;
                          document.getElementById("minus").value = answer;
                      }
                      
                      function multiplication() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 * num2;
                          document.getElementById("product").value = answer;
                      }
                      
                      function division() {
                          num1 = document.getElementById("fornum1").value;
                          num2 = document.getElementById("fornum2").value;
                          num1 = parseInt(num1)
                          num2 = parseInt(num2)
                          answer = num1 / num2;
                          document.getElementById("divs").value = answer;
                      }
                      <!DOCTYPE html>
                      <html>
                          <head>
                              <title>Four Basic Operators</title>
                              <style>
                                  #div1 {
                                      height: 300px;
                                      width: 500px;
                                      background-color: plum;
                                      margin: auto;
                                      padding: 5%;
                                  }
                                  body {
                                      font-family: Courier;
                                  }
                                  label {
                                      width: 300px;
                                      display: inline-block;
                                  }
                                  #div2 input {
                                      width: 120px;
                                  }
                              </style>
                          </head>
                          <body>
                              <div id="div1">
                                  <p style="text-align: center;">FOUR BASIC OPERATIONS</p>
                                  
                                  <label for="number1">Enter the First number :</label>
                                  <input type="number" value="0" id="fornum1">
                                  <br><br>
                      
                                  <label for="number2">Enter the Second number:</label>
                                  <input type="number" value="0" id="fornum2">
                                  <br><br><br><br>
                      
                                  <div align="center" id="div2">
                                      <button type="button" onclick="addition()">Add</button>
                                      <input type="text" id="sum" readonly>
                                      <button type="button" >Subtraction </button>
                                      <input type="text" id="minus" onclick="subtraction()" readonly>
                                      <br><br><br>
                      
                                      <button type="button">Multiplication</button>
                                      <input type="text" id="product" onclick="multiplication()" readonly>
                                      <button type="button">Division</button>
                                      <input type="text" id="divs" onclick="division()" readonly>
                                  </div>
                                 
                                  
                              </div>
                          </body>
                              <script src="script.js"></script>
                      </html>

                      Source https://stackoverflow.com/questions/71536448

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install plum

                      You can download it from GitHub.
                      You can use plum like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the plum component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Share this Page

                      share link
                      Consider Popular Java Libraries
                      Try Top Libraries by fitzyyf
                      Compare Java Libraries with Highest Support
                      Compare Java Libraries with Highest Quality
                      Compare Java Libraries with Highest Security
                      Compare Java Libraries with Permissive License
                      Compare Java Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.