List of usage examples for org.apache.commons.lang3.tuple ImmutablePair getLeft
@Override
public L getLeft()
From source file:com.foudroyantfactotum.mod.fousarchive.midi.generation.MidiImageGeneration.java
public static void main(String[] args) throws IOException, InvalidMidiDataException, InterruptedException, ExecutionException { try (InputStream is = new FileInputStream("")) { final long startTime = System.currentTimeMillis(); final ImmutablePair<String, BufferedImage> res = new MidiImageGeneration(is, 119, 5000).buildImage(); final long endTime = System.currentTimeMillis(); Logger.info(UserLogger.GENERAL, String.format("startTime: %s endTime: %s totalTime: %s file: %s", startTime, endTime, endTime - startTime, res.getLeft())); ImageIO.write(res.getRight(), "png", new File(String.format("/tmp/%s.png", res.getLeft()))); }/* w w w. j a va 2s.c o m*/ }
From source file:eu.scape_project.tool.toolwrapper.toolwrapper_bash_generator.BashWrapperGenerator.java
/** * Main method that parses the parameters, and for each operation generates * a bash wrapper and a Taverna workflow * // ww w.j a v a 2 s. c o m * @param args * command-line provided arguments */ public static void main(String[] args) { BashWrapperGenerator bwg = new BashWrapperGenerator(); int exitCode = 0; try { ImmutablePair<CommandLine, Tool> pair = bwg.processToolWrapperGenerationRequest(args); CommandLine cmd = null; Tool tool = null; Components components = null; if (pair != null) { cmd = pair.getLeft(); tool = pair.getRight(); File toolFile = cmd.hasOption("t") ? new File(cmd.getOptionValue("t")) : null; File componentsFile = cmd.hasOption("c") ? new File(cmd.getOptionValue("c")) : null; File outputdirFile = cmd.hasOption("o") ? new File(cmd.getOptionValue("o")) : null; // try to create a component instance if provided the components // spec file location if (componentsFile != null) { components = eu.scape_project.tool.toolwrapper.data.components_spec.utils.Utils .createComponents(componentsFile.getAbsolutePath()); bwg.setComponents(components); } if (componentsFile == null || components != null) { bwg.copySpecsToInstallDir(outputdirFile, toolFile, componentsFile); for (Operation operation : tool.getOperations().getOperation()) { // just to make sure it doesn't have an older value bwg.setComponent(null); if (components != null) { for (Component component : components.getComponent()) { if (component.getName().equalsIgnoreCase(operation.getName())) { bwg.setComponent(component); break; } } } // define wrapper name as operation name bwg.setWrapperName(operation.getName()); // generate the wrapper and Taverna workflow boolean generationOK = bwg.generateWrapper(tool, operation, outputdirFile); if (generationOK) { log.info("Ouputs for operation \"" + operation.getName() + "\"" + " generated with success!"); } else { log.error("[ERROR] Error generating outputs for operation \"" + operation.getName() + "\""); } } } else { log.error("[ERROR] Error loading components file!"); exitCode = 3; } } } catch (ErrorParsingCmdArgsException e) { log.error("[ERROR] " + e.getMessage()); bwg.printUsage(); exitCode = 2; } catch (SpecParsingException e) { log.error("[ERROR] " + e.getMessage(), e); bwg.printUsage(); exitCode = 1; } System.exit(exitCode); }
From source file:eu.scape_project.tool.toolwrapper.toolwrapper_bash_debian_generator.DebianBashWrapperGenerator.java
/** * Main method that parses the parameters, and depending on the parameters * provided, generates a Debian package for each operation artifacts or a * Debian package containing all operation artifacts * /*from ww w. java 2 s.co m*/ * @param args * command-line provided arguments */ public static void main(String[] args) { DebianBashWrapperGenerator dbwg = new DebianBashWrapperGenerator(); int exitCode = 0; try { ImmutablePair<CommandLine, Tool> pair = dbwg.processToolWrapperGenerationRequest(args); CommandLine cmd = null; Tool tool = null; if (pair != null) { cmd = pair.getLeft(); tool = pair.getRight(); File outputdirFile = cmd.hasOption("o") ? new File(cmd.getOptionValue("o")) : null; dbwg.setInputDir(cmd.getOptionValue("i")); dbwg.setMaintainerEmail(cmd.getOptionValue("e")); dbwg.setChangelog(cmd.getOptionValue("ch")); if (cmd.hasOption("ar")) { if (KNOWN_ARCHITECTURES.contains(cmd.getOptionValue("ar"))) { dbwg.setArchitecture(cmd.getOptionValue("ar")); } else { log.error( "The architecture parameter was specified but an invalid value was provided. Do \"$> dpkg-architecture -L\" to see all valid values."); exitCode = 6; } } if (cmd.hasOption("li")) { dbwg.setLintianOverride(cmd.getOptionValue("li")); } if (cmd.hasOption("pi")) { dbwg.setPi(cmd.getOptionValue("pi")); } if (cmd.hasOption("prm")) { dbwg.setPrm(cmd.getOptionValue("prm")); } if (cmd.hasOption("poi")) { dbwg.setPoi(cmd.getOptionValue("poi")); } if (cmd.hasOption("porm")) { dbwg.setPorm(cmd.getOptionValue("porm")); } if (areNonRequiredArgumentsThatCanBeCombinedInvalid(cmd)) { log.error("Missing required option: " + (cmd.hasOption("a") ? (cmd.hasOption("d") ? CMD_OPTIONS_DESCRIPTION_SHORT : "d") : "a") + "\n"); dbwg.printUsage(); exitCode = 5; } // if all required are present and all optional are valid if (exitCode == 0) { if (cmd.hasOption("a") && cmd.hasOption("d") && cmd.hasOption(CMD_OPTIONS_DESCRIPTION_SHORT)) { // only one Debian package will be generated exitCode = createOneDebianPackage(dbwg, cmd, tool, outputdirFile); } else { // generate a Debian package for each operation exitCode = createSeveralDebianPackages(dbwg, tool, outputdirFile); } } } } catch (ErrorParsingCmdArgsException e) { log.error("[ERROR] " + e.getMessage()); dbwg.printUsage(); exitCode = 2; } catch (SpecParsingException e) { log.error("[ERROR] " + e.getMessage(), e); dbwg.printUsage(); exitCode = 1; } System.exit(exitCode); }
From source file:com.netflix.imfutility.dpp.audio.AudioMapHelper.java
public static EBUTrackType createEbuTrack(int num, ImmutablePair<SequenceUUID, Integer> input) { EBUTrackType ebuTrack = new EBUTrackType(); ebuTrack.setNumber(num);/*from w ww.ja va 2s.c o m*/ ebuTrack.setCPLVirtualTrackId(input.getLeft().getUuid()); ebuTrack.setCPLVirtualTrackChannel(input.getRight()); return ebuTrack; }
From source file:com.yahoo.bard.webservice.util.Utils.java
/** * Given an ImmutablePair, and a right value, returns a new ImmutablePair with the same left value, * and the specified right value.//from w ww.j a v a2s . c o m * * @param pair Immutable Pair instance * @param right The right value, may be null * @param <T> Left type of the pair * @param <U> Right type of the pair * @param <V> The right value to have new Immutable Pair * * @return New instance of Immutable Pair */ public static <T, U, V> ImmutablePair<T, V> withRight(ImmutablePair<T, U> pair, V right) { return new ImmutablePair<>(pair.getLeft(), right); }
From source file:com.robertsmieja.test.utils.junit.GettersAndSettersUtils.java
static <T> void runGettersAndSettersTestOnField(T value, T differentValue, Field field) throws InvocationTargetException, IllegalAccessException { ImmutablePair<Method, Method> getterAndSetter = GettersAndSettersUtils.getGetterAndSetterForField(field); Method getter = getterAndSetter.getLeft(); Method setter = getterAndSetter.getRight(); ensureFieldCanHandleDifferentValues(value, differentValue, getter, setter); ensureFieldCanHandleNullValues(value, getter, setter); }
From source file:io.lavagna.web.helper.UserSession.java
private static void deleteTokenIfExist(String cookieVal, UserRepository userRepository) { ImmutablePair<Integer, String> uIdToken = extractUserIdAndToken(cookieVal); if (uIdToken != null) { userRepository.deleteRememberMeToken(uIdToken.getLeft(), uIdToken.getRight()); }// ww w . j a v a 2s . co m }
From source file:io.lavagna.web.helper.UserSession.java
public static void authenticateUserIfRemembered(HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { Cookie c;// ww w . j a v a 2s . c o m if (isUserAuthenticated(req) || (c = getCookie(req, "LAVAGNA_REMEMBER_ME")) == null) { return; } ImmutablePair<Integer, String> uIdToken = extractUserIdAndToken(c.getValue()); if (uIdToken != null && userRepository.rememberMeTokenExists(uIdToken.getLeft(), uIdToken.getRight())) { userRepository.deleteRememberMeToken(uIdToken.getLeft(), uIdToken.getRight()); User user = userRepository.findById(uIdToken.getLeft()); setUser(user.getId(), user.isAnonymous(), req, resp, userRepository, true); } else { // delete cookie because it's invalid c.setMaxAge(0); c.setValue(null); resp.addCookie(c); } }
From source file:com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByOperatorService.java
/** * Given a map from group by keys to results for multiple aggregation functions, trim the results to desired size and * put them into a list of group by results. * * @param aggrFuncList List of aggregation functions. * @param aggrGroupByResults Map from group by keys to result arrays. * @param trimmedGroupByResultList List of maps containing group by results returned. * @param numAggrFunctions Number of aggregation functions. * @param trimSize Desired trim size./*from w w w .j av a 2 s. c o m*/ */ @SuppressWarnings("unchecked") private static void trimToSize(List<AggregationFunction> aggrFuncList, Map<String, Serializable[]> aggrGroupByResults, List<Map<String, Serializable>> trimmedGroupByResultList, int numAggrFunctions, int trimSize) { MinMaxPriorityQueue<ImmutablePair<Serializable, String>>[] heaps = new MinMaxPriorityQueue[numAggrFunctions]; for (int i = 0; i < numAggrFunctions; i++) { boolean reverseOrder = aggrFuncList.get(i).getFunctionName().startsWith(MIN_PREFIX); heaps[i] = getMinMaxPriorityQueue(aggrGroupByResults.values().iterator().next()[i], trimSize, reverseOrder); } for (String key : aggrGroupByResults.keySet()) { Serializable[] results = aggrGroupByResults.get(key); for (int i = 0; i < numAggrFunctions; i++) { Serializable result = results[i]; MinMaxPriorityQueue<ImmutablePair<Serializable, String>> heap = heaps[i]; if (heap == null) { trimmedGroupByResultList.get(i).put(key, result); } else { heap.add(new ImmutablePair(result, key)); } } } for (int i = 0; i < numAggrFunctions; i++) { MinMaxPriorityQueue<ImmutablePair<Serializable, String>> heap = heaps[i]; ImmutablePair<Serializable, String> pair; if (heap != null) { while ((pair = heap.pollFirst()) != null) { trimmedGroupByResultList.get(i).put(pair.getRight(), pair.getLeft()); } } } }
From source file:com.capitati.omtc.core.negotiation.SemanticVersionComparator.java
public static final ImmutablePair<Integer, SemanticVersionComponent> compare(final ISemanticVersion verOne, final ISemanticVersion verTwo) { if (verOne.equals(verTwo) == true) { return new ImmutablePair<Integer, SemanticVersionComponent>(0, SemanticVersionComponent.INVALID); }/*from www . j a va2 s .co m*/ if (verOne.getMajor() == verTwo.getMajor()) { if (verOne.getMinor() == verTwo.getMinor()) { if (verOne.getPatch() == verTwo.getPatch()) { /* * Compare the pre-release components. */ final ImmutablePair<Integer, Boolean> preReleaseCompResult = compareArray( verOne.getPreRelease(), verTwo.getPreRelease()); /* * Compare the build components. */ final ImmutablePair<Integer, Boolean> buildCompResult = compareArray(verOne.getBuild(), verTwo.getBuild()); /* * Unpack the comparison values. */ final int prc = preReleaseCompResult.getLeft(); final int bc = buildCompResult.getLeft(); if ((preReleaseCompResult.getRight() == true) && (buildCompResult.getRight() == true)) { /* * There was at most one pre-release component, and at most one * build component in both versions. */ if ((Math.abs(prc) == 1) && (Math.abs(bc) == 1)) { return new ImmutablePair<Integer, SemanticVersionComponent>( (Math.signum((float) prc) == 1.0) ? -1 : 1, SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION); } else if ((Math.abs(prc) == 1) && (bc == 0)) { return new ImmutablePair<Integer, SemanticVersionComponent>( (Math.signum((float) prc) == 1.0) ? -1 : 1, SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION); } return new ImmutablePair<Integer, SemanticVersionComponent>(bc, SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION); } else if ((preReleaseCompResult.getRight() == true) && (buildCompResult.getRight() == false)) { /* * One of the versions had a null pre-release. */ return new ImmutablePair<Integer, SemanticVersionComponent>(bc, SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION); } /* * Either one of the version has a null build or both versions where * fully specified. */ return new ImmutablePair<Integer, SemanticVersionComponent>((Math.abs(prc) == 1) ? prc : bc, SemanticVersionComponent.PRE_RELEASE_AND_BUILD_VERSION); } else { return new ImmutablePair<Integer, SemanticVersionComponent>( verOne.getPatch() - verTwo.getPatch(), SemanticVersionComponent.PATCH_VERSION); } } else { return new ImmutablePair<Integer, SemanticVersionComponent>(verOne.getMinor() - verTwo.getMinor(), SemanticVersionComponent.MINOR_VERSION); } } return new ImmutablePair<Integer, SemanticVersionComponent>(verOne.getMajor() - verTwo.getMajor(), SemanticVersionComponent.MAJOR_VERSION); }