code-duplication

When and Where to call EventQueue.invokeLater() method

淺唱寂寞╮ 提交于 2021-01-21 11:41:32
问题 I'm totally fresh about threading and GUIs, therefore I couldn't figure out exactly where to call this EventQueue.invokeLater() method. Am I supposed to call it in every event listeners and something else? What are those "things" to call this method? If so, is there any alternative way to call-once-apply-everywhere method so that It won't take bunch of lines to tuck them to the Event dispatch thread? Thank you. 回答1: therefore I couldn't figure out exactly where to call this EventQueue

When and Where to call EventQueue.invokeLater() method

a 夏天 提交于 2021-01-21 11:39:07
问题 I'm totally fresh about threading and GUIs, therefore I couldn't figure out exactly where to call this EventQueue.invokeLater() method. Am I supposed to call it in every event listeners and something else? What are those "things" to call this method? If so, is there any alternative way to call-once-apply-everywhere method so that It won't take bunch of lines to tuck them to the Event dispatch thread? Thank you. 回答1: therefore I couldn't figure out exactly where to call this EventQueue

Java Generics method code duplication issue regarding primitive arrays

て烟熏妆下的殇ゞ 提交于 2020-02-29 04:37:09
问题 So I'm working on an implementation of a Grid class for a small, personal utilities library. After much work, I'm tidying up the Grid class and adding some functionality. One of the key pieces of functionality that I wish to use with my Grid class is to be able to take a single, 2D array of any given type as an argument to the constructor. This worked fine until I realized that I can't compile any code that attempts to pass in any array of primitives to the constructor. Since autoboxing doesn

How to reduce code duplication when dealing with recursive sum types

好久不见. 提交于 2020-02-17 05:16:34
问题 I am currently working on a simple interpreter for a programming language and I have a data type like this: data Expr = Variable String | Number Int | Add [Expr] | Sub Expr Expr And I have many functions that do simple things like: -- Substitute a value for a variable substituteName :: String -> Int -> Expr -> Expr substituteName name newValue = go where go (Variable x) | x == name = Number newValue go (Add xs) = Add $ map go xs go (Sub x y) = Sub (go x) (go y) go other = other -- Replace

How to reduce code duplication when dealing with recursive sum types

百般思念 提交于 2020-02-17 05:15:07
问题 I am currently working on a simple interpreter for a programming language and I have a data type like this: data Expr = Variable String | Number Int | Add [Expr] | Sub Expr Expr And I have many functions that do simple things like: -- Substitute a value for a variable substituteName :: String -> Int -> Expr -> Expr substituteName name newValue = go where go (Variable x) | x == name = Number newValue go (Add xs) = Add $ map go xs go (Sub x y) = Sub (go x) (go y) go other = other -- Replace

Automatic code deduplication of assembly language?

夙愿已清 提交于 2020-01-22 14:39:50
问题 I've been going through some Assembly Programming Videos to get a better understanding of how to manually optimize the *.s files left after compiling with gcc/g++ -S ... One of the topics covered was Refactoring Redundant Code that demonstrates how to move redundant code to its own labeled block ending with a ret and replacing it with a call. The example given in the video is 2 blocks containing: mov eax,power mul ebx mov power,eax inc count which it replaces with call CalculateNextPower and

Code duplication caused by primitive types: How to avoid insanity?

那年仲夏 提交于 2020-01-10 06:56:27
问题 In one of my Java projects I am plagued by code repetition due to the way Java handles (not) primitives. After having to manually copy the same change to four different locations ( int , long , float , double ) again , for the third time, again and again I came really close (?) to snapping. In various forms, this issue has been brought up now and then on StackOverflow: Managing highly repetitive code and documentation in Java How to avoid repetition when working with primitive types? Passing

How to avoid getters/setters in classes with many instance variables

限于喜欢 提交于 2020-01-01 05:51:06
问题 I'll try to keep it short. I have classes with many instance variables (30+) and hence many getters/setters. The classes by themselves are simple, but because of the getters/setters the LOC just exploded (and there also was way too much code duplicity). So I removed the attributes and stored them in a map, like this public class MyTechnicalToolClassX { //...constructor private Map<String, Object> data; public Object getAttributeByKey(AttributeKey key) { // ...doStuff, check data associated