List of usage examples for org.apache.commons.lang ArrayUtils toObject
public static Boolean[] toObject(boolean[] array)
Converts an array of primitive booleans to objects.
From source file:org.epochx.ge.model.epox.Multiplexer.java
/** * Calculates the fitness score for the given program. The fitness of a * program for the majority problem is calculated by evaluating it * using each of the possible sets of input values. There are * <code>2^noInputBits</code> possible sets of inputs. The fitness of the * program is the quantity of those input sequences that the program * returned an incorrect response for. That is, a fitness value of * <code>0.0</code> indicates the program responded correctly for every * possible set of input values.//from ww w .j a va 2 s .c om * * @param p {@inheritDoc} * @return the calculated fitness for the given program. */ @Override public double getFitness(final CandidateProgram p) { final GECandidateProgram program = (GECandidateProgram) p; double score = 0; // Evaluate all possible inputValues. for (final boolean[] vars : inputValues) { // Convert to object array. final Boolean[] objVars = ArrayUtils.toObject(vars); Boolean result = null; try { result = (Boolean) interpreter.eval(program.getSourceCode(), argNames, objVars); } catch (final MalformedProgramException e) { // Assign worst possible fitness and stop evaluating. score = 0; break; } if ((result != null) && (result == multiplex(vars))) { score++; } } return inputValues.length - score; }
From source file:org.epochx.ge.model.groovy.EvenParity.java
/** * Calculates the fitness score for the given program. The fitness of a * program for the even-parity problem is calculated by evaluating it * using each of the possible sets of input values. There are * <code>2^noInputBits</code> possible sets of inputs. The fitness of the * program is the quantity of those input sequences that the program * returned an incorrect response for. That is, a fitness value of * <code>0.0</code> indicates the program responded correctly for every * possible set of input values./* w w w. ja va 2s . c om*/ * * @param p {@inheritDoc} * @return the calculated fitness for the given program. */ @Override public double getFitness(final CandidateProgram p) { final GECandidateProgram program = (GECandidateProgram) p; double score = 0; // Evaluate all possible inputValues. for (final boolean[] vars : inputValues) { // Convert to object array. final Boolean[] objVars = ArrayUtils.toObject(vars); Boolean result = null; try { result = (Boolean) interpreter.eval(program.getSourceCode(), argNames, objVars); } catch (final MalformedProgramException e) { // Assign worst possible fitness and stop evaluating. score = 0; break; } // Increment score for a correct response. if ((result != null) && (result == isEvenNoTrue(vars))) { score++; } } return inputValues.length - score; }
From source file:org.epochx.gr.model.epox.EvenParity.java
/** * Calculates the fitness score for the given program. The fitness of a * program for the even-parity problem is calculated by evaluating it * using each of the possible sets of input values. There are * <code>2^noInputBits</code> possible sets of inputs. The fitness of the * program is the quantity of those input sequences that the program * returned an incorrect response for. That is, a fitness value of * <code>0.0</code> indicates the program responded correctly for every * possible set of input values./*from w w w . ja va 2s. c om*/ * * @param p {@inheritDoc} * @return the calculated fitness for the given program. */ @Override public double getFitness(final CandidateProgram p) { final GRCandidateProgram program = (GRCandidateProgram) p; double score = 0; // Evaluate all possible inputValues. for (final boolean[] vars : inputValues) { // Convert to object array. final Boolean[] objVars = ArrayUtils.toObject(vars); Boolean result = null; try { result = (Boolean) interpreter.eval(program.getSourceCode(), argNames, objVars); } catch (final MalformedProgramException e) { // Assign worst possible fitness and stop evaluating. score = 0; break; } // Increment score for a correct response. if ((result != null) && (result == isEvenNoTrue(vars))) { score++; } } return inputValues.length - score; }
From source file:org.epochx.gr.model.epox.Majority.java
/** * Calculates the fitness score for the given program. The fitness of a * program for the majority problem is calculated by evaluating it * using each of the possible sets of input values. There are * <code>2^noInputBits</code> possible sets of inputs. The fitness of the * program is the quantity of those input sequences that the program * returned an incorrect response for. That is, a fitness value of * <code>0.0</code> indicates the program responded correctly for every * possible set of input values.// w ww.ja v a 2s .c o m * * @param p {@inheritDoc} * @return the calculated fitness for the given program. */ @Override public double getFitness(final CandidateProgram p) { final GRCandidateProgram program = (GRCandidateProgram) p; double score = 0; // Evaluate all possible inputValues. for (final boolean[] vars : inputValues) { // Convert to object array. final Boolean[] objVars = ArrayUtils.toObject(vars); Boolean result = null; try { result = (Boolean) interpreter.eval(program.getSourceCode(), argNames, objVars); } catch (final MalformedProgramException e) { // Assign worst possible fitness and stop evaluating. score = 0; break; } if ((result != null) && (result == majorityTrue(vars))) { score++; } } return inputValues.length - score; }
From source file:org.epochx.gr.model.epox.Multiplexer.java
/** * Calculates the fitness score for the given program. The fitness of a * program for the majority problem is calculated by evaluating it * using each of the possible sets of input values. There are * <code>2^noInputBits</code> possible sets of inputs. The fitness of the * program is the quantity of those input sequences that the program * returned an incorrect response for. That is, a fitness value of * <code>0.0</code> indicates the program responded correctly for every * possible set of input values.//from w w w .j av a 2s . c om * * @param p {@inheritDoc} * @return the calculated fitness for the given program. */ @Override public double getFitness(final CandidateProgram p) { final GRCandidateProgram program = (GRCandidateProgram) p; double score = 0; // Evaluate all possible inputValues. for (final boolean[] vars : inputValues) { // Convert to object array. final Boolean[] objVars = ArrayUtils.toObject(vars); Boolean result = null; try { result = (Boolean) interpreter.eval(program.getSourceCode(), argNames, objVars); } catch (final MalformedProgramException e) { // Assign worst possible fitness and stop evaluating. score = 0; break; } if ((result != null) && (result == multiplex(vars))) { score++; } } return inputValues.length - score; }
From source file:org.everit.osgi.balance.ri.BalanceAccountComponent.java
@Override public long[] lockAccounts(final long... accountIds) { if (accountIds == null) { throw new IllegalArgumentException("accountIds cannot be null"); }/*w w w . j a va 2s .c o m*/ if (accountIds.length < 1) { throw new IllegalArgumentException("at least one accountId must be provided"); } final Long[] accountIdsToLock = ArrayUtils.toObject(accountIds); List<Long> lockedAccountIds = transactionHelper.mandatory(new Callback<List<Long>>() { @Override public List<Long> execute() { QBalanceAccount qBalanceAccount = QBalanceAccount.balAccount; try (Connection connection = dataSource.getConnection()) { return new SQLQuery(connection, sqlTemplates).from(qBalanceAccount) .where(qBalanceAccount.accountId.in(accountIdsToLock)).forUpdate() .list(qBalanceAccount.accountId); } catch (SQLException e) { throw new RuntimeException(e); } } }); for (long accountId : accountIds) { if (!lockedAccountIds.contains(accountId)) { throw new AccountLockException("failed to lock accountId [" + accountId + "]"); } } return ArrayUtils.toPrimitive(lockedAccountIds.toArray(new Long[] {})); }
From source file:org.exfio.csyncdroid.resource.LocalCalendar.java
protected Recurrence parseRecurrence(String property, TimeZone tz) throws ParseException { RRule tmpRecRule = new RRule(property); Recurrence.Frequency freq = null;/* ww w . j av a2 s . c om*/ switch (tmpRecRule.getFreq()) { case DAILY: freq = Recurrence.Frequency.DAILY; break; case HOURLY: freq = Recurrence.Frequency.HOURLY; break; case MINUTELY: freq = Recurrence.Frequency.MINUTELY; break; case MONTHLY: freq = Recurrence.Frequency.MONTHLY; break; case SECONDLY: freq = Recurrence.Frequency.SECONDLY; break; case WEEKLY: freq = Recurrence.Frequency.WEEKLY; break; case YEARLY: freq = Recurrence.Frequency.YEARLY; break; default: //Fail quietly } List<Recurrence.DayOfWeek> dows = new ArrayList<Recurrence.DayOfWeek>(); for (WeekdayNum wday : tmpRecRule.getByDay()) { switch (wday.wday) { case MO: dows.add(Recurrence.DayOfWeek.MONDAY); break; case TU: dows.add(Recurrence.DayOfWeek.TUESDAY); break; case WE: dows.add(Recurrence.DayOfWeek.WEDNESDAY); break; case TH: dows.add(Recurrence.DayOfWeek.THURSDAY); break; case FR: dows.add(Recurrence.DayOfWeek.FRIDAY); break; case SA: dows.add(Recurrence.DayOfWeek.SATURDAY); break; case SU: dows.add(Recurrence.DayOfWeek.SUNDAY); break; default: //Fail quietly } } Recurrence tmpRec = new Recurrence.Builder(freq).interval(tmpRecRule.getInterval()) .count(tmpRecRule.getCount()).until(dateValueToDate(tmpRecRule.getUntil())).byDay(dows) .byHour(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByHour())))) .byMinute(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByMinute())))) .byMonth(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByMonth())))) .byMonthDay(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByMonthDay())))) .bySecond(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getBySecond())))) .byWeekNo(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByWeekNo())))) .byYearDay(new ArrayList<Integer>(Arrays.asList(ArrayUtils.toObject(tmpRecRule.getByYearDay())))) .build(); return tmpRec; }
From source file:org.flinkspector.core.collection.OrderMatcher.java
public void indices(int first, int second, int... rest) { int[] front = new int[] { first, second }; List<Integer> list = Arrays.asList(ArrayUtils.toObject(ArrayUtils.addAll(front, rest))); matcher.indices(list);/*from w w w. ja v a 2s .co m*/ }
From source file:org.geoserver.security.iride.identity.IrideIdentityTest.java
/** * Test method for {@link org.geoserver.security.iride.entity.IrideIdentity} serialization. *//*from w ww . j ava 2 s.co m*/ @Test public void testIrideIdentitySuccesfulSerialization() { final String value = StringUtils.join(this.tokens, IrideIdentityToken.SEPARATOR); LOGGER.trace("BEGIN {}::testIrideIdentitySuccesfulSerialization - {}", this.getClass().getName(), value); try { final IrideIdentity irideIdentity = IrideIdentity.parseIrideIdentity(value); final byte[] serialized = SerializationUtils.serialize(irideIdentity); assertThat(serialized, is(not(nullValue()))); assertThat(ArrayUtils.toObject(serialized), is(arrayWithSize(greaterThan(0)))); } finally { LOGGER.trace("END {}::testIrideIdentitySuccesfulSerialization", this.getClass().getName()); } }
From source file:org.geoserver.security.iride.identity.IrideIdentityTest.java
/** * Test method for {@link org.geoserver.security.iride.entity.IrideIdentity} serialization. *//* w ww. j a v a2 s . c o m*/ @Test public void testIrideIdentitySuccesfulDeserialization() { final String value = StringUtils.join(this.tokens, IrideIdentityToken.SEPARATOR); LOGGER.trace("BEGIN {}::testIrideIdentitySuccesfulDeserialization - {}", this.getClass().getName(), value); try { final IrideIdentity irideIdentity1 = IrideIdentity.parseIrideIdentity(value); final byte[] serialized = SerializationUtils.serialize(irideIdentity1); assertThat(serialized, is(not(nullValue()))); assertThat(ArrayUtils.toObject(serialized), is(arrayWithSize(greaterThan(0)))); final Object deserialized = SerializationUtils.deserialize(serialized); assertThat(deserialized, is(not(nullValue()))); assertThat(deserialized, is(instanceOf(IrideIdentity.class))); final IrideIdentity irideIdentity2 = (IrideIdentity) deserialized; assertThat(irideIdentity1, is(not(sameInstance(irideIdentity2)))); assertThat(irideIdentity1, is(equalTo(irideIdentity2))); assertThat(irideIdentity1.compareTo(irideIdentity2), is(0)); } finally { LOGGER.trace("END {}::testIrideIdentitySuccesfulDeserialization", this.getClass().getName()); } }