@SuppressWarnings("unchecked")
		public SPairList<Integer,Double> getValueSortedBucket(int material)
		{
			material=(material&RawMaterial.MATERIAL_MASK)>>8;
			final int numMaterials=Material.values().length;
			if((material<0)||(material>=numMaterials))
				return null;
			if(buckets == null)
			{
				final SPairList<Integer,Double>[] newBuckets=new SPairList[numMaterials];
				for(int matIndex=0;matIndex<numMaterials;matIndex++)
				{
					final int matCode = Material.values()[matIndex].mask();
					final TreeSet<Pair<Integer,Double>> newBucket=new TreeSet<Pair<Integer,Double>>(
						new Comparator<Pair<Integer,Double>>()
						{
							@Override
							public int compare(Pair<Integer, Double> o1, Pair<Integer, Double> o2)
							{
								return o1.second.compareTo(o2.second);
							}
						});
					for(int i=0;i<total();i++)
					{
						final int resourceCode=get(i);
						if((resourceCode&RawMaterial.MATERIAL_MASK)==matCode)
						{
							final int resourceValue=value( resourceCode );
							newBucket.add(new Pair<Integer,Double>(Integer.valueOf(resourceCode),Double.valueOf(resourceValue)));
						}
					}
					final PairSVector<Integer,Double> finalBucket=new PairSVector<Integer,Double>();
					final double pieceSize=1.0 / newBucket.size();
					double currValue = 0.0;
					for (final Pair<Integer, Double> p : newBucket)
					{
						finalBucket.add(p.first, Double.valueOf(currValue));
						currValue += pieceSize;
					}
					newBuckets[matIndex]=finalBucket;
				}
				buckets=newBuckets;
			}
			return buckets[material];
		}