Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* ---------------------------------------------------------------------
* Numenta Platform for Intelligent Computing (NuPIC)
* Copyright (C) 2014, Numenta, Inc. Unless you have an agreement
* with Numenta, Inc., for a separate license for this software code, the
* following terms and conditions apply:
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero Public License for more details.
*
* You should have received a copy of the GNU Affero Public License
* along with this program. If not, see http://www.gnu.org/licenses.
*
* http://numenta.org/licenses/
* ---------------------------------------------------------------------
*/
package org.numenta.nupic.util;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.numenta.nupic.model.Persistable;
/**
* Immutable tuple which adds associative lookup functionality.
*
* @author David Ray
*/
public class NamedTuple extends Tuple {
private static final long serialVersionUID = 1L;
Bucket[] entries;
String[] keys;
int hash;
int thisHashcode;
private static final String[] EMPTY_KEYS = {};
protected NamedTuple() {}
/**
* Constructs and new {@code NamedTuple}
*
* @param keys
* @param objects
*/
public NamedTuple(String[] keys, Object... objects) {
super(interleave(keys, objects));
if(keys.length != objects.length) {
throw new IllegalArgumentException("Keys and values must be same length.");
}
this.keys = keys;
entries = new Bucket[keys.length * 2];
for(int i = 0;i < entries.length;i++) {
entries[i] = new Bucket(i);
}
for(int i = 0;i < keys.length;i++) {
addEntry(keys[i], objects[i]);
}
this.thisHashcode = hashCode();
}
protected void remake(String[] keys, Object... objects) {
super.remake(interleave(keys, objects));
if(keys.length != objects.length) {
throw new IllegalArgumentException("Keys and values must be same length.");
}
this.keys = keys;
entries = new Bucket[keys.length * 2];
for(int i = 0;i < entries.length;i++) {
entries[i] = new Bucket(i);
}
for(int i = 0;i < keys.length;i++) {
addEntry(keys[i], objects[i]);
}
this.thisHashcode = hashCode();
}
/**
* Returns a array copy of this {@code NamedTuple}'s keys.
* @return
*/
public String[] keys() {
if(keys == null || keys.length < 1) return EMPTY_KEYS;
return Arrays.copyOf(keys, keys.length);
}
/**
* Returns a Collection view of the values of this {@code NamedTuple}
* @return
*/
public Collection