@Test public void valuesToArray() { HazelcastClient hClient = getHazelcastClient(); IMap map = hClient.getMap("valuesToArray"); assertEquals(0, map.size()); map.put("a", "1"); map.put("b", "2"); map.put("c", "3"); assertEquals(3, map.size()); { final Object[] values = map.values().toArray(); Arrays.sort(values); assertArrayEquals(new Object[] {"1", "2", "3"}, values); } { final String[] values = (String[]) map.values().toArray(new String[3]); Arrays.sort(values); assertArrayEquals(new String[] {"1", "2", "3"}, values); } { final String[] values = (String[]) map.values().toArray(new String[2]); Arrays.sort(values); assertArrayEquals(new String[] {"1", "2", "3"}, values); } { final String[] values = (String[]) map.values().toArray(new String[5]); Arrays.sort(values, 0, 3); assertArrayEquals(new String[] {"1", "2", "3", null, null}, values); } }
/** * Copy from the copy method in StructUtil. Did not want to drag that code in. maybe this actually * should go to struct. * * @param from * @param to * @param excludes * @return * @throws Exception */ public static <T extends struct> T xcopy(struct from, T to, String... excludes) throws Exception { Arrays.sort(excludes); for (Field f : from.fields()) { if (Arrays.binarySearch(excludes, f.getName()) >= 0) continue; Object o = f.get(from); if (o == null) continue; Field tof = to.getField(f.getName()); if (tof != null) try { tof.set(to, Converter.cnv(tof.getGenericType(), o)); } catch (Exception e) { System.out.println( "Failed to convert " + f.getName() + " from " + from.getClass() + " to " + to.getClass() + " value " + o + " exception " + e); } } return to; }
/** * Adds a new int parameter to be altered for the model being tuned. * * @param param the model parameter * @param initialSearchValues the values to try for the specified parameter */ public void addParameter(IntParameter param, int... initialSearchValues) { searchParams.add(param); DoubleList dl = new DoubleList(initialSearchValues.length); for (double d : initialSearchValues) dl.add(d); Arrays.sort(dl.getBackingArray()); // convience, only really needed if param is warm if (param.isWarmParameter() && !param.preferredLowToHigh()) Collections.reverse(dl); // put it in the prefered order if (param.isWarmParameter()) // put it at the front! searchValues.add(0, dl); else searchValues.add(dl); }
/** * Adds a new double parameter to be altered for the model being tuned. * * @param param the model parameter * @param initialSearchValues the values to try for the specified parameter */ public void addParameter(DoubleParameter param, double... initialSearchValues) { if (param == null) throw new IllegalArgumentException("null not allowed for parameter"); searchParams.add(param); DoubleList dl = new DoubleList(initialSearchValues.length); for (double d : initialSearchValues) dl.add(d); Arrays.sort(dl.getBackingArray()); // convience, only really needed if param is warm if (param.isWarmParameter() && !param.preferredLowToHigh()) Collections.reverse(dl); // put it in the prefered order if (param.isWarmParameter()) // put it at the front! searchValues.add(0, dl); else searchValues.add(dl); }
public void run() { Comparator<Double> comp = new Comparator<Double>() { public int compare(Double i1, Double i2) { component.setValues(values, i1, i2); try { if (run) Thread.sleep(DELAY); else gate.acquire(); } catch (InterruptedException exception) { Thread.currentThread().interrupt(); } return i1.compareTo(i2); } }; Arrays.sort(values, comp); component.setValues(values, null, null); }