private <T> T doubleSingleNone(T dbl, T sgl, T none) { // @formatter:off switch (this) { case DOUBLE: return dbl; case SINGLE: return sgl; case NONE: return none; default: throw Unhandled.enumException(this); } // @formatter:on }
public static Unhandled objectException(Object obj) { return new Unhandled("Unhandled object '" + obj + "'"); } }
/** Returns a Comparison from the given result of a call to <code>Comparable.compareTo()</code> or <code>Comparator.compare</code>. */ @SuppressFBWarnings(value = "UC_USELESS_CONDITION", justification = "Throwing Unhandled keeps the full-enumeration more explicit.") public static Comparison from(int compareToResult) { if (compareToResult == 0) { return Comparison.EQUAL; } else if (compareToResult < 0) { return Comparison.LESSER; } else if (compareToResult > 0) { return Comparison.GREATER; } else { throw Unhandled.integerException(compareToResult); } } }
@Override public L getLeft() { throw Unhandled.operationException(); }
throw Unhandled.classException(result);
/** Returns a Comparison from the given result of a call to <code>Comparable.compareTo()</code> or <code>Comparator.compare</code>. */ @SuppressFBWarnings(value = "UC_USELESS_CONDITION", justification = "Throwing Unhandled keeps the full-enumeration more explicit.") public static Comparison from(int compareToResult) { if (compareToResult == 0) { return Comparison.EQUAL; } else if (compareToResult < 0) { return Comparison.LESSER; } else if (compareToResult > 0) { return Comparison.GREATER; } else { throw Unhandled.integerException(compareToResult); } } }
@Override public R getRight() { throw Unhandled.operationException(); }
@Override protected FileSignature calculateState() throws Exception { Set<File> files = new LinkedHashSet<>(); for (Object o : projConfigMaven) { if (o instanceof Project) { Project project = (Project) o; Jar jar = taskFor(project); files.add(jar.getArchivePath()); files.addAll(project.getConfigurations().getByName(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME).resolve()); } else if (o instanceof Configuration) { Configuration config = (Configuration) o; files.addAll(config.resolve()); } else if (o instanceof String) { String mavenCoord = (String) o; Dependency dep = setupTask.getProject().getDependencies().create(mavenCoord); files.addAll(setupTask.getProject().getConfigurations() .detachedConfiguration(dep) .setDescription(mavenCoord) .setTransitive(false) .resolve()); } else { throw Unhandled.classException(o); } } return FileSignature.signAsList(files); }
public static Unhandled floatException(float f) { return new Unhandled("Unhandled float '" + f + "'"); }
/** Return DND.DROP_COPY or DND.DROP_MOVE, as appropriate. */ public int flag() { // @formatter:off switch (this) { case COPY: return DND.DROP_COPY; case MOVE: return DND.DROP_MOVE; default: throw Unhandled.enumException(this); } // @formatter:on }
/** Returns a Comparison from the given result of a call to {@link Comparable#compareTo(Object)} or {@link Comparator#compare(Object, Object)}. */ @SuppressFBWarnings(value = "UC_USELESS_CONDITION", justification = "Throwing Unhandled keeps the full-enumeration more explicit.") @CheckReturnValue public static Comparison from(int compareToResult) { if (compareToResult == 0) { return Comparison.EQUAL; } else if (compareToResult < 0) { return Comparison.LESSER; } else if (compareToResult > 0) { return Comparison.GREATER; } else { throw Unhandled.integerException(compareToResult); } } }
public static Unhandled shortException(short s) { return new Unhandled("Unhandled short '" + s + "'"); }
/** Returns the appropriate T based on the Comparison value. */ public <T> T lesserEqualGreater(T lesser, T equal, T greater) { switch (this) { case LESSER: return lesser; case EQUAL: return equal; case GREATER: return greater; default: throw Unhandled.enumException(this); } }
@Override public void dragFinished(DragSourceEvent event) { Transfer selectedTransfer = findTransfer(event); data.forEach((transfer, value) -> { DropResult result; if (selectedTransfer == transfer) { // @formatter:off switch (event.detail) { case DND.DROP_MOVE: result = DropResult.MOVED; break; case DND.DROP_COPY: result = DropResult.COPIED; break; default: throw Unhandled.integerException(event.detail); } // @formatter:on } else { result = DropResult.NO_DROP; } handlers.get(transfer).handler.dropped(event, value, result); }); data.clear(); dragInProgress.set(false); } }
public static Unhandled stringException(String str) { return new Unhandled("Unhandled string '" + str + "'"); }
/** Returns the appropriate T based on the Comparison value. */ public <T> T lesserEqualGreater(T lesser, T equal, T greater) { switch (this) { case LESSER: return lesser; case EQUAL: return equal; case GREATER: return greater; default: throw Unhandled.enumException(this); } }
void writeBrandingPlugin(File ideDir) throws IOException { // load iconImg and splashImg BufferedImage iconImg, splashImg; int numSet = Booleans.countTrue(icon != null, splash != null); if (numSet == 0) { // nothing is set, use Goomph iconImg = BrandingProductPlugin.getGoomphIcon(); splashImg = BrandingProductPlugin.getGoomphSplash(); } else if (numSet == 1) { // anything is set, use it for everything iconImg = loadImg(Optional.ofNullable(icon).orElse(splash)); splashImg = iconImg; } else if (numSet == 2) { // both are set, use them each iconImg = loadImg(icon); splashImg = loadImg(splash); } else { throw Unhandled.integerException(numSet); } File branding = new File(ideDir, FileMisc.macContentsEclipse() + "dropins/com.diffplug.goomph.branding"); BrandingProductPlugin.create(branding, splashImg, iconImg, name, perspective, description); File bundlesInfo = new File(ideDir, FileMisc.macContentsEclipse() + "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info"); FileMisc.modifyFile(bundlesInfo, content -> { return content + "com.diffplug.goomph.branding,1.0.0,dropins/com.diffplug.goomph.branding/,4,true" + System.lineSeparator(); }); }
public static Unhandled charException(char c) { return new Unhandled("Unhandled char '" + c + "'"); }
/** Returns the appropriate T based on the Comparison value. */ @CheckReturnValue @Nullable public <T> T lesserEqualGreater(@Nullable T lesser, @Nullable T equal, @Nullable T greater) { switch (this) { case LESSER: return lesser; case EQUAL: return equal; case GREATER: return greater; default: throw Unhandled.enumException(this); } }