1 /******************************************************************************
2 
3     Map numbers to easier distinguishable names
4 
5     Copyright:
6         Copyright (c) 2009-2016 dunnhumby Germany GmbH.
7         All rights reserved.
8 
9     License:
10         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
11         Alternatively, this file may be distributed under the terms of the Tango
12         3-Clause BSD License (see LICENSE_BSD.txt for details).
13 
14 *******************************************************************************/
15 
16 module ocean.io.digest.FirstName;
17 
18 
19 
20 import ocean.meta.types.Qualifiers;
21 
22 import ocean.io.digest.Fnv1;
23 
24 
25 /*******************************************************************************
26 
27     Class to provide number -> name translation
28 
29     This class is useful for when you want to display a lot of numbers that
30     don't have an immediate meaning for a person (pointers, hashes, etc) but
31     where it still is helpful or important to easily see whether a number is
32     different from the other.
33 
34     Usage Example:
35     ---
36 
37     import ocean.io.digest.FirstName;
38 
39     MyClass myArray[] = ... ;
40 
41 
42     foreach ( c; myArray )
43     {
44         Stdout.formatln("{}.property = {}", FirstName(cast(void*) c), c.property);
45     }
46     ---
47 
48 *******************************************************************************/
49 
50 public static class FirstName
51 {
52     /***************************************************************************
53 
54         Static list of strings (preferably names) that a number can be mapped to
55 
56     ***************************************************************************/
57 
58     static private istring[] names =
59             ["Sarah",
60             "David",
61             "Gavin",
62             "Mathias",
63             "Hans",
64             "Ben",
65             "Tom",
66             "Hatem",
67             "Donald",
68             "Luca",
69             "Lautaro",
70             "Anja",
71             "Marine",
72             "Coco",
73             "Robert",
74             "Federico",
75             "Lars",
76             "Julia",
77             "Sanne",
78             "Aylin",
79             "Tomsen",
80             "Dylan",
81             "Margit",
82             "Daniel",
83             "Diana",
84             "Jessica",
85             "Francisco",
86             "Josh",
87             "Karin",
88             "Anke",
89             "Linus",
90             "BillGates",
91             "Superman",
92             "Batman",
93             "Joker",
94             "Katniss",
95             "Spiderman",
96             "Storm",
97             "Walter",
98             "Fawfzi"];
99 
100     /***************************************************************************
101 
102         Function to map an abitrary integer to a string for easier distinction
103 
104         Params:
105             T = integer type, should be Fnv1a compatible
106             value = an integer value to map
107 
108         Returns:
109             a string matching the hash of the given number
110 
111     ***************************************************************************/
112 
113     public static istring opCall ( T ) ( T value )
114     {
115         return names[Fnv1a64(value) % names.length];
116     }
117 }
118