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

8
votes
2answers
170 views

Optimize a generic foreach method that converts Datatable to my object using Reflection

I need to optimize this code block below, this method converts a Datatable object to the Object that I am passing by parameter, in another words, this serializes the object, however I have to run this ...
7
votes
4answers
113 views

Typed NSUserDefaults

I was looking around for a Swift wrapper around NSUserDefaults and found some very nice projects (see e.g. SwiftyUserDefaults). Unfortunately, it all boils down to ...
0
votes
1answer
66 views

Implementation of peak finder

I implemented this peak finder for practice. I have tested it. Everything looks pretty good to me. Please let me know if there is any improvement I can make. Peak Finder Let input be an ...
4
votes
0answers
34 views

Recursive flattening of Swift sequences

In Flatten to get all child controls of certain type in a UIView, methods were discussed to recursively flatten a tree-like structure in Swift, resulting in an array of all elements. Motivated by ...
2
votes
1answer
47 views

Generic classes with inheritance/equals/comparison operators

I would like to greatly reduce verbosity of following code fragment. What I'd like to do: Reduce number of occurrences of MaterialRangedParam<Value> and ...
3
votes
1answer
65 views

Java Generics - Write a generic method to find the maximal element in the range [begin, end] of a list

I'm a Java beginner, going through the Generics Questions and Exercises in Oracle's The Java Tutorials. Here's my solution to #8: Write a generic method to find the maximal element in the range ...
7
votes
0answers
125 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
6
votes
2answers
108 views

Generic NSMapTable replacement written in Swift

This is my attempt at writing a generic NSMapTable with weak keys and strong values (after your feedback I'll be trying to write Strong-Key/Weak-Value and ...
5
votes
1answer
45 views

Mergesort a LinkedList

I have made an attempt to write the mergesort routine on a LinkedList in Java. It will be great if somebody can review my implementation and point out the issues ...
2
votes
1answer
59 views

Web API controller to get details of a travel plan or a leave request

My web API has 3 controllers for get, post and users CRUD. I named it as DetailsControllor, FormControllor and ...
2
votes
2answers
47 views

Converting a DropDownList retrieval service to generics or delegate methods

mappingService below is actually just Automapper. I have a wrapper around it so that I can inject it. I want to refactor the following code to be cleaner: ...
2
votes
0answers
39 views

Implementing insertAt for both [a] and [(i,a)] lists

I've implemented generic insertAt function which inserts value to a list independently from is list indexed or not. Here are some examples: ...
2
votes
0answers
40 views

Advice on modelling with generics in Java

Use Case The third party library that I am working with implements its data model in this fashion. ...
3
votes
1answer
60 views

Fully Generic C++ Stack Implementation Without Lists, Arrays, or Vectors

I'm trying to write a fully generic Stack in C++. I'm not sure if this is the best way to do this. Right now I know that the Pop method needs improvement since ...
0
votes
1answer
80 views

Creating a Generic Template Interface/Class and injecting into another object

I would like to create a generic template class for my document processor. Assuming the template has a source file path and a "content", here's what I came up with: Template ...
7
votes
2answers
155 views

Generic queries and handlers without reflection

I'm trying to implement generic queries and handlers so that I can make requests with simple syntax, like this: ...
1
vote
1answer
32 views

A banded interpolator, for any type and any interpolation method

This is an extension of my Attributes system I wrote about in these questions: Lvl 1 upgradeable attributes Lvl2 upgradeable attributes It is unrelated to the core functionality under review in ...
3
votes
2answers
100 views

Immutable Queue in Java using an Immutable Stack

I am new to this Immutability concept and I have some coding experience in JAVA. Recently as a part of internship program, they gave me a 5-day task, which was to implement Immutable Queue. After some ...
5
votes
1answer
62 views

Self-made LinkedList and Node

I have recently made two kinds of linked lists in Java. I know that there is one with generic and one without. However, what I am really concerned about is which style should be used mostly (or which ...
4
votes
3answers
356 views

Generic sum method for a Collection<Number>

While answering this question, I wanted to use a generic sum of Collection function. Java doesn't have a native method, so I wrote one. There are a couple things ...
11
votes
3answers
276 views

Simple Generic output for Deserializer

Lately I have been learning about serialization so I decided to write a little helper class for my application to make it easy to use this feature in multiple places. I actually mixed some generics in ...
3
votes
3answers
155 views

Implementing a singly LinkedList and IList interface

I have implemented a LinkedList in C#. What would you change/make better? What naming conventions are misused? What would you add? Some of my ideas are to make it ...
0
votes
0answers
43 views

Refactoring ideas wanted [closed]

I have a several WebApi controllers have that use 2 generic classes for processing. Depending on the data sent in the request, one of the generic classes is called. This logic is wrapped in a ...
3
votes
2answers
72 views

Nullable Generics - Implementing SequentialSearchST in C#

For learning purposes, I am implementing certain code from Sedgewick & Wayne's Algorithms, Fourth Edition. Because of language features, a direct translation doesn't seem possible. For example, ...
1
vote
1answer
74 views

Does Java need an Observable object with generics?

This is the follow-up question from here. This is an Observable class similar to java.util.Observable. The difference is that ...
3
votes
2answers
272 views

java.util.Observable but with generics to avoid casts

This is an Observable class similar to java.util.Observable. The difference is that it uses generics to avoid casts. The ...
1
vote
2answers
96 views

Parse File or String input in a uniform way: Is it possible with Generics?

I have a Parser class which creates a collection of String pairs, parsed in the format key=value. ...
6
votes
1answer
215 views

VHDL mux in need of generics

I've built a multiplexer which takes 2 inputs: one array of std_logic_vector and one std_logic_vector to select the correct ...
5
votes
2answers
108 views

Applying TrimSideSpaces() method to multiple string properties

I am looking for generic ideas and guidelines of how to improve the style of my coding and make it more readable and robust. ...
6
votes
3answers
1k views

How can I make this StringToCollections method more generic?

I am new to C# and I have big functions that receives the following arguments: (Package inPackage, string materialIDs, string functionIDs, string companyIDs) ...
3
votes
2answers
92 views

Typetokens in C++11

I have written a typetoken library in C++11 and I want to know if it is indeed typesafe, threadsafe and complete. The purpose of this library is to give an unique ID to every requested typename ...
1
vote
1answer
43 views

A Java class for calculating size of iterable/array v2

Version 2 of A Java class for calculating size of iterable/array ...
3
votes
1answer
145 views

A Java class for calculating size of iterable/array

Another exercise of Java generics: ...
2
votes
5answers
542 views

A Java class that prints a matrix

I am trying to learn some generic programming with Java: ...
8
votes
1answer
161 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: ...
11
votes
4answers
457 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
74 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
76 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). ...
4
votes
1answer
29 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
56 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
322 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
82 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 ...
5
votes
1answer
98 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
254 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
68 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 ...
1
vote
2answers
1k 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
810 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
372 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 ...
5
votes
2answers
154 views

Generic equality checker

I use this method to check if two reference types are equal ...
7
votes
2answers
449 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 ...