Tagged Questions

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.

learn more… | top users | synonyms

4
votes
0answers
73 views

Transformation of abstract models

In one of my recent projects I faced the problem of transforming an abstract class into another abstract class. The classes were structured like this and are part of an api for questionnaires: ...
-1
votes
0answers
73 views

Extending unparametrized class vs. unchecked casting [on hold]

I have the following API code (unchangeable): ...
10
votes
4answers
446 views

Cutting it to Pages

I was working on representing a large List of information on a number of different pages, and a colleague of mine suggested that I try to make a generic method for ...
4
votes
2answers
50 views

Making a database entity superclass

I am using JPA for my database work and I need to create a database entity superclass which all of my table entities will extend. Every database entity will have a primary key named ...
2
votes
1answer
67 views

Functional interface uses uncheck or unsafe operations

First of all, I am absolutely surprised that this code even works. Originally what I did was create a version checking system for Minecraft plugins (specifically Bukkit, Craftbukkit, & Spigot). ...
3
votes
1answer
22 views

Generic Timing Class - Follow Up

I wrote a class which can time and compare functions. I already posted it here once before, and got great suggestions from @rolfl, which I have added to my code. my original question can be found ...
6
votes
1answer
46 views

Generic Timing Class

I have written a class which can time functions, and I'd like to have it reviewed. I'm interested in everything (better naming and commenting, accuracy of measurement, usability, structure, use of ...
2
votes
1answer
73 views

Best way to write generic factory in Java

I need to write a factory of generic converters to produce converters from/to MongoDB objects to/from Java objects. Here is my implementation, it doesn't look good enough to me, so I would like to see ...
8
votes
2answers
67 views

Generic mean function

It seems useful to have a generic function to calculate the mean of all elements in a container, so I wrote one. By default it calculates the arithmetic mean, but should be able to accommodate other ...
1
vote
0answers
48 views

Separation of concerns for security checks

I needed a nice typesafe way to implement security checks for various domain objects and actions that can be performed on them. I had an idea how to do it, so I implemented it as a simple proof of ...
6
votes
1answer
185 views

Cast a raw map to a generic map using a method, cleanly and safely in a fail early manner

Casting, instanceof, and @SuppressWarnings("unchecked") are noisy. It would be nice to stuff them down into a method where they won't need to be looked at. ...
3
votes
1answer
64 views

Get object in a Set that is an instance of a generically specified type

Are there ways to simplify the getLoadComponent(Class<T> type) method? The call ...
0
votes
2answers
228 views

RESTEasy client that should use generics

I have written some code using RESTEasy to handle RESTful service calls and parse the response XML into relevant JAXB annotated classes. At the moment I have seperate methods for each return type: ...
6
votes
3answers
723 views

Simplifying a series of type checks and casts in a generic method

The if/else statements below are not good. How can I improve this method? ...
2
votes
0answers
123 views

Generic Entity Framework Query in CQRS

I've been working on our application (CQRS and DDD) for awhile now. The application architecture is well layered and thought through. However we are having difficulties in decide where to put the ...
4
votes
2answers
125 views

Generic equality checker

I use this method to check if two reference types are equal ...
7
votes
2answers
410 views

Generic cached value class mimicking Lazy<T>

Before I wrote this I searched and found a number of solutions that make use of a caching provider to handle a set of items. I felt that was too cumbersome of an approach and set out to create a class ...
8
votes
2answers
124 views

Reasonable way to implement “safe” math operations using _Generic?

I've been thinking about a way to make it easier to safely use math operations with C's basic datatypes (e.g. using the CERT C coding standard). So far, I've come up with something like this: ...
4
votes
3answers
71 views

Idiomatic Scala Generics

I'm working on some Scala problems given here, specifically: ...
2
votes
2answers
64 views

Convert Extension methods to generic methods

I was looking at some Linq queries with multiple join statements. I was thinking that they could be cleaned up using extension methods that hide away the join / where statements. For example: ...
11
votes
2answers
333 views

Instantiating a run-time implementation of an interface

Below is my code that was written for the following task (based on an SO question): Given a Java Collection (of N elements) create an ...
14
votes
4answers
2k views

Reusability vs simplicity in a small game with a set of interfaces

I have a small game I'm working on with a set of interfaces: IHavePosition: ...
2
votes
2answers
142 views

Converting web-querying classes to a single generic class

I have two classes that do that same thing with different types. I was thinking of using generics (but I am open to all options). QueryPermissions and the ...
9
votes
3answers
648 views

Generic deque implementation

I implemented a generic Deque<T> data structure. Please, review this implementation. Deque.java: ...
2
votes
1answer
125 views

Many interfaces and lots of inheritance vs few interfaces and less inheritance? [closed]

I have a Visual Studio Solution which has a bunch of Projects in it. One of these projects is called "Services" and is basically the junction point between all remaining projects. When I built it ...
9
votes
4answers
360 views

Do I need Generics for these node and tree classes?

I want to implement KD tree. I have defined class Node as follows: ...
5
votes
1answer
80 views

Message Based Communication Design

I'm trying to design an API.NET for some communication purposes with Testing Equipment and I cannot figure out a proper way for designing the architecture. Basically, we have different (physical) ...
4
votes
3answers
383 views

Refactor C# Linq code to reduce duplication

I currently have the below code: ...
8
votes
2answers
195 views

C++(11/14) intercalate implementation

I wrote a simple generic intercalate function (that should be semantically equivalent to the Haskell intercalate). ...
4
votes
1answer
91 views

Is this a good way to deal with this tricky generic situation?

I have a project which should be thought of split into two layers: an IO layer which consists of sensors (input) and effectors (output), and a core layer which contains logic for determining which ...
5
votes
2answers
295 views

Static Data Helper for an Oracle Backend

What I would like to do is have a method call like: ...
5
votes
1answer
90 views

Generic property with AOP-functionality in Java

After playing around with Java 8 and Generics for some time, I came across an idea while reading some posts about Apple's new programming language Swift. Swift has AOP-like methods for properties ...
1
vote
0answers
55 views

Feedback for a mostly auto-generated generic data layer

I'm trying to make a reusable data layer that is mostly generated from a database via T4 templates. On top of this data layer, I'd like to have WebAPI endpoints for each repository, with most of the ...
2
votes
1answer
106 views

Generic util method to convert in single map from list of array of Object generally result of JPQL/ hibernate

I have designed a generic method to convert list of array of Objects to result into single map. This is working fine, but I want to check weather a key object is valid key (whether it is overriding ...
1
vote
3answers
119 views

Would ignoring generic types to provide default behavior when client uses my default constructor confuse people?

I'm wondering if providing default behavior is ever worth the confusion caused by ignoring generic type passed in. Another question brought up this issue: ...
5
votes
1answer
59 views

Having children call parent's public events with data generated from a protected event

I don't know that my title describes the code I want reviewed. Hopefully the code is explanatory. I have an abstract parent class with two children. The parent listens to some hardware notifications ...
2
votes
1answer
1k views

Generic, thread-safe MemoryCache manager for C#

Using this question as a base, and using some of the advice in the answers, I wanted to build out something that would be generic, thread-safe, and easy to use for at least one current and several ...
7
votes
1answer
174 views

Generic radix sort

This started out with my answer to Radix Sort on an Array of Strings?. Since I intend to write a generic radix sort for my own purposes anyway, I continued a little bit, and here is a version tested ...
5
votes
1answer
121 views

Is there a simpler way to create this Inheritance structure for overriding an internal Generic Type?

I have some code below which is designed for the following purposes: Implement a cache structure which stores cached elements, as well as a method for reloading those elements. Ensure the new ...
7
votes
2answers
367 views

Generic ArrayList

Can anyone recommend improvements to the compress() method? ...
10
votes
3answers
464 views

Recursive Fibonacci with Generic delegates

Here is a fast recursive Fibonacci-like for loop. How can it be more readable, and is it possible remove TArgs? ...
4
votes
2answers
82 views

Pattern for storing object of varying type

I have a situation where I need to store fields of differing types of some data structures along with some similar metadata (The application takes data from one of many sources, some data possibly ...
3
votes
1answer
126 views

Genericizing PropertyValues

This should be the last iteration for this code. Question 1 Does this approach make sense or am I heading down the wrong path? Question 2 The only thing I can see to make this better is to ...
3
votes
1answer
199 views

Session state wrapper, extending an existing application

I'm adding additional functionality to an existing MVC .net application, and to help prevent or at least reduce repeated reads to the dB I'm dumping a few custom entities in session. I'm limiting what ...
6
votes
2answers
1k views

Empty Interface usage - is this a code smell?

I've recently made a set of interfaces/classes to work with converting a spreadsheet into an object but I utilise an empty interface in my design: So first off I have my interface which defines what ...
7
votes
1answer
153 views

Model simulation using Java annotations

A couple of days ago I posted my code that models systems made up of moving parts. I got several great tips and ideas and here is my latest version. My actions are now methods annotated with @Action ...
7
votes
2answers
254 views

Game passive skill system

I'm trying to create some easily accessible database of different skills. General idea is that every skill should do something different and be able to act on different things (ex. one skill which ...
2
votes
1answer
350 views

Delegate that selects a writable property on a generic

In the following contrived example, I have a collection of PropertyManagers that each contains selector and assigner delegates to read from and write to a property ...
7
votes
1answer
90 views

Monadic Immutable Linked List in the Least Functional Language Evar

I've written a List monad as an example for a related question. This is a rather frustrating experience as I wanted to use Java, which (as of Java 7) still lacks lambda expressions and lacks ...
6
votes
2answers
110 views

A monad in Java (FriendSpace and People)

After asking a similar question on Stack Overflow, I'm picking up on the answer there to improve my monad. I'm not trying to solve the general case, just come up with one to see how it works. If I'm ...