List of usage examples for java.lang Float compare
public static int compare(float f1, float f2)
From source file:dev.drsoran.moloko.fragments.TaskFragment.java
private void setLocationSection(View view, final Task task) { String locationName = null;/* w w w. ja v a 2s. c om*/ boolean showSection = !TextUtils.isEmpty(task.getLocationId()); if (showSection) { // Tasks which are received by sharing from someone else may also have // a location ID set. But this ID is from the other ones DB. We identify // these tasks not by looking for the ID in our DB. These tasks do not // have a name and a location of 0.0, 0.0. // // @see: Issue 12: http://code.google.com/p/moloko/issues/detail?id=12 locationName = task.getLocationName(); showSection = !TextUtils.isEmpty(locationName) || Float.compare(task.getLongitude(), 0.0f) != 0 || Float.compare(task.getLatitude(), 0.0f) != 0; } if (!showSection) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); if (TextUtils.isEmpty(locationName)) { locationName = "Lon: " + task.getLongitude() + ", Lat: " + task.getLatitude(); } boolean locationIsClickable = task.isLocationViewable(); if (locationIsClickable) { final SpannableString clickableLocation = new SpannableString(locationName); UIUtils.initializeTitleWithTextLayoutAsLink(view, getString(R.string.task_location), clickableLocation, new ClickableSpan() { @Override public void onClick(View widget) { listener.onOpenLocation(task); } }); } else { UIUtils.initializeTitleWithTextLayout(view, getString(R.string.task_location), locationName); } } }
From source file:org.cesecore.certificates.endentity.ExtendedInformation.java
/** Implementation of UpgradableDataHashMap function upgrade. */ public void upgrade() { if (Float.compare(LATEST_VERSION, getVersion()) != 0) { // New version of the class, upgrade String msg = intres.getLocalizedMessage("endentity.extendedinfoupgrade", new Float(getVersion())); log.info(msg);//from w w w . ja va2s . com if (data.get(SUBJECTDIRATTRIBUTES) == null) { data.put(SUBJECTDIRATTRIBUTES, ""); } if (data.get(MAXFAILEDLOGINATTEMPTS) == null) { setMaxLoginAttempts(DEFAULT_MAXLOGINATTEMPTS); } if (data.get(REMAININGLOGINATTEMPTS) == null) { setRemainingLoginAttempts(DEFAULT_REMAININGLOGINATTEMPTS); } // In EJBCA 4.0.0 we changed the date format if (getVersion() < 3) { final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US); final FastDateFormat newDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm"); try { final String oldCustomStartTime = getCustomData(ExtendedInformation.CUSTOM_STARTTIME); if (!isEmptyOrRelative(oldCustomStartTime)) { // We use an absolute time format, so we need to upgrade final String newCustomStartTime = newDateFormat .format(oldDateFormat.parse(oldCustomStartTime)); setCustomData(ExtendedInformation.CUSTOM_STARTTIME, newCustomStartTime); if (log.isDebugEnabled()) { log.debug("Upgraded " + ExtendedInformation.CUSTOM_STARTTIME + " from \"" + oldCustomStartTime + "\" to \"" + newCustomStartTime + "\" in ExtendedInformation."); } } } catch (ParseException e) { log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_STARTTIME + " in extended user information.", e); } try { final String oldCustomEndTime = getCustomData(ExtendedInformation.CUSTOM_ENDTIME); if (!isEmptyOrRelative(oldCustomEndTime)) { // We use an absolute time format, so we need to upgrade final String newCustomEndTime = newDateFormat.format(oldDateFormat.parse(oldCustomEndTime)); setCustomData(ExtendedInformation.CUSTOM_ENDTIME, newCustomEndTime); if (log.isDebugEnabled()) { log.debug( "Upgraded " + ExtendedInformation.CUSTOM_ENDTIME + " from \"" + oldCustomEndTime + "\" to \"" + newCustomEndTime + "\" in ExtendedInformation."); } } } catch (ParseException e) { log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_ENDTIME + " in extended user information.", e); } } // In 4.0.2 we further specify the storage format by saying that UTC TimeZone is implied instead of local server time if (getVersion() < 4) { final String[] timePatterns = { "yyyy-MM-dd HH:mm" }; final String oldStartTime = getCustomData(ExtendedInformation.CUSTOM_STARTTIME); if (!isEmptyOrRelative(oldStartTime)) { try { final String newStartTime = ValidityDate .formatAsUTC(DateUtils.parseDateStrictly(oldStartTime, timePatterns)); setCustomData(ExtendedInformation.CUSTOM_STARTTIME, newStartTime); if (log.isDebugEnabled()) { log.debug("Upgraded " + ExtendedInformation.CUSTOM_STARTTIME + " from \"" + oldStartTime + "\" to \"" + newStartTime + "\" in EndEntityProfile."); } } catch (ParseException e) { log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_STARTTIME + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).", e); } } final String oldEndTime = getCustomData(ExtendedInformation.CUSTOM_ENDTIME); if (!isEmptyOrRelative(oldEndTime)) { // We use an absolute time format, so we need to upgrade try { final String newEndTime = ValidityDate .formatAsUTC(DateUtils.parseDateStrictly(oldEndTime, timePatterns)); setCustomData(ExtendedInformation.CUSTOM_ENDTIME, newEndTime); if (log.isDebugEnabled()) { log.debug("Upgraded " + ExtendedInformation.CUSTOM_ENDTIME + " from \"" + oldEndTime + "\" to \"" + newEndTime + "\" in EndEntityProfile."); } } catch (ParseException e) { log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_ENDTIME + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).", e); } } } data.put(VERSION, Float.valueOf(LATEST_VERSION)); } }
From source file:papaya.Rank.java
/** The actual ranking takes place here. * @param ranks: the IntFloat pair of ranks * @param out: the output ranks */ private static void rankIt(IntFloatPair[] ranks, float[] out, int tiesStrategy) { int pos = 1; // position in sorted array // Walk the sorted array, filling output array using sorted positions, // resolving ties as we go out[ranks[0].getPosition()] = pos;//ww w.ja v a 2 s .c o m List<Integer> tiesTrace = new ArrayList<Integer>(); tiesTrace.add(ranks[0].getPosition()); for (int i = 1; i < ranks.length; i++) { if (Float.compare(ranks[i].getValue(), ranks[i - 1].getValue()) > 0) { // tie sequence has ended (or had length 1) pos = i + 1; if (tiesTrace.size() > 1) { // if seq is nontrivial, resolve resolveTie(out, tiesTrace, tiesStrategy); } tiesTrace = new ArrayList<Integer>(); tiesTrace.add(ranks[i].getPosition()); } else { // tie sequence continues tiesTrace.add(ranks[i].getPosition()); } out[ranks[i].getPosition()] = pos; } if (tiesTrace.size() > 1) { // handle tie sequence at end resolveTie(out, tiesTrace, tiesStrategy); } }
From source file:com.linkedin.pinot.routing.builder.GeneratorBasedRoutingTableBuilder.java
@Override public List<ServerToSegmentSetMap> computeRoutingTableFromExternalView(String tableName, ExternalView externalView, List<InstanceConfig> instanceConfigList) { // The default routing table algorithm tries to balance all available segments across all servers, so that each // server is hit on every query. This works fine with small clusters (say less than 20 servers) but for larger // clusters, this adds up to significant overhead (one request must be enqueued for each server, processed, // returned, deserialized, aggregated, etc.). //// w w w .j a v a2 s .c o m // For large clusters, we want to avoid hitting every server, as this also has an adverse effect on client tail // latency. This is due to the fact that a query cannot return until it has received a response from each server, // and the greater the number of servers that are hit, the more likely it is that one of the servers will be a // straggler (eg. due to contention for query processing threads, GC, etc.). We also want to balance the segments // within any given routing table so that each server in the routing table has approximately the same number of // segments to process. // // To do so, we have a routing table generator that generates routing tables by picking a random subset of servers. // With this set of servers, we check if the set of segments served by these servers is complete. If the set of // segments served does not cover all of the segments, we compute the list of missing segments and pick a random // server that serves these missing segments until we have complete coverage of all the segments. // // We then order the segments in ascending number of replicas within our server set, in order to allocate the // segments with fewer replicas first. This ensures that segments that are 'easier' to allocate are more likely to // end up on a replica with fewer segments. // // Then, we pick a random replica for each segment, iterating from fewest replicas to most replicas, inversely // weighted by the number of segments already assigned to that replica. This ensures that we build a routing table // that's as even as possible. // // The algorithm to generate a routing table is thus: // 1. Compute the inverse external view, a mapping of servers to segments // 2. For each routing table to generate: // a) Pick TARGET_SERVER_COUNT_PER_QUERY distinct servers // b) Check if the server set covers all the segments; if not, add additional servers until it does. // c) Order the segments in our server set in ascending order of number of replicas present in our server set // d) For each segment, pick a random replica with proper weighting // e) Return that routing table // // Given that we can generate routing tables at will, we then generate many routing tables and use them to optimize // according to two criteria: the variance in workload per server for any individual table as well as the variance // in workload per server across all the routing tables. To do so, we generate an initial set of routing tables // according to a per-routing table metric and discard the worst routing tables. RoutingTableGenerator routingTableGenerator = buildRoutingTableGenerator(); routingTableGenerator.init(externalView, instanceConfigList); PriorityQueue<Pair<Map<String, Set<String>>, Float>> topRoutingTables = new PriorityQueue<>( ROUTING_TABLE_COUNT, new Comparator<Pair<Map<String, Set<String>>, Float>>() { @Override public int compare(Pair<Map<String, Set<String>>, Float> left, Pair<Map<String, Set<String>>, Float> right) { // Float.compare sorts in ascending order and we want a max heap, so we need to return the negative of the comparison return -Float.compare(left.getValue(), right.getValue()); } }); for (int i = 0; i < ROUTING_TABLE_COUNT; i++) { topRoutingTables.add(generateRoutingTableWithMetric(routingTableGenerator)); } // Generate routing more tables and keep the ROUTING_TABLE_COUNT top ones for (int i = 0; i < (ROUTING_TABLE_GENERATION_COUNT - ROUTING_TABLE_COUNT); ++i) { Pair<Map<String, Set<String>>, Float> newRoutingTable = generateRoutingTableWithMetric( routingTableGenerator); Pair<Map<String, Set<String>>, Float> worstRoutingTable = topRoutingTables.peek(); // If the new routing table is better than the worst one, keep it if (newRoutingTable.getRight() < worstRoutingTable.getRight()) { topRoutingTables.poll(); topRoutingTables.add(newRoutingTable); } } // Return the best routing tables List<ServerToSegmentSetMap> routingTables = new ArrayList<>(topRoutingTables.size()); while (!topRoutingTables.isEmpty()) { Pair<Map<String, Set<String>>, Float> routingTableWithMetric = topRoutingTables.poll(); routingTables.add(new ServerToSegmentSetMap(routingTableWithMetric.getKey())); } return routingTables; }
From source file:de.janrieke.contractmanager.ext.hibiscus.UmsatzImportListDialog.java
/** * Initialize the list of contracts by calculating the probability that the * contract is the intended contract. The list will be sorted by this * probability.//from www. j a v a 2 s. c om * * @return initialized list * @throws RemoteException */ private List<Contract> initializeContractList() throws RemoteException { final class SortedContract implements Comparable<SortedContract> { private float value; private Contract c; public SortedContract(Contract c, float value) { this.value = value; this.c = c; } public Contract getContract() { return c; } @Override public int compareTo(SortedContract o) { return Float.compare(this.value, o.value); } @Override public int hashCode() { return c.hashCode() + 1; } @Override public boolean equals(Object obj) { if (obj != null && obj instanceof SortedContract && ((SortedContract) obj).c == this.c) { return true; } else { return false; } } } List<SortedContract> sorted = new ArrayList<>(); GenericIterator<Contract> contracts = ContractControl.getContracts(); while (contracts.hasNext()) { Contract c = contracts.next(); float simliarity = calculateSimilarity(c, this.umsatz); sorted.add(new SortedContract(c, simliarity)); } Collections.sort(sorted); List<Contract> l = new LinkedList<>(); for (SortedContract c : sorted) { l.add(c.getContract()); } return l; }
From source file:org.apache.jackrabbit.core.query.lucene.JahiaNodeIndexer.java
/** * Returns the boost value for the given property name. * * @param propertyName the name of a property. * @return the boost value for the given property name. *//*from w w w .j a va 2 s . co m*/ protected float getPropertyBoost(Name propertyName) { float scoreBoost = super.getPropertyBoost(propertyName); if (Float.compare(scoreBoost, 1.0F) == 0) { ExtendedPropertyDefinition propDef = getExtendedPropertyDefinition(getPropertyName(propertyName)); if (propDef != null) { scoreBoost = (float) propDef.getScoreboost(); } } return scoreBoost; }
From source file:org.cesecore.certificates.ca.catoken.CAToken.java
/** @see org.cesecore.internal.UpgradeableDataHashMap#upgrade() */ @Override// www . j a va2s. c o m public void upgrade() { if (Float.compare(LATEST_VERSION, getVersion()) != 0) { // New version of the class, upgrade String msg = intres.getLocalizedMessage("token.upgrade", new Float(getVersion())); log.info(msg); // Put upgrade stuff here if (data.get(CAToken.SEQUENCE_FORMAT) == null) { // v7 log.info("Adding new sequence format to CA Token data: " + StringTools.KEY_SEQUENCE_FORMAT_NUMERIC); data.put(CAToken.SEQUENCE_FORMAT, StringTools.KEY_SEQUENCE_FORMAT_NUMERIC); } if (data.get(CAToken.SEQUENCE) == null) { // v7 log.info("Adding new default key sequence to CA Token data: " + CAToken.DEFAULT_KEYSEQUENCE); data.put(CAToken.SEQUENCE, CAToken.DEFAULT_KEYSEQUENCE); } if (data.get(CAToken.CLASSPATH) != null) { // v8 upgrade of classpaths for CESeCore final String classpath = (String) data.get(CAToken.CLASSPATH); log.info("Upgrading CA token classpath: " + classpath); String newclasspath = classpath; if (StringUtils.equals(classpath, "org.ejbca.core.model.ca.catoken.SoftCAToken")) { newclasspath = "org.cesecore.keys.token.SoftCryptoToken"; // Upgrade properties to set a default key, also for soft crypto tokens Properties prop = getProperties(); // A small unfortunate special property that we have to make in order to // be able to use soft keystores that does not have a specific test or default key if ((prop.getProperty(CATokenConstants.CAKEYPURPOSE_CERTSIGN_STRING) == null) && (prop.getProperty(CATokenConstants.CAKEYPURPOSE_DEFAULT_STRING) == null)) { log.info( "Setting CAKEYPURPOSE_CERTSIGN_STRING and CAKEYPURPOSE_CRLSIGN_STRING to privatesignkeyalias."); prop.setProperty(CATokenConstants.CAKEYPURPOSE_CERTSIGN_STRING, CAToken.SOFTPRIVATESIGNKEYALIAS); prop.setProperty(CATokenConstants.CAKEYPURPOSE_CRLSIGN_STRING, CAToken.SOFTPRIVATESIGNKEYALIAS); } if ((prop.getProperty(CATokenConstants.CAKEYPURPOSE_DEFAULT_STRING) == null) && (prop.getProperty(CATokenConstants.CAKEYPURPOSE_TESTKEY_STRING) == null)) { log.info("Setting CAKEYPURPOSE_DEFAULT_STRING to privatedeckeyalias."); prop.setProperty(CATokenConstants.CAKEYPURPOSE_DEFAULT_STRING, CAToken.SOFTPRIVATEDECKEYALIAS); } setCATokenPropertyData(storeProperties(prop)); // Stores property string in "data" } else if (StringUtils.equals(classpath, "org.ejbca.core.model.ca.catoken.PKCS11CAToken")) { newclasspath = "org.cesecore.keys.token.PKCS11CryptoToken"; } else if (StringUtils.equals(classpath, "org.ejbca.core.model.ca.catoken.NullCAToken")) { newclasspath = "org.cesecore.keys.token.NullCryptoToken"; } else if (StringUtils.equals(classpath, "org.ejbca.core.model.ca.catoken.NFastCAToken")) { log.error( "Upgrading of NFastCAToken not supported, you need to convert to using PKCS11CAToken before upgrading."); } data.put(CAToken.CLASSPATH, newclasspath); } data.put(VERSION, new Float(LATEST_VERSION)); } }
From source file:com.linkedin.pinot.broker.routing.builder.GeneratorBasedRoutingTableBuilder.java
@Override public void computeRoutingTableFromExternalView(String tableName, ExternalView externalView, List<InstanceConfig> instanceConfigs) { // The default routing table algorithm tries to balance all available segments across all servers, so that each // server is hit on every query. This works fine with small clusters (say less than 20 servers) but for larger // clusters, this adds up to significant overhead (one request must be enqueued for each server, processed, // returned, deserialized, aggregated, etc.). ///*from ww w . j a va 2 s. c o m*/ // For large clusters, we want to avoid hitting every server, as this also has an adverse effect on client tail // latency. This is due to the fact that a query cannot return until it has received a response from each server, // and the greater the number of servers that are hit, the more likely it is that one of the servers will be a // straggler (eg. due to contention for query processing threads, GC, etc.). We also want to balance the segments // within any given routing table so that each server in the routing table has approximately the same number of // segments to process. // // To do so, we have a routing table generator that generates routing tables by picking a random subset of servers. // With this set of servers, we check if the set of segments served by these servers is complete. If the set of // segments served does not cover all of the segments, we compute the list of missing segments and pick a random // server that serves these missing segments until we have complete coverage of all the segments. // // We then order the segments in ascending number of replicas within our server set, in order to allocate the // segments with fewer replicas first. This ensures that segments that are 'easier' to allocate are more likely to // end up on a server with fewer segments. // // Then, we pick a server with least segments already assigned for each segment. This ensures that we build a // routing table that's as even as possible. // // The algorithm to generate a routing table is thus: // 1. Compute the inverse external view, a mapping of servers to segments // 2. For each routing table to generate: // a) Pick _targetNumServersPerQuery distinct servers // b) Check if the server set covers all the segments; if not, add additional servers until it does // c) Order the segments in our server set in ascending order of number of replicas present in our server set // d) For each segment, pick a server with least segments already assigned // e) Return that routing table // // Given that we can generate routing tables at will, we then generate many routing tables and use them to optimize // according to two criteria: the variance in workload per server for any individual table as well as the variance // in workload per server across all the routing tables. To do so, we generate an initial set of routing tables // according to a per-routing table metric and discard the worst routing tables. RoutingTableGenerator routingTableGenerator = buildRoutingTableGenerator(); routingTableGenerator.init(externalView, instanceConfigs); PriorityQueue<Pair<Map<String, List<String>>, Float>> topRoutingTables = new PriorityQueue<>( ROUTING_TABLE_COUNT, new Comparator<Pair<Map<String, List<String>>, Float>>() { @Override public int compare(Pair<Map<String, List<String>>, Float> left, Pair<Map<String, List<String>>, Float> right) { // Float.compare sorts in ascending order and we want a max heap, so we need to return the negative of the comparison return -Float.compare(left.getValue(), right.getValue()); } }); for (int i = 0; i < ROUTING_TABLE_COUNT; i++) { topRoutingTables.add(generateRoutingTableWithMetric(routingTableGenerator)); } // Generate routing more tables and keep the ROUTING_TABLE_COUNT top ones for (int i = 0; i < (ROUTING_TABLE_GENERATION_COUNT - ROUTING_TABLE_COUNT); ++i) { Pair<Map<String, List<String>>, Float> newRoutingTable = generateRoutingTableWithMetric( routingTableGenerator); Pair<Map<String, List<String>>, Float> worstRoutingTable = topRoutingTables.peek(); // If the new routing table is better than the worst one, keep it if (newRoutingTable.getRight() < worstRoutingTable.getRight()) { topRoutingTables.poll(); topRoutingTables.add(newRoutingTable); } } // Return the best routing tables List<Map<String, List<String>>> routingTables = new ArrayList<>(topRoutingTables.size()); while (!topRoutingTables.isEmpty()) { routingTables.add(topRoutingTables.poll().getKey()); } setRoutingTables(routingTables); }
From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof BaseComplexFloat)) return false; BaseComplexFloat that = (BaseComplexFloat) o; if (Float.compare(that.real, real) != 0) return false; if (Math.abs(that.imag - imag) > 1e-12) return false; return true;/*from w ww . j a v a 2 s . co m*/ }
From source file:Main.java
/** * Finds the first occurrence in an array from specified given position and upto given length. *//*from w ww . jav a2 s. co m*/ public static int indexOf(float[] array, float[] sub, int startIndex, int endIndex) { int sublen = sub.length; if (sublen == 0) { return startIndex; } int total = endIndex - sublen + 1; float c = sub[0]; mainloop: for (int i = startIndex; i < total; i++) { if (Float.compare(array[i], c) != 0) { continue; } int j = 1; int k = i + 1; while (j < sublen) { if (Float.compare(sub[j], array[k]) != 0) { continue mainloop; } j++; k++; } return i; } return -1; }