Repository navigation
Expand file tree
/
Copy pathHList.java
More file actions
97 lines (78 loc) · 2.32 KB
/
Copy pathHList.java
File metadata and controls
97 lines (78 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// Copyright (c) 2016, Brian Frank
// Licensed under the Academic Free License version 3.0
//
// History:
// 06 June 2016 Matthew Giannini Creation
//
package org.projecthaystack;
import java.util.Arrays;
import java.util.List;
/**
* HList is an immutable list of HVal items.
*/
public class HList extends HVal
{
//////////////////////////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////////////////////////////////
public static final HList EMPTY = new HList(new HVal[0]);
/** Create a list of the given items. The items are copied */
public static HList make(HVal[] items)
{
HVal[] copy = new HVal[items.length];
System.arraycopy(items, 0, copy, 0, items.length);
return new HList(copy);
}
/** Create a list from the given items. The items are copied */
public static HList make(List items)
{
HVal[] copy = (HVal[])items.toArray(new HVal[items.size()]);
return new HList(copy);
}
private HList(HVal[] items)
{
this.items = items;
}
//////////////////////////////////////////////////////////////////////////
// Access
//////////////////////////////////////////////////////////////////////////
/** Get the number of items in the list */
public int size() { return items.length; }
/** Get the HVal at the given index */
public HVal get(int i) { return items[i]; }
//////////////////////////////////////////////////////////////////////////
// HVal
//////////////////////////////////////////////////////////////////////////
public String toZinc()
{
StringBuffer s = new StringBuffer();
s.append('[');
for (int i=0; i<items.length; ++i)
{
if (i > 0) s.append(',');
s.append(items[i].toZinc());
}
s.append(']');
return s.toString();
}
public String toJson()
{
throw new UnsupportedOperationException();
}
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HList hList = (HList) o;
return Arrays.equals(items, hList.items);
}
public int hashCode()
{
return Arrays.hashCode(items);
}
//////////////////////////////////////////////////////////////////////////
// Fields
//////////////////////////////////////////////////////////////////////////
private final HVal[] items;
}