/*
* [OSes.java]
*
* Summary: Macro to Generate a reference to a group of OSes.
*
* Copyright: (c) 2006-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 1.1 2006-03-16 add xxx:yyyy, IntelliJ Lint.
*/
package com.mindprod.htmlmacros.macro;
import com.mindprod.fastcat.FastCat;
import com.mindprod.htmlmacros.support.OS;
import java.util.EnumSet;
import static com.mindprod.htmlmacros.support.OS.*;
import static java.lang.System.*;
/**
* Macro to Generate a reference to a group of OSes.
*
*
* @author Roedy Green, Canadian Mind Products
* @version 1.1 2006-03-16
* @noinspection WeakerAccess
* @since 2006
*/
public final class OSes extends Macro
{
//I macro use enum names, not short or long names
/**
* how to use the macro
*/
private static final String USAGE = "\nOSes macro needs list of OSes e.g. W95:XP DOS: W31 OS2 W95 W98 ME NT W2K " +
"XP W3K3 VISTA W7 W732 W764 W8 W832 W864 W10 W1032 W1064 JAVA LINUX OS9 OSX";
/**
* guts of OSes macro
*
* @param parms for macro
*
* @return expands to formatted list of OSes.
*/
static String expand( String... parms )
{
String trouble = "unknown";
try
{
// start with no selections and add choices.
EnumSet pick = EnumSet.noneOf( OS.class );
for ( String choice : parms )
{
trouble = choice;
if ( choice.equalsIgnoreCase( "JAVA" ) )
{
// all but early WIN and CLASSICMAC
pick = EnumSet.complementOf( EnumSet.of(
/* exclude */
OS.DOS,
OS.W31,
OS.W95,
OS.W98,
OS.ME,
OS.OS2,
OS.NT,
OS.OS9 ) );
}
else if ( choice.equalsIgnoreCase( "JET" ) )
{
pick = EnumSet.of(
OS.VISTA,
OS.W2K8,
W2012,
W732,
W764,
W832,
W2012,
W1032,
W1064,
LINUX,
LINUXX86,
LINUXX64,
UBUNTU );
}
else if ( choice.equalsIgnoreCase( "WINDOWS" ) )
{
pick = EnumSet.range( OS.W95, OS.W1064 );
}
else if ( choice.equalsIgnoreCase( "W7" ) )
{
pick = EnumSet.range( OS.W732, OS.W764 );
}
else if ( choice.equalsIgnoreCase( "W8" ) )
{
pick = EnumSet.range( OS.W832, OS.W864 );
}
else if ( choice.equalsIgnoreCase( "W10" ) )
{
pick = EnumSet.range( OS.W1032, OS.W1064 );
}
else if ( choice.equalsIgnoreCase( "FAT" ) )
{
pick.addAll( EnumSet.range( OS.W95, OS.ME ) );
}
else if ( choice.equalsIgnoreCase( "8.3" ) )
{
pick.addAll( EnumSet.range( OS.DOS, OS.W31 ) );
}
else if ( choice.endsWith( ":" ) )
{
final OS starting = OS.valueOf( choice.substring( 0, choice.length() - 1 ).toUpperCase() );
final OS ending;
if ( EnumSet.range( OS.OS9, OS.OSX ).contains( starting ) )
{
ending = OS.OSX;
}
else if ( EnumSet.range( OS.LINUX, OS.UBUNTU ).contains( starting ) )
{
ending = OS.UBUNTU;
}
else
{
ending = OS.W1064;
}
pick.addAll( EnumSet.range( starting, ending ) );
}
else if ( choice.startsWith( ":" ) )
{
throw new IllegalArgumentException( choice + " option discontinued" );
}
else
{
// have a range. Do not allow W7, W8, W10 in ranges.
int place = choice.indexOf( ':' );
if ( 0 < place && place < choice.length() - 1 )
{
trouble = choice.substring( 0, place ).toUpperCase();
OS starting = OS.valueOf( trouble );
trouble = choice.substring( place + 1 ).toUpperCase();
OS ending = OS.valueOf( trouble );
pick.addAll( EnumSet.range( starting, ending ) );
}
else
{
// single OS by itself
pick.add( OS.valueOf( choice.toUpperCase() ) );
}
} // end else
} // end for
return "" + OS.andList( pick ) + "";
}
catch ( Exception e )
{
final FastCat sb = new FastCat( 5 + parms.length * 2 );
sb.append( "Unrecognised OSes parm [" );
sb.append( trouble );
sb.append( "]\n" );
sb.append( USAGE );
sb.append( "\nparms supplied:" );
for ( String parm : parms )
{
sb.append( " " );
sb.append( parm );
}
throw new IllegalArgumentException( sb.toString() );
}
}
/**
* test driver
*
* @param args not used
*/
public static void main( String[] args )
{
out.println( expand( "JAVA" ) );
// prints W2K XP W2K3 Vista W7-32 W7-64 Linux OSX
// selected OSes in chronological order.
}
/**
* Expands:
*
* <-- macro OSes W95: --> W95 and above
*
* <-- macro OSes :Me --> up to and including Me
*
* <-- macro OSes W2K XP -->
*
* <-- macro OSes W95:W764 --> <-- use enum name not short or long name
*
* * <-- macro OSes JAVA --> <-- all OSes supporting Java
* allow enums for individual os, xxx:yyyy for windows and presets WINDOWS JAVA FAT NTFS case
* insensitive. W95 W98 ME NT W2K XP W2K3 VISTA W7 W732 W764 LINUX OS9 OSX
*
* @param parms list of OSes to use.
* @param quiet true if want output suppressed.
* @param verbose @return expanded macro HTML
*/
public final String expandMacro( String[] parms,
final boolean quiet, final boolean verbose )
{
if ( !quiet )
{
out.print( "O" );
}
return expand( parms );
}
}